@symbol can't be used to dump the per-cpu variables. The same is
true for +offset(something) if "something" results in __percpu
pointer.

With this patch parse_probe_offset() treats "~" before the numeric
offset as "per cpu" mark and stores it in the lowest bit,
calc_probe_offset() simply adds per_cpu_offset(smp_processor_id())
if this bit is set.

We could turn {dprm,sc}->offset into the "struct probe_offset" which
holds offset + is_percpu, but this hack looks simple enough and I hope
that LONG_MAX/2 is enough for the numeric offset.

Test-case: 2088 == offsetof(struct rq, curr)

  # perf probe 'do_exit curr=%%current rq_curr=@runqueues+~2088:u64'
  # perf record -e probe:do_exit true
  # perf --no-pager script | tail -1
        true   537 [000]   521.282640: probe:do_exit: (ffffffff8103dd60) \
        curr=ffff88001da8c900 rq_curr=ffff88001da8c900

Signed-off-by: Oleg Nesterov <o...@redhat.com>
---
 kernel/trace/trace_probe.c |   35 ++++++++++++++++++++++++++++++++---
 1 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 723e6e9..bcf6827 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -593,15 +593,44 @@ static int pseudo_reg_query_offset(const char *name)
 
 static long calc_probe_offset(unsigned long offset)
 {
-       return offset;
+       long off = offset >> 1;
+
+       if (offset & 1)
+               off += per_cpu_offset(raw_smp_processor_id());
+
+       return off;
 }
 
 static int parse_probe_offset(const char *name, unsigned long *offset)
 {
-       if (name[0] == '+')     /* kstrtol() rejects '+' */
+       bool negative = false;
+       long percpu_bit = 0;
+       long off = 0;
+
+       switch (name[0]) {
+       case '-':
+               negative = true;
+       case '+':
                name++;
+       }
 
-       return kstrtol(name, 0, offset);
+       if (name[0] == '~') {
+               percpu_bit = 1;
+               name++;
+       }
+
+       if (name[0]) {
+               int err = kstrtoul(name, 0, &off);
+
+               if (err || off >= LONG_MAX/2)
+                       return -EINVAL;
+
+               if (negative)
+                       off = -off;
+       }
+
+       *offset = (off << 1) | percpu_bit;
+       return 0;
 }
 
 /* Recursive argument parser */
-- 
1.5.5.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to