Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2140928rdb; Mon, 20 Nov 2023 03:16:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcNUfHEP+IUcZS8uZsXt8F3scAN4GLlmnChxZ4Foshk67HF4GavxRbYHGMQghi2PqUpjHM X-Received: by 2002:a05:6a20:a105:b0:187:6cc4:5aea with SMTP id q5-20020a056a20a10500b001876cc45aeamr5811190pzk.59.1700478988276; Mon, 20 Nov 2023 03:16:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700478988; cv=none; d=google.com; s=arc-20160816; b=lq6hkbxjkRirsDmHv0DCAxcn/4xV37VpUFXaJiEUXPZslGBym/D+uNObx7n0J1XRHN MqQUDgNiV/8q6VvQLkvQeG+iR+7AdbBPIJ4GnQA7seaSF0AcKukW80SYTwEwXB/f8w0D ddQkbW1R9ApiTbSKhcv/XZcpiTeBI4tgVrIT0H0bgVHyUINgr432u6fQiSqXkxQ9qBv+ CnfPgsOCKbZJVh/NIW8EH/F96ASc6w3BT80HOIoSjQEOhDS+RvesjbtT0x3PB1v2gtbg GhTG++wbjbw4arutxPC5kf4+3h6lr9/0C2wiMu9COmqZRPsDP2w7a9SlvP5ESfIp0R72 r4ZQ== 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 :dkim-signature; bh=d7ODxNUpHdLH8P991X/7ehIauOEhUSHEdtUxSPtxepk=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=CLAjgCdDZ4fd0eBWgeYcCPtABS6heMStzoXcJQdLhkyZs5aG39h9Pyt8DMyBH1LqjY Fc3N3nl1Z61eoKET+UlmPLsCPiAWgHxaXI4rLoJi/YGxHgQ9uO5OcrilH4yB7+Lm8EdC ceds0KTTAzg9tbAc0APLhrd6AyftSMcUhceFDo7e/UGgsunQnCNwtEly5y3ZNffU1Kaa l6NQDlukXEQdfkQt7HwwTbYrpeVUUr6hpMG0f3bOl0tml5EwB2FLaCgysD8ZWh5OvvYo nX+qKRcSFfDaHocjFNXgKsdDRR7PbCHMeoWH/YjrYflzu5skJozztzql56PnoeHUOmEU H8gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=goHGwo8o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id t9-20020a170902e84900b001bbd70bdffbsi8188469plg.440.2023.11.20.03.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:16:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=goHGwo8o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 883AE8045C7B; Mon, 20 Nov 2023 03:16:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233207AbjKTLPV (ORCPT + 99 others); Mon, 20 Nov 2023 06:15:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233216AbjKTLPD (ORCPT ); Mon, 20 Nov 2023 06:15:03 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCA50E8; Mon, 20 Nov 2023 03:14:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700478899; x=1732014899; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qJR3Yh1PCea2cKAo8n0ASNwzadHfHGi8AqwYXStWT1o=; b=goHGwo8oyJbPpNVFLIit4A8frys/wFErYMjByfgDNKMXb0rvutavFEfL 260alfSJJPIJfxxMzmgQIZegLF1kmhC14meZtCBK08iOdmsPrY4995npp aXMwvCRQfVnKmRPCEr3kO8gFIlDlQtyj53fmS1eaHGQZYvZZQ2am6ci8Q 92EuyvwkOu4dvTF2VY6WD4cFqI7iNfmOy2rVfRifpj0PZBBk17qBeIUJ8 6iIoFo7wOe8dAanwu0zSSNhpXHq76fYAbsN3HscITfNTMTqcK1SxU26cH wcxZVSOrCGwwVpcRb6OnWvsVaHyVYcpDwyxrTyz3rQFKQq8RXrQQBy7xq w==; X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="477808916" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="477808916" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 03:14:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="7523246" Received: from sc9itsct4906.amr.corp.intel.com (HELO localhost) ([10.249.46.107]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 03:14:55 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= , Fenghua Yu Cc: linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v2 08/26] selftests/resctrl: Split measure_cache_vals() Date: Mon, 20 Nov 2023 13:13:22 +0200 Message-Id: <20231120111340.7805-9-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231120111340.7805-1-ilpo.jarvinen@linux.intel.com> References: <20231120111340.7805-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 20 Nov 2023 03:16:17 -0800 (PST) measure_cache_vals() does a different thing depending on the test case that called it: - For CAT, it measures LLC misses through perf. - For CMT, it measures LLC occupancy through resctrl. Split these two functionalities into own functions the CAT and CMT tests can call directly. Replace passing the struct resctrl_val_param parameter with the filename because it's more generic and all those functions need out of resctrl_val. Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 66 ++++++++++++------- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrl_val.c | 2 +- 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index 8aa6d67db978..129d1c293518 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -147,7 +147,7 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy) * * Return: 0 on success. non-zero on failure. */ -static int print_results_cache(char *filename, int bm_pid, +static int print_results_cache(const char *filename, int bm_pid, unsigned long llc_value) { FILE *fp; @@ -169,35 +169,51 @@ static int print_results_cache(char *filename, int bm_pid, return 0; } -int measure_cache_vals(struct resctrl_val_param *param, int bm_pid) +/* + * perf_event_measure - Measure perf events + * @filename: Filename for writing the results + * @bm_pid: PID that runs the benchmark + * + * Measures perf events (e.g., cache misses) and writes the results into + * @filename. @bm_pid is written to the results file along with the measured + * value. + * + * Return: =0 on success. <0 on failure. + */ +static int perf_event_measure(const char *filename, int bm_pid) { - unsigned long llc_perf_miss = 0, llc_occu_resc = 0, llc_value = 0; + unsigned long llc_perf_miss = 0; int ret; - /* - * Measure cache miss from perf. - */ - if (!strncmp(param->resctrl_val, CAT_STR, sizeof(CAT_STR))) { - ret = get_llc_perf(&llc_perf_miss); - if (ret < 0) - return ret; - llc_value = llc_perf_miss; - } + ret = get_llc_perf(&llc_perf_miss); + if (ret < 0) + return ret; - /* - * Measure llc occupancy from resctrl. - */ - if (!strncmp(param->resctrl_val, CMT_STR, sizeof(CMT_STR))) { - ret = get_llc_occu_resctrl(&llc_occu_resc); - if (ret < 0) - return ret; - llc_value = llc_occu_resc; - } - ret = print_results_cache(param->filename, bm_pid, llc_value); - if (ret) + ret = print_results_cache(filename, bm_pid, llc_perf_miss); + return ret; +} + +/* + * measure_llc_resctrl - Measure resctrl llc value from resctrl + * @filename: Filename for writing the results + * @bm_pid: PID that runs the benchmark + * + * Measures llc occupancy from resctrl and writes the results into @filename. + * @bm_pid is written to the results file along with the measured value. + * + * Return: =0 on success. <0 on failure. + */ +int measure_llc_resctrl(const char *filename, int bm_pid) +{ + unsigned long llc_occu_resc = 0; + int ret; + + ret = get_llc_occu_resctrl(&llc_occu_resc); + if (ret < 0) return ret; - return 0; + ret = print_results_cache(filename, bm_pid, llc_occu_resc); + return ret; } /* @@ -252,7 +268,7 @@ int cat_val(struct resctrl_val_param *param, size_t span) } sleep(1); - ret = measure_cache_vals(param, bm_pid); + ret = perf_event_measure(param->filename, bm_pid); if (ret) goto pe_close; } diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index a911b08fa595..d35e3ba4dfa2 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -114,7 +114,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd); unsigned int count_bits(unsigned long n); void cmt_test_cleanup(void); int get_core_sibling(int cpu_no); -int measure_cache_vals(struct resctrl_val_param *param, int bm_pid); +int measure_llc_resctrl(const char *filename, int bm_pid); int show_cache_info(unsigned long sum_llc_val, int no_of_bits, size_t cache_span, unsigned long max_diff, unsigned long max_diff_percent, unsigned long num_of_runs, diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 88789678917b..a07ba336db48 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -830,7 +830,7 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par break; } else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) { sleep(1); - ret = measure_cache_vals(param, bm_pid); + ret = measure_llc_resctrl(param->filename, bm_pid); if (ret) break; } -- 2.30.2