From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by sourceware.org (Postfix) with ESMTPS id BB9F33857009 for ; Tue, 18 Jul 2023 11:57:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BB9F33857009 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689681434; x=1721217434; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=0ILEnYRxki+VuRXQOGRiuVP1d2HYDMhlhTk2xioArYY=; b=NbxNptHepM7g4PltLMkF4QqluCjS56uYMwEqWdO2TUXfVN2jx4GNIzIg Q3ta6B8I8NHA3/SxKNx9RsPv1gIS/poW9l32NLHdvXC47ndamUTHX2KrD ViMqGB+zrbnu8mgH+kPRz2vFXAOoyYhSZDNkxjPVabxhRM7avxH6r6Jke +9nQApaKYXMmWjBQd/n2FpeGl33pQSAuSqR53NVp1UK3SExczw4yPDVjl hcDXXg6xi8Hc/BH0rZ3BCUfZ9eCSqucisIxYepEYoDXKgwNw9Kj27iWnz qoFle5Ka1tzhUGGBvigByHESUjLj/4rhbkuTyKIRJvR27ObZW+a54gCYX w==; X-IronPort-AV: E=McAfee;i="6600,9927,10774"; a="397024546" X-IronPort-AV: E=Sophos;i="6.01,214,1684825200"; d="scan'208";a="397024546" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2023 04:57:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10774"; a="1054259947" X-IronPort-AV: E=Sophos;i="6.01,214,1684825200"; d="scan'208";a="1054259947" Received: from unknown (HELO localhost) ([10.216.210.22]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2023 04:57:11 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org, markus.t.metzger@intel.com, simark@simark.ca Subject: [PATCH v10 08/10] btrace, linux: Enable ptwrite packets. Date: Tue, 18 Jul 2023 13:56:35 +0200 Message-Id: <20230718115637.3531-9-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230718115637.3531-1-felix.willgerodt@intel.com> References: <20230718115637.3531-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=-10.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Enable ptwrite in the PT config, if it is supported by the kernel. --- gdb/nat/linux-btrace.c | 58 ++++++++++++++++++++++++++++++++++++++++++ gdb/record-btrace.c | 5 ++++ 2 files changed, 63 insertions(+) diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c index c5b3f1c93cf..689f4c46dd4 100644 --- a/gdb/nat/linux-btrace.c +++ b/gdb/nat/linux-btrace.c @@ -417,6 +417,57 @@ cpu_supports_bts (void) } } +/* Read config bits. */ + +static bool +linux_read_pt_config_bit (const std::string &feature, uint64_t *config_bit) +{ + std::string filename + = "/sys/bus/event_source/devices/intel_pt/format/" + feature; + gdb_file_up file = gdb_fopen_cloexec (filename.c_str (), "r"); + + if (file.get () == nullptr || config_bit == nullptr) + return false; + + int found = fscanf (file.get (), "config:%lu", config_bit); + + if (found != 1) + { + warning (_("Failed to determine config bit from %s."), + filename.c_str ()); + return false; + } + + return true; +} + + +/* Check whether the linux target supports Intel Processor Trace PTWRITE. */ + +static bool +linux_supports_ptwrite (uint64_t *config_bit) +{ + 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; + } + + if (!linux_read_pt_config_bit ("ptw", config_bit)) + return false; + + return status == 1; +} + /* The perf_event_open syscall failed. Try to print a helpful error message. */ @@ -626,6 +677,13 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) pt->attr.exclude_hv = 1; pt->attr.exclude_idle = 1; + uint64_t config_bit; + if (conf->ptwrite && linux_supports_ptwrite (&config_bit)) + { + pt->attr.config |= 1 << config_bit; + 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 c93b3d7c8de..ad3160d42c5 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -3295,4 +3295,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.34.1 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