Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751944AbdF3RRz (ORCPT ); Fri, 30 Jun 2017 13:17:55 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:54615 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751189AbdF3RRx (ORCPT ); Fri, 30 Jun 2017 13:17:53 -0400 X-ME-Sender: X-Sasl-enc: izFv18NAE6ds6TcHSxl0MDV2LUI38o+AQXP3/7Jm4Sn8 1498843072 Date: Fri, 30 Jun 2017 11:17:50 -0600 From: Michael Sartain To: linux-kernel@vger.kernel.org Cc: Joel Fernandes , Steven Rostedt , Ingo Molnar Subject: [PATCH] tracing: Add saved_tgids file to show cached pid to tgid mappings Message-ID: <20170630171748.sf5rnjb7pyws6ewu@mikesart-cos> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: NeoMutt/20170306 (1.8.0) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3774 Lines: 141 Export the cached pid / tgid mappings to userspace. This allows user apps to translate the pids from a trace to their respective thread group. Example saved_tgids file with pid / tgid values separated by ' ': # cat saved_tgids 1048 1048 1047 1047 7 7 1049 1047 1054 1047 1053 1047 [ Impact: let userspace apps reading binary buffer know tgid's ] Signed-off-by: Michael Sartain --- kernel/trace/trace.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 68c214b..ca84c97 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -4692,6 +4692,7 @@ static const struct file_operations tracing_readme_fops = { static void *saved_cmdlines_next(struct seq_file *m, void *v, loff_t *pos) { unsigned int *ptr = v; + long tgid_check = (long) m->private; if (*pos || m->count) ptr++; @@ -4702,6 +4703,8 @@ static void *saved_cmdlines_next(struct seq_file *m, void *v, loff_t *pos) ptr++) { if (*ptr == -1 || *ptr == NO_CMDLINE_MAP) continue; + if (tgid_check && !trace_find_tgid(*ptr)) + continue; return ptr; } @@ -4713,6 +4716,10 @@ static void *saved_cmdlines_start(struct seq_file *m, loff_t *pos) { void *v; loff_t l = 0; + long tgid_check = (long) m->private; + + if (tgid_check && !tgid_map) + return NULL; preempt_disable(); arch_spin_lock(&trace_cmdline_lock); @@ -4743,6 +4750,14 @@ static int saved_cmdlines_show(struct seq_file *m, void *v) return 0; } +static int saved_tgids_show(struct seq_file *m, void *v) +{ + unsigned int *pid = v; + + seq_printf(m, "%d %d\n", *pid, trace_find_tgid(*pid)); + return 0; +} + static const struct seq_operations tracing_saved_cmdlines_seq_ops = { .start = saved_cmdlines_start, .next = saved_cmdlines_next, @@ -4750,12 +4765,45 @@ static const struct seq_operations tracing_saved_cmdlines_seq_ops = { .show = saved_cmdlines_show, }; +static const struct seq_operations tracing_saved_tgids_seq_ops = { + .start = saved_cmdlines_start, + .next = saved_cmdlines_next, + .stop = saved_cmdlines_stop, + .show = saved_tgids_show, +}; + static int tracing_saved_cmdlines_open(struct inode *inode, struct file *filp) { + int ret; + + if (tracing_disabled) + return -ENODEV; + + ret = seq_open(filp, &tracing_saved_cmdlines_seq_ops); + if (!ret) { + struct seq_file *m = filp->private_data; + + m->private = (void *) 0; /* Do not check for valid tgids */ + } + + return ret; +} + +static int tracing_saved_tgids_open(struct inode *inode, struct file *filp) +{ + int ret; + if (tracing_disabled) return -ENODEV; - return seq_open(filp, &tracing_saved_cmdlines_seq_ops); + ret = seq_open(filp, &tracing_saved_tgids_seq_ops); + if (!ret) { + struct seq_file *m = filp->private_data; + + m->private = (void *) 1; /* Check for valid tgids */ + } + + return ret; } static const struct file_operations tracing_saved_cmdlines_fops = { @@ -4765,6 +4813,13 @@ static const struct file_operations tracing_saved_cmdlines_fops = { .release = seq_release, }; +static const struct file_operations tracing_saved_tgids_fops = { + .open = tracing_saved_tgids_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + static ssize_t tracing_saved_cmdlines_size_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) @@ -7933,6 +7988,9 @@ static __init int tracer_init_tracefs(void) trace_create_file("saved_cmdlines_size", 0644, d_tracer, NULL, &tracing_saved_cmdlines_size_fops); + trace_create_file("saved_tgids", 0444, d_tracer, + NULL, &tracing_saved_tgids_fops); + trace_eval_init(); trace_create_eval_file(d_tracer); -- 2.11.0