From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by sourceware.org (Postfix) with ESMTPS id 752B6396E079 for ; Fri, 16 Sep 2022 11:38:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 752B6396E079 X-IronPort-AV: E=McAfee;i="6500,9779,10471"; a="279355075" X-IronPort-AV: E=Sophos;i="5.93,320,1654585200"; d="scan'208";a="279355075" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Sep 2022 04:38:41 -0700 X-IronPort-AV: E=Sophos;i="5.93,320,1654585200"; d="scan'208";a="617640044" Received: from mulvlfelix.iul.intel.com (HELO localhost) ([172.28.48.92]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Sep 2022 04:38:39 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org, markus.t.metzger@intel.com Subject: [PATCH v6 08/10] btrace, linux: Enable ptwrite packets. Date: Fri, 16 Sep 2022 13:36:44 +0200 Message-Id: <20220916113646.49749-9-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20220916113646.49749-1-felix.willgerodt@intel.com> References: <20220916113646.49749-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, 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 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: Fri, 16 Sep 2022 11:38:44 -0000 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 c31fb5ffe43..166994e85e2 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. */ @@ -624,6 +647,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 4e1ab60691f..a6ddf8237e1 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -3288,4 +3288,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.3 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