From: Oleg Nesterov <oleg@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Namhyung Kim <namhyung.kim@lge.com>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@redhat.com>, Jiri Olsa <jolsa@redhat.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] tracing: Introduce "pseudo registers" for FETCH_MTD_reg
Date: Sat, 23 Nov 2013 21:16:05 +0100 [thread overview]
Message-ID: <20131123201605.GB22148@redhat.com> (raw)
In-Reply-To: <20131123201543.GA22148@redhat.com>
The probe can dump the registers or memory, but it is not possible
to dump, say, current->pid. This patch adds the pseudo regs table,
currently it has only two methods to get current/smp_processor_id
but it can be trivially extended.
This syntax is %%pseudo-reg-name, I agree in advance with any other
naming.
Test-case: 452 == offsetof(task_struct, pid), 39 == __NR_getpid,
# perf probe 'sys_getpid%return ret=$retval:s32 pid=+452(%%current):s32'
# perf record -e probe:sys_getpid perl -e 'syscall 39'
# perf --no-pager script | tail -1
perl 586 [001] 753.102549: probe:sys_getpid: \
(ffffffff81052c00 <- ffffffff8134d012) ret=586 pid=586
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/trace/trace_probe.c | 57 +++++++++++++++++++++++++++++++++++++++++--
1 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 412e959..e167c0a 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -109,13 +109,14 @@ DEFINE_FETCH_##method(u64)
(FETCH_FUNC_NAME(method, string_size) == fn)) \
&& (fn != NULL))
+static unsigned long probe_get_register(struct pt_regs *, unsigned long);
+
/* Data fetch function templates */
#define DEFINE_FETCH_reg(type) \
static __kprobes void FETCH_FUNC_NAME(reg, type)(struct pt_regs *regs, \
void *offset, void *dest) \
{ \
- *(type *)dest = (type)regs_get_register(regs, \
- (unsigned int)((unsigned long)offset)); \
+ *(type *)dest = (type)probe_get_register(regs, (long)offset); \
}
DEFINE_BASIC_FETCH_FUNCS(reg)
/* No string on the register */
@@ -548,6 +549,52 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t,
return ret;
}
+#define PSEUDO_REG_OFFSET 4096 /* arbitrary value > MAX_REG_OFFSET */
+
+static unsigned long pseudo_reg_cpu(void)
+{
+ return (unsigned long)raw_smp_processor_id();
+}
+
+static unsigned long pseudo_reg_current(void)
+{
+ return (unsigned long)current;
+}
+
+static struct {
+ const char *name;
+ unsigned long (*fetch)(void);
+}
+const pseudo_reg_table[] = {
+ {
+ .name = "cpu",
+ .fetch = pseudo_reg_cpu,
+ },
+ {
+ .name = "current",
+ .fetch = pseudo_reg_current,
+ },
+};
+
+static unsigned long probe_get_register(struct pt_regs *regs, unsigned long offset)
+{
+ if (offset < PSEUDO_REG_OFFSET)
+ return regs_get_register(regs, offset);
+
+ return pseudo_reg_table[offset - PSEUDO_REG_OFFSET].fetch();
+}
+
+static int pseudo_reg_query_offset(const char *name)
+{
+ int nr;
+
+ for (nr = 0; nr < ARRAY_SIZE(pseudo_reg_table); ++nr)
+ if (strcmp(pseudo_reg_table[nr].name, name) == 0)
+ return PSEUDO_REG_OFFSET + nr;
+
+ return -EINVAL;
+}
+
/* Recursive argument parser */
static int parse_probe_arg(char *arg, const struct fetch_type *t,
struct fetch_param *f, bool is_return, bool is_kprobe)
@@ -569,7 +616,11 @@ static int parse_probe_arg(char *arg, const struct fetch_type *t,
break;
case '%': /* named register */
- ret = regs_query_register_offset(arg + 1);
+ if (arg[1] == '%')
+ ret = pseudo_reg_query_offset(arg + 2);
+ else
+ ret = regs_query_register_offset(arg + 1);
+
if (ret >= 0) {
f->fn = t->fetch[FETCH_MTD_reg];
f->data = (void *)(unsigned long)ret;
--
1.5.5.1
next prev parent reply other threads:[~2013-11-23 20:15 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-23 20:15 [PATCH 0/1] tracing: Introduce "pseudo registers" for FETCH_MTD_reg Oleg Nesterov
2013-11-23 20:16 ` Oleg Nesterov [this message]
2013-11-24 7:32 ` [PATCH 1/1] " Masami Hiramatsu
2013-11-25 8:04 ` Namhyung Kim
2013-11-25 14:35 ` Oleg Nesterov
2013-11-25 17:21 ` [RFC PATCH 0/3] tracing: Teach FETCH_MTD_{symbol,deref} to handle per-cpu data Oleg Nesterov
2013-11-25 17:21 ` [RFC PATCH 1/3] tracing: Don't mangle sc->addr in update_symbol_cache() Oleg Nesterov
2013-11-25 17:21 ` [RFC PATCH 2/3] tracing: introduce {calc,parse}_probe_offset() for FETCH_MTD_{symbol,deref} Oleg Nesterov
2013-11-25 17:22 ` [RFC PATCH 3/3] tracing: Teach FETCH_MTD_{symbol,deref} to handle per-cpu data Oleg Nesterov
2013-11-26 9:34 ` Masami Hiramatsu
2013-11-26 17:43 ` [RFC PATCH 0/2] tracing: Teach FETCH_MTD_symbol " Oleg Nesterov
2013-11-26 17:44 ` [RFC PATCH 1/2] tracing: Don't update sc->addr in update_symbol_cache() Oleg Nesterov
2013-11-26 17:44 ` [RFC PATCH 2/2] tracing: Teach FETCH_MTD_symbol to handle per-cpu data Oleg Nesterov
2013-11-26 17:50 ` modules, add_kallsyms() && DEFINE_PER_CPU Oleg Nesterov
2013-11-27 2:23 ` Masami Hiramatsu
2013-11-27 8:20 ` Namhyung Kim
2013-11-27 11:22 ` Masami Hiramatsu
2013-11-27 13:35 ` Oleg Nesterov
2013-11-28 2:02 ` Masami Hiramatsu
2013-11-27 11:30 ` [RFC PATCH 2/2] tracing: Teach FETCH_MTD_symbol to handle per-cpu data Masami Hiramatsu
2013-11-27 0:37 ` [RFC PATCH 0/2] " Namhyung Kim
2013-11-27 10:01 ` Masami Hiramatsu
2013-11-27 17:41 ` Oleg Nesterov
2013-11-28 2:55 ` Masami Hiramatsu
2013-11-25 19:29 ` [PATCH 0/2] tracing: Add $cpu and $current probe-vars Oleg Nesterov
2013-11-25 19:29 ` [PATCH 1/2] " Oleg Nesterov
2013-11-26 2:21 ` Masami Hiramatsu
2013-11-26 17:23 ` Oleg Nesterov
2013-11-27 8:22 ` Masami Hiramatsu
2013-11-27 17:05 ` Oleg Nesterov
2013-11-28 2:51 ` Masami Hiramatsu
2013-11-25 19:30 ` [PATCH 2/2] tracing: Kill FETCH_MTD_retval, reimplement $retval via pseudo_reg_retval() Oleg Nesterov
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=20131123201605.GB22148@redhat.com \
--to=oleg@redhat.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@redhat.com \
--cc=namhyung.kim@lge.com \
--cc=rostedt@goodmis.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.