tracepoint perf counter events and other stuff
cover tracepoint perf counter events and other stuff
RFC because the patch stack seems to not quite work as expected, will poke at it more in the morning, but thought I should post it so that other folks can see what's happening.
RFC PATCH 7/11 perf_counter: fix up counter free paths
I found another counter free path, create a free_counter() call to accomodate generic tear-down.
Fixes an RCU bug.
--- kernel/perf_counter.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/perf_counter.c +8 -3
@@ -1150,6 +1150,11 @@ static void free_counter_rcu(struct rcu_kfree (counter); } +static void free_counter (struct perf_counter *counter) +{ +call_rcu (&counter->rcu_head, free_counter_rcu); +} +/* * Called when the last reference to the file is gone. */
@@ -1168,7 +1173,7 @@ static int perf_release(struct inode *inmutex_unlock (&counter->mutex);mutex_unlock (&ctx->mutex); -call_rcu (&counter->rcu_head, free_counter_rcu); +free_counter (counter);put_context (ctx);return 0 ;
@@ -2128,10 +2133,10 @@ __perf_counter_exit_task(struct task_str list_entry) {if (sub->parent) {sync_child_counter (sub, sub->parent); -kfree (sub); +free_counter (sub); } } -kfree (child_counter); +free_counter (child_counter); } }
RFC PATCH 5/11 ftrace: ensure every event gets an id
In reply to Peter ZijlstraPreviously only TRACE_EVENT events got ids, because only they generated raw output which needs to be demuxed from the trace.
In order to provide a unique ID for each event, register everybody, regardless.
--- kernel/trace/trace_events_stage_3.h | 15 ++++++++++++++- kernel/trace/trace_output.c | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-)
kernel/trace/trace_events_stage_3.h +14 -1
@@ -130,7 +130,19 @@ static void ftrace_unreg_event_##call(vo { \ unregister_trace_##call(ftrace_event_##call); \ } \ - + \ +static struct ftrace_event_call event_##call; \ + \ +static int ftrace_init_event_##call(void) \ +{ \ + int id; \ + \ + id = register_ftrace_event(NULL); \ + if (!id) \ + return -ENODEV; \ + event_##call.id = id; \ + return 0; \ +}#undef TRACE_FORMAT#define TRACE_FORMAT (call, proto, args, fmt) \
@@ -140,6 +152,7 @@ __attribute__((__aligned__(4))) \ __attribute__((section("_ftrace_events"))) event_##call = { \ .name = #call, \ .system = __stringify(TRACE_SYSTEM), \ + .raw_init = ftrace_init_event_##call, \ .regfunc = ftrace_reg_event_##call, \ .unregfunc = ftrace_unreg_event_##call, \ }
kernel/trace/trace_output.c +5 -0
@@ -444,6 +444,11 @@ int register_ftrace_event(struct trace_emutex_lock (&trace_event_mutex); +if (!event) { + ret = next_event_type++; + goto out; + } +if (!event->type) event->type = next_event_type++;else if (event->type > __TRACE_LAST_TYPE) {
RFC PATCH 6/11 ftrace: event profile hooks
In reply to Peter ZijlstraProvide infrastructure to generate software perf counter events from tracepoints.
--- kernel/trace/Makefile | 1 kernel/trace/events.c | 1 kernel/trace/trace.h | 11 +++++++++ kernel/trace/trace_event_profile.c | 31 +++++++++++++++++++++++++ kernel/trace/trace_events.c | 9 +------ kernel/trace/trace_events_stage_3.h | 44 ++++++++++++++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 8 deletions(-)
kernel/trace/trace.h +11 -0
@@ -786,12 +786,23 @@ struct ftrace_event_call {int id;int (*raw_init)(void );int (*show_format)(struct trace_seq *s); + +#ifdef CONFIG_EVENT_PROFILE +atomic_t profile_count; +int (*profile_enable)(struct ftrace_event_call *); +void (*profile_disable)(struct ftrace_event_call *); +#endif };void event_trace_printk (unsigned long ip,const char *fmt, ...);extern struct ftrace_event_call __start_ftrace_events[];extern struct ftrace_event_call __stop_ftrace_events[]; +#define for_each_event (event) \ + for (event = __start_ftrace_events; \ + (unsigned long)event < (unsigned long)__stop_ftrace_events; \ + event++) +extern const char *__start___trace_bprintk_fmt[];extern const char *__stop___trace_bprintk_fmt[];
kernel/trace/trace_event_profile.c new file +31 -0
@@ -0,0 +1,31 @@ +/* +* trace event based perf counter profiling +* +* Copyright (C) 2009 Red Hat Inc, Peter Zijlstra <[email protected]> +* +*/ + +#include "trace.h" + +int ftrace_profile_enable (int event_id) +{ +struct ftrace_event_call *event; + +for_each_event (event) { +if (event->id == event_id) +return event->profile_enable (event); + } + +return -EINVAL ; +} + +void ftrace_profile_disable (int event_id) +{ +struct ftrace_event_call *event; + +for_each_event (event) { +if (event->id == event_id) +return event->profile_disable (event); + } +} +
kernel/trace/trace_events.c +2 -7
@@ -19,11 +19,6 @@static DEFINE_MUTEX (event_mutex); -#define events_for_each (event) \ - for (event = __start_ftrace_events; \ - (unsigned long)event < (unsigned long)__stop_ftrace_events; \ - event++) -static void ftrace_clear_events (void ) {struct ftrace_event_call *call = (void *)__start_ftrace_events;
@@ -90,7 +85,7 @@ static int ftrace_set_clr_event(char *bu }mutex_lock (&event_mutex); -events_for_each (call) { +for_each_event (call) {if (!call->name || !call->regfunc)continue ;
@@ -628,7 +623,7 @@ static __init int event_trace_init(void)if (!d_events)return 0 ; -events_for_each (call) { +for_each_event (call) {/* The linker may leave blanks */ if (!call->name)continue ;
kernel/trace/trace_events_stage_3.h +44 -0
72 lines not on this page · raw message
kernel/trace/Makefile +1 -0
@@ -44,5 +44,6 @@ obj-$(CONFIG_EVENT_TRACER) += trace_even obj-$(CONFIG_EVENT_TRACER) += events.o obj-$(CONFIG_EVENT_TRACER) += trace_export.o obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o +obj-$(CONFIG_EVENT_PROFILE) += trace_event_profile.o libftrace-y := ftrace.o
kernel/trace/events.c +0 -1
@@ -12,4 +12,3 @@#include "trace_events_stage_2.h" #include "trace_events_stage_3.h" -#include <trace/trace_event_types.h>
RFC PATCH 3/11 ftrace: fix memory leak
In reply to Peter ZijlstraDon't return after an allocation without freeing -- fix it by moving the check up a few lines.
--- kernel/trace/trace_events.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace_events.c +3 -3
@@ -380,15 +380,15 @@ event_format_read(struct file *filp, chachar *buf;int r; +if (*ppos) +return 0 ; + s =kmalloc (sizeof (*s),GFP_KERNEL );if (!s)return -ENOMEM ;trace_seq_init (s); -if (*ppos) -return 0 ; -/* If any of the first writes fail, so will the show_format. */ trace_seq_printf (s,"name: %s\n" , call->name);
RFC PATCH 2/11 perf_counter: generic context switch event
In reply to Peter Zijlstrause the generic software events for context switches.
--- include/linux/sched.h | 1 kernel/perf_counter.c | 60 +++----------------------------------------------- kernel/sched.c | 6 ----- 3 files changed, 4 insertions(+), 63 deletions(-)
include/linux/sched.h +0 -1
@@ -137,7 +137,6 @@ extern unsigned long nr_running(void);extern unsigned long nr_uninterruptible (void );extern unsigned long nr_active (void );extern unsigned long nr_iowait (void ); -extern u64 cpu_nr_switches (int cpu);extern u64 cpu_nr_migrations (int cpu);extern unsigned long get_parent_ip (unsigned long addr);
kernel/perf_counter.c +4 -56
83 lines not on this page · raw message
kernel/sched.c +0 -6
@@ -2911,14 +2911,8 @@ unsigned long nr_active(void)/* * Externally visible per-cpu scheduler statistics: -* cpu_nr_switches(cpu) - number of context switches on that cpu * cpu_nr_migrations(cpu) - number of migrations into that cpu */ -u64 cpu_nr_switches (int cpu) -{ -return cpu_rq (cpu)->nr_switches; -} -u64 cpu_nr_migrations (int cpu) {return cpu_rq (cpu)->nr_migrations_in;
RFC PATCH 10/11 perfcounters: abstract wakeup flag setting in core to fix powerpc build
In reply to Peter ZijlstraFrom: Paul Mackerras <[email protected]>
Impact: build fix for powerpc
Commit bd753921015e7905 ("perf_counter: software counter event infrastructure") introduced a use of TIF_PERF_COUNTERS into the core perfcounter code. This breaks the build on powerpc because we use a flag in a per-cpu area to signal wakeups on powerpc rather than a thread_info flag, because the thread_info flags have to be manipulated with atomic operations and are thus slower than per-cpu flags.
This fixes the by changing the core to use an abstracted set_perf_counter_pending() function, which is defined on x86 to set the TIF_PERF_COUNTERS flag and on powerpc to set the per-cpu flag (paca->perf_counter_pending). It changes the previous powerpc definition of set_perf_counter_pending to not take an argument and adds a clear_perf_counter_pending, so as to simplify the definition on x86.
On x86, set_perf_counter_pending() is defined as a macro. Defining it as a static inline in arch/x86/include/asm/perf_counters.h causes compile failures because <asm/perf_counters.h> gets included early in <linux/sched.h>, and the definitions of set_tsk_thread_flag etc. are therefore not available in <asm/perf_counters.h>. (On powerpc this problem is avoided by defining set_perf_counter_pending etc. in <asm/hw_irq.h>.)
--- arch/powerpc/include/asm/hw_irq.h | 14 +++++++++++--- arch/powerpc/kernel/irq.c | 11 +++-------- arch/powerpc/kernel/perf_counter.c | 3 +-- arch/x86/include/asm/perf_counter.h | 3 +++ kernel/perf_counter.c | 2 +- 5 files changed, 19 insertions(+), 14 deletions(-)
arch/powerpc/include/asm/hw_irq.h +11 -3
@@ -142,10 +142,17 @@ static inline unsigned long get_perf_coureturn x; } -static inline void set_perf_counter_pending (int x) +static inline void set_perf_counter_pending (void ) { asmvolatile ("stb %0,%1(13)" : : -"r" (x), +"r" (1 ), +"i" (offsetof(struct paca_struct , perf_counter_pending))); +} + +static inline void clear_perf_counter_pending (void ) +{ + asmvolatile ("stb %0,%1(13)" : : +"r" (0 ),"i" (offsetof(struct paca_struct , perf_counter_pending))); }
@@ -158,7 +165,8 @@ static inline unsigned long get_perf_cou return 0; } -static inline void set_perf_counter_pending (int x) {} +static inline void set_perf_counter_pending (void ) {} +static inline void clear_perf_counter_pending (void ) {}static inline void perf_counter_do_pending (void ) {}#endif /* CONFIG_PERF_COUNTERS */
arch/powerpc/kernel/irq.c +3 -8
@@ -104,13 +104,6 @@ static inline notrace void set_soft_enab : : "r" (enable), "i" (offsetof(struct paca_struct, soft_enabled))); } -#ifdef CONFIG_PERF_COUNTERS -notrace void __weak perf_counter_do_pending(void) -{ -set_perf_counter_pending (0 ); -} -#endif - notrace void raw_local_irq_restore(unsigned long en) {/*
@@ -142,8 +135,10 @@ notrace void raw_local_irq_restore(unsigiseries_handle_interrupts (); } -if (get_perf_counter_pending ()) +if (get_perf_counter_pending ()) { +clear_perf_counter_pending ();perf_counter_do_pending (); + }/* * if (get_paca()->hard_enabled) return;
arch/powerpc/kernel/perf_counter.c +1 -2
@@ -653,7 +653,6 @@ void perf_counter_do_pending(void)struct cpu_hw_counters *cpuhw = &__get_cpu_var (cpu_hw_counters);struct perf_counter *counter; -set_perf_counter_pending (0 );for (i =0 ; i < cpuhw->n_counters; ++i) { counter = cpuhw->counter[i];if (counter && counter->wakeup_pending) {
@@ -811,7 +810,7 @@ static void perf_counter_interrupt(strucperf_counter_do_pending ();irq_exit (); }else { -set_perf_counter_pending (1 ); +set_perf_counter_pending (); } } }
arch/x86/include/asm/perf_counter.h +3 -0
@@ -84,6 +84,9 @@ union cpuid10_edx {#define MSR_ARCH_PERFMON_FIXED_CTR2 0x30b#define X86_PMC_IDX_FIXED_BUS_CYCLES (X86_PMC_IDX_FIXED + 2) +#define set_perf_counter_pending () \ + set_tsk_thread_flag(current, TIF_PERF_COUNTERS); +#ifdef CONFIG_PERF_COUNTERS extern void init_hw_perf_counters (void );extern void perf_counters_lapic_init (int nmi);
kernel/perf_counter.c +1 -1
@@ -1438,7 +1438,7 @@ static void perf_swcounter_interrupt(strif (nmi) { counter->wakeup_pending =1 ; -set_tsk_thread_flag (current,TIF_PERF_COUNTERS ); +set_perf_counter_pending (); }else wake_up (&counter->waitq); }
RFC PATCH 1/11 perf_counter: fix uninitialized usage of event_list
In reply to Peter ZijlstraWhen doing the generic context switch event I ran into some early boot hangs, which were caused by inf func recursion (event, fault, event, fault).
I eventually tracked it down to event_list not being initialized at the time of the first event. Fix this.
--- kernel/perf_counter.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/perf_counter.c +1 -1
@@ -1506,7 +1506,7 @@ static void perf_swcounter_ctx_event(str {struct perf_counter *counter; -if (list_empty (&ctx->event_list)) +if (!ctx->is_active ||list_empty (&ctx->event_list))return ;rcu_read_lock ();
include/linux/init_task.h +2 -0
@@ -124,6 +124,8 @@ extern struct cred init_cred;# define INIT_PERF_COUNTERS (tsk) \ .perf_counter_ctx.counter_list = \ LIST_HEAD_INIT(tsk.perf_counter_ctx.counter_list), \ + .perf_counter_ctx.event_list = \ + LIST_HEAD_INIT(tsk.perf_counter_ctx.event_list), \ .perf_counter_ctx.lock = \ __SPIN_LOCK_UNLOCKED(tsk.perf_counter_ctx.lock),#else
RFC PATCH 4/11 ftrace: provide an id file for each event
In reply to Peter ZijlstraSince not every event has a format file to read the id from, expose it explicitly in a separate file.
--- kernel/trace/trace_events.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
kernel/trace/trace_events.c +36 -0
@@ -414,6 +414,29 @@ event_format_read(struct file *filp, chareturn r; } +static ssize_t +event_id_read (struct file *filp,char __user *ubuf,size_t cnt,loff_t *ppos) +{ +struct ftrace_event_call *call = filp->private_data; +struct trace_seq *s; +int r; + +if (*ppos) +return 0 ; + + s =kmalloc (sizeof (*s),GFP_KERNEL ); +if (!s) +return -ENOMEM ; + +trace_seq_init (s); +trace_seq_printf (s,"%d\n" , call->id); + + r =simple_read_from_buffer (ubuf, cnt, ppos, + s->buffer, s->len); +kfree (s); +return r; +} +static const struct seq_operations show_event_seq_ops = { .start = t_start, .next = t_next,
@@ -454,6 +477,11 @@ static const struct file_operations ftra .read = event_format_read, }; +static const struct file_operations ftrace_event_id_fops = { + .open = tracing_open_generic, + .read = event_id_read, +}; +static struct dentry *event_trace_events_dir (void ) {static struct dentry *d_tracer;
@@ -552,6 +580,14 @@ event_create_dir(struct ftrace_event_cal "'%s/enable' entry\n", call->name); } +if (call->id) { + entry =debugfs_create_file ("id" ,0444 , call->dir, call, + &ftrace_event_id_fops); +if (!entry) +pr_warning ("Could not create debugfs '%s/id' entry\n" , + call->name); + } +/* A trace may not want to export its format */ if (!call->show_format)return 0 ;
RFC PATCH 8/11 perf_counter: hook up the tracepoint events
In reply to Peter ZijlstraEnable usage of tracepoints as perf counter events.
tracepoint event ids can be found in /debug/tracing/event/*/*/id and (for now) are represented as -65536+id in the type field.
--- include/linux/perf_counter.h | 3 +++ init/Kconfig | 5 +++++ kernel/perf_counter.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+)
include/linux/perf_counter.h +3 -0
@@ -53,6 +53,8 @@ enum hw_event_types {PERF_COUNT_PAGE_FAULTS_MAJ =-7 ,PERF_SW_EVENTS_MIN =-8 , + + PERF_TP_EVENTS_MIN = -65536 };/*
@@ -222,6 +224,7 @@ struct perf_counter {struct perf_data *usrdata;struct perf_data data[2 ]; +void (*destroy)(struct perf_counter *);struct rcu_head rcu_head;#endif };
kernel/perf_counter.c +43 -0
61 lines not on this page · raw message
init/Kconfig +5 -0
@@ -945,6 +945,11 @@ config PERF_COUNTERS Say Y if unsure. +config EVENT_PROFILE + bool "Tracepoint profile sources" + depends on PERF_COUNTERS && EVENT_TRACER + default y + endmenu config VM_EVENT_COUNTERS
RFC PATCH 9/11 perf_counter: revamp syscall input ABI
In reply to Peter ZijlstraThe hardware/software classification in hw_event->type became a little strained due to the addition of tracepoint tracing.
Instead split up the field and provide a type field to explicitly specify the counter type, while using the event_id field to specify which event to use.
Raw counters still work as before, only the raw config now goes into raw_event.
Updated userspace at:
http://programming.kicks-ass.net/misc/perf_counter/
--- arch/powerpc/kernel/perf_counter.c | 2 arch/x86/kernel/cpu/perf_counter.c | 8 +-- include/linux/perf_counter.h | 83 ++++++++++++++++++++++--------------- kernel/perf_counter.c | 81 +++++++++++++++++++++--------------- 4 files changed, 104 insertions(+), 70 deletions(-)
arch/powerpc/kernel/perf_counter.c +1 -1
@@ -693,7 +693,7 @@ static void perf_handle_group(struct perlist_for_each_entry (sub, &leader->sibling_list, list_entry) {if (sub != counter) sub->hw_ops->read (sub); -perf_store_irq_data (counter, sub->hw_event.type); +perf_store_irq_data (counter, sub->hw_event.raw_event);perf_store_irq_data (counter,atomic64_read (&sub->count)); } }
arch/x86/kernel/cpu/perf_counter.c +4 -4
@@ -216,14 +216,14 @@ static int __hw_perf_counter_init(struct* Raw event type provide the config in the event structure */ if (hw_event->raw) { - hwc->config |= pmc_ops->raw_event (hw_event->type); + hwc->config |= pmc_ops->raw_event (hw_event->raw_event); }else { -if (hw_event->type >= pmc_ops->max_events) +if (hw_event->event_id >= pmc_ops->max_events)return -EINVAL ;/* * The generic map: */ - hwc->config |= pmc_ops->event_map (hw_event->type); + hwc->config |= pmc_ops->event_map (hw_event->event_id); } counter->wakeup_pending =0 ;
@@ -713,7 +713,7 @@ perf_handle_group(struct perf_counter *slist_for_each_entry (counter, &group_leader->sibling_list, list_entry) {x86_perf_counter_update (counter, &counter->hw, counter->hw.idx); -perf_store_irq_data (sibling, counter->hw_event.type); +perf_store_irq_data (sibling, counter->hw_event.raw_event);perf_store_irq_data (sibling,atomic64_read (&counter->count)); } }
include/linux/perf_counter.h +50 -33
123 lines not on this page · raw message
kernel/perf_counter.c +49 -32
175 lines not on this page · raw message
RFC PATCH 11/11 perf_counter: unify irq output code
In reply to Peter ZijlstraHaving 3 slightly different copies of the same code around does nobody any good. First step in revamping the output format.
--- arch/powerpc/kernel/perf_counter.c | 51 ----------------- arch/x86/kernel/cpu/perf_counter.c | 53 ------------------ include/linux/perf_counter.h | 2 kernel/perf_counter.c | 106 +++++++++++++++++++------------------ 4 files changed, 61 insertions(+), 151 deletions(-)
arch/powerpc/kernel/perf_counter.c +2 -49
@@ -663,41 +663,6 @@ void perf_counter_do_pending(void) }/* -* Record data for an irq counter. -* This function was lifted from the x86 code; maybe it should -* go in the core? -*/ -static void perf_store_irq_data (struct perf_counter *counter,u64 data) -{ -struct perf_data *irqdata = counter->irqdata; - -if (irqdata->len >PERF_DATA_BUFLEN -sizeof (u64)) { - irqdata->overrun++; - }else { -u64 *p = (u64 *) &irqdata->data[irqdata->len]; - - *p = data; - irqdata->len +=sizeof (u64); - } -} - -/* -* Record all the values of the counters in a group -*/ -static void perf_handle_group (struct perf_counter *counter) -{ -struct perf_counter *leader, *sub; - - leader = counter->group_leader; -list_for_each_entry (sub, &leader->sibling_list, list_entry) { -if (sub != counter) - sub->hw_ops->read (sub); -perf_store_irq_data (counter, sub->hw_event.raw_event); -perf_store_irq_data (counter,atomic64_read (&sub->count)); - } -} - -/* * A counter has overflowed; update its count and record * things if requested. Note that interrupts are hard-disabled * here so there is no possibility of being interrupted.
@@ -736,20 +701,8 @@ static void record_and_restart(struct pe/* * Finally record data if requested. */ -if (record) { -switch (counter->hw_event.record_type) { -case PERF_RECORD_SIMPLE : -break ; -case PERF_RECORD_IRQ : -perf_store_irq_data (counter,instruction_pointer (regs)); - counter->wakeup_pending =1 ; -break ; -case PERF_RECORD_GROUP : -perf_handle_group (counter); - counter->wakeup_pending =1 ; -break ; - } - } +if (record) +perf_counter_output (counter,1 , regs); }/*
arch/x86/kernel/cpu/perf_counter.c +1 -52
71 lines not on this page · raw message
include/linux/perf_counter.h +2 -0
@@ -309,6 +309,8 @@ extern int hw_perf_group_sched_in(structstruct perf_cpu_context *cpuctx, struct perf_counter_context *ctx, int cpu); +extern void perf_counter_output (struct perf_counter *counter, +int nmi,struct pt_regs *regs);/* * Return 1 for a software counter, 0 for a hardware counter */
kernel/perf_counter.c +56 -50
130 lines not on this page · raw message
Steven Rostedt
maintainerRe: [RFC][PATCH 03/11] ftrace: fix memory leak
In reply to Peter ZijlstraTom Zanussi beat you to it ;-)
http://marc.info/?l=linux-kernel&m=123727898221734&w=2
-- Steve
Quoted 35 lines · Peter Zijlstra
Don't return after an allocation without freeing -- fix it by moving the check up a few lines.
Signed-off-by Peter Zijlstra <[email protected]>--- kernel/trace/trace_events.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)Index:
linux-2.6/kernel/trace/trace_events.c
===================================================================kernel/trace/trace_events.c +3
-3@@ -380,15 +380,15 @@ event_format_read(struct file *filp, chachar *buf;int r; +if (*ppos) +return 0 ; + s =kmalloc (sizeof (*s),GFP_KERNEL );if (!s)return -ENOMEM ;trace_seq_init (s); -if (*ppos) -return 0 ; -/* If any of the first writes fail, so will the show_format. */ trace_seq_printf (s,"name: %s\n" , call->name);Signature · 1 line
--
Steven Rostedt
maintainerRe: [RFC][PATCH 04/11] ftrace: provide an id file for each event
In reply to Peter ZijlstraQuoted 2 lines · Peter Zijlstra
Since not every event has a format file to read the id from, expose it explicitly in a separate file.
If the format is not exported, the ID is pretty useless. It's used for binary formats.
But if you have a generic format defined in trace.h (I'll have to look at your other patches), then those are exported in
kernel/trace/trace_event_types.h
-- Steve
Quoted 71 lines
Signed-off-by Peter Zijlstra <[email protected]>--- kernel/trace/trace_events.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)Index:
linux-2.6/kernel/trace/trace_events.c
===================================================================kernel/trace/trace_events.c +36
-0@@ -414,6 +414,29 @@ event_format_read(struct file *filp, chareturn r; } +static ssize_t +event_id_read (struct file *filp,char __user *ubuf,size_t cnt,loff_t *ppos) +{ +struct ftrace_event_call *call = filp->private_data; +struct trace_seq *s; +int r; + +if (*ppos) +return 0 ; + + s =kmalloc (sizeof (*s),GFP_KERNEL ); +if (!s) +return -ENOMEM ; + +trace_seq_init (s); +trace_seq_printf (s,"%d\n" , call->id); + + r =simple_read_from_buffer (ubuf, cnt, ppos, + s->buffer, s->len); +kfree (s); +return r; +} +static const struct seq_operations show_event_seq_ops = { .start = t_start, .next = t_next,@@ -454,6 +477,11 @@ static const struct file_operations ftra .read = event_format_read, }; +static const struct file_operations ftrace_event_id_fops = { + .open = tracing_open_generic, + .read = event_id_read, +}; +static struct dentry *event_trace_events_dir (void ) {static struct dentry *d_tracer;@@ -552,6 +580,14 @@ event_create_dir(struct ftrace_event_cal "'%s/enable' entry\n", call->name); } +if (call->id) { + entry =debugfs_create_file ("id" ,0444 , call->dir, call, + &ftrace_event_id_fops); +if (!entry) +pr_warning ("Could not create debugfs '%s/id' entry\n" , + call->name); + } +/* A trace may not want to export its format */ if (!call->show_format)return 0 ;Signature · 1 line
--
Steven Rostedt
maintainerRe: [RFC][PATCH 05/11] ftrace: ensure every event gets an id
In reply to Peter ZijlstraQuoted 4 lines · Peter Zijlstra
Previously only
TRACE_EVENTevents got ids, because only they generated raw output which needs to be demuxed from the trace.In order to provide a unique ID for each event, register everybody, regardless.
If this is about the TRACE_FORMAT, they use the TRACE_PRINT format, which is exported.
Again, I need to look at the rest of the patches ;-)
-- Steve
Quoted 60 lines
Signed-off-by Peter Zijlstra <[email protected]>--- kernel/trace/trace_events_stage_3.h | 15 ++++++++++++++- kernel/trace/trace_output.c | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-)Index:
linux-2.6/kernel/trace/trace_events_stage_3.h
===================================================================kernel/trace/trace_events_stage_3.h +14
-1@@ -130,7 +130,19 @@ static void ftrace_unreg_event_##call(vo { \ unregister_trace_##call(ftrace_event_##call); \ } \ - + \ +static struct ftrace_event_call event_##call; \ + \ +static int ftrace_init_event_##call(void) \ +{ \ + int id; \ + \ + id = register_ftrace_event(NULL); \ + if (!id) \ + return -ENODEV; \ + event_##call.id = id; \ + return 0; \ +}#undef TRACE_FORMAT#define TRACE_FORMAT (call, proto, args, fmt) \@@ -140,6 +152,7 @@ __attribute__((__aligned__(4))) \ __attribute__((section("_ftrace_events"))) event_##call = { \ .name = #call, \ .system = __stringify(TRACE_SYSTEM), \ + .raw_init = ftrace_init_event_##call, \ .regfunc = ftrace_reg_event_##call, \ .unregfunc = ftrace_unreg_event_##call, \ }Index:
linux-2.6/kernel/trace/trace_output.c
===================================================================kernel/trace/trace_output.c +5
-0@@ -444,6 +444,11 @@ int register_ftrace_event(struct trace_emutex_lock (&trace_event_mutex); +if (!event) { + ret = next_event_type++; + goto out; + } +if (!event->type) event->type = next_event_type++;else if (event->type > __TRACE_LAST_TYPE) {Signature · 1 line
--
Re: [RFC][PATCH 09/11] perf_counter: revamp syscall input ABI
In reply to Peter ZijlstraQuoted 7 lines · Peter Zijlstra
The hardware/software classification in
hw_event->typebecame a little strained due to the addition of tracepoint tracing.Instead split up the field and provide a type field to explicitly specify the counter type, while using the
event_idfield to specify which event to use.Raw counters still work as before, only the raw config now goes into
raw_event.
Interesting idea, but why not also use it to express the distinction between generic and raw hardware events ids? Why not add a PERF_TYPE_RAW_HARDWARE to this list:
include/linux/perf_counter.h line 30
Quoted 7 lines
+ * hw_event.type
+ */include/linux/perf_counter.h +5
-0+enum perf_event_types { +PERF_TYPE_HARDWARE =0 , +PERF_TYPE_SOFTWARE =1 , +PERF_TYPE_TRACEPOINT =2 , +};
and get rid of the raw bit? That way, hw_event.raw_event is unique for every different event, whereas the way you have it, you still need to include the raw bit to get a unique id.
Paul.
Re: [RFC][PATCH 11/11] perf_counter: unify irq output code
In reply to Peter ZijlstraQuoted 2 lines · Peter Zijlstra
Having 3 slightly different copies of the same code around does nobody any good. First step in revamping the output format.
Nice cleanup, and thanks for updating powerpc too. With this, I think we'll need to update the powerpc perf_counter_interrupt a bit: we might as well use get_perf_counter_pending() instead of the wakeup variable now. I'll send an extra patch once I have done some testing.
Paul.
Re: [RFC][PATCH 09/11] perf_counter: revamp syscall input ABI
In reply to Peter ZijlstraQuoted 5 lines · Peter Zijlstra
The hardware/software classification in
hw_event->typebecame a little strained due to the addition of tracepoint tracing.Instead split up the field and provide a type field to explicitly specify the counter type, while using the
event_idfield to specify which event to use.
It would be nice if you didn't reuse the name 'type' but instead called the field something different ('class', perhaps?) to force a compile error on code that needs to be updated. For example, you missed a spot in arch/powerpc/kernel/perf_counter.c and you need to add on the patch below. (Thanks for updating powerpc BTW.)
Paul.
arch/powerpc/kernel/perf_counter.c +1 -1
@@ -602,7 +602,7 @@ hw_perf_counter_init(struct perf_counter *counter)return NULL ;if ((s64 )counter->hw_event.irq_period <0 )return NULL ; - ev = counter->hw_event.type; + ev = counter->hw_event.event_id;if (!counter->hw_event.raw) {if (ev >= ppmu->n_generic || ppmu->generic_events[ev] ==0 )
Re: [RFC][PATCH 11/11] perf_counter: unify irq output code
In reply to Paul MackerrasQuoted 4 lines · I wrote:
Nice cleanup, and thanks for updating powerpc too. With this, I think we'll need to update the powerpc
perf_counter_interrupta bit: we might as well useget_perf_counter_pending()instead of the wakeup variable now. I'll send an extra patch once I have done some testing.
This seems to work OK.
Paul.
arch/powerpc/kernel/perf_counter.c +7 -12
@@ -723,8 +723,6 @@ static void perf_counter_interrupt(struct pt_regs *regs)/* counter has overflowed */ found =1 ;record_and_restart (counter, val, regs); -if (counter->wakeup_pending) - need_wakeup =1 ; } }
@@ -754,17 +752,14 @@ static void perf_counter_interrupt(struct pt_regs *regs)/* * If we need a wakeup, check whether interrupts were soft-enabled * when we took the interrupt. If they were, we can wake stuff up -* immediately; otherwise we'll have to set a flag and do the -* wakeup when interrupts get soft-enabled. +* immediately; otherwise we'll have do the wakeup when interrupts +* get soft-enabled. */ -if (need_wakeup) { -if (regs->softe) { -irq_enter (); -perf_counter_do_pending (); -irq_exit (); - }else { -set_perf_counter_pending (); - } +if (get_perf_counter_pending () && regs->softe) { +irq_enter (); +clear_perf_counter_pending (); +perf_counter_do_pending (); +irq_exit (); } }
Re: [RFC][PATCH 09/11] perf_counter: revamp syscall input ABI
In reply to Paul MackerrasQuoted 14 lines · Paul Mackerras
Quoted 7 lines · Peter Zijlstra
The hardware/software classification in
hw_event->typebecame a little strained due to the addition of tracepoint tracing.Instead split up the field and provide a type field to explicitly specify the counter type, while using the
event_idfield to specify which event to use.Raw counters still work as before, only the raw config now goes into
raw_event.Interesting idea, but why not also use it to express the distinction between generic and raw hardware events ids? Why not add a
PERF_TYPE_RAW_HARDWAREto this list:
Quoted 11 lines
include/linux/perf_counter.h line 30
Quoted 7 lines
+ * hw_event.type
+ */include/linux/perf_counter.h +5
-0+enum perf_event_types { +PERF_TYPE_HARDWARE =0 , +PERF_TYPE_SOFTWARE =1 , +PERF_TYPE_TRACEPOINT =2 , +};and get rid of the raw bit? That way, hw_event.raw_event is unique for every different event, whereas the way you have it, you still need to include the raw bit to get a unique id.
Ah, I thought we should keep a pure 64 bit raw value. You never know what hardware will do.
Re: [RFC][PATCH 09/11] perf_counter: revamp syscall input ABI
In reply to Paul MackerrasQuoted 5 lines · Paul Mackerras
Quoted 3 lines · Peter Zijlstra
The hardware/software classification in
hw_event->typebecame a little strained due to the addition of tracepoint tracing.
Quoted 8 lines
Quoted 2 lines
Instead split up the field and provide a type field to explicitly specify the counter type, while using the
event_idfield to specify which event to use.It would be nice if you didn't reuse the name 'type' but instead called the field something different ('class', perhaps?) to force a compile error on code that needs to be updated. For example, you missed a spot in
arch/powerpc/kernel/perf_counter.cand you need to add on the patch below. (Thanks for updating powerpc BTW.)
Yeah, thought of that after I did the patch... :-)
Thanks.
Re: [RFC][PATCH 09/11] perf_counter: revamp syscall input ABI
In reply to Peter ZijlstraQuoted 2 lines · Peter Zijlstra
Ah, I thought we should keep a pure 64 bit raw value. You never know what hardware will do.
Oh I see, you use hw_event->raw_event if hw_event->raw is set. I missed that before.
Still, you're putting that into hwc->config along with other bits like ARCH_PERFMON_EVENTSEL_USR and ARCH_PERFMON_EVENTSEL_OS, so I would think we could spare two bits for the type, leaving 62 bits for the raw event code. And if that isn't enough, there's the hw_event.extra_config_len field, which allows userspace to pass in arbitrary amounts of extra PMU configuration data.
Paul.
Re: [RFC][PATCH 09/11] perf_counter: revamp syscall input ABI
Quoted 8 lines · Paul Mackerras
Quoted 2 lines · Peter Zijlstra
Ah, I thought we should keep a pure 64 bit raw value. You never know what hardware will do.
Oh I see, you use
hw_event->raw_eventifhw_event->rawis set. I missed that before.
Quoted 6 lines
Still, you're putting that into
hwc->configalong with other bits likeARCH_PERFMON_EVENTSEL_USRandARCH_PERFMON_EVENTSEL_OS, so I would think we could spare two bits for the type, leaving 62 bits for the raw event code. And if that isn't enough, there's the hw_event.extra_config_len field, which allows userspace to pass in arbitrary amounts of extra PMU configuration data.
Good point, overflow interrupt, and usr/os/hv event filter and enable bits are usually in the config word.
OK, how about the below? I didn't cut it to 2 bits, as that would already exhaust the TYPE space -- then again, 60 does feel cramped a bit..
include/linux/perf_counter.h +9 -10
@@ -27,6 +27,12 @@ enum perf_event_types {PERF_TYPE_HARDWARE =0 ,PERF_TYPE_SOFTWARE =1 ,PERF_TYPE_TRACEPOINT =2 , + +/* +* available TYPE space, raw is the max value. +*/ + + PERF_TYPE_RAW = 15, };/*
@@ -79,14 +85,8 @@ enum perf_counter_record_type {* Hardware event to monitor via a performance monitoring counter: */ struct perf_counter_hw_event { -union { -__u64 raw_event; -struct { -__u64 event_id :32 , - type :8 , - __reserved_0 :24 ; - }; - }; +__u64 event_id :60 , + type :4 ;__u64 irq_period;__u64 record_type;
@@ -94,7 +94,6 @@ struct perf_counter_hw_event { __u64 disabled : 1, /* off by default */ nmi : 1, /* NMI sampling */ - raw : 1, /* raw event type */ inherit : 1, /* children inherit it */ pinned : 1, /* must always be on PMU */ exclusive : 1, /* only group on PMU */
@@ -103,7 +102,7 @@ struct perf_counter_hw_event { exclude_hv : 1, /* ditto hypervisor */ exclude_idle : 1, /* don't count when idle */ - __reserved_1 : 54; + __reserved_1 : 55;__u32 extra_config_len;__u32 __reserved_4;
Peter Zijlstra
maintainerRe: [RFC][PATCH 09/11] perf_counter: revamp syscall input ABI
Quoted 16 lines · Peter Zijlstra
Quoted 8 lines · Paul Mackerras
Quoted 2 lines · Peter Zijlstra
Ah, I thought we should keep a pure 64 bit raw value. You never know what hardware will do.
Oh I see, you use
hw_event->raw_eventifhw_event->rawis set. I missed that before.Quoted 6 lines
Still, you're putting that into
hwc->configalong with other bits likeARCH_PERFMON_EVENTSEL_USRandARCH_PERFMON_EVENTSEL_OS, so I would think we could spare two bits for the type, leaving 62 bits for the raw event code. And if that isn't enough, there's the hw_event.extra_config_len field, which allows userspace to pass in arbitrary amounts of extra PMU configuration data.
Quoted 6 lines
Good point, overflow interrupt, and
usr/os/hvevent filter and enable bits are usually in the config word.OK, how about the below? I didn't cut it to 2 bits, as that would already exhaust the TYPE space -- then again, 60 does feel cramped a bit..
Hmm, we could play dirty and do:
union {
struct {
__u64 raw_event_id : 63,
raw : 1;
};
struct {
__u64 event_id : 56,
type 8; };
};
Giving us 7 bit type space.