From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2CyjL3Fwx2CkRAAAWB0awg (envelope-from ) for ; Mon, 14 Jun 2021 11:06:25 -0400 Received: by simark.ca (Postfix, from userid 112) id C11B51F163; Mon, 14 Jun 2021 11:06:25 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 04A581E813 for ; Mon, 14 Jun 2021 11:06:25 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB02F394FC2A for ; Mon, 14 Jun 2021 15:06:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB02F394FC2A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623683184; bh=CDnLPDd0aQbJaoJE8tPnXaBo3w32wUnV40hxdruDfAo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=i/WI4zw5yM4ZO10ioQXqsKUlNWlStqek+4Z0MJhY5bbJhg4amyzShyLAYLvpr1tfO Ai79NngivqmVzlE1B+AFApYnKrb2erSNoeYy5nEDCNH/Nu27Fet6++2WotCV/XWSN2 FPqoDtf0QKin6MJ6l18NiE3D6/+4NnZqHl1bmajs= 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 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-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: , From: Felix Willgerodt via Gdb-patches Reply-To: Felix Willgerodt Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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