Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3808466pxv; Tue, 13 Jul 2021 04:23:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6sBAprQeH0eNL+yeMhgsImFj8vU/OGlWDFFfFsjpSoMZ4OLimuQK8HbNOx5RLTE/goRh4 X-Received: by 2002:a5d:974f:: with SMTP id c15mr2702518ioo.190.1626175421549; Tue, 13 Jul 2021 04:23:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626175421; cv=none; d=google.com; s=arc-20160816; b=Skp0aiq3iCJnJRGWr9dSCQ0WIA2eGUiMzCXpENh5bGx43O4cH8ky+ZvtPbPvAn8eq4 V6EBMaxsjOmHgXcSDwws800bStdKnphc7VeG+JGLUhBkhbayvaAeqF30sLgm+4Z2mTzI OEdf2cL3MUtouzuTd1grQtuqt1xkj4AeioAoKgjfEHq5SwzUrvj4LsvyIROSIIgSMKBQ Ry7EnEfiTUWbx+wZ0l01JO19A/vhPVvb0PoufWlnngAfNWFh9bp2cZo5bRkWzaVmQS4o ee2uuboAF8YRZcDT6qnFSDg+h8JJoMygcbvsnqPMTpPWM0Rdsv5DFuHN8ek/cSfkPysQ 6wmA== 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 :message-id:date:subject:cc:to:from; bh=EawvbB7PJXJKFDvL38mTTbf0o/q+v8LRQxaquIvrvGI=; b=WwforCowQD2Xr7VhMpaXZp+g6B8n6CInMgmIG1GMnPXa1CyvZndoZx82qf/0UZ5WYj BOKIQ31Vm1ixyInbxwuInv7C8cqkMJ2646zGvkB07rJvaN0a8DHR1UVR/m5pXtTl4YgG NeNljtdghequPkLmNR7R7OSAQeddMu84sdvOZat5zpmWDYEJ1AQI7yoZpE8Lu8dRVMBL MgSpvxlCFW9LMnTUgEviI4sNHCIIiTMWRQ3M8CxTYCoiLfQYA8OrMPRlTw7yayTIcD/s C/aRmYGlVXbL/F0bsk4q9YL8ZJuXC7ybL+dCRgI4dFYg+3jB51OrRufzOYhqFhyliQKv k39g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d6si20204912ilr.154.2021.07.13.04.23.29; Tue, 13 Jul 2021 04:23:41 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235574AbhGMLZr (ORCPT + 99 others); Tue, 13 Jul 2021 07:25:47 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:6809 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235413AbhGMLZr (ORCPT ); Tue, 13 Jul 2021 07:25:47 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GPJ4n2Z0czXs9R; Tue, 13 Jul 2021 19:17:13 +0800 (CST) Received: from dggpemm000003.china.huawei.com (7.185.36.128) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 13 Jul 2021 19:22:50 +0800 Received: from ubuntu1804.huawei.com (10.67.174.61) by dggpemm000003.china.huawei.com (7.185.36.128) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 13 Jul 2021 19:22:49 +0800 From: Yang Jihong To: , , , , , , , , , , CC: Subject: [PATCH] perf sched: Fix record failed when CONFIG_SCHEDSTATS is not set Date: Tue, 13 Jul 2021 19:23:58 +0800 Message-ID: <20210713112358.194693-1-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.61] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm000003.china.huawei.com (7.185.36.128) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 to be executed. 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 --- 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 954ce2f594e9..3e5b7faf0c16 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -3335,6 +3335,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; @@ -3346,21 +3356,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) @@ -3376,6 +3398,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.GIT