[DTrace-devel] [PATCH 3/5] Add -xcpu support to profile provider
eugene.loh at oracle.com
eugene.loh at oracle.com
Tue Sep 5 04:11:40 UTC 2023
From: Eugene Loh <eugene.loh at oracle.com>
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
libdtrace/dt_prov_profile.c | 13 ++++++++++---
test/unittest/options/tst.cpu-profile.sh | 20 ++++++++++++++++++++
test/unittest/options/tst.cpu-tick.sh | 20 ++++++++++++++++++++
3 files changed, 50 insertions(+), 3 deletions(-)
create mode 100755 test/unittest/options/tst.cpu-profile.sh
create mode 100755 test/unittest/options/tst.cpu-tick.sh
diff --git a/libdtrace/dt_prov_profile.c b/libdtrace/dt_prov_profile.c
index 476dea7c..f3f3bf23 100644
--- a/libdtrace/dt_prov_profile.c
+++ b/libdtrace/dt_prov_profile.c
@@ -33,7 +33,9 @@ static const dtrace_pattr_t pattr = {
{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
};
-#define FDS_CNT(kind) ((kind) == KIND_TICK ? 1 : dtp->dt_conf.num_online_cpus)
+#define FDS_CNT(kind) ((kind) == KIND_TICK || \
+ dtp->dt_options[DTRACEOPT_CPU] != DTRACEOPT_UNSET ? \
+ 1 : dtp->dt_conf.num_online_cpus)
typedef struct profile_probe {
int kind;
uint64_t period;
@@ -274,8 +276,13 @@ static int attach(dtrace_hdl_t *dtp, const dt_probe_t *prp, int bpf_fd)
for (i = 0; i < cnt; i++) {
int j = i, fd;
- /* if there is only one fd, place it at random */
- if (cnt == 1)
+ /*
+ * If -xcpu is set, use that CPU.
+ * If there is only one fd, place it at random.
+ */
+ if (dtp->dt_options[DTRACEOPT_CPU] != DTRACEOPT_UNSET)
+ j = dtp->dt_options[DTRACEOPT_CPU];
+ else if (cnt == 1)
j = rand() % dtp->dt_conf.num_online_cpus;
fd = perf_event_open(&attr, -1, dtp->dt_conf.cpus[j].cpu_id,
diff --git a/test/unittest/options/tst.cpu-profile.sh b/test/unittest/options/tst.cpu-profile.sh
new file mode 100755
index 00000000..3730ced9
--- /dev/null
+++ b/test/unittest/options/tst.cpu-profile.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+#
+
+dtrace=$1
+
+nerr=0
+for cpu0 in `awk '/^processor[ ]*: [0-9]*$/ {print $3}' /proc/cpuinfo`; do
+ cpu=`$dtrace $dt_flags -xcpu=$cpu0 -qn 'profile-100ms { trace(cpu); exit(0); }'`
+ echo expected cpu $cpu0 got cpu $cpu
+ if [ $cpu != $cpu0 ]; then
+ nerr=$(($nerr + 1))
+ fi
+done
+
+exit $nerr
diff --git a/test/unittest/options/tst.cpu-tick.sh b/test/unittest/options/tst.cpu-tick.sh
new file mode 100755
index 00000000..c0dbb517
--- /dev/null
+++ b/test/unittest/options/tst.cpu-tick.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+#
+
+dtrace=$1
+
+nerr=0
+for cpu0 in `awk '/^processor[ ]*: [0-9]*$/ {print $3}' /proc/cpuinfo`; do
+ cpu=`$dtrace $dt_flags -xcpu=$cpu0 -qn 'tick-100ms { trace(cpu); exit(0); }'`
+ echo expected cpu $cpu0 got cpu $cpu
+ if [ $cpu != $cpu0 ]; then
+ nerr=$(($nerr + 1))
+ fi
+done
+
+exit $nerr
--
2.18.4
More information about the DTrace-devel
mailing list