Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 140879
b: refs/heads/master
c: 769b044
h: refs/heads/master
i:
  140877: 71f31d1
  140875: a68256b
  140871: a1c4aab
  140863: 35dcd73
v: v3
  • Loading branch information
Frederic Weisbecker authored and Ingo Molnar committed Mar 6, 2009
1 parent 208c4b3 commit 05808f9
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 310 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1ba28e02a18cbdbea123836f6c98efb09cbf59ec
refs/heads/master: 769b0441f438c4bb4872cb8560eb6fe51bcc09ee
25 changes: 0 additions & 25 deletions trunk/include/linux/ftrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,31 +223,6 @@ extern int ftrace_make_nop(struct module *mod,
*/
extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);

#ifdef CONFIG_TRACE_BPRINTK
extern int trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
extern int __trace_bprintk(unsigned long ip, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));

static inline void ____trace_bprintk_check_format(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
static inline void ____trace_bprintk_check_format(const char *fmt, ...) {}
#define __trace_bprintk_check_format(fmt, args...) \
do { \
if (0) \
____trace_bprintk_check_format(fmt, ##args); \
} while (0)

#define trace_bprintk(fmt, args...) \
do { \
static char *__attribute__((section("__trace_bprintk_fmt"))) \
trace_bprintk_fmt = fmt; \
__trace_bprintk_check_format(fmt, ##args); \
__trace_bprintk(_THIS_IP_, trace_bprintk_fmt, ##args); \
} while (0)
#else
#define trace_bprintk trace_printk
#endif

/* May be defined in arch */
extern int ftrace_arch_read_dyn_info(char *buf, int size);

Expand Down
34 changes: 31 additions & 3 deletions trunk/include/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,16 @@ extern void ftrace_off_permanent(void);
extern void
ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);

static inline void __attribute__ ((format (printf, 1, 2)))
____trace_printk_check_format(const char *fmt, ...)
{
}
#define __trace_printk_check_format(fmt, args...) \
do { \
if (0) \
____trace_printk_check_format(fmt, ##args); \
} while (0)

/**
* trace_printk - printf formatting in the ftrace buffer
* @fmt: the printf format for printing
Expand All @@ -439,13 +449,31 @@ ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
* Please refrain from leaving trace_printks scattered around in
* your code.
*/
# define trace_printk(fmt...) __trace_printk(_THIS_IP_, fmt)

#define trace_printk(fmt, args...) \
do { \
static const char *trace_printk_fmt \
__attribute__((section("__trace_printk_fmt"))); \
trace_printk_fmt = fmt; \
__trace_printk_check_format(fmt, ##args); \
__trace_printk(_THIS_IP_, trace_printk_fmt, ##args); \
} while (0)

extern int
__trace_printk(unsigned long ip, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
# define ftrace_vprintk(fmt, ap) __trace_printk(_THIS_IP_, fmt, ap)

#define ftrace_vprintk(fmt, vargs) \
do { \
static const char *trace_printk_fmt \
__attribute__((section("__trace_printk_fmt"))); \
trace_printk_fmt = fmt; \
__ftrace_vprintk(_THIS_IP_, trace_printk_fmt, vargs); \
} while (0)

extern int
__ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);

extern void ftrace_dump(void);
#else
static inline void
Expand All @@ -467,7 +495,7 @@ ftrace_vprintk(const char *fmt, va_list ap)
return 0;
}
static inline void ftrace_dump(void) { }
#endif
#endif /* CONFIG_TRACING */

/*
* Display an IP address in readable format.
Expand Down
2 changes: 1 addition & 1 deletion trunk/include/linux/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ struct module
unsigned int num_tracepoints;
#endif

#ifdef CONFIG_TRACE_BPRINTK
#ifdef CONFIG_TRACING
const char **trace_bprintk_fmt_start;
unsigned int num_trace_bprintk_fmt;
#endif
Expand Down
7 changes: 1 addition & 6 deletions trunk/kernel/trace/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ config TRACING
select STACKTRACE if STACKTRACE_SUPPORT
select TRACEPOINTS
select NOP_TRACER
select BINARY_PRINTF

#
# Minimum requirements an architecture has to meet for us to
Expand Down Expand Up @@ -97,12 +98,6 @@ config FUNCTION_GRAPH_TRACER
This is done by setting the current return address on the current
task structure into a stack of calls.

config TRACE_BPRINTK
bool "Binary printk for tracing"
default y
depends on TRACING
select BINARY_PRINTF

config IRQSOFF_TRACER
bool "Interrupts-off Latency Tracer"
default n
Expand Down
2 changes: 1 addition & 1 deletion trunk/kernel/trace/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ obj-$(CONFIG_TRACING) += trace.o
obj-$(CONFIG_TRACING) += trace_clock.o
obj-$(CONFIG_TRACING) += trace_output.o
obj-$(CONFIG_TRACING) += trace_stat.o
obj-$(CONFIG_TRACE_BPRINTK) += trace_bprintk.o
obj-$(CONFIG_TRACING) += trace_printk.o
obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o
obj-$(CONFIG_SYSPROF_TRACER) += trace_sysprof.o
obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o
Expand Down
212 changes: 62 additions & 150 deletions trunk/kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,67 @@ void trace_graph_return(struct ftrace_graph_ret *trace)
}
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */


/**
* trace_vprintk - write binary msg to tracing buffer
*
*/
int trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args)
{
static DEFINE_SPINLOCK(trace_buf_lock);
static u32 trace_buf[TRACE_BUF_SIZE];

struct ring_buffer_event *event;
struct trace_array *tr = &global_trace;
struct trace_array_cpu *data;
struct print_entry *entry;
unsigned long flags;
int resched;
int cpu, len = 0, size, pc;

if (unlikely(tracing_selftest_running || tracing_disabled))
return 0;

/* Don't pollute graph traces with trace_vprintk internals */
pause_graph_tracing();

pc = preempt_count();
resched = ftrace_preempt_disable();
cpu = raw_smp_processor_id();
data = tr->data[cpu];

if (unlikely(atomic_read(&data->disabled)))
goto out;

spin_lock_irqsave(&trace_buf_lock, flags);
len = vbin_printf(trace_buf, TRACE_BUF_SIZE, fmt, args);

if (len > TRACE_BUF_SIZE || len < 0)
goto out_unlock;

size = sizeof(*entry) + sizeof(u32) * len;
event = trace_buffer_lock_reserve(tr, TRACE_PRINT, size, flags, pc);
if (!event)
goto out_unlock;
entry = ring_buffer_event_data(event);
entry->ip = ip;
entry->depth = depth;
entry->fmt = fmt;

memcpy(entry->buf, trace_buf, sizeof(u32) * len);
ring_buffer_unlock_commit(tr->buffer, event);

out_unlock:
spin_unlock_irqrestore(&trace_buf_lock, flags);

out:
ftrace_preempt_enable(resched);
unpause_graph_tracing();

return len;
}
EXPORT_SYMBOL_GPL(trace_vprintk);

enum trace_file_type {
TRACE_FILE_LAT_FMT = 1,
TRACE_FILE_ANNOTATE = 2,
Expand Down Expand Up @@ -1564,7 +1625,7 @@ static enum print_line_t print_printk_msg_only(struct trace_iterator *iter)

trace_assign_type(field, entry);

ret = trace_seq_printf(s, "%s", field->buf);
ret = trace_seq_bprintf(s, field->fmt, field->buf);
if (!ret)
return TRACE_TYPE_PARTIAL_LINE;

Expand Down Expand Up @@ -3714,155 +3775,6 @@ static __init int tracer_init_debugfs(void)
return 0;
}

int trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args)
{
static raw_spinlock_t trace_buf_lock = __RAW_SPIN_LOCK_UNLOCKED;
static char trace_buf[TRACE_BUF_SIZE];

struct ring_buffer_event *event;
struct trace_array *tr = &global_trace;
struct trace_array_cpu *data;
int cpu, len = 0, size, pc;
struct print_entry *entry;
unsigned long irq_flags;

if (tracing_disabled || tracing_selftest_running)
return 0;

pc = preempt_count();
preempt_disable_notrace();
cpu = raw_smp_processor_id();
data = tr->data[cpu];

if (unlikely(atomic_read(&data->disabled)))
goto out;

pause_graph_tracing();
raw_local_irq_save(irq_flags);
__raw_spin_lock(&trace_buf_lock);
len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args);

len = min(len, TRACE_BUF_SIZE-1);
trace_buf[len] = 0;

size = sizeof(*entry) + len + 1;
event = trace_buffer_lock_reserve(tr, TRACE_PRINT, size, irq_flags, pc);
if (!event)
goto out_unlock;
entry = ring_buffer_event_data(event);
entry->ip = ip;
entry->depth = depth;

memcpy(&entry->buf, trace_buf, len);
entry->buf[len] = 0;
ring_buffer_unlock_commit(tr->buffer, event);

out_unlock:
__raw_spin_unlock(&trace_buf_lock);
raw_local_irq_restore(irq_flags);
unpause_graph_tracing();
out:
preempt_enable_notrace();

return len;
}
EXPORT_SYMBOL_GPL(trace_vprintk);

int __trace_printk(unsigned long ip, const char *fmt, ...)
{
int ret;
va_list ap;

if (!(trace_flags & TRACE_ITER_PRINTK))
return 0;

va_start(ap, fmt);
ret = trace_vprintk(ip, task_curr_ret_stack(current), fmt, ap);
va_end(ap);
return ret;
}
EXPORT_SYMBOL_GPL(__trace_printk);

int __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap)
{
if (!(trace_flags & TRACE_ITER_PRINTK))
return 0;

return trace_vprintk(ip, task_curr_ret_stack(current), fmt, ap);
}
EXPORT_SYMBOL_GPL(__ftrace_vprintk);

/**
* trace_vbprintk - write binary msg to tracing buffer
*
* Caller must insure @fmt are valid when msg is in tracing buffer.
*/
int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
{
static DEFINE_SPINLOCK(trace_buf_lock);
static u32 trace_buf[TRACE_BUF_SIZE];

struct ring_buffer_event *event;
struct trace_array *tr = &global_trace;
struct trace_array_cpu *data;
struct bprintk_entry *entry;
unsigned long flags;
int resched;
int cpu, len = 0, size, pc;

if (tracing_disabled || !trace_bprintk_enable)
return 0;

pc = preempt_count();
resched = ftrace_preempt_disable();
cpu = raw_smp_processor_id();
data = tr->data[cpu];

if (unlikely(atomic_read(&data->disabled)))
goto out;

spin_lock_irqsave(&trace_buf_lock, flags);
len = vbin_printf(trace_buf, TRACE_BUF_SIZE, fmt, args);

if (len > TRACE_BUF_SIZE || len < 0)
goto out_unlock;

size = sizeof(*entry) + sizeof(u32) * len;
event = trace_buffer_lock_reserve(tr, TRACE_BPRINTK, size, flags, pc);
if (!event)
goto out_unlock;
entry = ring_buffer_event_data(event);
entry->ip = ip;
entry->fmt = fmt;

memcpy(entry->buf, trace_buf, sizeof(u32) * len);
ring_buffer_unlock_commit(tr->buffer, event);

out_unlock:
spin_unlock_irqrestore(&trace_buf_lock, flags);

out:
ftrace_preempt_enable(resched);

return len;
}
EXPORT_SYMBOL_GPL(trace_vbprintk);

int __trace_bprintk(unsigned long ip, const char *fmt, ...)
{
int ret;
va_list ap;

if (!fmt)
return 0;

va_start(ap, fmt);
ret = trace_vbprintk(ip, fmt, ap);
va_end(ap);
return ret;
}
EXPORT_SYMBOL_GPL(__trace_bprintk);

static int trace_panic_handler(struct notifier_block *this,
unsigned long event, void *unused)
{
Expand Down
Loading

0 comments on commit 05808f9

Please sign in to comment.