Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf: Account freq events globally

Freq events may not always be affine to a particular CPU. As such,
account_event_cpu() may crash if we account per cpu a freq event
that has event->cpu == -1.

To solve this, lets account freq events globally. In practice
this doesn't change much the picture because perf tools create
per-task perf events with one event per CPU by default. Profiling a
single CPU is usually a corner case so there is no much point in
optimizing things that way.

Reported-by: Jiri Olsa <jolsa@redhat.com>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Tested-by: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Stephane Eranian <eranian@google.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1375460996-16329-3-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Frederic Weisbecker and committed by
Ingo Molnar
948b26b6 fc3b86d6

+8 -11
+8 -11
kernel/events/core.c
··· 141 141 struct static_key_deferred perf_sched_events __read_mostly; 142 142 static DEFINE_PER_CPU(atomic_t, perf_cgroup_events); 143 143 static DEFINE_PER_CPU(atomic_t, perf_branch_stack_events); 144 - static DEFINE_PER_CPU(atomic_t, perf_freq_events); 145 144 146 145 static atomic_t nr_mmap_events __read_mostly; 147 146 static atomic_t nr_comm_events __read_mostly; 148 147 static atomic_t nr_task_events __read_mostly; 148 + static atomic_t nr_freq_events __read_mostly; 149 149 150 150 static LIST_HEAD(pmus); 151 151 static DEFINE_MUTEX(pmus_lock); ··· 1871 1871 perf_pmu_enable(cpuctx->ctx.pmu); 1872 1872 perf_ctx_unlock(cpuctx, task_ctx); 1873 1873 1874 - if (atomic_read(&__get_cpu_var(perf_freq_events))) 1875 - tick_nohz_full_kick(); 1876 - 1877 1874 return 0; 1878 1875 } 1879 1876 ··· 2808 2811 #ifdef CONFIG_NO_HZ_FULL 2809 2812 bool perf_event_can_stop_tick(void) 2810 2813 { 2811 - if (atomic_read(&__get_cpu_var(perf_freq_events)) || 2814 + if (atomic_read(&nr_freq_events) || 2812 2815 __this_cpu_read(perf_throttled_count)) 2813 2816 return false; 2814 2817 else ··· 3137 3140 } 3138 3141 if (is_cgroup_event(event)) 3139 3142 atomic_dec(&per_cpu(perf_cgroup_events, cpu)); 3140 - 3141 - if (event->attr.freq) 3142 - atomic_dec(&per_cpu(perf_freq_events, cpu)); 3143 3143 } 3144 3144 3145 3145 static void unaccount_event(struct perf_event *event) ··· 3152 3158 atomic_dec(&nr_comm_events); 3153 3159 if (event->attr.task) 3154 3160 atomic_dec(&nr_task_events); 3161 + if (event->attr.freq) 3162 + atomic_dec(&nr_freq_events); 3155 3163 if (is_cgroup_event(event)) 3156 3164 static_key_slow_dec_deferred(&perf_sched_events); 3157 3165 if (has_branch_stack(event)) ··· 6485 6489 } 6486 6490 if (is_cgroup_event(event)) 6487 6491 atomic_inc(&per_cpu(perf_cgroup_events, cpu)); 6488 - 6489 - if (event->attr.freq) 6490 - atomic_inc(&per_cpu(perf_freq_events, cpu)); 6491 6492 } 6492 6493 6493 6494 static void account_event(struct perf_event *event) ··· 6500 6507 atomic_inc(&nr_comm_events); 6501 6508 if (event->attr.task) 6502 6509 atomic_inc(&nr_task_events); 6510 + if (event->attr.freq) { 6511 + if (atomic_inc_return(&nr_freq_events) == 1) 6512 + tick_nohz_full_kick_all(); 6513 + } 6503 6514 if (has_branch_stack(event)) 6504 6515 static_key_slow_inc(&perf_sched_events.key); 6505 6516 if (is_cgroup_event(event))