From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by sourceware.org (Postfix) with ESMTPS id 6E5FD3947427 for ; Mon, 14 Jun 2021 14:57:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E5FD3947427 IronPort-SDR: eR8aD2L21CSqNaUgACSg1+doywWD/wTRGIrmeJiejvi6I2R0hnleXtlfEpE2+Kx/nl41kYsXDL kLj4owSnsH2w== X-IronPort-AV: E=McAfee;i="6200,9189,10015"; a="269673057" X-IronPort-AV: E=Sophos;i="5.83,273,1616482800"; d="scan'208";a="269673057" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2021 07:57:41 -0700 IronPort-SDR: RMWnmD2nc0loHEtnbLtHBTXlSARHYRBStuL18SJH0a1r5FIUr/kqBF6VPZUh3dQq+kEg7oNdkv gVQqtM29pDqg== X-IronPort-AV: E=Sophos;i="5.83,273,1616482800"; d="scan'208";a="484111371" Received: from mulvlfelix.iul.intel.com (HELO localhost) ([172.28.48.31]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2021 07:57:40 -0700 From: Felix Willgerodt To: markus.t.metzger@intel.com, gdb-patches@sourceware.org Subject: [PATCH v2 08/12] btrace, linux: Enable ptwrite packets. Date: Mon, 14 Jun 2021 16:54:07 +0200 Message-Id: <20210614145411.689277-4-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210614145411.689277-1-felix.willgerodt@intel.com> References: <20210614145411.689277-1-felix.willgerodt@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jun 2021 14:57:45 -0000 Enable ptwrite in the PT config, if it is supported by the kernel. gdb/ChangeLog: 2021-06-14 Felix Willgerodt * nat/linux-btrace.c (linux_supports_ptw): New function. (linux_enable_pt): Set attr.config if ptwrite is supported. * record-btrace.c (_initialize_record_btrace): Initialize ptwrite in record_btrace_conf.pt. --- gdb/nat/linux-btrace.c | 29 +++++++++++++++++++++++++++++ gdb/record-btrace.c | 5 +++++ 2 files changed, 34 insertions(+) diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c index 324f7ef0407..5a48f397908 100644 --- a/gdb/nat/linux-btrace.c +++ b/gdb/nat/linux-btrace.c @@ -415,6 +415,29 @@ cpu_supports_bts (void) } } +/* 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; +} + /* The perf_event_open syscall failed. Try to print a helpful error message. */ @@ -607,6 +630,12 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) pt->attr.exclude_hv = 1; pt->attr.exclude_idle = 1; + if (conf->ptwrite && linux_supports_ptwrite ()) + { + pt->attr.config |= 0x1000; + tinfo->conf.pt.ptwrite = conf->ptwrite; + } + errno = 0; scoped_fd fd (syscall (SYS_perf_event_open, &pt->attr, pid, -1, -1, 0)); if (fd.get () < 0) diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 3d0c344e8e6..99d962455ea 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -3312,4 +3312,9 @@ to see the actual buffer size."), NULL, show_record_pt_buffer_size_value, record_btrace_conf.bts.size = 64 * 1024; record_btrace_conf.pt.size = 16 * 1024; +#if (LIBIPT_VERSION >= 0x200) + record_btrace_conf.pt.ptwrite = true; +#else + record_btrace_conf.pt.ptwrite = false; +#endif } -- 2.25.4 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928