Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3712697pxv; Mon, 26 Jul 2021 10:02:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTl/pydjggWBal/ynOrA+cEJZ18N4/cJ2Md9RW86aih1GWUHnr1vtUDwCctoKTnpc+/Jb0 X-Received: by 2002:a92:d3d1:: with SMTP id c17mr13273111ilh.86.1627318920212; Mon, 26 Jul 2021 10:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627318920; cv=none; d=google.com; s=arc-20160816; b=0QMIEk00EheFwhNQrSOT2bVMhPzxMun+9SzxdIbFOe9Yll6qA6gTXeNZ102ov7CNnY K+vn5GzaoEFb1AIqN5eIvu0MAO+5shHIGNJ00hBAHvD/ZZRQKxFc98Du9rXQOu6wgQZX mKJlrvcidTLrlodxJDx8JT+01Qhj8AkzPI9XVCoLJL9MFWka0DpYB7rJSFY8HYPTkuCm ggrdCQwC9sJz9jXdvIrJmN3Xjw2ojznm/M+FfMpVbY91ObCYAc8gQSAnir3D6xbbB+Aq rs6y7NAoSu6XG8CxmRBrWbOIRa9FdnxT5pSbHi1lRhaT81qQ0/7pmN+dQ3qGw7nI7Ko8 cKlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sKNHOrZS1TKgszHAOvhKD8ZdU58vTudSZryk6Hhh6No=; b=NGN39WOVTb1qmpZ+4E6U9QcE+ghJHfvEUrJ/Wi+36NBtBAbFBSdwusaI0fKtZWDawG U3UNWV/2+ejpvqQpZdi0i29W0NdKnhzGY3BqtW8tlTVvwnlJVvn0Ab6vQUaEqgP4qMZE 8cgolePTLljqJlo2/yVP8nIU4GWLrsrtNhvMK5sIiZOWkcx74jPpoDQBikOwan1HRzEp M2hZ/EssW9JmVv/xAUvsbhp30iLRIm4bdMKSuqJ6fsruobEYPxyH0/bRtOx0UOtGCVDn 5m4GDmdtvQNo4Erphd3+g6SSNjqSZqQuyhNxMvfxmF3igpGSmDIb80aDb6ui9jlPeYol ECBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wJqU7eD/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 7si412714ilx.20.2021.07.26.10.01.48; Mon, 26 Jul 2021 10:02:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wJqU7eD/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234731AbhGZPhH (ORCPT + 99 others); Mon, 26 Jul 2021 11:37:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:35502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237178AbhGZPVV (ORCPT ); Mon, 26 Jul 2021 11:21:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 46F2D61037; Mon, 26 Jul 2021 16:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315310; bh=pWl8n2vIRJUpmu1xxlkutJC4RwJu6aIIgdtM3BB5MBw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wJqU7eD/HaQvbCDjCIdXNzYX33vHcc9URMPCmYRZNhP9i6uA3tyXA9MjW5A0xl0qV OOCJ4EGPLJ0BwOU/5SQNuiy+QCZua0n+lLvMXM9gKgHQcL8VNvY7sw88InAuLMxXv3 eqUHrN5LJe6vjsP3Ek5lXMucCUNEH0feh9X/cs74= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yang Jihong , Alexander Shishkin , Jiri Olsa , Mark Rutland , Namhyung Kim , Peter Zijlstra , "Steven Rostedt (VMware)" , Yafang Shao , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.10 047/167] perf sched: Fix record failure when CONFIG_SCHEDSTATS is not set Date: Mon, 26 Jul 2021 17:38:00 +0200 Message-Id: <20210726153840.972990128@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153839.371771838@linuxfoundation.org> References: <20210726153839.371771838@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yang Jihong [ Upstream commit b0f008551f0bf4d5f6db9b5f0e071b02790d6a2e ] 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 [] [] or: perf record [] -- [] -e, --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: 2a09b5de235a6 ("sched/fair: do not expose some tracepoints to user if CONFIG_SCHEDSTATS is not set") Signed-off-by: Yang Jihong Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Steven Rostedt (VMware) Cc: Yafang Shao Link: http://lore.kernel.org/lkml/20210713112358.194693-1-yangjihong1@huawei.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/builtin-sched.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 0e16f9d5a947..d3b5f5faf8c1 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -3337,6 +3337,16 @@ static void setup_sorting(struct perf_sched *sched, const struct option *options sort_dimension__add("pid", &sched->cmp_pid); } +static bool schedstat_events_exposed(void) +{ + /* + * Select "sched:sched_stat_wait" event to check + * whether schedstat tracepoints are exposed. + */ + return IS_ERR(trace_event__tp_format("sched", "sched_stat_wait")) ? + false : true; +} + static int __cmd_record(int argc, const char **argv) { unsigned int rec_argc, i, j; @@ -3348,21 +3358,33 @@ static int __cmd_record(int argc, const char **argv) "-m", "1024", "-c", "1", "-e", "sched:sched_switch", - "-e", "sched:sched_stat_wait", - "-e", "sched:sched_stat_sleep", - "-e", "sched:sched_stat_iowait", "-e", "sched:sched_stat_runtime", "-e", "sched:sched_process_fork", "-e", "sched:sched_wakeup_new", "-e", "sched:sched_migrate_task", }; + + /* + * The tracepoints trace_sched_stat_{wait, sleep, iowait} + * are not exposed to user if CONFIG_SCHEDSTATS is not set, + * to prevent "perf sched record" execution failure, determine + * whether to record schedstat events according to actual situation. + */ + const char * const schedstat_args[] = { + "-e", "sched:sched_stat_wait", + "-e", "sched:sched_stat_sleep", + "-e", "sched:sched_stat_iowait", + }; + unsigned int schedstat_argc = schedstat_events_exposed() ? + ARRAY_SIZE(schedstat_args) : 0; + struct tep_event *waking_event; /* * +2 for either "-e", "sched:sched_wakeup" or * "-e", "sched:sched_waking" */ - rec_argc = ARRAY_SIZE(record_args) + 2 + argc - 1; + rec_argc = ARRAY_SIZE(record_args) + 2 + schedstat_argc + argc - 1; rec_argv = calloc(rec_argc + 1, sizeof(char *)); if (rec_argv == NULL) @@ -3378,6 +3400,9 @@ static int __cmd_record(int argc, const char **argv) else rec_argv[i++] = strdup("sched:sched_wakeup"); + for (j = 0; j < schedstat_argc; j++) + rec_argv[i++] = strdup(schedstat_args[j]); + for (j = 1; j < (unsigned int)argc; j++, i++) rec_argv[i] = argv[j]; -- 2.30.2