From patchwork Mon Dec 11 12:18:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 176659 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7002573vqy; Mon, 11 Dec 2023 04:20:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFywt15KV8pBdv23zxuR6EQ11R79IimZyBUmGjxSg4TKlh9DUHullELNdGWETxwGOxGcQPA X-Received: by 2002:a05:6e02:216b:b0:35d:54cc:1df4 with SMTP id s11-20020a056e02216b00b0035d54cc1df4mr6663062ilv.19.1702297255653; Mon, 11 Dec 2023 04:20:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702297255; cv=none; d=google.com; s=arc-20160816; b=MqOYq+vnpXUi96JoxjWVXzKGGWlQ2yKWIX/1HPHIrDTaA6C67dc+b6uqU1QY9zRkI8 w63LE0lS5fr1tr7l2vDbhwwV/tFwcp8WV5KZ4ZesmLGC1cqWIwfsJGqknuFgvE95q3Et 5YN6v+G1PSpgT417wUJ93h+3a1K4Us+/P/Yk3k5705c9Ef+Fdd0do+ysGNDlgGgWpEm8 ob9TJpmHhzBY2kQNYwHroCk9kd/RxMy1Z/JUnlWUdifsm5T+ie38gB6sfX2wuOBvh5z7 LVw524DY4rpJpYXJZp+J8JrTO7Iu7lD5poRu4gg09ZXUz4DXph8wIkQW3LCa5lPpAsQR lUeA== 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=TmB+Dc6GFmvjqlrMK43fvX5i5efrurMR3OWLc4dS898=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=IKOsyDPOGnHhDXWnt+/8BX6dszTvPfeshDZb/oIrpP6+AWB02MXGsywHH2W5+jr9NM pUiLpsshZWS4U2D0AYa2ve2PooGMh4+A4nqAxRx3WtVR04k3DUNZVvWcjLJZVGberkeX ZptSAPNwphJPNB5v7AoXUDX4lqpHgPoKffXPtcDIoJniXzw4lPZAX0S6m3mtNP4wq6Q4 yqbLXZx1EXV4nt7kqGheRvUyZKw5fTBfs/Q+roPrCBhBbvFDgYR/FACeyRNcBN+ZN/d4 Pa79F0BNK8fU5eeWqSHhxaoJGSLf4I/C3abkJH7OqHIO4wlQ/2pNx1Cd7q7jUFI4yFRa TbMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PEVQ1icz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id b8-20020a6541c8000000b005c626072edfsi5813295pgq.773.2023.12.11.04.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 04:20:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PEVQ1icz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 354BC807BEC9; Mon, 11 Dec 2023 04:20:47 -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 S234792AbjLKMUN (ORCPT + 99 others); Mon, 11 Dec 2023 07:20:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343586AbjLKMT5 (ORCPT ); Mon, 11 Dec 2023 07:19:57 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF5EA18D; Mon, 11 Dec 2023 04:20:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702297204; x=1733833204; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NviBydXIehb8k6mjTqN4kQVTwpJ5zdXEYrNU9xsRc0E=; b=PEVQ1iczJkzk6Lyv50Fr+Q4wh1ea+c9Tn0a8r6SO7VG/Rz7eHK5hzGsY nAVF26s1wDmZGCLL4q7S4IwVf97AJgUxubPHYq5rFJ0s/enolUZppctQM I7YRv98D5qD2uq71C+JC1FmnerMj9YTd3rtJWp7EW7Jpqp3+JWhUVGp5u oTK/UIIGYX69GCUNJ3UV/inCpZa0+HMUXxXsnr3kUnfRfHCFEYEeHNfVI 9rYpjuxWVjtTplUBqZB7l8RVb0ciYnRKhvelBnjo4oQ5yXKG00kk99gg6 +ncRadgcTXrEzIqShArCrPEuJbDg8+dBWRzreuD3IW94t+8/z7B7LoBIE g==; X-IronPort-AV: E=McAfee;i="6600,9927,10920"; a="1708234" X-IronPort-AV: E=Sophos;i="6.04,267,1695711600"; d="scan'208";a="1708234" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 04:20:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10920"; a="896441019" X-IronPort-AV: E=Sophos;i="6.04,267,1695711600"; d="scan'208";a="896441019" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.246.50.188]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 04:19:58 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , =?utf-8?q?Maciej_Wiecz=C3=B3r-R?= =?utf-8?q?etman?= , Fenghua Yu Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v3 09/29] selftests/resctrl: Create cache_portion_size() helper Date: Mon, 11 Dec 2023 14:18:06 +0200 Message-Id: <20231211121826.14392-10-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231211121826.14392-1-ilpo.jarvinen@linux.intel.com> References: <20231211121826.14392-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 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, 11 Dec 2023 04:20:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784988047372704327 X-GMAIL-MSGID: 1784988047372704327 CAT and CMT tests calculate size of the cache portion for the n-bits cache allocation on their own. Add cache_portion_size() helper that calculates size of the cache portion for the given number of bits and use it to replace the existing span calculations. This also prepares for the new CAT test that will need to determine the size of the cache portion also during results processing. Rename also 'cache_size' local variables to 'cache_total_size' to prevent misinterpretations. Signed-off-by: Ilpo Järvinen Reviewed-by: Reinette Chatre --- tools/testing/selftests/resctrl/cat_test.c | 10 +++++----- tools/testing/selftests/resctrl/cmt_test.c | 8 ++++---- tools/testing/selftests/resctrl/resctrl.h | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 242c4c6200aa..f18c95dda5d3 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -91,7 +91,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) { unsigned long l_mask, l_mask_1; int ret, pipefd[2], sibling_cpu_no; - unsigned long cache_size = 0; + unsigned long cache_total_size = 0; unsigned long long_mask; int count_of_bits; char pipe_message; @@ -102,10 +102,10 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) return ret; /* Get L3/L2 cache size */ - ret = get_cache_size(cpu_no, cache_type, &cache_size); + ret = get_cache_size(cpu_no, cache_type, &cache_total_size); if (ret) return ret; - ksft_print_msg("Cache size :%lu\n", cache_size); + ksft_print_msg("Cache size :%lu\n", cache_total_size); count_of_bits = count_bits(long_mask); @@ -136,7 +136,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) /* Set param values for parent thread which will be allocated bitmask * with (max_bits - n) bits */ - span = cache_size * (count_of_bits - n) / count_of_bits; + span = cache_portion_size(cache_total_size, l_mask, long_mask); strcpy(param.ctrlgrp, "c2"); strcpy(param.mongrp, "m2"); strcpy(param.filename, RESULT_FILE_NAME2); @@ -158,7 +158,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) param.mask = l_mask_1; strcpy(param.ctrlgrp, "c1"); strcpy(param.mongrp, "m1"); - span = cache_size * n / count_of_bits; + span = cache_portion_size(cache_total_size, l_mask_1, long_mask); strcpy(param.filename, RESULT_FILE_NAME1); param.num_of_runs = 0; param.cpu_no = sibling_cpu_no; diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index a18c6825802c..a14d46353865 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -72,7 +72,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) { const char * const *cmd = benchmark_cmd; const char *new_cmd[BENCHMARK_ARGS]; - unsigned long cache_size = 0; + unsigned long cache_total_size = 0; unsigned long long_mask; char *span_str = NULL; int count_of_bits; @@ -83,10 +83,10 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) if (ret) return ret; - ret = get_cache_size(cpu_no, "L3", &cache_size); + ret = get_cache_size(cpu_no, "L3", &cache_total_size); if (ret) return ret; - ksft_print_msg("Cache size :%lu\n", cache_size); + ksft_print_msg("Cache size :%lu\n", cache_total_size); count_of_bits = count_bits(long_mask); @@ -107,7 +107,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) .setup = cmt_setup, }; - span = cache_size * n / count_of_bits; + span = cache_portion_size(cache_total_size, param.mask, long_mask); if (strcmp(cmd[0], "fill_buf") == 0) { /* Duplicate the command to be able to replace span in it */ diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 9e5777e1eee3..0e3a4da5f6ec 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -116,4 +116,19 @@ int show_cache_info(unsigned long sum_llc_val, int no_of_bits, unsigned long max_diff_percent, unsigned long num_of_runs, bool platform, bool cmt); +/* + * cache_portion_size - Calculate the size of a cache portion + * @cache_size: Total cache size in bytes + * @portion_mask: Cache portion mask + * @full_cache_mask: Full Cache Bit Mask (CBM) for the cache + * + * Return: The size of the cache portion in bytes. + */ +static inline int cache_portion_size(unsigned long cache_size, + unsigned long portion_mask, + unsigned long full_cache_mask) +{ + return cache_size * count_bits(portion_mask) / count_bits(full_cache_mask); +} + #endif /* RESCTRL_H */