From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by sourceware.org (Postfix) with ESMTPS id 58D873858D3C for ; Tue, 21 Mar 2023 15:47:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58D873858D3C 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=1679413648; x=1710949648; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pYcR0TVRuIfIzaJkXmbc9nF9den2cMRUGG5Z7Y05dNM=; b=OTOh0tIyBhql4cwlI/byiE7ikEWYNHlMOXwbiPhhEHQumsvp2UkpjZ3d BN+JIBa72MjOtcW9qPx11++BBoAcvmkGM3Hc9s9BIMgcVySop1iwrDc7d DQtEh2nfl34AkxjwFV2ep2DevTlgErTQyeC0RDM+YsHJX6xGiduJPm4gT vORaY0d0NXsgEb4XlELs0dKEkHbG3Q+95fuljzemd/Tkgp4xq90BUX9cR K/RUFQ7cJqeej8edivUrgq5qYyNQo6hxJk7OrsZEmz1hCCnbWZe0VfBnx ZMyGN5JoR1X/bedItgfXncTTJx/GnLi4EVnvZ1KRHQLpIdnoZbQaX2vjP w==; X-IronPort-AV: E=McAfee;i="6600,9927,10656"; a="340517838" X-IronPort-AV: E=Sophos;i="5.98,279,1673942400"; d="scan'208";a="340517838" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2023 08:47:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10656"; a="681530395" X-IronPort-AV: E=Sophos;i="5.98,279,1673942400"; d="scan'208";a="681530395" Received: from mulfelix.iul.intel.com (HELO localhost) ([172.28.49.163]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2023 08:47:27 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org Cc: Felix Willgerodt Subject: [PATCH v8 08/10] btrace, linux: Enable ptwrite packets. Date: Tue, 21 Mar 2023 16:46:24 +0100 Message-Id: <20230321154626.448816-9-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230321154626.448816-1-felix.willgerodt@intel.com> References: <20230321154626.448816-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.3 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 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 | 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 c5b3f1c93cf..e320eaa12ce 100644 --- a/gdb/nat/linux-btrace.c +++ b/gdb/nat/linux-btrace.c @@ -417,6 +417,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. */ @@ -626,6 +649,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 22687e889ec..0b36ce5fdf6 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -3291,4 +3291,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.39.2 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