From: Felix Willgerodt <felix.willgerodt@intel.com>
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 [thread overview]
Message-ID: <20230718115637.3531-9-felix.willgerodt@intel.com> (raw)
In-Reply-To: <20230718115637.3531-1-felix.willgerodt@intel.com>
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 <http://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
next prev parent reply other threads:[~2023-07-18 11:57 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-18 11:56 [PATCH v10 00/10] Extensions for PTWRITE Felix Willgerodt
2023-07-18 11:56 ` [PATCH v10 01/10] btrace: Introduce auxiliary instructions Felix Willgerodt
2023-07-18 11:56 ` [PATCH v10 02/10] btrace: Enable auxiliary instructions in record instruction-history Felix Willgerodt
2023-07-18 11:56 ` [PATCH v10 03/10] btrace: Enable auxiliary instructions in record function-call-history Felix Willgerodt
2023-07-18 11:56 ` [PATCH v10 04/10] btrace: Handle stepping and goto for auxiliary instructions Felix Willgerodt
2023-07-18 11:56 ` [PATCH v10 05/10] python: Introduce gdb.RecordAuxiliary class Felix Willgerodt
2023-07-25 13:30 ` Metzger, Markus T
2023-08-07 9:08 ` Willgerodt, Felix
2023-08-08 9:37 ` Metzger, Markus T
2023-08-09 9:32 ` Willgerodt, Felix
2023-08-09 10:00 ` Metzger, Markus T
2023-08-30 8:39 ` Willgerodt, Felix
2023-07-18 11:56 ` [PATCH v10 06/10] python: Add clear() to gdb.Record Felix Willgerodt
2023-07-18 13:00 ` Eli Zaretskii
2023-07-18 11:56 ` [PATCH v10 07/10] btrace, gdbserver: Add ptwrite to btrace_config_pt Felix Willgerodt
2023-07-18 11:56 ` Felix Willgerodt [this message]
2023-07-25 13:30 ` [PATCH v10 08/10] btrace, linux: Enable ptwrite packets Metzger, Markus T
2023-08-07 9:10 ` Willgerodt, Felix
2023-08-08 10:13 ` Metzger, Markus T
2023-08-09 9:31 ` Willgerodt, Felix
2023-08-09 9:48 ` Metzger, Markus T
2023-08-30 8:42 ` Willgerodt, Felix
2023-09-06 14:07 ` Metzger, Markus T
2023-07-18 11:56 ` [PATCH v10 09/10] btrace, python: Enable ptwrite filter registration Felix Willgerodt
2023-07-18 11:56 ` [PATCH v10 10/10] btrace: Extend ptwrite event decoding Felix Willgerodt
2023-07-18 13:01 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230718115637.3531-9-felix.willgerodt@intel.com \
--to=felix.willgerodt@intel.com \
--cc=gdb-patches@sourceware.org \
--cc=markus.t.metzger@intel.com \
--cc=simark@simark.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).