perf evsel: Fallback to task-clock when not system wide
Ian Rogers
reviewerRFC PATCH 1/1 perf evsel: Fallback to task-clock when not system wide
When the cycles event isn't available evsel will fallback to the cpu-clock software event. task-clock is similar to cpu-clock but only runs when the process is running. Falling back to cpu-clock when not system wide leads to confusion, by falling back to task-clock it is hoped the confusion is less.
Update a nearby comment and debug string for the change.
--- tools/perf/util/evsel.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
tools/perf/util/evsel.c +8 -7
@@ -2861,18 +2861,19 @@ bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize) evsel->core.attr.type == PERF_TYPE_HARDWARE && evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES) {/* -* If it's cycles then fall back to hrtimer based -* cpu-clock-tick sw counter, which is always available even if -* no PMU support. +* If it's cycles then fall back to hrtimer based cpu-clock sw +* counter, which is always available even if no PMU support. * * PPC returns ENXIO until 2.6.37 (behavior changed with commit * b0a873e). */ -scnprintf (msg, msgsize,"%s" , -"The cycles event is not supported, trying to fall back to cpu-clock-ticks" ); - evsel->core.attr.type =PERF_TYPE_SOFTWARE ; - evsel->core.attr.config =PERF_COUNT_SW_CPU_CLOCK ; + evsel->core.attr.config = evsel->core.system_wide + ?PERF_COUNT_SW_CPU_CLOCK + :PERF_COUNT_SW_TASK_CLOCK ; +scnprintf (msg, msgsize, +"The cycles event is not supported, trying to fall back to %s" , + evsel->core.system_wide ?"cpu-clock" :"task-clock" );zfree (&evsel->name);return true;
Signature · 1 line
2.43.0.rc0.421.g78406f8d94-goog
Namhyung Kim
maintainerHi Ian,
Quoted 6 lines · Ian Rogers
When the cycles event isn't available evsel will fallback to the cpu-clock software event. task-clock is similar to cpu-clock but only runs when the process is running. Falling back to cpu-clock when not system wide leads to confusion, by falling back to task-clock it is hoped the confusion is less.
I think they are almost the same and no meaningful difference. The cpu-clock event also runs only when the task is running if it's a per-task event.
Quoted 21 lines
Update a nearby comment and debug string for the change.
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/evsel.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)tools/perf/util/evsel.c +2
-3@@ -2861,18 +2861,19 @@ bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize) evsel->core.attr.type == PERF_TYPE_HARDWARE && evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES) {/* -* If it's cycles then fall back to hrtimer based -* cpu-clock-tick sw counter, which is always available even if -* no PMU support. +* If it's cycles then fall back to hrtimer based cpu-clock sw +* counter, which is always available even if no PMU support.
tools/perf/util/evsel.c bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize) · line 2871
Quoted 10 lines
tools/perf/util/evsel.c +1
-4* * PPC returns ENXIO until 2.6.37 (behavior changed with commit * b0a873e). */ -scnprintf (msg, msgsize,"%s" , -"The cycles event is not supported, trying to fall back to cpu-clock-ticks" ); - evsel->core.attr.type =PERF_TYPE_SOFTWARE ; - evsel->core.attr.config =PERF_COUNT_SW_CPU_CLOCK ; + evsel->core.attr.config = evsel->core.system_wide
I'm not sure you can use the system_wide flag for this. IIUC it's to override the target setting in some cases (e.g. a dummy event to track sideband events in all CPUs) and I think you need to check target__has_cpu() instead.
But as I said above, it won't make any difference in the output. Conceptually it'd be more natural to use task-clock event for per-task sessions though.
Thanks,
Namhyung
Quoted 11 lines
tools/perf/util/evsel.c +5
-1+ ? PERF_COUNT_SW_CPU_CLOCK + :PERF_COUNT_SW_TASK_CLOCK ; +scnprintf (msg, msgsize, +"The cycles event is not supported, trying to fall back to %s" , + evsel->core.system_wide ?"cpu-clock" :"task-clock" );zfree (&evsel->name);return true; --2.43.0.rc0.421.g78406f8d94-goog