Skip to content

Commit 57efe4f

Browse files
Yang Jihonggregkh
authored andcommitted
perf sched: Fix record failure when CONFIG_SCHEDSTATS is not set
[ Upstream commit b0f0085 ] The tracepoints trace_sched_stat_{wait, sleep, iowait} are not exposed to user if CONFIG_SCHEDSTATS is not set, "perf sched record" records the three events. As a result, the command fails. Before: #perf sched record sleep 1 event syntax error: 'sched:sched_stat_wait' \___ unknown tracepoint Error: File /sys/kernel/tracing/events/sched/sched_stat_wait not found. Hint: Perhaps this kernel misses some CONFIG_ setting to enable this feature?. Run 'perf list' for a list of valid events Usage: perf record [<options>] [<command>] or: perf record [<options>] -- <command> [<options>] -e, --event <event> event selector. use 'perf list' to list available events Solution: Check whether schedstat tracepoints are exposed. If no, these events are not recorded. After: # perf sched record sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.163 MB perf.data (1091 samples) ] # perf sched report run measurement overhead: 4736 nsecs sleep measurement overhead: 9059979 nsecs the run test took 999854 nsecs the sleep test took 8945271 nsecs nr_run_events: 716 nr_sleep_events: 785 nr_wakeup_events: 0 ... ------------------------------------------------------------ Fixes: 2a09b5d ("sched/fair: do not expose some tracepoints to user if CONFIG_SCHEDSTATS is not set") Signed-off-by: Yang Jihong <yangjihong1@huawei.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt (VMware) <rostedt@goodmis.org> Cc: Yafang Shao <laoar.shao@gmail.com> Link: http://lore.kernel.org/lkml/20210713112358.194693-1-yangjihong1@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 61f2e1e commit 57efe4f

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

‎tools/perf/builtin-sched.c‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,6 +3337,16 @@ static void setup_sorting(struct perf_sched *sched, const struct option *options
33373337
sort_dimension__add("pid", &sched->cmp_pid);
33383338
}
33393339

3340+
static bool schedstat_events_exposed(void)
3341+
{
3342+
/*
3343+
* Select "sched:sched_stat_wait" event to check
3344+
* whether schedstat tracepoints are exposed.
3345+
*/
3346+
return IS_ERR(trace_event__tp_format("sched", "sched_stat_wait")) ?
3347+
false : true;
3348+
}
3349+
33403350
static int __cmd_record(int argc, const char **argv)
33413351
{
33423352
unsigned int rec_argc, i, j;
@@ -3348,21 +3358,33 @@ static int __cmd_record(int argc, const char **argv)
33483358
"-m", "1024",
33493359
"-c", "1",
33503360
"-e", "sched:sched_switch",
3351-
"-e", "sched:sched_stat_wait",
3352-
"-e", "sched:sched_stat_sleep",
3353-
"-e", "sched:sched_stat_iowait",
33543361
"-e", "sched:sched_stat_runtime",
33553362
"-e", "sched:sched_process_fork",
33563363
"-e", "sched:sched_wakeup_new",
33573364
"-e", "sched:sched_migrate_task",
33583365
};
3366+
3367+
/*
3368+
* The tracepoints trace_sched_stat_{wait, sleep, iowait}
3369+
* are not exposed to user if CONFIG_SCHEDSTATS is not set,
3370+
* to prevent "perf sched record" execution failure, determine
3371+
* whether to record schedstat events according to actual situation.
3372+
*/
3373+
const char * const schedstat_args[] = {
3374+
"-e", "sched:sched_stat_wait",
3375+
"-e", "sched:sched_stat_sleep",
3376+
"-e", "sched:sched_stat_iowait",
3377+
};
3378+
unsigned int schedstat_argc = schedstat_events_exposed() ?
3379+
ARRAY_SIZE(schedstat_args) : 0;
3380+
33593381
struct tep_event *waking_event;
33603382

33613383
/*
33623384
* +2 for either "-e", "sched:sched_wakeup" or
33633385
* "-e", "sched:sched_waking"
33643386
*/
3365-
rec_argc = ARRAY_SIZE(record_args) + 2 + argc - 1;
3387+
rec_argc = ARRAY_SIZE(record_args) + 2 + schedstat_argc + argc - 1;
33663388
rec_argv = calloc(rec_argc + 1, sizeof(char *));
33673389

33683390
if (rec_argv == NULL)
@@ -3378,6 +3400,9 @@ static int __cmd_record(int argc, const char **argv)
33783400
else
33793401
rec_argv[i++] = strdup("sched:sched_wakeup");
33803402

3403+
for (j = 0; j < schedstat_argc; j++)
3404+
rec_argv[i++] = strdup(schedstat_args[j]);
3405+
33813406
for (j = 1; j < (unsigned int)argc; j++, i++)
33823407
rec_argv[i] = argv[j];
33833408

0 commit comments

Comments
 (0)