From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10561 invoked by alias); 5 Mar 2013 20:06:34 -0000 Received: (qmail 10522 invoked by uid 22791); 5 Mar 2013 20:06:33 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_XZ X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 05 Mar 2013 20:06:27 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r25K6Prj026850 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 5 Mar 2013 15:06:25 -0500 Received: from host2.jankratochvil.net (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r25K6KtY031690 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 5 Mar 2013 15:06:22 -0500 Date: Tue, 05 Mar 2013 20:06:00 -0000 From: Jan Kratochvil To: Markus Metzger Cc: gdb-patches@sourceware.org, markus.t.metzger@gmail.com Subject: Re: [patch v9 02/23] linux, btrace: perf_event based branch tracing Message-ID: <20130305200619.GB2386@host2.jankratochvil.net> References: <1362416770-19750-1-git-send-email-markus.t.metzger@intel.com> <1362416770-19750-3-git-send-email-markus.t.metzger@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1362416770-19750-3-git-send-email-markus.t.metzger@intel.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2013-03/txt/msg00165.txt.bz2 On Mon, 04 Mar 2013 18:05:49 +0100, Markus Metzger wrote: > Implement branch tracing on Linux based on perf_event such taht it can be shared > between gdb and gdbserver. > > The actual btrace target ops will be implemented on top. > > 2013-03-04 Markus Metzger > > * common/linux_btrace.h: New file. > * common/linux_btrace.c: New file. > * Makefile.in (SFILES): Add btrace.c. > (HFILES_NO_SRCDIR): Add common/linux-btrace.h. > (COMMON_OBS): Add btrace.o. > (linux-btrace.o): New rule. > > gdbserver/ > * Makefile.in (SFILES): Add $(srcdir)/common/linux-btrace.c. > (linux_btrace_h): New variable. > (linux-btrace.o): New rule. [...] > --- /dev/null > +++ b/gdb/common/linux-btrace.c [...] > +/* See linux-btrace.h. */ > + > +struct btrace_target_info * > +linux_enable_btrace (ptid_t ptid) > +{ > + struct btrace_target_info *tinfo; > + int pid; > + > + tinfo = xzalloc (sizeof (*tinfo)); > + tinfo->ptid = ptid; > + > + tinfo->attr.size = sizeof (tinfo->attr); > + tinfo->attr.type = PERF_TYPE_HARDWARE; > + tinfo->attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS; > + tinfo->attr.sample_period = 1; > + > + /* We sample from and to address. */ > + tinfo->attr.sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_ADDR; > + > + tinfo->attr.exclude_kernel = 1; > + tinfo->attr.exclude_hv = 1; > + tinfo->attr.exclude_idle = 1; > + > + tinfo->ptr_bits = 0; > + > + pid = ptid_get_lwp (ptid); > + if (pid == 0) > + pid = ptid_get_pid (ptid); > + > + errno = 0; > + tinfo->file = syscall (SYS_perf_event_open, &tinfo->attr, pid, -1, -1, 0); > + if (tinfo->file < 0) > + goto err; > + > + /* We hard-code the trace buffer size. > + At some later time, we should make this configurable. */ > + tinfo->size = 1; > + tinfo->buffer = mmap (NULL, perf_event_mmap_size (tinfo), > + PROT_READ, MAP_SHARED, tinfo->file, 0); > + if (tinfo->buffer == MAP_FAILED) > + goto err_file; > + > + return tinfo; > + > +err_file: Labels should be indented by one space so they do not clash with function names, like: err_file: > + close (tinfo->file); > + > +err: > + xfree (tinfo); > + return NULL; > +} OK for check-in. Thanks, Jan