From patchwork Thu Jul 27 08:28:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 126849 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp966992vqo; Thu, 27 Jul 2023 02:20:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlHwVIEYfpZRaeNqsn7zqn4H+NzwHtCvD0XQmZwTymFRg2LQC+vkhxHT8X51LIrw9Wa8KKK4 X-Received: by 2002:a05:6808:3092:b0:3a1:e59f:7582 with SMTP id bl18-20020a056808309200b003a1e59f7582mr2452565oib.49.1690449640120; Thu, 27 Jul 2023 02:20:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690449640; cv=none; d=google.com; s=arc-20160816; b=Iz8pPGcDJdKgG3p0KHk0pH1pOoyokpKZqvNqsZMwj/bgaOpDy9v+syqCAQCG+JuO0a Y9IDHGbu86k7OKBmvbYCExsOir6U17R9BxRemEq6Yb3yZTTOn9F1w5UWY36a2ANjls+N 6JxymSySotxq4sHfBv6a3WbFo3qAT37L1GavheZiKiZ8J64rJLYcG6KTiKneNj4eLz0X VjlCf9pX4xw4MU+vp0T0gBFhVKabdXMYMl0h/mHVYSUmxmDTvSvx7d0bHDUWnKCzfSbr 0wo9L2CSQ1+663bXKMpRa2IWPftP0qenGcpiYztC9NrPKB+2TaErt71Mm/fiMqhB9Bye nGjA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4WXuNiq2XksXyJcd/DafobBIKOIi9/bRrPT+S1CDZuE=; fh=ApeLdK2xurAeWAFDrmxfomKJVPpeLi5+JFM/i5kBxGg=; b=oreRFkHzJDXvXDKWfgQmipZ6BOLHFpiPIKSj9JQG6OZreenIzj5r8i875fuHHotQge urHVdbleZv+bsWXkVsWkuqzbsq7n4x3eeEqhsed8jpS9gy3+5l1iyA8w93hi8+RQh3kt OlaFoUQStH6fbNGQihS9/QQF4xLURIZMqGoq6zSdSsP7Y94gcvBrTnd5owVj/0z9I2fk 2goLYV+bHdpimkYEM4SOiE9n2hbqGCbKm17lSuAR/xFGrMZv9IHcNuNWK+nu6GZytH7+ 0ns7og904Wsqehh7lvSjNtg7NxlI/WAo0y+flE9G0EKCZhjiK1MfQ4Yv4AQ0oaBajtq3 fUqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 194-20020a6300cb000000b00563dd9b6da6si933427pga.718.2023.07.27.02.20.27; Thu, 27 Jul 2023 02:20:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233226AbjG0Ir0 (ORCPT + 99 others); Thu, 27 Jul 2023 04:47:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232861AbjG0IrF (ORCPT ); Thu, 27 Jul 2023 04:47:05 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B3249A9D; Thu, 27 Jul 2023 01:29:41 -0700 (PDT) Received: from kwepemi500013.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RBP6f3PQMz1GDM5; Thu, 27 Jul 2023 16:28:26 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemi500013.china.huawei.com (7.221.188.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 27 Jul 2023 16:29:19 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , , , Hui Wang , Changbin Du Subject: [PATCH v4 1/4] perf cpumap: Add __perf_cpu_map__new and perf_cpu_map__2_cpuset Date: Thu, 27 Jul 2023 16:28:49 +0800 Message-ID: <20230727082852.916093-2-changbin.du@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230727082852.916093-1-changbin.du@huawei.com> References: <20230727082852.916093-1-changbin.du@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.110.54.157] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500013.china.huawei.com (7.221.188.120) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772564922108659383 X-GMAIL-MSGID: 1772564922108659383 This adds two new api which will be used later. - __perf_cpu_map__new: accept a specified separator instead of ','. - perf_cpu_map__2_cpuset: convert perf_cpu_map to cpu_set_t. Signed-off-by: Changbin Du --- tools/lib/perf/cpumap.c | 45 ++++++++++++++++++++++++++-- tools/lib/perf/include/perf/cpumap.h | 4 +++ tools/lib/perf/libperf.map | 2 ++ tools/perf/tests/cpumap.c | 23 ++++++++++++++ 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 2a5a29217374..23e907078b28 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only +#define _GNU_SOURCE #include #include #include @@ -7,6 +8,7 @@ #include #include #include +#include #include #include @@ -201,7 +203,7 @@ static struct perf_cpu_map *cpu_map__read_all_cpu_map(void) return cpus; } -struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) +struct perf_cpu_map *__perf_cpu_map__new(const char *cpu_list, char sep) { struct perf_cpu_map *cpus = NULL; unsigned long start_cpu, end_cpu = 0; @@ -225,7 +227,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) p = NULL; start_cpu = strtoul(cpu_list, &p, 0); if (start_cpu >= INT_MAX - || (*p != '\0' && *p != ',' && *p != '-')) + || (*p != '\0' && *p != sep && *p != '-')) goto invalid; if (*p == '-') { @@ -233,7 +235,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) p = NULL; end_cpu = strtoul(cpu_list, &p, 0); - if (end_cpu >= INT_MAX || (*p != '\0' && *p != ',')) + if (end_cpu >= INT_MAX || (*p != '\0' && *p != sep)) goto invalid; if (end_cpu < start_cpu) @@ -278,6 +280,11 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) return cpus; } +struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) +{ + return __perf_cpu_map__new(cpu_list, ','); +} + static int __perf_cpu_map__nr(const struct perf_cpu_map *cpus) { return RC_CHK_ACCESS(cpus)->nr; @@ -479,3 +486,35 @@ struct perf_cpu_map *perf_cpu_map__intersect(struct perf_cpu_map *orig, free(tmp_cpus); return merged; } + +/* The caller is responsible for freeing returned cpu_set_t with CPU_FREE(). */ +cpu_set_t *perf_cpu_map__2_cpuset(struct perf_cpu_map *cpus, size_t *cpuset_size) +{ + cpu_set_t *cpusetp; + int max_cpu; + struct perf_cpu cpu; + int idx; + + if (perf_cpu_map__has_any_cpu(cpus)) + return NULL; + + max_cpu = perf_cpu_map__max(cpus).cpu; + if (max_cpu < 0) + return NULL; + + cpusetp = CPU_ALLOC(max_cpu + 1); + if (cpusetp == NULL) + return NULL; + + *cpuset_size = CPU_ALLOC_SIZE(max_cpu + 1); + CPU_ZERO_S(*cpuset_size, cpusetp); + + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + if (cpu.cpu == -1) + continue; + + CPU_SET_S(cpu.cpu, *cpuset_size, cpusetp); + } + + return cpusetp; +} diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h index e38d859a384d..1a0498f92dbe 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -3,6 +3,7 @@ #define __LIBPERF_CPUMAP_H #include +#include #include #include @@ -23,6 +24,7 @@ struct perf_cpu_map; */ LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void); LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void); +LIBPERF_API struct perf_cpu_map *__perf_cpu_map__new(const char *cpu_list, char sep); LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file); LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map); @@ -46,6 +48,8 @@ LIBPERF_API bool perf_cpu_map__equal(const struct perf_cpu_map *lhs, */ LIBPERF_API bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map); +LIBPERF_API cpu_set_t *perf_cpu_map__2_cpuset(struct perf_cpu_map *cpus, size_t *cpuset_size); + #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx); \ (idx) < perf_cpu_map__nr(cpus); \ diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index 190b56ae923a..fe0946e34471 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -5,6 +5,7 @@ LIBPERF_0.0.1 { perf_cpu_map__default_new; perf_cpu_map__get; perf_cpu_map__put; + __perf_cpu_map__new; perf_cpu_map__new; perf_cpu_map__read; perf_cpu_map__nr; @@ -12,6 +13,7 @@ LIBPERF_0.0.1 { perf_cpu_map__empty; perf_cpu_map__max; perf_cpu_map__has; + perf_cpu_map__2_cpuset; perf_thread_map__new_array; perf_thread_map__new_dummy; perf_thread_map__set_pid; diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c index 7730fc2ab40b..ae5e5337ea4f 100644 --- a/tools/perf/tests/cpumap.c +++ b/tools/perf/tests/cpumap.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "tests.h" +#include #include #include "cpumap.h" #include "event.h" @@ -247,12 +248,34 @@ static int test__cpu_map_equal(struct test_suite *test __maybe_unused, int subte return TEST_OK; } +static int test__cpu_map_convert(struct test_suite *test __maybe_unused, int subtest __maybe_unused) +{ + struct perf_cpu_map *any = perf_cpu_map__dummy_new(); + struct perf_cpu_map *cpus = perf_cpu_map__new("1-2"); + cpu_set_t *cpu_set; + size_t setsize; + + cpu_set = perf_cpu_map__2_cpuset(any, &setsize); + TEST_ASSERT_VAL("not equal", cpu_set == NULL); + CPU_FREE(cpu_set); + + cpu_set = perf_cpu_map__2_cpuset(cpus, &setsize); + TEST_ASSERT_VAL("cpus", cpu_set != NULL); + TEST_ASSERT_VAL("bad cpuset", !CPU_ISSET_S(0, setsize, cpu_set)); + TEST_ASSERT_VAL("bad cpuset", CPU_ISSET_S(1, setsize, cpu_set)); + TEST_ASSERT_VAL("bad cpuset", CPU_ISSET_S(2, setsize, cpu_set)); + CPU_FREE(cpu_set); + + return TEST_OK; +} + static struct test_case tests__cpu_map[] = { TEST_CASE("Synthesize cpu map", cpu_map_synthesize), TEST_CASE("Print cpu map", cpu_map_print), TEST_CASE("Merge cpu map", cpu_map_merge), TEST_CASE("Intersect cpu map", cpu_map_intersect), TEST_CASE("Equal cpu map", cpu_map_equal), + TEST_CASE("Convert cpu map", cpu_map_convert), { .name = NULL, } }; From patchwork Thu Jul 27 08:28:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 126851 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp966998vqo; Thu, 27 Jul 2023 02:20:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlFfsSxRSFwPpDlEgJPerZYLfsBKwS2HtGW2oose/A7C0WFsXu1H6mVepLkPjdrLAVVzRnlF X-Received: by 2002:a05:6808:181d:b0:3a5:a78b:f773 with SMTP id bh29-20020a056808181d00b003a5a78bf773mr3141075oib.6.1690449641080; Thu, 27 Jul 2023 02:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690449641; cv=none; d=google.com; s=arc-20160816; b=ab36KuH2QtQLjhX14Zt8s5boO31cm3jqnYhPJ/EuD5MtmoSZywWX0mhXyJqAVJE3m/ w2jqIBcNDLKY1ikLo5suU5nrJzhLDrVPzYfqlj7E/uhpnnVhjuHFxTc9L/N9IkL1snca bCalv3qsHn3HkoTmvhviRe6Sz7LZoGkWGmSzoH8hJbsgRsdQpACNcWq3HaNZPcUCuueY kkgcRrlyzEVImyr43+Od+0XcfGeXiP3pmV3gviYmKIuKdlMeaopewCby3Vx6FWwZ/fjZ odJRDOG44089lhT9p1S7Vo8MHHaoZgqEeDEjtz8j9ECa6UlKbDep/tED5vb9g3lii7F1 N1Kw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/QLyf8KCKKpL4YjCoaHue4vB2cz9dsxShGa028rT8yI=; fh=ONxpmEQdvUQImVsMkt7M9y+OmwTPKfkzew4GODFkEeE=; b=sUyIZhpYICr5eExrcDRg58jzr0kZbINI3FWvO3bjDGDhNh06+zwJl+I0efr+3BhmpI KvRlgvZYR5jzM5+oe34rTmLmTTgOgIxmxWAn2/8EtB32+VtRvVLR+gR+OWHz3u2w38HV Lf5D7eQBSTDaLGvrdqWlfDeEI2GJmijRYkJtiBCSl8vRVWqd2H/Qc090h9sqVLhHg2Gm btfIs3GsUwO6RtoN6AGoL0c/4eCnCYJATA1vldY45bZPxTFQHD5WnORi3Qal3bnu0Soo OAUq2kTxUbnd6PA5tgGB5DB4oMx2HmahrCSQcy5jW3SnJkEJw47LT4vDPITlXqgy5zOU j7Zw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t71-20020a63814a000000b00563e7aacaa1si979801pgd.393.2023.07.27.02.20.27; Thu, 27 Jul 2023 02:20:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233655AbjG0Irf (ORCPT + 99 others); Thu, 27 Jul 2023 04:47:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232904AbjG0IrG (ORCPT ); Thu, 27 Jul 2023 04:47:06 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9053F9C; Thu, 27 Jul 2023 01:29:42 -0700 (PDT) Received: from kwepemi500013.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RBP3y3CcKztRdX; Thu, 27 Jul 2023 16:26:06 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemi500013.china.huawei.com (7.221.188.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 27 Jul 2023 16:29:20 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , , , Hui Wang , Changbin Du , kernel test robot Subject: [PATCH v4 2/4] perf: add new option '--workload-attr' to set workload sched_policy/priority/cpumask Date: Thu, 27 Jul 2023 16:28:50 +0800 Message-ID: <20230727082852.916093-3-changbin.du@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230727082852.916093-1-changbin.du@huawei.com> References: <20230727082852.916093-1-changbin.du@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.110.54.157] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500013.china.huawei.com (7.221.188.120) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772564922383578967 X-GMAIL-MSGID: 1772564923175362954 To get consistent benchmarking results, sometimes we need to set the sched_policy/priority/cpumask of the workload to reduce system noise. For example, CPU binding is required on big.little system. $ perf stat -- taskset -c 0 ls Nevertheless, the 'taskset' is also counted here. To get away of the middleman, this adds a new option '--workload-attr' to do the same jobs for stat and record commands. $ sudo perf stat --workload-attr fifo,40,0-3:7 -- ls Above will make 'ls' run on CPU #0-#3 and #7 with fifo scheduler and realtime priority is 40. Cc: kernel test robot Signed-off-by: Changbin Du --- v2: Use cpu list spec instead of cpu mask number. --- tools/perf/Documentation/perf-record.txt | 7 ++ tools/perf/Documentation/perf-stat.txt | 6 ++ tools/perf/builtin-record.c | 26 +++++ tools/perf/builtin-stat.c | 18 ++++ tools/perf/util/evlist.c | 116 +++++++++++++++++++++++ tools/perf/util/evlist.h | 3 + tools/perf/util/target.h | 9 ++ 7 files changed, 185 insertions(+) diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index 137771b36578..8ee5d60225ec 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt @@ -843,6 +843,13 @@ filtered through the mask provided by -C option. only, as of now. So the applications built without the frame pointer might see bogus addresses. +--workload-attr :: + setup target workload (the ) attributes: + + sched_policy: other|fifo|rr|batch|idle + priority: scheduling priority for fifo|rr, nice value for other + cpu-list: CPU affinity. e.g. 1-2:4 is processors #1, #2, and #4 + include::intel-hybrid.txt[] SEE ALSO diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 8f789fa1242e..18d0f73458b1 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -262,6 +262,12 @@ disable events during measurements: wait -n ${perf_pid} exit $? +--workload-attr :: + setup target workload (the ) attributes: + + sched_policy: other|fifo|rr|batch|idle + priority: scheduling priority for fifo|rr, nice value for other + cpu-list: CPU affinity. e.g. 1-2:4 is processors #1, #2, and #4 --pre:: --post:: diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index aec18db7ff23..c16e230afcd5 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -3289,6 +3289,17 @@ static int parse_record_synth_option(const struct option *opt, return 0; } +static int record_parse_workload_attr_opt(const struct option *opt, + const char *arg, + int unset __maybe_unused) +{ + struct record_opts *opts = opt->value; + + return evlist__parse_workload_attr(arg, &opts->target.workload.sched_policy, + &opts->target.workload.sched_priority, + &opts->target.workload.cpu_map); +} + /* * XXX Ideally would be local to cmd_record() and passed to a record__new * because we need to have access to it in record__exit, that is called @@ -3309,6 +3320,8 @@ static struct record record = { .target = { .uses_mmap = true, .default_per_cpu = true, + .workload.sched_policy = -1, + .workload.sched_priority = 0, }, .mmap_flush = MMAP_FLUSH_DEFAULT, .nr_threads_synthesize = 1, @@ -3333,6 +3346,12 @@ static struct record record = { const char record_callchain_help[] = CALLCHAIN_RECORD_HELP "\n\t\t\t\tDefault: fp"; +const char record_workload_attr_help[] = + "setup target workload (the ) attributes:\n\n" + HELP_PAD "sched_policy: other|fifo|rr|batch|idle\n" + HELP_PAD "priority: scheduling priority for fifo|rr, nice value for other\n" + HELP_PAD "cpu-list: CPU affinity. e.g. 1-2:4 is processors #1, #2, and #4"; + static bool dry_run; static struct parse_events_option_args parse_events_option_args = { @@ -3551,6 +3570,9 @@ static struct option __record_options[] = { "write collected trace data into several data files using parallel threads", record__parse_threads), OPT_BOOLEAN(0, "off-cpu", &record.off_cpu, "Enable off-cpu analysis"), + OPT_CALLBACK(0, "workload-attr", &record.opts, + "sched_policy[,priority][,cpu-list]", record_workload_attr_help, + &record_parse_workload_attr_opt), OPT_END() }; @@ -4266,6 +4288,10 @@ int cmd_record(int argc, const char **argv) record__free_thread_masks(rec, rec->nr_threads); rec->nr_threads = 0; evlist__close_control(rec->opts.ctl_fd, rec->opts.ctl_fd_ack, &rec->opts.ctl_fd_close); + if (rec->opts.target.workload.cpu_map) { + perf_cpu_map__put(rec->opts.target.workload.cpu_map); + rec->opts.target.workload.cpu_map = NULL; + } return err; } diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 07b48f6df48e..bb755cb44103 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -108,6 +108,8 @@ static bool all_counters_use_bpf = true; static struct target target = { .uid = UINT_MAX, + .workload.sched_policy = -1, + .workload.sched_priority = 0, }; #define METRIC_ONLY_LEN 20 @@ -1160,6 +1162,14 @@ static int parse_cache_level(const struct option *opt, return 0; } +static int parse_workload_attr_opt(const struct option *opt __maybe_unused, const char *arg, + int unset __maybe_unused) +{ + return evlist__parse_workload_attr(arg, &target.workload.sched_policy, + &target.workload.sched_priority, + &target.workload.cpu_map); +} + static struct option stat_options[] = { OPT_BOOLEAN('T', "transaction", &transaction_run, "hardware transaction statistics"), @@ -1220,6 +1230,9 @@ static struct option stat_options[] = { OPT_BOOLEAN(0, "append", &append_file, "append to the output file"), OPT_INTEGER(0, "log-fd", &output_fd, "log output to fd, instead of stderr"), + OPT_CALLBACK(0, "workload-attr", &stat_config, + "sched_policy[,priority][,cpu-list]", record_workload_attr_help, + &parse_workload_attr_opt), OPT_STRING(0, "pre", &pre_cmd, "command", "command to run prior to the measured command"), OPT_STRING(0, "post", &post_cmd, "command", @@ -2893,5 +2906,10 @@ int cmd_stat(int argc, const char **argv) metricgroup__rblist_exit(&stat_config.metric_events); evlist__close_control(stat_config.ctl_fd, stat_config.ctl_fd_ack, &stat_config.ctl_fd_close); + if (target.workload.cpu_map) { + perf_cpu_map__put(target.workload.cpu_map); + target.workload.cpu_map = NULL; + } + return status; } diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 7ef43f72098e..6a9ff6a331aa 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -1398,6 +1399,118 @@ int evlist__open(struct evlist *evlist) return err; } +int evlist__parse_workload_attr(const char *str, int *sched_policy, int *sched_priority, + struct perf_cpu_map **cpu_map) +{ + char *tok, *saveptr = NULL; + char *buf; + int ret = -1; + + /* We need buffer that we know we can write to. */ + buf = strdup(str); + if (!buf) + return -ENOMEM; + + tok = strtok_r((char *)buf, ",", &saveptr); + do { + /* sched policy */ + if (!strncmp(tok, "other", sizeof("other"))) + *sched_policy = SCHED_OTHER; + else if (!strncmp(tok, "fifo", sizeof("fifo"))) { + *sched_policy = SCHED_FIFO; + /* default to lowest priority */ + *sched_priority = 99; + } else if (!strncmp(tok, "rr", sizeof("rr"))) { + *sched_policy = SCHED_RR; + *sched_priority = 99; + } else if (!strncmp(tok, "batch", sizeof("batch"))) + *sched_policy = SCHED_BATCH; + else if (!strncmp(tok, "idle", sizeof("idle"))) + *sched_policy = SCHED_IDLE; + else { + pr_err("workload_attr: unknown sched policy %s\n", tok); + break; + } + + /* sched priority */ + tok = strtok_r(NULL, ",", &saveptr); + if (tok) { + int priority; + char *endptr; + + priority = strtol(tok, &endptr, 0); + if (*endptr) { + pr_err("workload_attr: invalid sched priority %s\n", tok); + break; + } + + if (*sched_policy == SCHED_FIFO || *sched_policy == SCHED_RR) { + if (priority < 1 || priority > 99) { + pr_err("workload_attr: invalid priority %d for fifo and rr, allowed [1,99]\n", + priority); + break; + } + } + *sched_priority = priority; + } + + /* cpu list */ + tok = strtok_r(NULL, ",", &saveptr); + if (tok) { + *cpu_map = __perf_cpu_map__new(tok, ':'); + if (!*cpu_map) { + pr_err("workload_attr: failed to get cpus map from %s\n", tok); + break; + } + } + ret = 0; + } while (0); + + free(buf); + return ret; +} + +static int setup_workload_attr(struct target *target) +{ + struct sched_param param; + int policy = target->workload.sched_policy; + int priority = target->workload.sched_priority; + + if (policy >= 0) { + param.sched_priority = (policy == SCHED_FIFO || policy == SCHED_RR) ? + priority : 0; + if (sched_setscheduler(0, policy, ¶m) != 0) { + perror("failed to set the sched policy"); + return -1; + } + + if (policy == SCHED_OTHER) { + if (setpriority(PRIO_PROCESS, 0, priority) != 0) { + perror("failed to set the nice value"); + return -1; + } + } + } + + if (target->workload.cpu_map) { + size_t cpuset_size = -1; + cpu_set_t *cpu_set; + + cpu_set = perf_cpu_map__2_cpuset(target->workload.cpu_map, &cpuset_size); + if (!cpu_set) + return -1; + + if (sched_setaffinity(0, cpuset_size, cpu_set) != 0) { + perror("failed to set the sched affinity"); + CPU_FREE(cpu_set); + return -1; + } + CPU_FREE(cpu_set); + } + + return 0; +} + int evlist__prepare_workload(struct evlist *evlist, struct target *target, const char *argv[], bool pipe_output, void (*exec_error)(int signo, siginfo_t *info, void *ucontext)) { @@ -1464,6 +1577,9 @@ int evlist__prepare_workload(struct evlist *evlist, struct target *target, const exit(ret); } + if (setup_workload_attr(target) != 0) + exit(-1); + execvp(argv[0], (char **)argv); if (exec_error) { diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 664c6bf7b3e0..761ae102dda6 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -15,6 +15,7 @@ #include #include #include +#include struct pollfd; struct thread_map; @@ -180,6 +181,8 @@ void evlist__set_id_pos(struct evlist *evlist); void evlist__config(struct evlist *evlist, struct record_opts *opts, struct callchain_param *callchain); int record_opts__config(struct record_opts *opts); +int evlist__parse_workload_attr(const char *str, int *sched_policy, int *sched_priority, + struct perf_cpu_map **cpu_set); int evlist__prepare_workload(struct evlist *evlist, struct target *target, const char *argv[], bool pipe_output, void (*exec_error)(int signo, siginfo_t *info, void *ucontext)); diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h index d582cae8e105..16fe33dda2ef 100644 --- a/tools/perf/util/target.h +++ b/tools/perf/util/target.h @@ -4,6 +4,7 @@ #include #include +#include struct target { const char *pid; @@ -19,6 +20,12 @@ struct target { bool use_bpf; int initial_delay; const char *attr_map; + + struct { + int sched_policy; + int sched_priority; + struct perf_cpu_map *cpu_map; + } workload; }; enum target_errno { @@ -103,4 +110,6 @@ static inline bool target__uses_dummy_map(struct target *target) return use_dummy; } +extern const char record_workload_attr_help[]; + #endif /* _PERF_TARGET_H */ From patchwork Thu Jul 27 08:28:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 126870 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp979317vqo; Thu, 27 Jul 2023 02:49:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlHIkMrygdM4305/wqMRwvhUFqyEyhdFpmmrCwoKAqy2FOWRk4hqeHCvaJ7sXMfjhgi/21JA X-Received: by 2002:a05:6a20:9388:b0:123:4ffe:4018 with SMTP id x8-20020a056a20938800b001234ffe4018mr5979584pzh.60.1690451387227; Thu, 27 Jul 2023 02:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690451387; cv=none; d=google.com; s=arc-20160816; b=HbXwo31NeaeNTO5t5vbKlXokHGu/HHDgUrwli3+xWpAtNmzoYSpQg9oZBC67j7vVP9 cTdzbasXhTM23Xo7rPH2kWSp0425kfmVNksdO8ukANPSW3Ht6k/n/poyB/QMb7mR7omP Mma24XYwtIUb0acBHUUnvL0awt/OhBriX2kH0RW7Kb2YlsKts5N/0gcAOrRbKoG0p9xl mfk/PbvXlunN5yj+eIDtx0kIoF9K04WK/DqRhv5nql56HK5VgBpT1alZn6Nx9OAO3TAH iJyMLsKStIyQOFcrVa+el6RleZLQOczSd6EN78ZhpYuFv6sAxacbGLdCaX47M3ImlzED finw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=71VE8a/1Tx49GpbNs96CsMzbmBJ+k4OzpaO5mZwJ58g=; fh=ApeLdK2xurAeWAFDrmxfomKJVPpeLi5+JFM/i5kBxGg=; b=yxgFncjQHtSw9yLa23DzcTh5n177QUSm+sQZgJDG+qQFoaPMV3sg2nVjqJibIK5Ih8 KpyZ0huE0wbJ+85HfInXaV+tUINc2SlciHUu0yAa7kgFv5o11pI7Z9iemsZfTdMBWsMq S88g3vXZLaEx63FKb5C3aUtf3/9pkJKDqx0OGlAw5jp4MbjLJ4Z2kp1uZk6Go9TFcsYW 7jqczY2zHeLoN6w68nCdK7kXlD3M5hsRGCYofuqUaT0k5OZLTzir1FbNa+x7+B9MRQXA I5M117d5PoXngedv3Thq3/lH7MySHCNzwamldhye6xnLRJvSPMT+LXkv6wsTSk1AZkWm gBvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 187-20020a6300c4000000b0055bdec69c2fsi1007249pga.260.2023.07.27.02.49.34; Thu, 27 Jul 2023 02:49:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233003AbjG0IrX (ORCPT + 99 others); Thu, 27 Jul 2023 04:47:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234000AbjG0IrE (ORCPT ); Thu, 27 Jul 2023 04:47:04 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11E7049C2; Thu, 27 Jul 2023 01:29:42 -0700 (PDT) Received: from kwepemi500013.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RBP3q4CL4zNmZN; Thu, 27 Jul 2023 16:25:59 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemi500013.china.huawei.com (7.221.188.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 27 Jul 2023 16:29:21 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , , , Hui Wang , Changbin Du Subject: [PATCH v4 3/4] perf: replace taskset with --workload-attr option Date: Thu, 27 Jul 2023 16:28:51 +0800 Message-ID: <20230727082852.916093-4-changbin.du@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230727082852.916093-1-changbin.du@huawei.com> References: <20230727082852.916093-1-changbin.du@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.110.54.157] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500013.china.huawei.com (7.221.188.120) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772566753452579593 X-GMAIL-MSGID: 1772566753452579593 Replace the taskset with our new option --workload-attr. Signed-off-by: Changbin Du --- tools/perf/Documentation/intel-hybrid.txt | 2 +- tools/perf/Documentation/perf-stat.txt | 2 +- tools/perf/tests/shell/stat_bpf_counters_cgrp.sh | 2 +- tools/perf/tests/shell/test_arm_coresight.sh | 2 +- tools/perf/tests/shell/test_data_symbol.sh | 2 +- tools/perf/tests/shell/test_intel_pt.sh | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/perf/Documentation/intel-hybrid.txt b/tools/perf/Documentation/intel-hybrid.txt index e7a776ad25d7..b4adb1eeba3f 100644 --- a/tools/perf/Documentation/intel-hybrid.txt +++ b/tools/perf/Documentation/intel-hybrid.txt @@ -132,7 +132,7 @@ displayed. The percentage is the event's running time/enabling time. One example, 'triad_loop' runs on cpu16 (atom core), while we can see the scaled value for core cycles is 160,444,092 and the percentage is 0.47%. -perf stat -e cycles \-- taskset -c 16 ./triad_loop +perf stat -e cycles --workload-attr other,0,16 \-- ./triad_loop As previous, two events are created. diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 18d0f73458b1..fb52ddcea622 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -464,7 +464,7 @@ on workload with changing phases. To interpret the results it is usually needed to know on which CPUs the workload runs on. If needed the CPUs can be forced using -taskset. +--workload-attr option. --td-level:: Print the top-down statistics that equal the input level. It allows diff --git a/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh b/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh index d724855d097c..b13bf391b137 100755 --- a/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh +++ b/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh @@ -64,7 +64,7 @@ check_cpu_list_counted() { local output - output=$(perf stat -C 1 --bpf-counters --for-each-cgroup ${test_cgroups} -e cpu-clock -x, taskset -c 1 sleep 1 2>&1) + output=$(perf stat -C 1 --bpf-counters --for-each-cgroup ${test_cgroups} -e cpu-clock -x, --workload-attr other,0,1 -- sleep 1 2>&1) if echo ${output} | grep -q -F " $1" rm -f $file perf record -o ${perfdata} -e cs_etm/@$1/u --per-thread \ - -- taskset -c $2 touch $file > /dev/null 2>&1 + --workload-attr other,0,$2 -- touch $file > /dev/null 2>&1 } perf_script_branch_samples() { diff --git a/tools/perf/tests/shell/test_data_symbol.sh b/tools/perf/tests/shell/test_data_symbol.sh index 69bb6fe86c50..02c6a97e3d0f 100755 --- a/tools/perf/tests/shell/test_data_symbol.sh +++ b/tools/perf/tests/shell/test_data_symbol.sh @@ -50,7 +50,7 @@ echo "Recording workload..." # specific CPU and test in per-CPU mode. is_amd=$(grep -E -c 'vendor_id.*AuthenticAMD' /proc/cpuinfo) if (($is_amd >= 1)); then - perf mem record -o ${PERF_DATA} -C 0 -- taskset -c 0 $TEST_PROGRAM & + perf mem record -o ${PERF_DATA} -C 0 --workload-attr other,0,0 -- $TEST_PROGRAM & else perf mem record --all-user -o ${PERF_DATA} -- $TEST_PROGRAM & fi diff --git a/tools/perf/tests/shell/test_intel_pt.sh b/tools/perf/tests/shell/test_intel_pt.sh index 3a8b9bffa022..0dc085c72593 100755 --- a/tools/perf/tests/shell/test_intel_pt.sh +++ b/tools/perf/tests/shell/test_intel_pt.sh @@ -110,7 +110,7 @@ test_system_wide_side_band() can_cpu_wide 1 || return $? # Record on CPU 0 a task running on CPU 1 - perf_record_no_decode -o "${perfdatafile}" -e intel_pt//u -C 0 -- taskset --cpu-list 1 uname + perf_record_no_decode -o "${perfdatafile}" -e intel_pt//u -C 0 --workload-attr other,0,1 -- uname # Should get MMAP events from CPU 1 because they can be needed to decode mmap_cnt=$(perf script -i "${perfdatafile}" --no-itrace --show-mmap-events -C 1 2>/dev/null | grep -c MMAP) From patchwork Thu Jul 27 08:28:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 126850 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp966999vqo; Thu, 27 Jul 2023 02:20:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlEEhxbownPJICV2NRLRJG5Y5jbKI/omku1BoiSbpTOSGGzkAc9j3oJbG8Y01GqjN/zsotIE X-Received: by 2002:a05:6a00:3a1f:b0:682:4c9f:aa0 with SMTP id fj31-20020a056a003a1f00b006824c9f0aa0mr5431439pfb.29.1690449641091; Thu, 27 Jul 2023 02:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690449641; cv=none; d=google.com; s=arc-20160816; b=QbJhhlkD3UotKibNx5E3q5FZvYMV/5uRJ7C4QRy5kMlQaVR2w+3IvKdyPnrZz7Om66 E9VqVcf56+3hbouTmWQ1vkD16wJfkazTbCcyxtaUGJCDzxpQlzS6m2e2Wy8GBdKgcSEd UR4HTvUudbbWJWTS4HPVEYkdgB1q6Kup2hGfKZX6FYMovJ/N4MVAWh/46D7c3rqI8Y7H hf5vSgzAifFn4V4yzwJkqyF2AMFnkPvFgWE5h4rVAwJ2LSPzRZeNcNV/3UmrDV7gRHhE R0ZJL6Ccb1wkTSfeNUOriR2jrwcnd2D+SJcwMeHfNYqegpgEmh7CGeXPkDKoc9kW8US6 sKdQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ZdSWka75n6AHHN16zmq/6K9spymduaQMNA87WghEJoM=; fh=ApeLdK2xurAeWAFDrmxfomKJVPpeLi5+JFM/i5kBxGg=; b=n7O9nV7RrX5dZR0smOYa1iaKQkvnQVntVZRZhyZHu2m2S/w8uToottUubs1CkwAFk3 9WxW30wlQNssYEXW3+5zZjaVVQFuwbhbvq4FLeRAWDGtkPDylCJHH2I3Xgejs08gsn9B 10oZ4qUDoAqD6biOhwqFCPuce/yAnXIi+l8ZQpEIvGHeEpmRoilp9Rrlisbn/d6nyTNo PTVhe5/FxZA2xsN+EzlcKpWf+zGip/VxNRm/6HMxKIiUo11dSyCVMoBBDAvzSCK5hG9e VShN6cdLlJ7QEHZdhBURjgyiQ7s1dg7Ymc0jJYFKku8MPhm5w+MT9IpMNLUIc5Cib06t T44w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020a635545000000b0056399efdbdcsi936698pgm.846.2023.07.27.02.20.27; Thu, 27 Jul 2023 02:20:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234181AbjG0Iri (ORCPT + 99 others); Thu, 27 Jul 2023 04:47:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232941AbjG0IrG (ORCPT ); Thu, 27 Jul 2023 04:47:06 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42EAE9A9F; Thu, 27 Jul 2023 01:29:44 -0700 (PDT) Received: from kwepemi500013.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RBP404xWWztRdS; Thu, 27 Jul 2023 16:26:08 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemi500013.china.huawei.com (7.221.188.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 27 Jul 2023 16:29:22 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , , , Hui Wang , Changbin Du Subject: [PATCH v4 4/4] perf test: add test case for --workload-attr option Date: Thu, 27 Jul 2023 16:28:52 +0800 Message-ID: <20230727082852.916093-5-changbin.du@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230727082852.916093-1-changbin.du@huawei.com> References: <20230727082852.916093-1-changbin.du@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.110.54.157] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500013.china.huawei.com (7.221.188.120) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772564922905751482 X-GMAIL-MSGID: 1772564922905751482 Ensure the sched attributes are applied to workload. Signed-off-by: Changbin Du --- tools/perf/tests/shell/stat.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/perf/tests/shell/stat.sh b/tools/perf/tests/shell/stat.sh index 3f1e67795490..b2279f118a97 100755 --- a/tools/perf/tests/shell/stat.sh +++ b/tools/perf/tests/shell/stat.sh @@ -16,6 +16,24 @@ test_default_stat() { echo "Basic stat command test [Success]" } +test_stat_workload_attr() { + echo "stat with --workload-attr test" + if ! perf stat --workload-attr other,10,1 -- bash -c 'taskset -pc $$' 2>&1 | grep -E -q "current affinity list: 1" + then + echo "stat with --workload-attr test [Failed]" + err=1 + return + fi + + if ! perf stat --workload-attr other,10,1 -- bash -c 'ps -o pid,cls,ni,cmd -p $$' 2>&1 | grep -E -q "TS\s+10" + then + echo "stat with --workload-attr test [Failed]" + err=1 + return + fi + echo "stat with --workload-attr test [Success]" +} + test_stat_record_report() { echo "stat record and report test" if ! perf stat record -o - true | perf stat report -i - 2>&1 | \ @@ -147,6 +165,7 @@ test_cputype() { } test_default_stat +test_stat_workload_attr test_stat_record_report test_stat_record_script test_stat_repeat_weak_groups