From patchwork Wed May 29 08:47:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Willgerodt, Felix" X-Patchwork-Id: 32888 Received: (qmail 11323 invoked by alias); 29 May 2019 08:48:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 10973 invoked by uid 89); 29 May 2019 08:48:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=caps, H*r:LOCAL X-HELO: mga18.intel.com Received: from mga18.intel.com (HELO mga18.intel.com) (134.134.136.126) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 May 2019 08:48:21 +0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 May 2019 01:48:13 -0700 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 29 May 2019 01:48:12 -0700 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id x4T8mBt7007667; Wed, 29 May 2019 09:48:12 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id x4T8mBrR030812; Wed, 29 May 2019 10:48:11 +0200 Received: (from fwillger@localhost) by ulvlx001.iul.intel.com with LOCAL id x4T8mBWd030808; Wed, 29 May 2019 10:48:11 +0200 From: felix.willgerodt@intel.com To: gdb-patches@sourceware.org Cc: markus.t.metzger@intel.com, Felix Willgerodt Subject: [PATCH 07/10] btrace, linux: Enable ptwrite packets. Date: Wed, 29 May 2019 10:47:50 +0200 Message-Id: <1559119673-30516-8-git-send-email-felix.willgerodt@intel.com> In-Reply-To: <1559119673-30516-1-git-send-email-felix.willgerodt@intel.com> References: <1559119673-30516-1-git-send-email-felix.willgerodt@intel.com> X-IsSubscribed: yes From: Felix Willgerodt Enable ptwrite in the PT config if the kernel supports it. 2019-05-29 Felix Willgerodt gdb/ChangeLog: * nat/linux-btrace.c (linux_supports_ptw): New function. (linux_enable_pt): Set attr.config if ptwrite is supported. --- gdb/nat/linux-btrace.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c index ef291ec2310..6eb5334e0ae 100644 --- a/gdb/nat/linux-btrace.c +++ b/gdb/nat/linux-btrace.c @@ -32,6 +32,10 @@ #include +#if defined (HAVE_LIBIPT) +#include +#endif + #if HAVE_LINUX_PERF_EVENT_H && defined(SYS_perf_event_open) #include #include @@ -409,6 +413,31 @@ cpu_supports_bts (void) } } +#if defined (PERF_ATTR_SIZE_VER5) +/* Check whether the linux target supports Intel Processor Trace PTWRITE. */ + +static bool +linux_supports_ptwrite () +{ + static const char filename[] + = "/sys/bus/event_source/devices/intel_pt/caps/ptwrite"; + gdb_file_up file = gdb_fopen_cloexec (filename, "r"); + + if (file.get () == nullptr) + return false; + + int status, found = fscanf (file.get (), "%d", &status); + + if (found != 1) + { + warning (_("Failed to determine ptwrite support from %s."), filename); + return false; + } + + return status == 1; +} +#endif /* defined (PERF_ATTR_SIZE_VER5) */ + /* The perf_event_open syscall failed. Try to print a helpful error message. */ @@ -601,6 +630,9 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) pt->attr.exclude_hv = 1; pt->attr.exclude_idle = 1; + if (linux_supports_ptwrite ()) + pt->attr.config |= 0x1000; + errno = 0; scoped_fd fd (syscall (SYS_perf_event_open, &pt->attr, pid, -1, -1, 0)); if (fd.get () < 0)