tracing: More updates for 4.11
Subsystems (7)
Steven Rostedt
maintainercover tracing: More updates for 4.11
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next
Head SHA1: 8f0994bb8cbde5452e58ce0cacdbf6cb58079d01
Arnd Bergmann (1):
tracing: Use modern function declaration
Jason Baron (1):
jump_label: Reduce the size of struct static_key
Luiz Capitulino (1):
tracing/hwlat: Update old comment about migration
Masami Hiramatsu (1):
tracing/probe: Show subsystem name in messages
Steven Rostedt (VMware) (2):
tracing: Have COMM event filter key be treated as a string
tracing: Have traceprobe_probes_write() not access userspace unnecessarily
Thomas Gleixner (1):
timers: Make flags output in the timer_start tracepoint useful
Wei Yongjun (1):
tracing: Fix return value check in trace_benchmark_reg()
----
Documentation/static-keys.txt | 4 +- include/linux/jump_label.h | 23 ++++--- include/linux/timer.h | 2 + include/trace/events/timer.h | 14 +++- kernel/jump_label.c | 153 ++++++++++++++++++++++++++++++++++------- kernel/trace/trace.h | 5 +- kernel/trace/trace_benchmark.c | 4 +- kernel/trace/trace_hwlat.c | 5 +- kernel/trace/trace_kprobe.c | 1 + kernel/trace/trace_probe.c | 49 ++++++++----- kernel/trace/trace_uprobe.c | 1 + 11 files changed, 197 insertions(+), 64 deletions(-)
Steven Rostedt
maintainerPATCH 1/8 tracing: Have COMM event filter key be treated as a string
From: "Steven Rostedt (VMware)" <[email protected]>
The GLOB operation "~" should be able to work with the COMM filter key in order to trace programs with a glob. For example
echo 'COMM ~ "systemd*"' > events/syscalls/filter
--- kernel/trace/trace.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/trace.h +2 -1
@@ -1312,7 +1312,8 @@ static inline bool is_string_field(struct ftrace_event_field *field) {return field->filter_type ==FILTER_DYN_STRING || field->filter_type ==FILTER_STATIC_STRING || - field->filter_type ==FILTER_PTR_STRING ; + field->filter_type ==FILTER_PTR_STRING || + field->filter_type ==FILTER_COMM ; }static inline bool is_function_field (struct ftrace_event_field *field)
Signature · 1 line
2.10.2
Steven Rostedt
maintainerPATCH 2/8 tracing: Have traceprobe_probes_write() not access userspace unnecessarily
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
The code in traceprobe_probes_write() reads up to 4096 bytes from userpace for each line. If userspace passes in several lines to execute, the code will do a large read for each line, even though, it is highly likely that the first read from userspace received all of the lines at once.
I changed the logic to do a single read from userspace, and to only read from userspace again if not all of the read from userspace made it in.
I tested this by adding printk()s and writing files that would test -1, ==, and +1 the buffer size, to make sure that there's no overflows and that if a single line is written with +1 the buffer size, that it fails properly.
--- kernel/trace/trace_probe.c | 48 ++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-)
kernel/trace/trace_probe.c +29 -19
@@ -647,7 +647,7 @@ ssize_t traceprobe_probes_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos, int (*createfn)(int, char **)) { - char *kbuf, *tmp; + char *kbuf, *buf, *tmp;int ret =0 ;size_t done =0 ;size_t size;
@@ -667,27 +667,37 @@ ssize_t traceprobe_probes_write(struct file *file, const char __user *buffer, goto out; } kbuf[size] ='\0' ; - tmp =strchr (kbuf,'\n' ); + buf = kbuf; +do { + tmp =strchr (buf,'\n' ); +if (tmp) { + *tmp ='\0' ; + size = tmp - buf +1 ; + }else { + size =strlen (buf); +if (done + size < count) { +if (buf != kbuf) +break ; +pr_warn ("Line length is too long: Should be less than %d\n" , +WRITE_BUFSIZE ); + ret = -EINVAL ; + goto out; + } + } + done += size; -if (tmp) { - *tmp ='\0' ; - size = tmp - kbuf +1 ; - }else if (done + size < count) { -pr_warn ("Line length is too long: Should be less than %d\n" , -WRITE_BUFSIZE ); - ret = -EINVAL ; - goto out; - } - done += size; -/* Remove comments */ - tmp =strchr (kbuf,'#' ); +/* Remove comments */ + tmp =strchr (buf,'#' ); -if (tmp) - *tmp ='\0' ; +if (tmp) + *tmp ='\0' ; - ret =traceprobe_command (kbuf, createfn); -if (ret) - goto out; + ret =traceprobe_command (buf, createfn); +if (ret) + goto out; + buf += size; + + }while (done < count); } ret = done;
Signature · 1 line
2.10.2
Steven Rostedt
maintainerPATCH 3/8 timers: Make flags output in the timer_start tracepoint useful
In reply to Steven RostedtFrom: Thomas Gleixner <[email protected]>
The timer flags in the timer_start trace event contain lots of useful information, but the meaning is not clear in the trace output. Making tools rely on the bit positions is bad as they might change over time.
Decode the flags in the print out. Tools can retrieve the bits and their meaning from the trace format file.
--- include/linux/timer.h | 2 ++ include/trace/events/timer.h | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
include/linux/timer.h +2 -0
@@ -66,6 +66,8 @@ struct timer_list {#define TIMER_ARRAYSHIFT 22#define TIMER_ARRAYMASK 0xFFC00000 +#define TIMER_TRACE_FLAGMASK (TIMER_MIGRATING | TIMER_DEFERRABLE | TIMER_PINNED | TIMER_IRQSAFE) +#define __TIMER_INITIALIZER (_function, _expires, _data, _flags) { \ .entry = { .next = TIMER_ENTRY_STATIC }, \ .function = (_function), \
include/trace/events/timer.h +12 -2
@@ -36,6 +36,13 @@ DEFINE_EVENT(timer_class, timer_init,TP_ARGS (timer) ); +#define decode_timer_flags (flags) \ + __print_flags(flags, "|", \ + { TIMER_MIGRATING, "M" }, \ + { TIMER_DEFERRABLE, "D" }, \ + { TIMER_PINNED, "P" }, \ + { TIMER_IRQSAFE, "I" }) +/** * timer_start - called when the timer is started * @timer: pointer to struct timer_list
@@ -65,9 +72,12 @@ TRACE_EVENT(timer_start, __entry->flags = flags; ), -TP_printk ("timer=%p function=%pf expires=%lu [timeout=%ld] flags=0x%08x" , +TP_printk ("timer=%p function=%pf expires=%lu [timeout=%ld] cpu=%u idx=%u flags=%s" , __entry->timer, __entry->function, __entry->expires, - (long )__entry->expires - __entry->now, __entry->flags) + (long )__entry->expires - __entry->now, + __entry->flags &TIMER_CPUMASK , + __entry->flags >>TIMER_ARRAYSHIFT , +decode_timer_flags (__entry->flags &TIMER_TRACE_FLAGMASK )) );/**
Signature · 1 line
2.10.2
Steven Rostedt
maintainerPATCH 4/8 tracing/hwlat: Update old comment about migration
In reply to Steven RostedtFrom: Luiz Capitulino <[email protected]>
The ftrace hwlat does support a cpumask.
--- kernel/trace/trace_hwlat.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
kernel/trace/trace_hwlat.c +1 -4
@@ -322,10 +322,7 @@ static void move_to_next_cpu(void)* need to ensure nothing else might be running (and thus preempting). * Obviously this should never be used in production environments. * -* Currently this runs on which ever CPU it was scheduled on, but most -* real-world hardware latency situations occur across several CPUs, -* but we might later generalize this if we find there are any actualy -* systems with alternate SMI delivery or other hardware latencies. +* Executes one loop interaction on each CPU in tracing_cpumask sysfs file. */ static int kthread_fn (void *data) {
Signature · 1 line
2.10.2
Steven Rostedt
maintainerPATCH 5/8 tracing/probe: Show subsystem name in messages
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Show "trace_probe:", "trace_kprobe:" and "trace_uprobe:" headers for each warning/error/info message. This will help people to notice that kprobe/uprobe events caused those messages.
--- kernel/trace/trace_kprobe.c | 1 + kernel/trace/trace_probe.c | 1 + kernel/trace/trace_uprobe.c | 1 + 3 files changed, 3 insertions(+)
kernel/trace/trace_kprobe.c +1 -0
@@ -16,6 +16,7 @@* along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#define pr_fmt (fmt) "trace_kprobe: " fmt#include <linux/module.h> #include <linux/uaccess.h>
kernel/trace/trace_probe.c +1 -0
@@ -21,6 +21,7 @@* Copyright (C) IBM Corporation, 2010-2011 * Author: Srikar Dronamraju */ +#define pr_fmt (fmt) "trace_probe: " fmt#include "trace_probe.h"
kernel/trace/trace_uprobe.c +1 -0
@@ -17,6 +17,7 @@* Copyright (C) IBM Corporation, 2010-2012 * Author: Srikar Dronamraju <[email protected]> */ +#define pr_fmt (fmt) "trace_kprobe: " fmt#include <linux/module.h> #include <linux/uaccess.h>
Signature · 1 line
2.10.2
Steven Rostedt
maintainerPATCH 6/8 jump_label: Reduce the size of struct static_key
In reply to Steven RostedtFrom: Jason Baron <[email protected]>
The static_key->next field goes mostly unused. The field is used for associating module uses with a static key. Most uses of struct static_key define a static key in the core kernel and make use of it entirely within the core kernel, or define the static key in a module and make use of it only from within that module. In fact, of the ~3,000 static keys defined, I found only about 5 or so that did not fit this pattern.
Thus, we can remove the static_key->next field entirely and overload the static_key->entries field. That is, when all the static_key uses are contained within the same module, static_key->entries continues to point to those uses. However, if the static_key uses are not contained within the module where the static_key is defined, then we allocate a struct static_key_mod, store a pointer to the uses within that struct static_key_mod, and have the static key point at the static_key_mod. This does incur some extra memory usage when a static_key is used in a module that does not define it, but since there are only a handful of such cases there is a net savings.
In order to identify if the static_key->entries pointer contains a struct static_key_mod or a struct jump_entry pointer, bit 1 of static_key->entries is set to 1 if it points to a struct static_key_mod and is 0 if it points to a struct jump_entry. We were already using bit 0 in a similar way to store the initial value of the static_key. This does mean that allocations of struct static_key_mod and that the struct jump_entry tables need to be at least 4-byte aligned in memory. As far as I can tell all arches meet this criteria.
For my .config, the patch increased the text by 778 bytes, but reduced the data + bss size by 14912, for a net savings of 14,134 bytes.
text data bss dec hex filename
8092427 5016512 790528 13899467 d416cb vmlinux.pre
8093205 5001600 790528 13885333 d3df95 vmlinux.post
--- Documentation/static-keys.txt | 4 +- include/linux/jump_label.h | 23 ++++--- kernel/jump_label.c | 153 +++++++++++++++++++++++++++++++++++------- 3 files changed, 145 insertions(+), 35 deletions(-)
Documentation/static-keys.txt +3 -1
@@ -155,7 +155,9 @@ or: There are a few functions and macros that architectures must implement in order to take advantage of this optimization. If there is no architecture support, we -simply fall back to a traditional, load, test, and jump sequence. +simply fall back to a traditional, load, test, and jump sequence. Also, the +struct jump_entry table must be at least 4-byte aligned because the +static_key->entry field makes use of the two least significant bits. * select HAVE_ARCH_JUMP_LABEL, see: arch/x86/Kconfig
include/linux/jump_label.h +15 -8
@@ -89,11 +89,17 @@ extern bool static_key_initialized;struct static_key {atomic_t enabled; -/* Set lsb bit to 1 if branch is default true, 0 ot */ -struct jump_entry *entries; -#ifdef CONFIG_MODULES -struct static_key_mod *next; -#endif +/* +* bit 0 => 1 if key is initially true +* 0 if initially false +* bit 1 => 1 if points to struct static_key_mod +* 0 if points to struct jump_entry +*/ +union { +unsigned long type; +struct jump_entry *entries; +struct static_key_mod *next; + }; };#else
@@ -118,9 +124,10 @@ struct module;#ifdef HAVE_JUMP_LABEL -#define JUMP_TYPE_FALSE 0UL -#define JUMP_TYPE_TRUE 1UL -#define JUMP_TYPE_MASK 1UL +#define JUMP_TYPE_FALSE 0UL +#define JUMP_TYPE_TRUE 1UL +#define JUMP_TYPE_LINKED 2UL +#define JUMP_TYPE_MASK 3UL static __always_inline bool static_key_false(struct static_key *key) {
kernel/jump_label.c +127 -26
243 lines not on this page · raw message
Signature · 1 line
2.10.2
Steven Rostedt
maintainerPATCH 7/8 tracing: Use modern function declaration
In reply to Steven RostedtFrom: Arnd Bergmann <[email protected]>
We get a lot of harmless warnings about this header file at W=1 level because of an unusual function declaration:
kernel/trace/trace.h:766:1: error: 'inline' is not at beginning of declaration [-Werror=old-style-declaration]
This moves the inline statement where it normally belongs, avoiding the warning.
--- kernel/trace/trace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace.h +1 -1
@@ -763,7 +763,7 @@ struct ftrace_hash {struct ftrace_func_entry *ftrace_lookup_ip (struct ftrace_hash *hash,unsigned long ip); -static bool __always_inline ftrace_hash_empty(struct ftrace_hash *hash) +static __always_inline bool ftrace_hash_empty(struct ftrace_hash *hash) {return !hash || !hash->count; }
Signature · 1 line
2.10.2
Steven Rostedt
maintainerPATCH 8/8 tracing: Fix return value check in trace_benchmark_reg()
In reply to Steven RostedtFrom: Wei Yongjun <[email protected]>
In case of error, the function kthread_run() returns ERR_PTR() and never returns NULL. The NULL test in the return value check should be replaced with IS_ERR().
--- kernel/trace/trace_benchmark.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_benchmark.c +2 -2
@@ -175,9 +175,9 @@ int trace_benchmark_reg(void) bm_event_thread =kthread_run (benchmark_event_kthread,NULL ,"event_benchmark" ); -if (!bm_event_thread) { +if (IS_ERR (bm_event_thread)) {pr_warning ("trace benchmark failed to create kernel thread\n" ); -return -ENOMEM ; +return PTR_ERR (bm_event_thread); }return 0 ;
Signature · 1 line
2.10.2