Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3927265rdb; Mon, 11 Dec 2023 04:20:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IEljrZ+8EEDgdm9DZJdmgr+SnKU8R+xoU4ZvheXzx0x7/UkKcI0rjg9ln61VzlCLylkFzU6 X-Received: by 2002:a05:6a20:1455:b0:18f:97c:5b7d with SMTP id a21-20020a056a20145500b0018f097c5b7dmr1798467pzi.75.1702297256255; Mon, 11 Dec 2023 04:20:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702297256; cv=none; d=google.com; s=arc-20160816; b=pyv69S85juFhj6rUt2uaOL9h3OOUa/5bwNLZRF58ZtXyqdRw4psEt3ptoA6xOoHLW1 FV0jUdf+KirKrZlNgK/oR7lObS1BEKeb1dzTqRcDm8fvpigEBrVf5bO1shnbLJ58VBuE rh2jFHAVpjGUUE19DiSau6Nv6MJQjszAjTdZh2DX4A98mM/n1IH/gsIq9ax0ZTrIEHJb AF38ND/snlS95Dl8ES5BY+moykxjwPyEP0yUCiB7O/+tb5yx5fVzBmYAK5vmm6IYz2f3 iUeaE/pgnBF0k7DTVzAM4ptu0B7YuxF0mq5tblcmkKAw0Rx84XyvRHDiRDCBgjKLhZce DHdA== 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 Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id z10-20020a65610a000000b005c1b311a152si6046485pgu.657.2023.12.11.04.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 04:20:56 -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 CE21F805F843; Mon, 11 Dec 2023 04:20:52 -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=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 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 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, 11 Dec 2023 04:20:53 -0800 (PST) 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 */ -- 2.30.2