Skip to content

Commit

Permalink
Merge tag 'trace-v4.17' of git://git.kernel.org/pub/scm/linux/kernel/…
Browse files Browse the repository at this point in the history
…git/rostedt/linux-trace

Pull tracing updates from Steven Rostedt:
 "New features:

   - Tom Zanussi's extended histogram work.

     This adds the synthetic events to have histograms from multiple
     event data Adds triggers "onmatch" and "onmax" to call the
     synthetic events Several updates to the histogram code from this

   - Allow way to nest ring buffer calls in the same context

   - Allow absolute time stamps in ring buffer

   - Rewrite of filter code parsing based on Al Viro's suggestions

   - Setting of trace_clock to global if TSC is unstable (on boot)

   - Better OOM handling when allocating large ring buffers

   - Added initcall tracepoints (consolidated initcall_debug code with
     them)

  And other various fixes and clean ups"

* tag 'trace-v4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (68 commits)
  init: Have initcall_debug still work without CONFIG_TRACEPOINTS
  init, tracing: Have printk come through the trace events for initcall_debug
  init, tracing: instrument security and console initcall trace events
  init, tracing: Add initcall trace events
  tracing: Add rcu dereference annotation for test func that touches filter->prog
  tracing: Add rcu dereference annotation for filter->prog
  tracing: Fixup logic inversion on setting trace_global_clock defaults
  tracing: Hide global trace clock from lockdep
  ring-buffer: Add set/clear_current_oom_origin() during allocations
  ring-buffer: Check if memory is available before allocation
  lockdep: Add print_irqtrace_events() to __warn
  vsprintf: Do not preprocess non-dereferenced pointers for bprintf (%px and %pK)
  tracing: Uninitialized variable in create_tracing_map_fields()
  tracing: Make sure variable string fields are NULL-terminated
  tracing: Add action comparisons when testing matching hist triggers
  tracing: Don't add flag strings when displaying variable references
  tracing: Fix display of hist trigger expressions containing timestamps
  ftrace: Drop a VLA in module_exists()
  tracing: Mention trace_clock=global when warning about unstable clocks
  tracing: Default to using trace_global_clock if sched_clock is unstable
  ...
  • Loading branch information
torvalds committed Apr 10, 2018
2 parents 9f3a094 + b0dc52f commit 2a56bb5
Show file tree
Hide file tree
Showing 30 changed files with 8,605 additions and 3,501 deletions.
1,548 changes: 1 addition & 1,547 deletions Documentation/trace/events.rst

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions Documentation/trace/ftrace.rst
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,30 @@ of ftrace. Here is a list of some of the key files:

See events.txt for more information.

timestamp_mode:

Certain tracers may change the timestamp mode used when
logging trace events into the event buffer. Events with
different modes can coexist within a buffer but the mode in
effect when an event is logged determines which timestamp mode
is used for that event. The default timestamp mode is
'delta'.

Usual timestamp modes for tracing:

# cat timestamp_mode
[delta] absolute

The timestamp mode with the square brackets around it is the
one in effect.

delta: Default timestamp mode - timestamp is a delta against
a per-buffer timestamp.

absolute: The timestamp is a full timestamp, not a delta
against some other value. As such it takes up more
space and is less efficient.

hwlat_detector:

Directory for the Hardware Latency Detector.
Expand Down
1,995 changes: 1,995 additions & 0 deletions Documentation/trace/histogram.txt

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions include/linux/ring_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ struct ring_buffer_event {
* array[0] = time delta (28 .. 59)
* size = 8 bytes
*
* @RINGBUF_TYPE_TIME_STAMP: Sync time stamp with external clock
* array[0] = tv_nsec
* array[1..2] = tv_sec
* size = 16 bytes
* @RINGBUF_TYPE_TIME_STAMP: Absolute timestamp
* Same format as TIME_EXTEND except that the
* value is an absolute timestamp, not a delta
* event.time_delta contains bottom 27 bits
* array[0] = top (28 .. 59) bits
* size = 8 bytes
*
* <= @RINGBUF_TYPE_DATA_TYPE_LEN_MAX:
* Data record
Expand All @@ -54,12 +56,12 @@ enum ring_buffer_type {
RINGBUF_TYPE_DATA_TYPE_LEN_MAX = 28,
RINGBUF_TYPE_PADDING,
RINGBUF_TYPE_TIME_EXTEND,
/* FIXME: RINGBUF_TYPE_TIME_STAMP not implemented */
RINGBUF_TYPE_TIME_STAMP,
};

unsigned ring_buffer_event_length(struct ring_buffer_event *event);
void *ring_buffer_event_data(struct ring_buffer_event *event);
u64 ring_buffer_event_time_stamp(struct ring_buffer_event *event);

/*
* ring_buffer_discard_commit will remove an event that has not
Expand Down Expand Up @@ -115,6 +117,9 @@ int ring_buffer_unlock_commit(struct ring_buffer *buffer,
int ring_buffer_write(struct ring_buffer *buffer,
unsigned long length, void *data);

void ring_buffer_nest_start(struct ring_buffer *buffer);
void ring_buffer_nest_end(struct ring_buffer *buffer);

struct ring_buffer_event *
ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts,
unsigned long *lost_events);
Expand Down Expand Up @@ -178,6 +183,8 @@ void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer,
int cpu, u64 *ts);
void ring_buffer_set_clock(struct ring_buffer *buffer,
u64 (*clock)(void));
void ring_buffer_set_time_stamp_abs(struct ring_buffer *buffer, bool abs);
bool ring_buffer_time_stamp_abs(struct ring_buffer *buffer);

size_t ring_buffer_page_len(void *page);

Expand Down
14 changes: 8 additions & 6 deletions include/linux/trace_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,13 @@ enum event_trigger_type {

extern int filter_match_preds(struct event_filter *filter, void *rec);

extern enum event_trigger_type event_triggers_call(struct trace_event_file *file,
void *rec);
extern void event_triggers_post_call(struct trace_event_file *file,
enum event_trigger_type tt,
void *rec);
extern enum event_trigger_type
event_triggers_call(struct trace_event_file *file, void *rec,
struct ring_buffer_event *event);
extern void
event_triggers_post_call(struct trace_event_file *file,
enum event_trigger_type tt,
void *rec, struct ring_buffer_event *event);

bool trace_event_ignore_this_pid(struct trace_event_file *trace_file);

Expand All @@ -454,7 +456,7 @@ trace_trigger_soft_disabled(struct trace_event_file *file)

if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) {
if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
event_triggers_call(file, NULL);
event_triggers_call(file, NULL, NULL);
if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
return true;
if (eflags & EVENT_FILE_FL_PID_FILTER)
Expand Down
66 changes: 66 additions & 0 deletions include/trace/events/initcall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM initcall

#if !defined(_TRACE_INITCALL_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_INITCALL_H

#include <linux/tracepoint.h>

TRACE_EVENT(initcall_level,

TP_PROTO(const char *level),

TP_ARGS(level),

TP_STRUCT__entry(
__string(level, level)
),

TP_fast_assign(
__assign_str(level, level);
),

TP_printk("level=%s", __get_str(level))
);

TRACE_EVENT(initcall_start,

TP_PROTO(initcall_t func),

TP_ARGS(func),

TP_STRUCT__entry(
__field(initcall_t, func)
),

TP_fast_assign(
__entry->func = func;
),

TP_printk("func=%pS", __entry->func)
);

TRACE_EVENT(initcall_finish,

TP_PROTO(initcall_t func, int ret),

TP_ARGS(func, ret),

TP_STRUCT__entry(
__field(initcall_t, func)
__field(int, ret)
),

TP_fast_assign(
__entry->func = func;
__entry->ret = ret;
),

TP_printk("func=%pS ret=%d", __entry->func, __entry->ret)
);

#endif /* if !defined(_TRACE_GPIO_H) || defined(TRACE_HEADER_MULTI_READ) */

/* This part must be outside protection */
#include <trace/define_trace.h>
84 changes: 67 additions & 17 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
#include <asm/sections.h>
#include <asm/cacheflush.h>

#define CREATE_TRACE_POINTS
#include <trace/events/initcall.h>

static int kernel_init(void *);

extern void init_IRQ(void);
Expand Down Expand Up @@ -491,6 +494,17 @@ void __init __weak thread_stack_cache_init(void)

void __init __weak mem_encrypt_init(void) { }

bool initcall_debug;
core_param(initcall_debug, initcall_debug, bool, 0644);

#ifdef TRACEPOINTS_ENABLED
static void __init initcall_debug_enable(void);
#else
static inline void initcall_debug_enable(void)
{
}
#endif

/*
* Set up kernel memory allocators
*/
Expand Down Expand Up @@ -612,6 +626,9 @@ asmlinkage __visible void __init start_kernel(void)
/* Trace events are available after this */
trace_init();

if (initcall_debug)
initcall_debug_enable();

context_tracking_init();
/* init some links before init_ISA_irqs() */
early_irq_init();
Expand Down Expand Up @@ -728,9 +745,6 @@ static void __init do_ctors(void)
#endif
}

bool initcall_debug;
core_param(initcall_debug, initcall_debug, bool, 0644);

#ifdef CONFIG_KALLSYMS
struct blacklist_entry {
struct list_head next;
Expand Down Expand Up @@ -800,37 +814,71 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
#endif
__setup("initcall_blacklist=", initcall_blacklist);

static int __init_or_module do_one_initcall_debug(initcall_t fn)
static __init_or_module void
trace_initcall_start_cb(void *data, initcall_t fn)
{
ktime_t calltime, delta, rettime;
unsigned long long duration;
int ret;
ktime_t *calltime = (ktime_t *)data;

printk(KERN_DEBUG "calling %pF @ %i\n", fn, task_pid_nr(current));
calltime = ktime_get();
ret = fn();
*calltime = ktime_get();
}

static __init_or_module void
trace_initcall_finish_cb(void *data, initcall_t fn, int ret)
{
ktime_t *calltime = (ktime_t *)data;
ktime_t delta, rettime;
unsigned long long duration;

rettime = ktime_get();
delta = ktime_sub(rettime, calltime);
delta = ktime_sub(rettime, *calltime);
duration = (unsigned long long) ktime_to_ns(delta) >> 10;
printk(KERN_DEBUG "initcall %pF returned %d after %lld usecs\n",
fn, ret, duration);
}

return ret;
static ktime_t initcall_calltime;

#ifdef TRACEPOINTS_ENABLED
static void __init initcall_debug_enable(void)
{
int ret;

ret = register_trace_initcall_start(trace_initcall_start_cb,
&initcall_calltime);
ret |= register_trace_initcall_finish(trace_initcall_finish_cb,
&initcall_calltime);
WARN(ret, "Failed to register initcall tracepoints\n");
}
# define do_trace_initcall_start trace_initcall_start
# define do_trace_initcall_finish trace_initcall_finish
#else
static inline void do_trace_initcall_start(initcall_t fn)
{
if (!initcall_debug)
return;
trace_initcall_start_cb(&initcall_calltime, fn);
}
static inline void do_trace_initcall_finish(initcall_t fn, int ret)
{
if (!initcall_debug)
return;
trace_initcall_finish_cb(&initcall_calltime, fn, ret);
}
#endif /* !TRACEPOINTS_ENABLED */

int __init_or_module do_one_initcall(initcall_t fn)
{
int count = preempt_count();
int ret;
char msgbuf[64];
int ret;

if (initcall_blacklisted(fn))
return -EPERM;

if (initcall_debug)
ret = do_one_initcall_debug(fn);
else
ret = fn();
do_trace_initcall_start(fn);
ret = fn();
do_trace_initcall_finish(fn, ret);

msgbuf[0] = 0;

Expand Down Expand Up @@ -874,7 +922,7 @@ static initcall_t *initcall_levels[] __initdata = {

/* Keep these in sync with initcalls in include/linux/init.h */
static char *initcall_level_names[] __initdata = {
"early",
"pure",
"core",
"postcore",
"arch",
Expand All @@ -895,6 +943,7 @@ static void __init do_initcall_level(int level)
level, level,
NULL, &repair_env_string);

trace_initcall_level(initcall_level_names[level]);
for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
do_one_initcall(*fn);
}
Expand Down Expand Up @@ -929,6 +978,7 @@ static void __init do_pre_smp_initcalls(void)
{
initcall_t *fn;

trace_initcall_level("early");
for (fn = __initcall_start; fn < __initcall0_start; fn++)
do_one_initcall(*fn);
}
Expand Down
2 changes: 2 additions & 0 deletions kernel/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
else
dump_stack();

print_irqtrace_events(current);

print_oops_end_marker();

/* Just a warning, don't kill lockdep. */
Expand Down
7 changes: 6 additions & 1 deletion kernel/printk/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <linux/uaccess.h>
#include <asm/sections.h>

#include <trace/events/initcall.h>
#define CREATE_TRACE_POINTS
#include <trace/events/printk.h>

Expand Down Expand Up @@ -2780,6 +2781,7 @@ EXPORT_SYMBOL(unregister_console);
*/
void __init console_init(void)
{
int ret;
initcall_t *call;

/* Setup the default TTY line discipline. */
Expand All @@ -2790,8 +2792,11 @@ void __init console_init(void)
* inform about problems etc..
*/
call = __con_initcall_start;
trace_initcall_level("console");
while (call < __con_initcall_end) {
(*call)();
trace_initcall_start((*call));
ret = (*call)();
trace_initcall_finish((*call), ret);
call++;
}
}
Expand Down
5 changes: 4 additions & 1 deletion kernel/trace/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,10 @@ config HIST_TRIGGERS
event activity as an initial guide for further investigation
using more advanced tools.

See Documentation/trace/events.txt.
Inter-event tracing of quantities such as latencies is also
supported using hist triggers under this option.

See Documentation/trace/histogram.txt.
If in doubt, say N.

config MMIOTRACE_TEST
Expand Down
Loading

0 comments on commit 2a56bb5

Please sign in to comment.