From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E44051C4A; Fri, 18 Oct 2024 02:22:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218159; cv=none; b=OsUoA5dZijHj0+2xJZKqGi2jv0zMlNG5+IMm5VKlt4C3SQsnd8njEcxm6aIqp9RDVGQgGTkXVHXNB/SXmgHCQagHt2kZRFd0TmmeZeU4YV5mGp+xdLeTwk44FgspZ5I4gZ9KmAGFVJ2G7UAgas1vUC50evypYhi7RvAlDtZFmFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218159; c=relaxed/simple; bh=KrVngyFGE5oudkQB75kRR5MAeQoNnD4X59aZn9uB91E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NVfbULcHz8eR528BJ/Ostb2k+2v9tdATXcxCbLQprVY4mo43rK+/Q4jGkO8LM0vyQZDe4Njx8vzF0x2WD0AkkjlMJx4NRcv7D6LlHpBoISopK2Sz/gUgDHuKAlQpwShiXXTg6TvCNxNQZYgP+UQSftvFlfzuA0lLlty9tB+bmnM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Dj8Rcggx; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Dj8Rcggx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218159; x=1760754159; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KrVngyFGE5oudkQB75kRR5MAeQoNnD4X59aZn9uB91E=; b=Dj8RcggxR09Likhd3NipBCU49hM3nvBKrUIRVxmaSZkR0ApoGkaEqtAn W94NIy9qe6VaAl7DecHo1AkLo+wvoUB7nWOwGvjP6Hm5VwczyFvVWCDuP yVwouJxC9PoaCZjI+W8yz5LsJwApwJadouABnzAnR/ZO1m+wYajnpzvbn rQiGFiXI5jHAgWkZ8jidO0ZTRkENg1hp8vLikkj9ofp+Ds6UEYeY4VGjq j+hZk5PQb5cRK+UlPs6w8jmgLHRInhaWkmQZlPcFgVjJhXW5wOQdDaN9T TzZAbTrCCrFmyfbE/zbUBds+V3KWDTRSch28unl3LrJOlH/9or1s69m9p Q==; X-CSE-ConnectionGUID: mrUJVxQWRqO4kGLZXnmKug== X-CSE-MsgGUID: KTlwA4j+QiiDRThCQZ3zag== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149667" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149667" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 X-CSE-ConnectionGUID: +bZBXRaqRC6JHsNpKtRJoA== X-CSE-MsgGUID: /P3/vDGOTY6b669hWsuGEQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697698" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:36 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 01/15] selftests/resctrl: Make functions only used in same file static Date: Thu, 17 Oct 2024 19:33:16 -0700 Message-ID: <551f786b1df77ef2f4e25d1448dea4c6e62a2f72.1729218182.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Fix following sparse warnings: tools/testing/selftests/resctrl/resctrl_val.c:47:6: warning: symbol 'membw= _initialize_perf_event_attr' was not declared. Should it be static? tools/testing/selftests/resctrl/resctrl_val.c:64:6: warning: symbol 'membw= _ioctl_perf_event_ioc_reset_enable' was not declared. Should it be static? tools/testing/selftests/resctrl/resctrl_val.c:70:6: warning: symbol 'membw= _ioctl_perf_event_ioc_disable' was not declared. Should it be static? tools/testing/selftests/resctrl/resctrl_val.c:81:6: warning: symbol 'get_e= vent_and_umask' was not declared. Should it be static? Signed-off-by: Reinette Chatre Reviewed-by: Ilpo J=C3=A4rvinen --- Changes since v1: - Add Ilpo's Reviewed-by tag. - Let subject describe the change, not the tool that found it. (checkpatch.= pl) --- tools/testing/selftests/resctrl/resctrl_val.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index 8c275f6b4dd7..70e8e31f5d1a 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -44,7 +44,7 @@ static int imcs; static struct imc_counter_config imc_counters_config[MAX_IMCS][2]; static const struct resctrl_test *current_test; =20 -void membw_initialize_perf_event_attr(int i, int j) +static void membw_initialize_perf_event_attr(int i, int j) { memset(&imc_counters_config[i][j].pe, 0, sizeof(struct perf_event_attr)); @@ -61,13 +61,13 @@ void membw_initialize_perf_event_attr(int i, int j) PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING; } =20 -void membw_ioctl_perf_event_ioc_reset_enable(int i, int j) +static void membw_ioctl_perf_event_ioc_reset_enable(int i, int j) { ioctl(imc_counters_config[i][j].fd, PERF_EVENT_IOC_RESET, 0); ioctl(imc_counters_config[i][j].fd, PERF_EVENT_IOC_ENABLE, 0); } =20 -void membw_ioctl_perf_event_ioc_disable(int i, int j) +static void membw_ioctl_perf_event_ioc_disable(int i, int j) { ioctl(imc_counters_config[i][j].fd, PERF_EVENT_IOC_DISABLE, 0); } @@ -78,7 +78,7 @@ void membw_ioctl_perf_event_ioc_disable(int i, int j) * @count: iMC number * @op: Operation (read/write) */ -void get_event_and_umask(char *cas_count_cfg, int count, bool op) +static void get_event_and_umask(char *cas_count_cfg, int count, bool op) { char *token[MAX_TOKENS]; int i =3D 0; --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D72014F136; Fri, 18 Oct 2024 02:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218160; cv=none; b=X4ZmOUemESxpH+H2dE84WEW6tlZ3G63cq97YfSbg+NLvisA4tVCaA71dQEDCNLKDW/z0fwnwfCxdubAmSr7v3/9t+Cg5w6vfAiFvVAGEa+ZFDnrLAX5eebHJjTVSZLcV9WU+GViXqm52Lopmddns2eOn5yupm+tLp97FUFc/Rh8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218160; c=relaxed/simple; bh=RQwgwAvH1yN3WgCkSsFG9U5A6uInT75JDIW0Wm5kvAI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BTrnkrptwETctMGJuj1aL4w8edVwG8NTxNtGdlOb3T+v/rVzzE/cpQO97VPiYw2abMK2yL/Emy/JBkJLNp7V75R2cuGmfr9Hsgu5bc0irt6XRZHldQcGLgscTWnIG9bdy2rpVDoSUvK54UYwxJ1w9tyzpnwXTMWJIOMON61rr00= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=fail smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=C2Y08xqy; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="C2Y08xqy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218159; x=1760754159; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RQwgwAvH1yN3WgCkSsFG9U5A6uInT75JDIW0Wm5kvAI=; b=C2Y08xqy8wVF+zc05OlsLN1KdhynfZFccQnzVTReoDKGohzUt6PEEfTp WoeXsTbuxqenQ6sTkw0adT7SSphQQb3OJBiVRTcfGxzEXchPUfDsqmtaW GBgrOMflRQTVZUgk/kgAGVph/2E+Ob5pvm95S5oB8B0FFCIJRFDxfJ/pL tCO2d9BY0/miNj3KzMnu+M8Y/id/FYZOQsujgnBfVQ+55hrTpXBb7hOWH MLqQWx7jNdKDUod3dxmZXK+VfJ7aVF1DErPcaXsVUnxpWjOoBHE8xBdkp 6+84km4a7QkET9daz4OpLIh+HFVxmkABY3TGyyPwTgLnL2J4yovKWxYd0 g==; X-CSE-ConnectionGUID: jODhIKreRj+e9Y+Lg3t5xw== X-CSE-MsgGUID: 9GfiYav+QsGFm5aGsCk6mg== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149673" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149673" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 X-CSE-ConnectionGUID: KZhemtkoQjeZ7UzJNcRgeA== X-CSE-MsgGUID: seUgJXrCRw+kT529DcBUNw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697701" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:36 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 02/15] selftests/resctrl: Print accurate buffer size as part of MBM results Date: Thu, 17 Oct 2024 19:33:17 -0700 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" By default the MBM test uses the "fill_buf" benchmark to keep reading from a buffer with size DEFAULT_SPAN while measuring memory bandwidth. User space can provide an alternate benchmark or amend the size of the buffer "fill_buf" should use. Analysis of the MBM measurements do not require that a buffer be used and thus do not require knowing the size of the buffer if it was used during testing. Even so, the buffer size is printed as informational as part of the MBM test results. What is printed as buffer size is hardcoded as DEFAULT_SPAN, even if the test relied on another benchmark (that may or may not use a buffer) or if user space amended the buffer size. Ensure that accurate buffer size is printed when using "fill_buf" benchmark and omit the buffer size information if another benchmark is used. Fixes: ecdbb911f22d ("selftests/resctrl: Add MBM test") Signed-off-by: Reinette Chatre --- Backporting is not recommended. Backporting this fix will be a challenge with all the refactoring done since then. This issue does not impact default tests and there is no sign that folks run these tests with anything but the defaults. This issue is also minor since it does not impact actual test runs or results, just the information printed during a test run. Changes since V2: - Make user input checks more robust. (Ilpo) Changes since V1: - New patch. --- tools/testing/selftests/resctrl/mbm_test.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/sel= ftests/resctrl/mbm_test.c index 6b5a3b52d861..36ae29a03784 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -40,7 +40,8 @@ show_bw_info(unsigned long *bw_imc, unsigned long *bw_res= c, size_t span) ksft_print_msg("%s Check MBM diff within %d%%\n", ret ? "Fail:" : "Pass:", MAX_DIFF_PERCENT); ksft_print_msg("avg_diff_per: %d%%\n", avg_diff_per); - ksft_print_msg("Span (MB): %zu\n", span / MB); + if (span) + ksft_print_msg("Span (MB): %zu\n", span / MB); ksft_print_msg("avg_bw_imc: %lu\n", avg_bw_imc); ksft_print_msg("avg_bw_resc: %lu\n", avg_bw_resc); =20 @@ -138,15 +139,26 @@ static int mbm_run_test(const struct resctrl_test *te= st, const struct user_param .setup =3D mbm_setup, .measure =3D mbm_measure, }; + char *endptr =3D NULL; + size_t span =3D 0; int ret; =20 remove(RESULT_FILE_NAME); =20 + if (uparams->benchmark_cmd[0] && strcmp(uparams->benchmark_cmd[0], "fill_= buf") =3D=3D 0) { + if (uparams->benchmark_cmd[1]) { + errno =3D 0; + span =3D strtoul(uparams->benchmark_cmd[1], &endptr, 10); + if (errno || *endptr !=3D '\0') + return -errno; + } + } + ret =3D resctrl_val(test, uparams, uparams->benchmark_cmd, ¶m); if (ret) return ret; =20 - ret =3D check_results(DEFAULT_SPAN); + ret =3D check_results(span); if (ret && (get_vendor() =3D=3D ARCH_INTEL)) ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is = enabled. Check BIOS configuration.\n"); =20 --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8AA8158DB1; Fri, 18 Oct 2024 02:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218162; cv=none; b=Pvap6AU2yRg9PFHRHgsRwAf/LJgP7rdylPVoGAjSevJdAAxh4Bo3vw5iTcHjIqNrTWjYhCqKqPJEibI0g3aGbmV7PIcwVVHlqEb5dmzdRZPvrVk9kQQo9RU0jL1DSwszWHX4bRGlmwNYm9/1k1CSJ4NBfa0hJcFx88/9xlS9nJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218162; c=relaxed/simple; bh=2MBkITOraGEw2CIFCHHG4AS4AEaaronvpkHeMTP5ofs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U8qxTghbvvJciKC0RVJ9wKrWkDDFDcsT/nGPV72ZOw7jHODLcsuO1IhlhB2LaF1SOjnU7lgcYWzqu55zmKdPnd0usQVKuxQESkaCY17HPB+BLe4wWYWpt8q+3TaA1BjmA7J7+hhMcAk4sACx6WKOcggeQXPrbVVL/uxku+F40vA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=SdAZi4Sg; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SdAZi4Sg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218160; x=1760754160; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2MBkITOraGEw2CIFCHHG4AS4AEaaronvpkHeMTP5ofs=; b=SdAZi4SgNE8tiUQxPzWTia3EHidU5bqrY00/FlJ3qBFOxxXsrWpb7cbY YbawOSssNVDpoDUKPPHXazG4P0uJCJ79BoliB6rOTMMRIiuj67AFeENHY 04FJb4oaYBt4QfuGmiNUXrdyNvyMRBFPM8/+EyMWoI9l7gnhWGTYpxsTq NRMBcdzM0LnrLKp+Etvxi5kCTh1zQkKjaJ0p9kFMvqNTZ6dl/GiqSvum/ wRFMZkInJVvYGbg59mHFRGxKGZ6HtWIIbCvkT02p58IzwucXQG7QvSfjZ wFsUCTIjBz6fjZZlH74CG+QmWBtwtWY424xRvmaSMmDyQilISoHYX7GGy A==; X-CSE-ConnectionGUID: O7T3lv6lQzebpFPjE+NTjg== X-CSE-MsgGUID: 4z+cjZsxScu+LaQo6i0LtA== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149682" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149682" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 X-CSE-ConnectionGUID: xTYmW/x7T1qrJllEzu6Rag== X-CSE-MsgGUID: sVOQzbYcTQ26IfWtweFxqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697704" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:36 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 03/15] selftests/resctrl: Fix memory overflow due to unhandled wraparound Date: Thu, 17 Oct 2024 19:33:18 -0700 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable alloc_buffer() allocates and initializes (with random data) a buffer of requested size. The initialization starts from the beginning of the allocated buffer and incrementally assigns sizeof(uint64_t) random data to each cache line. The initialization uses the size of the buffer to control the initialization flow, decrementing the amount of buffer needing to be initialized after each iteration. The size of the buffer is stored in an unsigned (size_t) variable s64 and the test "s64 > 0" is used to decide if initialization is complete. The problem is that decrementing the buffer size may wrap around if the buffer size is not divisible by "CL_SIZE / sizeof(uint64_t)" resulting in the "s64 > 0" test being true and memory beyond the buffer "initialized". Use a signed value for the buffer size to support all buffer sizes. Fixes: a2561b12fe39 ("selftests/resctrl: Add built in benchmark") Signed-off-by: Reinette Chatre Reviewed-by: Ilpo J=C3=A4rvinen --- Changes since V2: - Add Ilpo's Reviewed-by tag. Changes since V1: - New patch. --- tools/testing/selftests/resctrl/fill_buf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/sel= ftests/resctrl/fill_buf.c index ae120f1735c0..34e5df721430 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -127,7 +127,7 @@ unsigned char *alloc_buffer(size_t buf_size, int memflu= sh) { void *buf =3D NULL; uint64_t *p64; - size_t s64; + ssize_t s64; int ret; =20 ret =3D posix_memalign(&buf, PAGE_SIZE, buf_size); --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AC1A17B505; Fri, 18 Oct 2024 02:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218161; cv=none; b=kq6nMSi+fZr8iBeFhqJT/MVmjRFsQ7h4+4yiKLPNg4haYfWUTQSErw3CwpL9uhckDgTKamZr78P2mndxxYJ1wty1O0nivs6p5cBfmTjspCj4vfN3xKMqEoognTzd13sRa5Aa8X5kfIJhWM0+Pre7y0luOg2Q57RoNUBmQk6exS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218161; c=relaxed/simple; bh=grJ4cRTsHWngr55kCknBb9PxXbOJjDYnItK5kuxBfjY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=X24dyMDQPou9zCpqCFOHWH6mUXee9ZGK2rYZ/fEIyidPPkLEO7LWSUUCa5XiXyuJOKE0aRVCmmaCPL+tcJbSsWiRw0EtVFSBzgmvsODxS+DVkKoaNFgFoKR3X1L/pDr2G+pMUaon9Z0lD/VE5Svncv5tuFvTCvoLrbRLJ44ULQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dcVabV6h; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dcVabV6h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218160; x=1760754160; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=grJ4cRTsHWngr55kCknBb9PxXbOJjDYnItK5kuxBfjY=; b=dcVabV6hzQGdDxxEQjuzYBLE9NtUvmMk41nyfCsLuEyMJu+/IZsqj01Q E00+KbTqMPAGwkrMQ7qqtzNOWV2ohHiemeAYhNIBplziwF2Pz9vHmx2MS 3qDqcDKE6o1FTMiFnDIf67xool9UZqDdWxcFEiyrAO4WpX2ap6bxJInrN 2frI0eAtz0YwoOWuiFsGpODtYkjw27PZl/BXB1pvRRvDeb9Tt3bypPBHC kgMJuCgmpTGkaVkDtYep/T6udvUS30NnxGV4ahRsRPNPxKYvFx4kYf+D1 ZqUQp/m2TGIgjzWmDHogz/y4uRa/4Nz7kGT58L/9gZ5S3/ASdALHV40B7 Q==; X-CSE-ConnectionGUID: YAqdUpf9Rm2bmIwWN9UbUA== X-CSE-MsgGUID: LVr6YLvkSzK1QrzaxFIiSQ== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149688" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149688" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 X-CSE-ConnectionGUID: i6obbGvASnKAf/vjFOjfuQ== X-CSE-MsgGUID: 7l+1HKJBSHu7Sa2cyq6XpA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697708" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:36 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 04/15] selftests/resctrl: Protect against array overrun during iMC config parsing Date: Thu, 17 Oct 2024 19:33:19 -0700 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The MBM and MBA tests need to discover the event and umask with which to configure the performance event used to measure read memory bandwidth. This is done by parsing the /sys/bus/event_source/devices/uncore_imc_/events/cas_count_re= ad file for each iMC instance that contains the formatted output: "event=3D,umask=3D" Parsing of cas_count_read contents is done by initializing an array of MAX_TOKENS elements with tokens (deliminated by "=3D,") from this file. Remove the unnecessary append of a delimiter to the string needing to be parsed. Per the strtok() man page: "delimiter bytes at the start or end of the string are ignored". This has no impact on the token placement within the array. After initialization, the actual event and umask is determined by parsing the tokens directly following the "event" and "umask" tokens respectively. Iterating through the array up to index "i < MAX_TOKENS" but then accessing index "i + 1" risks array overrun during the final iteration. Avoid array overrun by ensuring that the index used within for loop will always be valid. Fixes: 1d3f08687d76 ("selftests/resctrl: Read memory bandwidth from perf IM= C counter and from resctrl file system") Signed-off-by: Reinette Chatre Reviewed-by: Ilpo J=C3=A4rvinen --- Changes since V2: - Rephrase changelog. (Ilpo) - Add Ilpo's Reviewed-by tag. Changes since V1: - New patch. --- tools/testing/selftests/resctrl/resctrl_val.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index 70e8e31f5d1a..e88d5ca30517 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -83,13 +83,12 @@ static void get_event_and_umask(char *cas_count_cfg, in= t count, bool op) char *token[MAX_TOKENS]; int i =3D 0; =20 - strcat(cas_count_cfg, ","); token[0] =3D strtok(cas_count_cfg, "=3D,"); =20 for (i =3D 1; i < MAX_TOKENS; i++) token[i] =3D strtok(NULL, "=3D,"); =20 - for (i =3D 0; i < MAX_TOKENS; i++) { + for (i =3D 0; i < MAX_TOKENS - 1; i++) { if (!token[i]) break; if (strcmp(token[i], "event") =3D=3D 0) { --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D726F17C21C; Fri, 18 Oct 2024 02:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218162; cv=none; b=KQUyW1tNdNuIpHQOpVRTYHh1cbnkwS02DwFCZvkCLYWfnNnn4KQUfPswGrbXpybo0qRflAu/wbOyMwlbXAaHww7dVBL5909MZlgqfg1leTiBBsvA61tVu2SIxkGv0ga8sjuWXCJzbyT5032TTst81KRL/5i1bmcrx05GEW0eZpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218162; c=relaxed/simple; bh=cwi+GNrykzBZWK3vNEOThjGdwWrEwDOu0Vqo1PrdesE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BOBHnxYdBo3Fx8A7TZm8Y2whlJ+x0R03l5CKf+B2s6T+GDdzOdfX19XKQmp4PzYvX8WaHUV0pYexESTjBd9bz1cpuQ7FDLXsrU/KIToGq39kYZD5SKDXQBW5xrtMKUygJkrOxr++OttkOEEYrb1v07CKcA5ORsXxk2rCBBZE0hI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=SzN6YK2f; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SzN6YK2f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218161; x=1760754161; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cwi+GNrykzBZWK3vNEOThjGdwWrEwDOu0Vqo1PrdesE=; b=SzN6YK2fdXzbe4i3ME19hPLCkwx8E/pBAiv7JAApWrV83/Mj1Ov6OYCj kZ5s/VHKy7AqZgXFp06MiXrpFkmyuu+DVClMUvw2c+wfVzzkmDffg68my ox2IAkGnqzRb8ztQtKYucKn3zKYPjAhwO10MJOxFE+/LHng4eUIHdtEIN FyGnW5X8GjW22saLXYgSHXNJYDAEeHRPRvhlQl3YF26IFkxQzeTemCwg9 9m2HWWQyMl/TZQhi+YXH2wlr1iDxzNO5oV+ZftK5UnnmikbSJs6hr31RU /crl/oCWwz8xPdrUqfjFExK5P724NzTb63cQHqNLviSPgH+Zw4dt7eraq w==; X-CSE-ConnectionGUID: 9nj3zLboQ8+LigpJGcbzPQ== X-CSE-MsgGUID: rfJlyb+LTOa0g93RF+Xbcg== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149695" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149695" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 X-CSE-ConnectionGUID: SdtlWhQlRLuka4srtVWbjA== X-CSE-MsgGUID: Fc/YGfGdRPCg4lu9BTXX8g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697711" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:36 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 05/15] selftests/resctrl: Protect against array overflow when reading strings Date: Thu, 17 Oct 2024 19:33:20 -0700 Message-ID: <4adf01b3ee7019163ea4fc00b5d03d514d41b4b7.1729218182.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" resctrl selftests discover system properties via a variety of sysfs files. The MBM and MBA tests need to discover the event and umask with which to configure the performance event used to measure read memory bandwidth. This is done by parsing the contents of /sys/bus/event_source/devices/uncore_imc_/events/cas_count_re= ad Similarly, the resctrl selftests discover the cache size via /sys/bus/cpu/devices/cpu/cache/index/size. Take care to do bounds checking when using fscanf() to read the contents of files into a string buffer because by default fscanf() assumes arbitrarily long strings. If the file contains more bytes than the array can accommodate then an overflow will occur. Provide a maximum field width to the conversion specifier to protect against array overflow. The maximum is one less than the array size because string input stores a terminating null byte that is not covered by the maximum field width. Signed-off-by: Reinette Chatre Reviewed-by: Ilpo J=C3=A4rvinen --- This makes the code robust against any changes in information read from sysfs. The existing sysfs content fit well into the arrays, thus this is not considered a bugfix. Changes since V2: - New patch --- tools/testing/selftests/resctrl/resctrl_val.c | 4 ++-- tools/testing/selftests/resctrl/resctrlfs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index e88d5ca30517..c9dd70ce3ea8 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -159,7 +159,7 @@ static int read_from_imc_dir(char *imc_dir, int count) =20 return -1; } - if (fscanf(fp, "%s", cas_count_cfg) <=3D 0) { + if (fscanf(fp, "%1023s", cas_count_cfg) <=3D 0) { ksft_perror("Could not get iMC cas count read"); fclose(fp); =20 @@ -177,7 +177,7 @@ static int read_from_imc_dir(char *imc_dir, int count) =20 return -1; } - if (fscanf(fp, "%s", cas_count_cfg) <=3D 0) { + if (fscanf(fp, "%1023s", cas_count_cfg) <=3D 0) { ksft_perror("Could not get iMC cas count write"); fclose(fp); =20 diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/se= lftests/resctrl/resctrlfs.c index 250c320349a7..a53cd1cb6e0c 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -182,7 +182,7 @@ int get_cache_size(int cpu_no, const char *cache_type, = unsigned long *cache_size =20 return -1; } - if (fscanf(fp, "%s", cache_str) <=3D 0) { + if (fscanf(fp, "%63s", cache_str) <=3D 0) { ksft_perror("Could not get cache_size"); fclose(fp); =20 --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE95B17CA0B; Fri, 18 Oct 2024 02:22:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218163; cv=none; b=ZGv0gTGDdScfbP2MIc/GkYMPY3paKCSbhgilbqICcOd4aLU5w6hyLKIFSmffKd5Ooj0j81MgqqTvlUbCvTLwjI+7aIQ6dPiiwfFbX/E3rtlj8v65RtDNCPDWBmpPSSt7KTn1YgoD/cHOjJLA4UWG3zrrk8oAsF5ZaRFKXcGn6RY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218163; c=relaxed/simple; bh=WDQXKvgThl+Gw40TkwesnKGx7YMUmY4xzJANs5XXJ0E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uDjZkIecQDuboti9xeOMZ97JlxD2m8kE8OYCGzXYo7WHNHuyuS/4MOYpdynCaNpPCOmr6sO66EO2GlQuDC7NG0m7ZxupliTnLX8epVKiRRNGX+sjWTPF38yzyy58a5CYbUU7FnLtv5izoYBxBwsJjeGRQ284j/wTa/GVWiWg3so= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=j2lUcBeA; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="j2lUcBeA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218162; x=1760754162; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WDQXKvgThl+Gw40TkwesnKGx7YMUmY4xzJANs5XXJ0E=; b=j2lUcBeA0kjyQhrny+hu40422qCQ/xsm/+7ZxB9UH/K0PYBp5ZAH3PSP b/eBkkYdbMOfYmV5fLlklQjfV4w6xYzoGjUwajwfgwpaVCKh67h9oqNZx +br8AnMs6JW6Eg+uuaDRUZQKP1FL336PlWcfrgR/5HtAaLbGlFjzXDXhO g0ug6wA0QWWD7HvVQkIdkGI16daN2cnWiX27j54N3tLswwrplR3UfL7kC IJiYlSDqibioHvXvqBBYTvj50CJnkuuz+qnPzMGWDwvq3FioBNp1KQTM2 zppVF2IfnMODaSFtO7jjXb0fo6u/4JNowPXB05LfbiSvZTabkyjKxYAVc Q==; X-CSE-ConnectionGUID: lR8yhIxITiW47EcLL7SdEQ== X-CSE-MsgGUID: UmLADvKLSHOlVlIwRyN8fg== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149696" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149696" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 X-CSE-ConnectionGUID: iydpUy+uQjeT0BT1/sSs/g== X-CSE-MsgGUID: 3gWlkkdPTkKqew8URjcQxw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697714" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:36 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 06/15] selftests/resctrl: Make wraparound handling obvious Date: Thu, 17 Oct 2024 19:33:21 -0700 Message-ID: <46b9094f4ecd8188b559bdd4146aa365b13799b9.1729218182.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Within mba_setup() the programmed bandwidth delay value starts at the maximum (100, or rather ALLOCATION_MAX) and progresses towards ALLOCATION_MIN by decrementing with ALLOCATION_STEP. The programmed bandwidth delay should never be negative, so representing it with an unsigned int is most appropriate. This may introduce confusion because of the "allocation > ALLOCATION_MAX" check used to check wraparound of the subtraction. Modify the mba_setup() flow to start at the minimum, ALLOCATION_MIN, and incrementally, with ALLOCATION_STEP steps, adjust the bandwidth delay value. This avoids wraparound while making the purpose of "allocation > ALLOCATION_MAX" clear and eliminates the need for the "allocation < ALLOCATION_MIN" check. Reported-by: Ilpo J=C3=A4rvinen Closes: https://lore.kernel.org/lkml/1903ac13-5c9c-ef8d-78e0-417ac34a971b@l= inux.intel.com/ Signed-off-by: Reinette Chatre Reviewed-by: Ilpo J=C3=A4rvinen --- Changes since V1: - New patch - Add Ilpo's Reviewed-by tag. --- tools/testing/selftests/resctrl/mba_test.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/sel= ftests/resctrl/mba_test.c index ab8496a4925b..da40a8ed4413 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -39,7 +39,8 @@ static int mba_setup(const struct resctrl_test *test, const struct user_params *uparams, struct resctrl_val_param *p) { - static int runs_per_allocation, allocation =3D 100; + static unsigned int allocation =3D ALLOCATION_MIN; + static int runs_per_allocation; char allocation_str[64]; int ret; =20 @@ -50,7 +51,7 @@ static int mba_setup(const struct resctrl_test *test, if (runs_per_allocation++ !=3D 0) return 0; =20 - if (allocation < ALLOCATION_MIN || allocation > ALLOCATION_MAX) + if (allocation > ALLOCATION_MAX) return END_OF_TESTS; =20 sprintf(allocation_str, "%d", allocation); @@ -59,7 +60,7 @@ static int mba_setup(const struct resctrl_test *test, if (ret < 0) return ret; =20 - allocation -=3D ALLOCATION_STEP; + allocation +=3D ALLOCATION_STEP; =20 return 0; } @@ -72,8 +73,9 @@ static int mba_measure(const struct user_params *uparams, =20 static bool show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc) { - int allocation, runs; + unsigned int allocation; bool ret =3D false; + int runs; =20 ksft_print_msg("Results are displayed in (MB)\n"); /* Memory bandwidth from 100% down to 10% */ @@ -103,7 +105,7 @@ static bool show_mba_info(unsigned long *bw_imc, unsign= ed long *bw_resc) avg_diff_per > MAX_DIFF_PERCENT ? "Fail:" : "Pass:", MAX_DIFF_PERCENT, - ALLOCATION_MAX - ALLOCATION_STEP * allocation); + ALLOCATION_MIN + ALLOCATION_STEP * allocation); =20 ksft_print_msg("avg_diff_per: %d%%\n", avg_diff_per); ksft_print_msg("avg_bw_imc: %lu\n", avg_bw_imc); --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29F1D17E003; Fri, 18 Oct 2024 02:22:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218163; cv=none; b=lPBtPea9AHLmg+8PxiMtLIkRzRNmkqWMQMmhM8mri75J9xr3Bqn//0Wb49r0dzTAjcUROomlMyIb88tcIfsUdM5KyVWfKOUE+eEEgQmJaInapMQS+lvP+eBSROaRf5o1ZNkIyzlKxnmpkbsYIVNUezHpxR2AQIzBYz32Kux94aw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218163; c=relaxed/simple; bh=Uy3NsyHGrTIOaOBOdWrwbIKqErrl3314XWdNn/0fdeA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=S8s46eduxBuqehI+8k4wedNJftMTQ186z2r/w1UoDc25lkAC5Jq79hr0X3NO03RlACwxVn6DEIMqtFmbF7XiM1/JKePgW0+ccMrS0j2M2BXB6LTRmXpol6UToPGze/dQIKOM9cS5oRnewKIUO/PPqgnhp/NeuANPFhNc6HPovJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=maK/gWjk; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="maK/gWjk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218162; x=1760754162; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Uy3NsyHGrTIOaOBOdWrwbIKqErrl3314XWdNn/0fdeA=; b=maK/gWjkyIebFBDP5aI0bpvnd6Q2BJBym0DvNrbvm6Q7L4DO3qKiAfG2 m0nlyVQIuP5yRASqwOF4asRFp8jd6fVqVf8fy/RCPcKk4RQnyozaW7ahu dIgeZIGA2PtBs4y+R3dknyEPN5EwhafpjRy3gMMvhSNIQiN4ypnfwtr8c 31tKvsrOTrnFeaMNdjfawfnyK/5Spj7eeySFOxga2NHNaPenbUHffPt22 20oZr5IO+Box1hV+13Y/VStb/W+tyx6EQNlRrGbOyxmLmMKMiAbfkVxLP JivdWDpZjOOD7kSt32a3JbGnQLjYGuWQf3g0JF+2gdCeJDA5ifdus5v0Q A==; X-CSE-ConnectionGUID: ETzGKCauR7Ov9HJxHDv1Kg== X-CSE-MsgGUID: rXpu2AwcRmiSN5mh68sCEA== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149703" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149703" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:38 -0700 X-CSE-ConnectionGUID: h/BfrWXvQsC+rXBTnCilKA== X-CSE-MsgGUID: yhRKHipfT7uYU6YM4e2nAw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697717" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 07/15] selftests/resctrl: Remove "once" parameter required to be false Date: Thu, 17 Oct 2024 19:33:22 -0700 Message-ID: <8749a13135c7e66bd9d463d94b15a9214b8c4b69.1729218182.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The CMT, MBM, and MBA tests rely on a benchmark that runs while the test makes changes to needed configuration (for example memory bandwidth allocation) and takes needed measurements. By default the "fill_buf" benchmark is used and by default (via its "once =3D false" setting) "fill_buf" is configured to run until terminated after the test completes. An unintended consequence of enabling the user to override the benchmark also enables the user to change parameters to the "fill_buf" benchmark. This enables the user to set "fill_buf" to only cycle through the buffer once (by setting "once =3D true") and thus breaking the CMT, MBA, and MBM tests that expect workload/interference to be reflected by their measurements. Prevent user space from changing the "once" parameter and ensure that it is always false for the CMT, MBA, and MBM tests. Suggested-by: Ilpo J=C3=A4rvinen Signed-off-by: Reinette Chatre Reviewed-by: Ilpo J=C3=A4rvinen --- Changes since V2: - Remove unnecessary assignment to benchmark_cmd[5]. (Ilpo) Changes since V1: - New patch --- tools/testing/selftests/resctrl/fill_buf.c | 7 ++++--- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrl_tests.c | 9 +++++++-- tools/testing/selftests/resctrl/resctrl_val.c | 11 +---------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/sel= ftests/resctrl/fill_buf.c index 34e5df721430..854f0108d8e6 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -151,7 +151,7 @@ unsigned char *alloc_buffer(size_t buf_size, int memflu= sh) return buf; } =20 -int run_fill_buf(size_t buf_size, int memflush, int op, bool once) +int run_fill_buf(size_t buf_size, int memflush, int op) { unsigned char *buf; =20 @@ -160,9 +160,10 @@ int run_fill_buf(size_t buf_size, int memflush, int op= , bool once) return -1; =20 if (op =3D=3D 0) - fill_cache_read(buf, buf_size, once); + fill_cache_read(buf, buf_size, false); else - fill_cache_write(buf, buf_size, once); + fill_cache_write(buf, buf_size, false); + free(buf); =20 return 0; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index 2dda56084588..51f5f4b25e06 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -142,7 +142,7 @@ int perf_event_open(struct perf_event_attr *hw_event, p= id_t pid, int cpu, unsigned char *alloc_buffer(size_t buf_size, int memflush); void mem_flush(unsigned char *buf, size_t buf_size); void fill_cache_read(unsigned char *buf, size_t buf_size, bool once); -int run_fill_buf(size_t buf_size, int memflush, int op, bool once); +int run_fill_buf(size_t buf_size, int memflush, int op); int initialize_mem_bw_imc(void); int measure_mem_bw(const struct user_params *uparams, struct resctrl_val_param *param, pid_t bm_pid, diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testin= g/selftests/resctrl/resctrl_tests.c index ecbb7605a981..e7878077883f 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -266,8 +266,13 @@ int main(int argc, char **argv) uparams.benchmark_cmd[1] =3D span_str; uparams.benchmark_cmd[2] =3D "1"; uparams.benchmark_cmd[3] =3D "0"; - uparams.benchmark_cmd[4] =3D "false"; - uparams.benchmark_cmd[5] =3D NULL; + /* + * Fourth parameter was previously used to indicate + * how long "fill_buf" should run for, with "false" + * ("fill_buf" will keep running until terminated) + * the only option that works. + */ + uparams.benchmark_cmd[4] =3D NULL; } =20 ksft_set_plan(tests); diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index c9dd70ce3ea8..b0f3c594c4da 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -625,7 +625,6 @@ static void run_benchmark(int signum, siginfo_t *info, = void *ucontext) int operation, ret, memflush; char **benchmark_cmd; size_t span; - bool once; FILE *fp; =20 benchmark_cmd =3D info->si_ptr; @@ -645,16 +644,8 @@ static void run_benchmark(int signum, siginfo_t *info,= void *ucontext) span =3D strtoul(benchmark_cmd[1], NULL, 10); memflush =3D atoi(benchmark_cmd[2]); operation =3D atoi(benchmark_cmd[3]); - if (!strcmp(benchmark_cmd[4], "true")) { - once =3D true; - } else if (!strcmp(benchmark_cmd[4], "false")) { - once =3D false; - } else { - ksft_print_msg("Invalid once parameter\n"); - parent_exit(ppid); - } =20 - if (run_fill_buf(span, memflush, operation, once)) + if (run_fill_buf(span, memflush, operation)) fprintf(stderr, "Error in running fill buffer\n"); } else { /* Execute specified benchmark */ --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B16B517BB0C; Fri, 18 Oct 2024 02:22:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218165; cv=none; b=eslfklMSWXxqTCtoZ1/0TbkzDpAevq9dcKlBtZqiYybzUR0dNRgtDzr4NcvQb0dCxL+N2ufyiVCTO7ZUd/s2XQNs7TY5tatCpYv6/sYq5fZopaRR/CX++A/Eyngq3HO4dwq6xwn1/2RW15ArdvGP63XQ96PBaLEi6Ddw6vq8DLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218165; c=relaxed/simple; bh=4fILn7na/aW84mv4lohoLeaRP0yj+magIYxVwwrx9U8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R70sg1sZcTD2YTr/I7IK1eQ68Leq4Kx1K4zMNfF1OsNpiYDsGfoqSUDT4V6raJgoXRT5AL5q2QZn9h5HSRaYn128PjYhgk/W/KVwmyf9W2iQ68taRZ7+9JfWKp4TTlLLZVMrsAhcUuEeRBjCCvPBfPpLGAaSIf43Sl2rLMHilmo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ejAsSolL; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ejAsSolL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218164; x=1760754164; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4fILn7na/aW84mv4lohoLeaRP0yj+magIYxVwwrx9U8=; b=ejAsSolLJFFiuFXnp9E5lFHh+jvt4q0YFgVNdfY8zPBBAHE0Rx80glsg MJERuXlnRdOO/vttNDq0ZNlQnW1XDTLbDFEhiuxMxiAc56ouAKzJg9QR9 PrRfE6R/3IHhtiLMn9fGy7mdhD2AdCiQV1793jS5/XghC9RtJ4DnRYQYn Jb5ppRJeHqAq6v8++XGiehpALtpdQxp4gVJ0t3lDjgCAcAuOpL3Uid5pe WDUdPqwIfvzkGyA9v2Z5BM5VS5+XbbMvsfVLpe/he5lU2AYY50WskAVxv x2pi7fvWflbyUZS41K2NbhTq3ZAF9P8C6GXRWoOfAb70I5va10TbJe1Pg A==; X-CSE-ConnectionGUID: CdDd8Tt6SkOvyIVYdPmmUw== X-CSE-MsgGUID: 59zKvyEaQ8+lUcOAMhiRyQ== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149705" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149705" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:38 -0700 X-CSE-ConnectionGUID: S90sLa7zR0ebGd1yO543fw== X-CSE-MsgGUID: 15JIJBfZQwy9VDmmSIP9/g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697722" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 08/15] selftests/resctrl: Only support measured read operation Date: Thu, 17 Oct 2024 19:33:23 -0700 Message-ID: <3e451b37bf88a96018d6ab6564dbdf2f853c86ee.1729218182.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The CMT, MBM, and MBA tests rely on a benchmark to generate memory traffic. By default this is the "fill_buf" benchmark that can be replaced via the "-b" command line argument. The original intent of the "-b" command line parameter was to replace the default "fill_buf" benchmark, but the implementation also exposes an alternative use case where the "fill_buf" parameters itself can be modified. One of the parameters to "fill_buf" is the "operation" that can be either "read" or "write" and indicates whether the "fill_buf" should use "read" or "write" operations on the allocated buffer. While replacing "fill_buf" default parameters is technically possible, replacing the default "read" parameter with "write" is not supported because the MBA and MBM tests only measure "read" operations. The "read" operation is also most appropriate for the CMT test that aims to use the benchmark to allocate into the cache. Avoid any potential inconsistencies between test and measurement by removing code for unsupported "write" operations to the buffer. Ignore any attempt from user space to enable this unsupported test configuration, instead always use read operations. Keep the initialization of the, now unused, "fill_buf" parameters to reserve these parameter positions since it has been exposed as an API. Future parameter additions cannot use these parameter positions. Signed-off-by: Reinette Chatre Reviewed-by: Ilpo J=C3=A4rvinen --- Changes since V2: - Update changelog to justify keeping the assignment to benchmark_cmd[4]. (Ilpo) Changes since V1: - New patch. --- tools/testing/selftests/resctrl/fill_buf.c | 28 ++----------------- tools/testing/selftests/resctrl/resctrl.h | 2 +- .../testing/selftests/resctrl/resctrl_tests.c | 5 +++- tools/testing/selftests/resctrl/resctrl_val.c | 5 ++-- 4 files changed, 9 insertions(+), 31 deletions(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/sel= ftests/resctrl/fill_buf.c index 854f0108d8e6..e4f1cea317f1 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -88,18 +88,6 @@ static int fill_one_span_read(unsigned char *buf, size_t= buf_size) return sum; } =20 -static void fill_one_span_write(unsigned char *buf, size_t buf_size) -{ - unsigned char *end_ptr =3D buf + buf_size; - unsigned char *p; - - p =3D buf; - while (p < end_ptr) { - *p =3D '1'; - p +=3D (CL_SIZE / 2); - } -} - void fill_cache_read(unsigned char *buf, size_t buf_size, bool once) { int ret =3D 0; @@ -114,15 +102,6 @@ void fill_cache_read(unsigned char *buf, size_t buf_si= ze, bool once) *value_sink =3D ret; } =20 -static void fill_cache_write(unsigned char *buf, size_t buf_size, bool onc= e) -{ - while (1) { - fill_one_span_write(buf, buf_size); - if (once) - break; - } -} - unsigned char *alloc_buffer(size_t buf_size, int memflush) { void *buf =3D NULL; @@ -151,7 +130,7 @@ unsigned char *alloc_buffer(size_t buf_size, int memflu= sh) return buf; } =20 -int run_fill_buf(size_t buf_size, int memflush, int op) +int run_fill_buf(size_t buf_size, int memflush) { unsigned char *buf; =20 @@ -159,10 +138,7 @@ int run_fill_buf(size_t buf_size, int memflush, int op) if (!buf) return -1; =20 - if (op =3D=3D 0) - fill_cache_read(buf, buf_size, false); - else - fill_cache_write(buf, buf_size, false); + fill_cache_read(buf, buf_size, false); =20 free(buf); =20 diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index 51f5f4b25e06..ba1ce1b35699 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -142,7 +142,7 @@ int perf_event_open(struct perf_event_attr *hw_event, p= id_t pid, int cpu, unsigned char *alloc_buffer(size_t buf_size, int memflush); void mem_flush(unsigned char *buf, size_t buf_size); void fill_cache_read(unsigned char *buf, size_t buf_size, bool once); -int run_fill_buf(size_t buf_size, int memflush, int op); +int run_fill_buf(size_t buf_size, int memflush); int initialize_mem_bw_imc(void); int measure_mem_bw(const struct user_params *uparams, struct resctrl_val_param *param, pid_t bm_pid, diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testin= g/selftests/resctrl/resctrl_tests.c index e7878077883f..0f91c475b255 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -265,13 +265,16 @@ int main(int argc, char **argv) ksft_exit_fail_msg("Out of memory!\n"); uparams.benchmark_cmd[1] =3D span_str; uparams.benchmark_cmd[2] =3D "1"; - uparams.benchmark_cmd[3] =3D "0"; /* + * Third parameter was previously used for "operation" + * (read/write) of which only (now default) "read"/"0" + * works. * Fourth parameter was previously used to indicate * how long "fill_buf" should run for, with "false" * ("fill_buf" will keep running until terminated) * the only option that works. */ + uparams.benchmark_cmd[3] =3D NULL; uparams.benchmark_cmd[4] =3D NULL; } =20 diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index b0f3c594c4da..113ca18d67c1 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -622,8 +622,8 @@ int measure_mem_bw(const struct user_params *uparams, */ static void run_benchmark(int signum, siginfo_t *info, void *ucontext) { - int operation, ret, memflush; char **benchmark_cmd; + int ret, memflush; size_t span; FILE *fp; =20 @@ -643,9 +643,8 @@ static void run_benchmark(int signum, siginfo_t *info, = void *ucontext) /* Execute default fill_buf benchmark */ span =3D strtoul(benchmark_cmd[1], NULL, 10); memflush =3D atoi(benchmark_cmd[2]); - operation =3D atoi(benchmark_cmd[3]); =20 - if (run_fill_buf(span, memflush, operation)) + if (run_fill_buf(span, memflush)) fprintf(stderr, "Error in running fill buffer\n"); } else { /* Execute specified benchmark */ --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C095D181D00; Fri, 18 Oct 2024 02:22:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218165; cv=none; b=FhlHvZOadxoM4QlQtWdkezE71MB32h5WVqJOTkQHJYF8lL8OesH2+0eOvPpZ2Xny27qb/x8vDX2K+EqP/X3Pjb1V5RohY2JQbLaF547M9dGAyKFReqMhSnjR/b4lLOG7uk33AMYR32U8AvWur6o3pjhtm4CsL2/k93FfUDCi3w4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218165; c=relaxed/simple; bh=S7bbGjsCsnLvdIa2S2fp7sRvKgZS8ax6fpv4SxjDnig=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DWpDZfb0aXGoJAurLVs6h1qE03v0omEtnGC3OT0B0lZtIpyiQDXeNjvf84/JUg45vQv9FOyuCFbXOyezgnZI/fvETvOnYpP7zNZoslGPXvNseRfH+yWaQZWnGrNLRh/5qHE2ghhkL0/Xg1YBtvPFqlluRxxCIdi/HBgFJ0CcKow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=RtWQTLnP; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RtWQTLnP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218163; x=1760754163; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S7bbGjsCsnLvdIa2S2fp7sRvKgZS8ax6fpv4SxjDnig=; b=RtWQTLnPdrjzynI10G38qwNv0GhcB46+Y1/eaVcKINY6THrkIN8nDcGw dJcJ/CR4REAast4yeupNS8uADjVXpeO1d0B/3g4v8yEzoaLj6gu3S2Yia zovJZhYHpeEg6RZpG0KzGc2ld8tDZX63D3rfdBVOGy3tV5Zjp5c265f6S bjXXYKOp2yUAZwK1lzUcwnmWzY9cXO1A+bqMvAWp42R43/CuwcXFixs0y z3tex9Vk/PSVOGtWIySwz+sSt8hMTKANa1Sk+pB0GIeR0w5QEO7YAO4Fj 3ocL9TgAO9A/wUht9mLf/QxdTwAZkwXWjfnlr63Ok6Xz8BqJU3ST0p/37 g==; X-CSE-ConnectionGUID: zTityY8DQDOPq3e0odhUtg== X-CSE-MsgGUID: FclgbYNsR1mcf76zvzS6Hw== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149713" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149713" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:38 -0700 X-CSE-ConnectionGUID: y7BlBC1ZRHe3ZsHJQWuJFA== X-CSE-MsgGUID: lst87ACoTc6GzX2E2o1IFw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697725" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 09/15] selftests/resctrl: Remove unused measurement code Date: Thu, 17 Oct 2024 19:33:24 -0700 Message-ID: <2f3c4a34fa0dcf8902823f292c921c36062517b0.1729218182.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The MBM and MBA resctrl selftests run a benchmark during which it takes measurements of read memory bandwidth via perf. Code exists to support measurements of write memory bandwidth but there exists no path with which this code can execute. While code exists for write memory bandwidth measurement there has not yet been a use case for it. Remove this unused code. Rename relevant functions to include "read" so that it is clear that it relates only to memory bandwidth reads, while renaming the functions also add consistency by changing the "membw" instances to more prevalent "mem_bw". Signed-off-by: Reinette Chatre Reviewed-by: Ilpo J=C3=A4rvinen --- Changes since V2: - Add Ilpo's Reviewed-by tag. Changes since V1: - New patch. --- tools/testing/selftests/resctrl/mba_test.c | 4 +- tools/testing/selftests/resctrl/mbm_test.c | 4 +- tools/testing/selftests/resctrl/resctrl.h | 8 +- tools/testing/selftests/resctrl/resctrl_val.c | 234 ++++++------------ tools/testing/selftests/resctrl/resctrlfs.c | 17 -- 5 files changed, 85 insertions(+), 182 deletions(-) diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/sel= ftests/resctrl/mba_test.c index da40a8ed4413..be0ead73e55d 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -21,7 +21,7 @@ static int mba_init(const struct resctrl_val_param *param= , int domain_id) { int ret; =20 - ret =3D initialize_mem_bw_imc(); + ret =3D initialize_read_mem_bw_imc(); if (ret) return ret; =20 @@ -68,7 +68,7 @@ static int mba_setup(const struct resctrl_test *test, static int mba_measure(const struct user_params *uparams, struct resctrl_val_param *param, pid_t bm_pid) { - return measure_mem_bw(uparams, param, bm_pid, "reads"); + return measure_read_mem_bw(uparams, param, bm_pid); } =20 static bool show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc) diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/sel= ftests/resctrl/mbm_test.c index 36ae29a03784..f516a2da1163 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -91,7 +91,7 @@ static int mbm_init(const struct resctrl_val_param *param= , int domain_id) { int ret; =20 - ret =3D initialize_mem_bw_imc(); + ret =3D initialize_read_mem_bw_imc(); if (ret) return ret; =20 @@ -122,7 +122,7 @@ static int mbm_setup(const struct resctrl_test *test, static int mbm_measure(const struct user_params *uparams, struct resctrl_val_param *param, pid_t bm_pid) { - return measure_mem_bw(uparams, param, bm_pid, "reads"); + return measure_read_mem_bw(uparams, param, bm_pid); } =20 static void mbm_test_cleanup(void) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index ba1ce1b35699..82801245e4c1 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -126,7 +126,6 @@ int filter_dmesg(void); int get_domain_id(const char *resource, int cpu_no, int *domain_id); int mount_resctrlfs(void); int umount_resctrlfs(void); -const char *get_bw_report_type(const char *bw_report); bool resctrl_resource_exists(const char *resource); bool resctrl_mon_feature_exists(const char *resource, const char *feature); bool resource_info_file_exists(const char *resource, const char *file); @@ -143,10 +142,9 @@ unsigned char *alloc_buffer(size_t buf_size, int memfl= ush); void mem_flush(unsigned char *buf, size_t buf_size); void fill_cache_read(unsigned char *buf, size_t buf_size, bool once); int run_fill_buf(size_t buf_size, int memflush); -int initialize_mem_bw_imc(void); -int measure_mem_bw(const struct user_params *uparams, - struct resctrl_val_param *param, pid_t bm_pid, - const char *bw_report); +int initialize_read_mem_bw_imc(void); +int measure_read_mem_bw(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid); void initialize_mem_bw_resctrl(const struct resctrl_val_param *param, int domain_id); int resctrl_val(const struct resctrl_test *test, diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index 113ca18d67c1..c4ebf70a46ef 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -12,13 +12,10 @@ =20 #define UNCORE_IMC "uncore_imc" #define READ_FILE_NAME "events/cas_count_read" -#define WRITE_FILE_NAME "events/cas_count_write" #define DYN_PMU_PATH "/sys/bus/event_source/devices" #define SCALE 0.00006103515625 #define MAX_IMCS 20 #define MAX_TOKENS 5 -#define READ 0 -#define WRITE 1 =20 #define CON_MBM_LOCAL_BYTES_PATH \ "%s/%s/mon_data/mon_L3_%02d/mbm_local_bytes" @@ -41,44 +38,43 @@ struct imc_counter_config { =20 static char mbm_total_path[1024]; static int imcs; -static struct imc_counter_config imc_counters_config[MAX_IMCS][2]; +static struct imc_counter_config imc_counters_config[MAX_IMCS]; static const struct resctrl_test *current_test; =20 -static void membw_initialize_perf_event_attr(int i, int j) +static void read_mem_bw_initialize_perf_event_attr(int i) { - memset(&imc_counters_config[i][j].pe, 0, + memset(&imc_counters_config[i].pe, 0, sizeof(struct perf_event_attr)); - imc_counters_config[i][j].pe.type =3D imc_counters_config[i][j].type; - imc_counters_config[i][j].pe.size =3D sizeof(struct perf_event_attr); - imc_counters_config[i][j].pe.disabled =3D 1; - imc_counters_config[i][j].pe.inherit =3D 1; - imc_counters_config[i][j].pe.exclude_guest =3D 0; - imc_counters_config[i][j].pe.config =3D - imc_counters_config[i][j].umask << 8 | - imc_counters_config[i][j].event; - imc_counters_config[i][j].pe.sample_type =3D PERF_SAMPLE_IDENTIFIER; - imc_counters_config[i][j].pe.read_format =3D + imc_counters_config[i].pe.type =3D imc_counters_config[i].type; + imc_counters_config[i].pe.size =3D sizeof(struct perf_event_attr); + imc_counters_config[i].pe.disabled =3D 1; + imc_counters_config[i].pe.inherit =3D 1; + imc_counters_config[i].pe.exclude_guest =3D 0; + imc_counters_config[i].pe.config =3D + imc_counters_config[i].umask << 8 | + imc_counters_config[i].event; + imc_counters_config[i].pe.sample_type =3D PERF_SAMPLE_IDENTIFIER; + imc_counters_config[i].pe.read_format =3D PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING; } =20 -static void membw_ioctl_perf_event_ioc_reset_enable(int i, int j) +static void read_mem_bw_ioctl_perf_event_ioc_reset_enable(int i) { - ioctl(imc_counters_config[i][j].fd, PERF_EVENT_IOC_RESET, 0); - ioctl(imc_counters_config[i][j].fd, PERF_EVENT_IOC_ENABLE, 0); + ioctl(imc_counters_config[i].fd, PERF_EVENT_IOC_RESET, 0); + ioctl(imc_counters_config[i].fd, PERF_EVENT_IOC_ENABLE, 0); } =20 -static void membw_ioctl_perf_event_ioc_disable(int i, int j) +static void read_mem_bw_ioctl_perf_event_ioc_disable(int i) { - ioctl(imc_counters_config[i][j].fd, PERF_EVENT_IOC_DISABLE, 0); + ioctl(imc_counters_config[i].fd, PERF_EVENT_IOC_DISABLE, 0); } =20 /* - * get_event_and_umask: Parse config into event and umask + * get_read_event_and_umask: Parse config into event and umask * @cas_count_cfg: Config * @count: iMC number - * @op: Operation (read/write) */ -static void get_event_and_umask(char *cas_count_cfg, int count, bool op) +static void get_read_event_and_umask(char *cas_count_cfg, int count) { char *token[MAX_TOKENS]; int i =3D 0; @@ -91,34 +87,22 @@ static void get_event_and_umask(char *cas_count_cfg, in= t count, bool op) for (i =3D 0; i < MAX_TOKENS - 1; i++) { if (!token[i]) break; - if (strcmp(token[i], "event") =3D=3D 0) { - if (op =3D=3D READ) - imc_counters_config[count][READ].event =3D - strtol(token[i + 1], NULL, 16); - else - imc_counters_config[count][WRITE].event =3D - strtol(token[i + 1], NULL, 16); - } - if (strcmp(token[i], "umask") =3D=3D 0) { - if (op =3D=3D READ) - imc_counters_config[count][READ].umask =3D - strtol(token[i + 1], NULL, 16); - else - imc_counters_config[count][WRITE].umask =3D - strtol(token[i + 1], NULL, 16); - } + if (strcmp(token[i], "event") =3D=3D 0) + imc_counters_config[count].event =3D strtol(token[i + 1], NULL, 16); + if (strcmp(token[i], "umask") =3D=3D 0) + imc_counters_config[count].umask =3D strtol(token[i + 1], NULL, 16); } } =20 -static int open_perf_event(int i, int cpu_no, int j) +static int open_perf_read_event(int i, int cpu_no) { - imc_counters_config[i][j].fd =3D - perf_event_open(&imc_counters_config[i][j].pe, -1, cpu_no, -1, + imc_counters_config[i].fd =3D + perf_event_open(&imc_counters_config[i].pe, -1, cpu_no, -1, PERF_FLAG_FD_CLOEXEC); =20 - if (imc_counters_config[i][j].fd =3D=3D -1) { + if (imc_counters_config[i].fd =3D=3D -1) { fprintf(stderr, "Error opening leader %llx\n", - imc_counters_config[i][j].pe.config); + imc_counters_config[i].pe.config); =20 return -1; } @@ -126,7 +110,7 @@ static int open_perf_event(int i, int cpu_no, int j) return 0; } =20 -/* Get type and config (read and write) of an iMC counter */ +/* Get type and config of an iMC counter's read event. */ static int read_from_imc_dir(char *imc_dir, int count) { char cas_count_cfg[1024], imc_counter_cfg[1024], imc_counter_type[1024]; @@ -140,7 +124,7 @@ static int read_from_imc_dir(char *imc_dir, int count) =20 return -1; } - if (fscanf(fp, "%u", &imc_counters_config[count][READ].type) <=3D 0) { + if (fscanf(fp, "%u", &imc_counters_config[count].type) <=3D 0) { ksft_perror("Could not get iMC type"); fclose(fp); =20 @@ -148,9 +132,6 @@ static int read_from_imc_dir(char *imc_dir, int count) } fclose(fp); =20 - imc_counters_config[count][WRITE].type =3D - imc_counters_config[count][READ].type; - /* Get read config */ sprintf(imc_counter_cfg, "%s%s", imc_dir, READ_FILE_NAME); fp =3D fopen(imc_counter_cfg, "r"); @@ -167,34 +148,19 @@ static int read_from_imc_dir(char *imc_dir, int count) } fclose(fp); =20 - get_event_and_umask(cas_count_cfg, count, READ); - - /* Get write config */ - sprintf(imc_counter_cfg, "%s%s", imc_dir, WRITE_FILE_NAME); - fp =3D fopen(imc_counter_cfg, "r"); - if (!fp) { - ksft_perror("Failed to open iMC config file"); - - return -1; - } - if (fscanf(fp, "%1023s", cas_count_cfg) <=3D 0) { - ksft_perror("Could not get iMC cas count write"); - fclose(fp); - - return -1; - } - fclose(fp); - - get_event_and_umask(cas_count_cfg, count, WRITE); + get_read_event_and_umask(cas_count_cfg, count); =20 return 0; } =20 /* * A system can have 'n' number of iMC (Integrated Memory Controller) - * counters, get that 'n'. For each iMC counter get it's type and config. - * Also, each counter has two configs, one for read and the other for writ= e. - * A config again has two parts, event and umask. + * counters, get that 'n'. Discover the properties of the available + * counters in support of needed performance measurement via perf. + * For each iMC counter get it's type and config. Also obtain each + * counter's event and umask for the memory read events that will be + * measured. + * * Enumerate all these details into an array of structures. * * Return: >=3D 0 on success. < 0 on failure. @@ -255,55 +221,46 @@ static int num_of_imcs(void) return count; } =20 -int initialize_mem_bw_imc(void) +int initialize_read_mem_bw_imc(void) { - int imc, j; + int imc; =20 imcs =3D num_of_imcs(); if (imcs <=3D 0) return imcs; =20 /* Initialize perf_event_attr structures for all iMC's */ - for (imc =3D 0; imc < imcs; imc++) { - for (j =3D 0; j < 2; j++) - membw_initialize_perf_event_attr(imc, j); - } + for (imc =3D 0; imc < imcs; imc++) + read_mem_bw_initialize_perf_event_attr(imc); =20 return 0; } =20 -static void perf_close_imc_mem_bw(void) +static void perf_close_imc_read_mem_bw(void) { int mc; =20 for (mc =3D 0; mc < imcs; mc++) { - if (imc_counters_config[mc][READ].fd !=3D -1) - close(imc_counters_config[mc][READ].fd); - if (imc_counters_config[mc][WRITE].fd !=3D -1) - close(imc_counters_config[mc][WRITE].fd); + if (imc_counters_config[mc].fd !=3D -1) + close(imc_counters_config[mc].fd); } } =20 /* - * perf_open_imc_mem_bw - Open perf fds for IMCs + * perf_open_imc_read_mem_bw - Open perf fds for IMCs * @cpu_no: CPU number that the benchmark PID is bound to * * Return: =3D 0 on success. < 0 on failure. */ -static int perf_open_imc_mem_bw(int cpu_no) +static int perf_open_imc_read_mem_bw(int cpu_no) { int imc, ret; =20 - for (imc =3D 0; imc < imcs; imc++) { - imc_counters_config[imc][READ].fd =3D -1; - imc_counters_config[imc][WRITE].fd =3D -1; - } + for (imc =3D 0; imc < imcs; imc++) + imc_counters_config[imc].fd =3D -1; =20 for (imc =3D 0; imc < imcs; imc++) { - ret =3D open_perf_event(imc, cpu_no, READ); - if (ret) - goto close_fds; - ret =3D open_perf_event(imc, cpu_no, WRITE); + ret =3D open_perf_read_event(imc, cpu_no); if (ret) goto close_fds; } @@ -311,60 +268,52 @@ static int perf_open_imc_mem_bw(int cpu_no) return 0; =20 close_fds: - perf_close_imc_mem_bw(); + perf_close_imc_read_mem_bw(); return -1; } =20 /* - * do_mem_bw_test - Perform memory bandwidth test + * do_imc_read_mem_bw_test - Perform memory bandwidth test * * Runs memory bandwidth test over one second period. Also, handles starti= ng * and stopping of the IMC perf counters around the test. */ -static void do_imc_mem_bw_test(void) +static void do_imc_read_mem_bw_test(void) { int imc; =20 - for (imc =3D 0; imc < imcs; imc++) { - membw_ioctl_perf_event_ioc_reset_enable(imc, READ); - membw_ioctl_perf_event_ioc_reset_enable(imc, WRITE); - } + for (imc =3D 0; imc < imcs; imc++) + read_mem_bw_ioctl_perf_event_ioc_reset_enable(imc); =20 sleep(1); =20 - /* Stop counters after a second to get results (both read and write) */ - for (imc =3D 0; imc < imcs; imc++) { - membw_ioctl_perf_event_ioc_disable(imc, READ); - membw_ioctl_perf_event_ioc_disable(imc, WRITE); - } + /* Stop counters after a second to get results. */ + for (imc =3D 0; imc < imcs; imc++) + read_mem_bw_ioctl_perf_event_ioc_disable(imc); } =20 /* - * get_mem_bw_imc - Memory bandwidth as reported by iMC counters - * @bw_report: Bandwidth report type (reads, writes) + * get_read_mem_bw_imc - Memory read bandwidth as reported by iMC counters * - * Memory bandwidth utilized by a process on a socket can be calculated - * using iMC counters. Perf events are used to read these counters. + * Memory read bandwidth utilized by a process on a socket can be calculat= ed + * using iMC counters' read events. Perf events are used to read these + * counters. * * Return: =3D 0 on success. < 0 on failure. */ -static int get_mem_bw_imc(const char *bw_report, float *bw_imc) +static int get_read_mem_bw_imc(float *bw_imc) { - float reads, writes, of_mul_read, of_mul_write; + float reads =3D 0, of_mul_read =3D 1; int imc; =20 - /* Start all iMC counters to log values (both read and write) */ - reads =3D 0, writes =3D 0, of_mul_read =3D 1, of_mul_write =3D 1; - /* - * Get results which are stored in struct type imc_counter_config + * Log read event values from all iMC counters into + * struct imc_counter_config. * Take overflow into consideration before calculating total bandwidth. */ for (imc =3D 0; imc < imcs; imc++) { struct imc_counter_config *r =3D - &imc_counters_config[imc][READ]; - struct imc_counter_config *w =3D - &imc_counters_config[imc][WRITE]; + &imc_counters_config[imc]; =20 if (read(r->fd, &r->return_value, sizeof(struct membw_read_format)) =3D=3D -1) { @@ -372,12 +321,6 @@ static int get_mem_bw_imc(const char *bw_report, float= *bw_imc) return -1; } =20 - if (read(w->fd, &w->return_value, - sizeof(struct membw_read_format)) =3D=3D -1) { - ksft_perror("Couldn't get write bandwidth through iMC"); - return -1; - } - __u64 r_time_enabled =3D r->return_value.time_enabled; __u64 r_time_running =3D r->return_value.time_running; =20 @@ -385,27 +328,10 @@ static int get_mem_bw_imc(const char *bw_report, floa= t *bw_imc) of_mul_read =3D (float)r_time_enabled / (float)r_time_running; =20 - __u64 w_time_enabled =3D w->return_value.time_enabled; - __u64 w_time_running =3D w->return_value.time_running; - - if (w_time_enabled !=3D w_time_running) - of_mul_write =3D (float)w_time_enabled / - (float)w_time_running; reads +=3D r->return_value.value * of_mul_read * SCALE; - writes +=3D w->return_value.value * of_mul_write * SCALE; } =20 - if (strcmp(bw_report, "reads") =3D=3D 0) { - *bw_imc =3D reads; - return 0; - } - - if (strcmp(bw_report, "writes") =3D=3D 0) { - *bw_imc =3D writes; - return 0; - } - - *bw_imc =3D reads + writes; + *bw_imc =3D reads; return 0; } =20 @@ -551,35 +477,31 @@ static int print_results_bw(char *filename, pid_t bm_= pid, float bw_imc, } =20 /* - * measure_mem_bw - Measures memory bandwidth numbers while benchmark runs + * measure_read_mem_bw - Measures read memory bandwidth numbers while benc= hmark runs * @uparams: User supplied parameters * @param: Parameters passed to resctrl_val() * @bm_pid: PID that runs the benchmark - * @bw_report: Bandwidth report type (reads, writes) * * Measure memory bandwidth from resctrl and from another source which is * perf imc value or could be something else if perf imc event is not * available. Compare the two values to validate resctrl value. It takes * 1 sec to measure the data. + * resctrl does not distinguish between read and write operations so + * its data includes all memory operations. */ -int measure_mem_bw(const struct user_params *uparams, - struct resctrl_val_param *param, pid_t bm_pid, - const char *bw_report) +int measure_read_mem_bw(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid) { unsigned long bw_resc, bw_resc_start, bw_resc_end; FILE *mem_bw_fp; float bw_imc; int ret; =20 - bw_report =3D get_bw_report_type(bw_report); - if (!bw_report) - return -1; - mem_bw_fp =3D open_mem_bw_resctrl(mbm_total_path); if (!mem_bw_fp) return -1; =20 - ret =3D perf_open_imc_mem_bw(uparams->cpu); + ret =3D perf_open_imc_read_mem_bw(uparams->cpu); if (ret < 0) goto close_fp; =20 @@ -589,17 +511,17 @@ int measure_mem_bw(const struct user_params *uparams, =20 rewind(mem_bw_fp); =20 - do_imc_mem_bw_test(); + do_imc_read_mem_bw_test(); =20 ret =3D get_mem_bw_resctrl(mem_bw_fp, &bw_resc_end); if (ret < 0) goto close_imc; =20 - ret =3D get_mem_bw_imc(bw_report, &bw_imc); + ret =3D get_read_mem_bw_imc(&bw_imc); if (ret < 0) goto close_imc; =20 - perf_close_imc_mem_bw(); + perf_close_imc_read_mem_bw(); fclose(mem_bw_fp); =20 bw_resc =3D (bw_resc_end - bw_resc_start) / MB; @@ -607,7 +529,7 @@ int measure_mem_bw(const struct user_params *uparams, return print_results_bw(param->filename, bm_pid, bw_imc, bw_resc); =20 close_imc: - perf_close_imc_mem_bw(); + perf_close_imc_read_mem_bw(); close_fp: fclose(mem_bw_fp); return ret; diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/se= lftests/resctrl/resctrlfs.c index a53cd1cb6e0c..d38d6dd90be4 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -831,23 +831,6 @@ int filter_dmesg(void) return 0; } =20 -const char *get_bw_report_type(const char *bw_report) -{ - if (strcmp(bw_report, "reads") =3D=3D 0) - return bw_report; - if (strcmp(bw_report, "writes") =3D=3D 0) - return bw_report; - if (strcmp(bw_report, "nt-writes") =3D=3D 0) { - return "writes"; - } - if (strcmp(bw_report, "total") =3D=3D 0) - return bw_report; - - fprintf(stderr, "Requested iMC bandwidth report type unavailable\n"); - - return NULL; -} - int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags) { --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02FB5185B77; Fri, 18 Oct 2024 02:22:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218166; cv=none; b=VjWGrQ83vV0jpdtjyNQUtSBF6ptaKstwS/PR8V1bD+o7GCFBovCTdFbdjpdaHEbPtd8LxvcXKWi3ubO7PQ+0Jhho3T2L8Kzx3iqxu82cQ/xqZc0hshHMwGC+ypzXVbtVH49XyTfBFuTNyO8zegqWWf9h8pob9xx2xBckMa5sN1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218166; c=relaxed/simple; bh=BxenALi9lbp+uZ/HDmyPQsYWfN57ff8IwoXFhqnFVN8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L+H1WIgD8+5OiB3W7q+e8INZcCu8COxyU/juAKgjTdRhkP6qY19MoxrwI7ABTh3OxL5iq09dYgiUi31mBZ7qlvqQboO7jRX1YGLMjNK7k67ewNMybmHzjc/OMAbIDhUDEAbxm/bhAGUQo0M5eQkGbxamEf5O2kKGBiM1catd/mw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=fFwpUIH+; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fFwpUIH+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218164; x=1760754164; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BxenALi9lbp+uZ/HDmyPQsYWfN57ff8IwoXFhqnFVN8=; b=fFwpUIH+0jJ3960FXyd/p+XTR+VpwYhIu3UC46FYYzQX1vhkMuJ4D5NT YHl1sqAhftl50c4NqRe3l27ULEnHjabpwqG4nwnTr87S7QQgEnA1FRYby rjn5ymXEkO8gPHJPGWueZUnZsJe1mogCKEm5rsY4Rp3rHq8fxHrrjHBiF 3lCHPS6tQFKtTNERetFk6JmGyXy0HFCVO1WO3ou0A9AgXXpknQSw4SJKw /LDhMAMUfGdJdD1zeWkFijVKlvYjUQYZdW1gKlaw+PRXnizdve2CEckwE nEuBtBrEwpZbQH3aeHL+k74qBIWSQhHEqOYS3Swuip5b9ySB/du9yWh4E g==; X-CSE-ConnectionGUID: vRHn9lUfTEevpeAnroavHQ== X-CSE-MsgGUID: F8YDIFVqQ0SKoe5d43yy9g== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149715" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149715" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:38 -0700 X-CSE-ConnectionGUID: 55SoTL6DRqCGJdgX6LuRbA== X-CSE-MsgGUID: 606baLEtSqGY+mOamLz7Eg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697728" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 10/15] selftests/resctrl: Make benchmark parameter passing robust Date: Thu, 17 Oct 2024 19:33:25 -0700 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The benchmark used during the CMT, MBM, and MBA tests can be provided by the user via (-b) parameter, if not provided the default "fill_buf" benchmark is used. The user is additionally able to override any of the "fill_buf" default parameters when running the tests with "-b fill_buf ". The "fill_buf" parameters are managed as an array of strings. Using an array of strings is complex because it requires transformations to/from strings at every producer and consumer. This is made worse for the individual tests where the default benchmark parameters values may not be appropriate and additional data wrangling is required. For example, the CMT test duplicates the entire array of strings in order to replace one of the parameters. More issues appear when combining the usage of an array of strings with the use case of user overriding default parameters by specifying "-b fill_buf ". This use case is fragile with opportunities to trigger a SIGSEGV because of opportunities for NULL pointers to exist in the array of strings. For example, by running below (thus by specifying "fill_buf" should be used but all parameters are NULL): $ sudo resctrl_tests -t mbm -b fill_buf Replace the "array of strings" parameters used for "fill_buf" with new struct fill_buf_param that contains the "fill_buf" parameters that can be used directly without transformations to/from strings. Two instances of struct fill_buf_param may exist at any point in time: * If the user provides new parameters to "fill_buf", the user parameter structure (struct user_params) will point to a fully initialized and immutable struct fill_buf_param containing the user provided parameters. * If "fill_buf" is the benchmark that should be used by a test, then the test parameter structure (struct resctrl_val_param) will point to a fully initialized struct fill_buf_param. The latter may contain (a) the user provided parameters verbatim, (b) user provided parameters adjusted to be appropriate for the test, or (c) the default parameters for "fill_buf" that is appropriate for the test if the user did not provide "fill_buf" parameters nor an alternate benchmark. The existing behavior of CMT test is to use test defined value for the buffer size even if the user provides another value via command line. This behavior is maintained since the test requires that the buffer size matches the size of the cache allocated, and the amount of cache allocated can instead be changed by the user with the "-n" command line parameter. Signed-off-by: Reinette Chatre --- Changes since V2: - Use empty initializers. (Ilpo) - Let memflush be bool instead of int. (Ilpo) - Make user input checks more robust. (Ilpo) - Assign values as part of local variable definition. (Ilpo) Changes since V1: - Maintain original behavior where user can override "fill_buf" parameters via command line ... but only those that can actually be changed. (Ilpo) - Fix parsing issues associated with original behavior to ensure any parameter is valid before any attempt to use it. - Move patch earlier in series to highlight that this fixes existing issues. - Make struct fill_buf_param dynamic to support user provided parameters as well as test specific parameters. - Rewrite changelog. --- tools/testing/selftests/resctrl/cmt_test.c | 32 ++---- tools/testing/selftests/resctrl/fill_buf.c | 4 +- tools/testing/selftests/resctrl/mba_test.c | 13 ++- tools/testing/selftests/resctrl/mbm_test.c | 22 ++-- tools/testing/selftests/resctrl/resctrl.h | 59 +++++++--- .../testing/selftests/resctrl/resctrl_tests.c | 103 ++++++++++++++---- tools/testing/selftests/resctrl/resctrl_val.c | 41 ++++--- 7 files changed, 178 insertions(+), 96 deletions(-) diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/sel= ftests/resctrl/cmt_test.c index 0c045080d808..4c3cf2c25a38 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -116,15 +116,13 @@ static void cmt_test_cleanup(void) =20 static int cmt_run_test(const struct resctrl_test *test, const struct user= _params *uparams) { - const char * const *cmd =3D uparams->benchmark_cmd; - const char *new_cmd[BENCHMARK_ARGS]; + struct fill_buf_param fill_buf =3D {}; unsigned long cache_total_size =3D 0; int n =3D uparams->bits ? : 5; unsigned long long_mask; - char *span_str =3D NULL; int count_of_bits; size_t span; - int ret, i; + int ret; =20 ret =3D get_full_cbm("L3", &long_mask); if (ret) @@ -155,32 +153,26 @@ static int cmt_run_test(const struct resctrl_test *te= st, const struct user_param =20 span =3D cache_portion_size(cache_total_size, param.mask, long_mask); =20 - if (strcmp(cmd[0], "fill_buf") =3D=3D 0) { - /* Duplicate the command to be able to replace span in it */ - for (i =3D 0; uparams->benchmark_cmd[i]; i++) - new_cmd[i] =3D uparams->benchmark_cmd[i]; - new_cmd[i] =3D NULL; - - ret =3D asprintf(&span_str, "%zu", span); - if (ret < 0) - return -1; - new_cmd[1] =3D span_str; - cmd =3D new_cmd; + if (uparams->fill_buf) { + fill_buf.buf_size =3D span; + fill_buf.memflush =3D uparams->fill_buf->memflush; + param.fill_buf =3D &fill_buf; + } else if (!uparams->benchmark_cmd[0]) { + fill_buf.buf_size =3D span; + fill_buf.memflush =3D true; + param.fill_buf =3D &fill_buf; } =20 remove(RESULT_FILE_NAME); =20 - ret =3D resctrl_val(test, uparams, cmd, ¶m); + ret =3D resctrl_val(test, uparams, ¶m); if (ret) - goto out; + return ret; =20 ret =3D check_results(¶m, span, n); if (ret && (get_vendor() =3D=3D ARCH_INTEL)) ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is = enabled. Check BIOS configuration.\n"); =20 -out: - free(span_str); - return ret; } =20 diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/sel= ftests/resctrl/fill_buf.c index e4f1cea317f1..39545f9369e8 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -102,7 +102,7 @@ void fill_cache_read(unsigned char *buf, size_t buf_siz= e, bool once) *value_sink =3D ret; } =20 -unsigned char *alloc_buffer(size_t buf_size, int memflush) +unsigned char *alloc_buffer(size_t buf_size, bool memflush) { void *buf =3D NULL; uint64_t *p64; @@ -130,7 +130,7 @@ unsigned char *alloc_buffer(size_t buf_size, int memflu= sh) return buf; } =20 -int run_fill_buf(size_t buf_size, int memflush) +int run_fill_buf(size_t buf_size, bool memflush) { unsigned char *buf; =20 diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/sel= ftests/resctrl/mba_test.c index be0ead73e55d..74d95c460bd0 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -172,11 +172,22 @@ static int mba_run_test(const struct resctrl_test *te= st, const struct user_param .setup =3D mba_setup, .measure =3D mba_measure, }; + struct fill_buf_param fill_buf =3D {}; int ret; =20 remove(RESULT_FILE_NAME); =20 - ret =3D resctrl_val(test, uparams, uparams->benchmark_cmd, ¶m); + if (uparams->fill_buf) { + fill_buf.buf_size =3D uparams->fill_buf->buf_size; + fill_buf.memflush =3D uparams->fill_buf->memflush; + param.fill_buf =3D &fill_buf; + } else if (!uparams->benchmark_cmd[0]) { + fill_buf.buf_size =3D DEFAULT_SPAN; + fill_buf.memflush =3D true; + param.fill_buf =3D &fill_buf; + } + + ret =3D resctrl_val(test, uparams, ¶m); if (ret) return ret; =20 diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/sel= ftests/resctrl/mbm_test.c index f516a2da1163..72261413c868 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -139,26 +139,26 @@ static int mbm_run_test(const struct resctrl_test *te= st, const struct user_param .setup =3D mbm_setup, .measure =3D mbm_measure, }; - char *endptr =3D NULL; - size_t span =3D 0; + struct fill_buf_param fill_buf =3D {}; int ret; =20 remove(RESULT_FILE_NAME); =20 - if (uparams->benchmark_cmd[0] && strcmp(uparams->benchmark_cmd[0], "fill_= buf") =3D=3D 0) { - if (uparams->benchmark_cmd[1]) { - errno =3D 0; - span =3D strtoul(uparams->benchmark_cmd[1], &endptr, 10); - if (errno || *endptr !=3D '\0') - return -errno; - } + if (uparams->fill_buf) { + fill_buf.buf_size =3D uparams->fill_buf->buf_size; + fill_buf.memflush =3D uparams->fill_buf->memflush; + param.fill_buf =3D &fill_buf; + } else if (!uparams->benchmark_cmd[0]) { + fill_buf.buf_size =3D DEFAULT_SPAN; + fill_buf.memflush =3D true; + param.fill_buf =3D &fill_buf; } =20 - ret =3D resctrl_val(test, uparams, uparams->benchmark_cmd, ¶m); + ret =3D resctrl_val(test, uparams, ¶m); if (ret) return ret; =20 - ret =3D check_results(span); + ret =3D check_results(param.fill_buf ? param.fill_buf->buf_size : 0); if (ret && (get_vendor() =3D=3D ARCH_INTEL)) ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is = enabled. Check BIOS configuration.\n"); =20 diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index 82801245e4c1..c9336f9c2cae 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -43,16 +43,36 @@ =20 #define DEFAULT_SPAN (250 * MB) =20 +/* + * fill_buf_param: "fill_buf" benchmark parameters + * @buf_size: Size (in bytes) of buffer used in benchmark. + * "fill_buf" allocates and initializes buffer of + * @buf_size. User can change value via command line. + * @memflush: If false the buffer will not be flushed after + * allocation and initialization, otherwise the + * buffer will be flushed. User can change value via + * command line (via integers with 0 interpreted as + * false and anything else as true). + */ +struct fill_buf_param { + size_t buf_size; + bool memflush; +}; + /* * user_params: User supplied parameters * @cpu: CPU number to which the benchmark will be bound to * @bits: Number of bits used for cache allocation size * @benchmark_cmd: Benchmark command to run during (some of the) tests + * @fill_buf: Pointer to user provided parameters for "fill_buf", + * NULL if user did not provide parameters and test + * specific defaults should be used. */ struct user_params { int cpu; int bits; const char *benchmark_cmd[BENCHMARK_ARGS]; + const struct fill_buf_param *fill_buf; }; =20 /* @@ -87,21 +107,29 @@ struct resctrl_test { * @init: Callback function to initialize test environment * @setup: Callback function to setup per test run environment * @measure: Callback that performs the measurement (a single test) + * @fill_buf: Parameters for default "fill_buf" benchmark. + * Initialized with user provided parameters, possibly + * adapted to be relevant to the test. If user does + * not provide parameters for "fill_buf" nor a + * replacement benchmark then initialized with defaults + * appropriate for test. NULL if user provided + * benchmark. */ struct resctrl_val_param { - const char *ctrlgrp; - const char *mongrp; - char filename[64]; - unsigned long mask; - int num_of_runs; - int (*init)(const struct resctrl_val_param *param, - int domain_id); - int (*setup)(const struct resctrl_test *test, - const struct user_params *uparams, - struct resctrl_val_param *param); - int (*measure)(const struct user_params *uparams, - struct resctrl_val_param *param, - pid_t bm_pid); + const char *ctrlgrp; + const char *mongrp; + char filename[64]; + unsigned long mask; + int num_of_runs; + int (*init)(const struct resctrl_val_param *param, + int domain_id); + int (*setup)(const struct resctrl_test *test, + const struct user_params *uparams, + struct resctrl_val_param *param); + int (*measure)(const struct user_params *uparams, + struct resctrl_val_param *param, + pid_t bm_pid); + struct fill_buf_param *fill_buf; }; =20 struct perf_event_read { @@ -138,10 +166,10 @@ int write_schemata(const char *ctrlgrp, char *schemat= a, int cpu_no, int write_bm_pid_to_resctrl(pid_t bm_pid, const char *ctrlgrp, const char = *mongrp); int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags); -unsigned char *alloc_buffer(size_t buf_size, int memflush); +unsigned char *alloc_buffer(size_t buf_size, bool memflush); void mem_flush(unsigned char *buf, size_t buf_size); void fill_cache_read(unsigned char *buf, size_t buf_size, bool once); -int run_fill_buf(size_t buf_size, int memflush); +int run_fill_buf(size_t buf_size, bool memflush); int initialize_read_mem_bw_imc(void); int measure_read_mem_bw(const struct user_params *uparams, struct resctrl_val_param *param, pid_t bm_pid); @@ -149,7 +177,6 @@ void initialize_mem_bw_resctrl(const struct resctrl_val= _param *param, int domain_id); int resctrl_val(const struct resctrl_test *test, const struct user_params *uparams, - const char * const *benchmark_cmd, struct resctrl_val_param *param); unsigned long create_bit_mask(unsigned int start, unsigned int len); unsigned int count_contiguous_bits(unsigned long val, unsigned int *start); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testin= g/selftests/resctrl/resctrl_tests.c index 0f91c475b255..88768f4d4961 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -148,6 +148,78 @@ static void run_single_test(const struct resctrl_test = *test, const struct user_p test_cleanup(test); } =20 +/* + * Allocate and initialize a struct fill_buf_param with user provided + * (via "-b fill_buf ") parameters. + * + * Use defaults (that may not be appropriate for all tests) for any + * fill_buf parameters omitted by the user. + * + * Historically it may have been possible for user space to provide + * additional parameters, "operation" ("read" vs "write") in + * benchmark_cmd[3] and "once" (run "once" or until terminated) in + * benchmark_cmd[4]. Changing these parameters have never been + * supported with the default of "read" operation and running until + * terminated built into the tests. Any unsupported values for + * (original) "fill_buf" parameters are treated as failure. + * + * Return: On failure, forcibly exits the test on any parsing failure, + * returns NULL if no parsing needed (user did not actually provide + * "-b fill_buf"). + * On success, returns pointer to newly allocated and fully + * initialized struct fill_buf_param that caller must free. + */ +static struct fill_buf_param *alloc_fill_buf_param(struct user_params *upa= rams) +{ + struct fill_buf_param *fill_param =3D NULL; + char *endptr =3D NULL; + + if (!uparams->benchmark_cmd[0] || strcmp(uparams->benchmark_cmd[0], "fill= _buf")) + return NULL; + + fill_param =3D malloc(sizeof(*fill_param)); + if (!fill_param) + ksft_exit_skip("Unable to allocate memory for fill_buf parameters.\n"); + + if (uparams->benchmark_cmd[1]) { + errno =3D 0; + fill_param->buf_size =3D strtoul(uparams->benchmark_cmd[1], &endptr, 10); + if (errno || *endptr !=3D '\0') { + free(fill_param); + ksft_exit_skip("Unable to parse benchmark buffer size.\n"); + } + } else { + fill_param->buf_size =3D DEFAULT_SPAN; + } + + if (uparams->benchmark_cmd[2]) { + errno =3D 0; + fill_param->memflush =3D strtol(uparams->benchmark_cmd[2], &endptr, 10) = !=3D 0; + if (errno || *endptr !=3D '\0') { + free(fill_param); + ksft_exit_skip("Unable to parse benchmark memflush parameter.\n"); + } + } else { + fill_param->memflush =3D true; + } + + if (uparams->benchmark_cmd[3]) { + if (strcmp(uparams->benchmark_cmd[3], "0")) { + free(fill_param); + ksft_exit_skip("Only read operations supported.\n"); + } + } + + if (uparams->benchmark_cmd[4]) { + if (strcmp(uparams->benchmark_cmd[4], "false")) { + free(fill_param); + ksft_exit_skip("fill_buf is required to run until termination.\n"); + } + } + + return fill_param; +} + static void init_user_params(struct user_params *uparams) { memset(uparams, 0, sizeof(*uparams)); @@ -158,11 +230,11 @@ static void init_user_params(struct user_params *upar= ams) =20 int main(int argc, char **argv) { + struct fill_buf_param *fill_param =3D NULL; int tests =3D ARRAY_SIZE(resctrl_tests); bool test_param_seen =3D false; struct user_params uparams; - char *span_str =3D NULL; - int ret, c, i; + int c, i; =20 init_user_params(&uparams); =20 @@ -239,6 +311,10 @@ int main(int argc, char **argv) } last_arg: =20 + fill_param =3D alloc_fill_buf_param(&uparams); + if (fill_param) + uparams.fill_buf =3D fill_param; + ksft_print_header(); =20 /* @@ -257,32 +333,11 @@ int main(int argc, char **argv) =20 filter_dmesg(); =20 - if (!uparams.benchmark_cmd[0]) { - /* If no benchmark is given by "-b" argument, use fill_buf. */ - uparams.benchmark_cmd[0] =3D "fill_buf"; - ret =3D asprintf(&span_str, "%u", DEFAULT_SPAN); - if (ret < 0) - ksft_exit_fail_msg("Out of memory!\n"); - uparams.benchmark_cmd[1] =3D span_str; - uparams.benchmark_cmd[2] =3D "1"; - /* - * Third parameter was previously used for "operation" - * (read/write) of which only (now default) "read"/"0" - * works. - * Fourth parameter was previously used to indicate - * how long "fill_buf" should run for, with "false" - * ("fill_buf" will keep running until terminated) - * the only option that works. - */ - uparams.benchmark_cmd[3] =3D NULL; - uparams.benchmark_cmd[4] =3D NULL; - } - ksft_set_plan(tests); =20 for (i =3D 0; i < ARRAY_SIZE(resctrl_tests); i++) run_single_test(resctrl_tests[i], &uparams); =20 - free(span_str); + free(fill_param); ksft_finished(); } diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index c4ebf70a46ef..00b3808d3bca 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -535,6 +535,11 @@ int measure_read_mem_bw(const struct user_params *upar= ams, return ret; } =20 +struct benchmark_info { + const struct user_params *uparams; + struct resctrl_val_param *param; +}; + /* * run_benchmark - Run a specified benchmark or fill_buf (default benchmar= k) * in specified signal. Direct benchmark stdio to /dev/null. @@ -544,12 +549,11 @@ int measure_read_mem_bw(const struct user_params *upa= rams, */ static void run_benchmark(int signum, siginfo_t *info, void *ucontext) { - char **benchmark_cmd; - int ret, memflush; - size_t span; + struct benchmark_info *benchmark_info =3D info->si_ptr; + const struct user_params *uparams =3D benchmark_info->uparams; + struct resctrl_val_param *param =3D benchmark_info->param; FILE *fp; - - benchmark_cmd =3D info->si_ptr; + int ret; =20 /* * Direct stdio of child to /dev/null, so that only parent writes to @@ -561,16 +565,13 @@ static void run_benchmark(int signum, siginfo_t *info= , void *ucontext) parent_exit(ppid); } =20 - if (strcmp(benchmark_cmd[0], "fill_buf") =3D=3D 0) { - /* Execute default fill_buf benchmark */ - span =3D strtoul(benchmark_cmd[1], NULL, 10); - memflush =3D atoi(benchmark_cmd[2]); - - if (run_fill_buf(span, memflush)) + if (param->fill_buf) { + if (run_fill_buf(param->fill_buf->buf_size, + param->fill_buf->memflush)) fprintf(stderr, "Error in running fill buffer\n"); - } else { + } else if (uparams->benchmark_cmd[0]) { /* Execute specified benchmark */ - ret =3D execvp(benchmark_cmd[0], benchmark_cmd); + ret =3D execvp(uparams->benchmark_cmd[0], (char **)uparams->benchmark_cm= d); if (ret) ksft_perror("execvp"); } @@ -585,16 +586,15 @@ static void run_benchmark(int signum, siginfo_t *info= , void *ucontext) * the benchmark * @test: test information structure * @uparams: user supplied parameters - * @benchmark_cmd: benchmark command and its arguments * @param: parameters passed to resctrl_val() * * Return: 0 when the test was run, < 0 on error. */ int resctrl_val(const struct resctrl_test *test, const struct user_params *uparams, - const char * const *benchmark_cmd, struct resctrl_val_param *param) { + struct benchmark_info benchmark_info; struct sigaction sigact; int ret =3D 0, pipefd[2]; char pipe_message =3D 0; @@ -610,6 +610,9 @@ int resctrl_val(const struct resctrl_test *test, return ret; } =20 + benchmark_info.uparams =3D uparams; + benchmark_info.param =3D param; + /* * If benchmark wasn't successfully started by child, then child should * kill parent, so save parent's pid @@ -671,13 +674,7 @@ int resctrl_val(const struct resctrl_test *test, =20 ksft_print_msg("Benchmark PID: %d\n", (int)bm_pid); =20 - /* - * The cast removes constness but nothing mutates benchmark_cmd within - * the context of this process. At the receiving process, it becomes - * argv, which is mutable, on exec() but that's after fork() so it - * doesn't matter for the process running the tests. - */ - value.sival_ptr =3D (void *)benchmark_cmd; + value.sival_ptr =3D (void *)&benchmark_info; =20 /* Taskset benchmark to specified cpu */ ret =3D taskset_benchmark(bm_pid, uparams->cpu, NULL); --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28815187FE7; Fri, 18 Oct 2024 02:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218168; cv=none; b=HDC1A+8YveV8XI1+oCnScHd6w41dUCux1q8eJwl/RS1dh2mQyOfvyVV63eYjUCCw8GN/QXy0uo1NfqKF54Kj4VECIiO6CLW/VrBvmIf9w3Ofvjt+V9d1WpbzJsKNTkJaVPvcAHm7yI3Cd3WMdQwEypddf7Qyz3jTH/qJgPF3pNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218168; c=relaxed/simple; bh=4+M6xPEB2/ZL6vA1056PHbtU7tkTsMHLCA4D25GFk7Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qzO47DEEMJ3+hWnMvVpKXF72Pd5+yH1NUNYE8Ylub/wLtYCOrvRSXBvqbPhoEtKHmhYxfsWzw6G6kIiHwb5REXxM92Wm7NXqncdMEBwWzmpfViRGSUP7sAEbrMVO+J8bWeaIYW903+Nj1SiDK7uwxKdMihpVsdchaTeZB9kuazc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=RKMBJAOs; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RKMBJAOs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218165; x=1760754165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4+M6xPEB2/ZL6vA1056PHbtU7tkTsMHLCA4D25GFk7Y=; b=RKMBJAOsH3uvyCA3EwVmE03BZ9rw2H8fNGXNhQcB7tZIQBAumuMJ8Ebh 0KJ4MA+n7yL6Pk1mE2QbIb/1p6TWv0+FPwvNSzQfd7FpDCmKrg/JAFr5i pvWY7+siV/dWTBCYPalNI/E8Jy1azKlDDbUK2wLGFszfvwX3QgGpHJHkH 50l0sceGvckAicGNGzYomWA/5Zy3HiHnqgGhg3yE5UXD4dwuNaO3ibmMr HrgVXLRKiSk7K99j6m9gNmcfwaV29T0EHl6iBebnj0ccj98grTkBUfoj4 Fv++q00nIXc1dnOIDLbhYiMkATr1EdWfG/ransCsuLGGZ4uOqS0QuWWt4 A==; X-CSE-ConnectionGUID: 4fBi2I0BSS22I0qC/0g0sw== X-CSE-MsgGUID: kiB5lJzPR5mkC4j/231fyQ== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149718" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149718" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:38 -0700 X-CSE-ConnectionGUID: hJ7vuQ2cSb6y3Q3lmgqfyg== X-CSE-MsgGUID: 9+vTA36JREi7xxRu6lE7Ow== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697731" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 11/15] selftests/resctrl: Ensure measurements skip initialization of default benchmark Date: Thu, 17 Oct 2024 19:33:26 -0700 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The CMT, MBA, and MBM tests rely on the resctrl_val() wrapper to start and run a benchmark while providing test specific flows via callbacks to do test specific configuration and measurements. At a high level, the resctrl_val() flow is: a) Start by fork()ing a child process that installs a signal handler for SIGUSR1 that, on receipt of SIGUSR1, will start running a benchmark. b) Assign the child process created in (a) to the resctrl control and monitoring group that dictates the memory and cache allocations with which the process can run and will contain all resctrl monitoring data of that process. c) Once parent and child are considered "ready" (determined via a message over a pipe) the parent signals the child (via SIGUSR1) to start the benchmark, waits one second for the benchmark to run, and then starts collecting monitoring data for the tests, potentially also changing allocation configuration depending on the various test callbacks. A problem with the above flow is the "black box" view of the benchmark that is combined with an arbitrarily chosen "wait one second" before measurements start. No matter what the benchmark does, it is given one second to initialize before measurements start. The default benchmark "fill_buf" consists of two parts, first it prepares a buffer (allocate, initialize, then flush), then it reads from the buffer (in unpredictable ways) until terminated. Depending on the system and the size of the buffer, the first "prepare" part may not be complete by the time the one second delay expires. Test measurements may thus start before the work needing to be measured runs. Split the default benchmark into its "prepare" and "runtime" parts and simplify the resctrl_val() wrapper while doing so. This same split cannot be done for the user provided benchmark (without a user interface change), so the current behavior is maintained for user provided benchmark. Assign the test itself to the control and monitoring group and run the "prepare" part of the benchmark in this context, ensuring it runs with required cache and memory bandwidth allocations. With the benchmark preparation complete it is only needed to fork() the "runtime" part of the benchmark (or entire user provided benchmark). Keep the "wait one second" delay before measurements start. For the default "fill_buf" benchmark this time now covers only the "runtime" portion that needs to be measured. For the user provided benchmark this delay maintains current behavior. Signed-off-by: Reinette Chatre Reviewed-by: Ilpo J=C3=A4rvinen --- Changes since V2: - Add Ilpo's Reviewed-by tag. Changes since V1: - Keep the fflush(stdout) before fork() to avoid duplicate messages. (Ilpo) - Re-order in series to that the new behavior is introduced after issues with existing behavior is addressed. --- tools/testing/selftests/resctrl/fill_buf.c | 15 -- tools/testing/selftests/resctrl/resctrl.h | 1 - tools/testing/selftests/resctrl/resctrl_val.c | 195 +++++------------- 3 files changed, 50 insertions(+), 161 deletions(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/sel= ftests/resctrl/fill_buf.c index 39545f9369e8..380cc35f10c6 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -129,18 +129,3 @@ unsigned char *alloc_buffer(size_t buf_size, bool memf= lush) =20 return buf; } - -int run_fill_buf(size_t buf_size, bool memflush) -{ - unsigned char *buf; - - buf =3D alloc_buffer(buf_size, memflush); - if (!buf) - return -1; - - fill_cache_read(buf, buf_size, false); - - free(buf); - - return 0; -} diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index c9336f9c2cae..032cd9ebd761 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -169,7 +169,6 @@ int perf_event_open(struct perf_event_attr *hw_event, p= id_t pid, int cpu, unsigned char *alloc_buffer(size_t buf_size, bool memflush); void mem_flush(unsigned char *buf, size_t buf_size); void fill_cache_read(unsigned char *buf, size_t buf_size, bool once); -int run_fill_buf(size_t buf_size, bool memflush); int initialize_read_mem_bw_imc(void); int measure_read_mem_bw(const struct user_params *uparams, struct resctrl_val_param *param, pid_t bm_pid); diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index 00b3808d3bca..7c08e936572d 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -373,7 +373,7 @@ static int get_mem_bw_resctrl(FILE *fp, unsigned long *= mbm_total) return 0; } =20 -static pid_t bm_pid, ppid; +static pid_t bm_pid; =20 void ctrlc_handler(int signum, siginfo_t *info, void *ptr) { @@ -431,13 +431,6 @@ void signal_handler_unregister(void) } } =20 -static void parent_exit(pid_t ppid) -{ - kill(ppid, SIGKILL); - umount_resctrlfs(); - exit(EXIT_FAILURE); -} - /* * print_results_bw: the memory bandwidth results are stored in a file * @filename: file that stores the results @@ -535,52 +528,6 @@ int measure_read_mem_bw(const struct user_params *upar= ams, return ret; } =20 -struct benchmark_info { - const struct user_params *uparams; - struct resctrl_val_param *param; -}; - -/* - * run_benchmark - Run a specified benchmark or fill_buf (default benchmar= k) - * in specified signal. Direct benchmark stdio to /dev/null. - * @signum: signal number - * @info: signal info - * @ucontext: user context in signal handling - */ -static void run_benchmark(int signum, siginfo_t *info, void *ucontext) -{ - struct benchmark_info *benchmark_info =3D info->si_ptr; - const struct user_params *uparams =3D benchmark_info->uparams; - struct resctrl_val_param *param =3D benchmark_info->param; - FILE *fp; - int ret; - - /* - * Direct stdio of child to /dev/null, so that only parent writes to - * stdio (console) - */ - fp =3D freopen("/dev/null", "w", stdout); - if (!fp) { - ksft_perror("Unable to direct benchmark status to /dev/null"); - parent_exit(ppid); - } - - if (param->fill_buf) { - if (run_fill_buf(param->fill_buf->buf_size, - param->fill_buf->memflush)) - fprintf(stderr, "Error in running fill buffer\n"); - } else if (uparams->benchmark_cmd[0]) { - /* Execute specified benchmark */ - ret =3D execvp(uparams->benchmark_cmd[0], (char **)uparams->benchmark_cm= d); - if (ret) - ksft_perror("execvp"); - } - - fclose(stdout); - ksft_print_msg("Unable to run specified benchmark\n"); - parent_exit(ppid); -} - /* * resctrl_val: execute benchmark and measure memory bandwidth on * the benchmark @@ -594,12 +541,11 @@ int resctrl_val(const struct resctrl_test *test, const struct user_params *uparams, struct resctrl_val_param *param) { - struct benchmark_info benchmark_info; - struct sigaction sigact; - int ret =3D 0, pipefd[2]; - char pipe_message =3D 0; - union sigval value; + unsigned char *buf =3D NULL; + cpu_set_t old_affinity; int domain_id; + int ret =3D 0; + pid_t ppid; =20 if (strcmp(param->filename, "") =3D=3D 0) sprintf(param->filename, "stdio"); @@ -610,108 +556,65 @@ int resctrl_val(const struct resctrl_test *test, return ret; } =20 - benchmark_info.uparams =3D uparams; - benchmark_info.param =3D param; - - /* - * If benchmark wasn't successfully started by child, then child should - * kill parent, so save parent's pid - */ ppid =3D getpid(); =20 - if (pipe(pipefd)) { - ksft_perror("Unable to create pipe"); + /* Taskset test to specified CPU. */ + ret =3D taskset_benchmark(ppid, uparams->cpu, &old_affinity); + if (ret) + return ret; =20 - return -1; + /* Write test to specified control & monitoring group in resctrl FS. */ + ret =3D write_bm_pid_to_resctrl(ppid, param->ctrlgrp, param->mongrp); + if (ret) + goto reset_affinity; + + if (param->init) { + ret =3D param->init(param, domain_id); + if (ret) + goto reset_affinity; } =20 /* - * Fork to start benchmark, save child's pid so that it can be killed - * when needed + * If not running user provided benchmark, run the default + * "fill_buf". First phase of "fill_buf" is to prepare the + * buffer that the benchmark will operate on. No measurements + * are needed during this phase and prepared memory will be + * passed to next part of benchmark via copy-on-write thus + * no impact on the benchmark that relies on reading from + * memory only. */ + if (param->fill_buf) { + buf =3D alloc_buffer(param->fill_buf->buf_size, + param->fill_buf->memflush); + if (!buf) { + ret =3D -ENOMEM; + goto reset_affinity; + } + } + fflush(stdout); bm_pid =3D fork(); if (bm_pid =3D=3D -1) { + ret =3D -errno; ksft_perror("Unable to fork"); - - return -1; + goto free_buf; } =20 + /* + * What needs to be measured runs in separate process until + * terminated. + */ if (bm_pid =3D=3D 0) { - /* - * Mask all signals except SIGUSR1, parent uses SIGUSR1 to - * start benchmark - */ - sigfillset(&sigact.sa_mask); - sigdelset(&sigact.sa_mask, SIGUSR1); - - sigact.sa_sigaction =3D run_benchmark; - sigact.sa_flags =3D SA_SIGINFO; - - /* Register for "SIGUSR1" signal from parent */ - if (sigaction(SIGUSR1, &sigact, NULL)) { - ksft_perror("Can't register child for signal"); - parent_exit(ppid); - } - - /* Tell parent that child is ready */ - close(pipefd[0]); - pipe_message =3D 1; - if (write(pipefd[1], &pipe_message, sizeof(pipe_message)) < - sizeof(pipe_message)) { - ksft_perror("Failed signaling parent process"); - close(pipefd[1]); - return -1; - } - close(pipefd[1]); - - /* Suspend child until delivery of "SIGUSR1" from parent */ - sigsuspend(&sigact.sa_mask); - - ksft_perror("Child is done"); - parent_exit(ppid); + if (param->fill_buf) + fill_cache_read(buf, param->fill_buf->buf_size, false); + else if (uparams->benchmark_cmd[0]) + execvp(uparams->benchmark_cmd[0], (char **)uparams->benchmark_cmd); + exit(EXIT_SUCCESS); } =20 ksft_print_msg("Benchmark PID: %d\n", (int)bm_pid); =20 - value.sival_ptr =3D (void *)&benchmark_info; - - /* Taskset benchmark to specified cpu */ - ret =3D taskset_benchmark(bm_pid, uparams->cpu, NULL); - if (ret) - goto out; - - /* Write benchmark to specified control&monitoring grp in resctrl FS */ - ret =3D write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp); - if (ret) - goto out; - - if (param->init) { - ret =3D param->init(param, domain_id); - if (ret) - goto out; - } - - /* Parent waits for child to be ready. */ - close(pipefd[1]); - while (pipe_message !=3D 1) { - if (read(pipefd[0], &pipe_message, sizeof(pipe_message)) < - sizeof(pipe_message)) { - ksft_perror("Failed reading message from child process"); - close(pipefd[0]); - goto out; - } - } - close(pipefd[0]); - - /* Signal child to start benchmark */ - if (sigqueue(bm_pid, SIGUSR1, value) =3D=3D -1) { - ksft_perror("sigqueue SIGUSR1 to child"); - ret =3D -1; - goto out; - } - - /* Give benchmark enough time to fully run */ + /* Give benchmark enough time to fully run. */ sleep(1); =20 /* Test runs until the callback setup() tells the test to stop. */ @@ -729,8 +632,10 @@ int resctrl_val(const struct resctrl_test *test, break; } =20 -out: kill(bm_pid, SIGKILL); - +free_buf: + free(buf); +reset_affinity: + taskset_restore(ppid, &old_affinity); return ret; } --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89B4B188012; Fri, 18 Oct 2024 02:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218167; cv=none; b=V4OwmjKr5+oAkR9aasX4ebfnxHEtdZbX4Axs46jkpUpjvvFqOXPpoSvHyzhp0eOAggbzWO/6exUPLidFq2sApaQ+9jw+lkqSkbHveBqwomG/hJMqHBGksQrJkNEgsj2oJ+A/nLAta1DxTT1jJTlH2s3+KnhdH3FpkCNBMij28Tc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218167; c=relaxed/simple; bh=LF2o/Era7xSNvAB0Kk818hm/mieubwe/KElr/Vt+Yrg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UZmgtcbK1aH9s6gf2SH4eY5t5mSfakUTAvbqWrEkmXtWrJsS7nQeEWbEb2oITIC7ICZ1p1IWWUDXD38DKzd/aUdou0DyUknON2p9HJROZbnOZ/CpWx55D00ZSL9cpRJD4RwcUwPp9DqNrrgE2RvIyxuNHmzxp7iVGsxZO8vHnnQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Bssk2wt/; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Bssk2wt/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218166; x=1760754166; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LF2o/Era7xSNvAB0Kk818hm/mieubwe/KElr/Vt+Yrg=; b=Bssk2wt/5+BBZC2m6G1Qpwvqiz86nvl9nmbfCvXIVJ7/gO+o8er+0Gzt 9ArzQLaIgRzYAipBAefPmh8AorQvjLIOMzip6FtwCmOQkvQ8bmsxJoAEi wT+b0uGdX3rhY1YrTtp+MtO7BlLPojqLlMsKXfCL/ysvZcyeEPzmSMXU8 n5dTNBua7HsQ249S1aTzVOtqRcmh9SXbWLJI5a1tEx7gi2oi7vf4pvjVU fHaVUD8YyXFwUsW7qp0AvdldbxYVDI7aR1vpNQnK2IBpOv4JQoziGybK9 8G9b+GiAjfUd0cJS/8/DGmuuz6DFkonVWJ02eh9er3gUKoP34JTHU297w A==; X-CSE-ConnectionGUID: l+ZA4yaURSqE7EuYrKq1Cg== X-CSE-MsgGUID: LBolW/dIQYaM9WY1mqeNUA== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149720" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149720" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:38 -0700 X-CSE-ConnectionGUID: 7SRKs+ZNRDmg0VmC5TZpjw== X-CSE-MsgGUID: KLZW7h8zS5SbNpsazrYVrA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697734" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 12/15] selftests/resctrl: Use cache size to determine "fill_buf" buffer size Date: Thu, 17 Oct 2024 19:33:27 -0700 Message-ID: <388c93423d9a071f5877f3edb4f55ef64bf384bc.1729218182.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" By default the MBM and MBA tests use the "fill_buf" benchmark to read from a buffer with the goal to measure the memory bandwidth generated by this buffer access. Care should be taken when sizing the buffer used by the "fill_buf" benchmark. If the buffer is small enough to fit in the cache then it cannot be expected that the benchmark will generate much memory bandwidth. For example, on a system with 320MB L3 cache the existing hardcoded default of 250MB is insufficient. Use the measured cache size to determine a buffer size that can be expected to trigger memory access while keeping the existing default as minimum, now renamed to MINIMUM_SPAN, that has been appropriate for testing so far. Signed-off-by: Reinette Chatre Reviewed-by: Ilpo J=C3=A4rvinen --- Changes since V2: - Move duplicate code into helper. (Ilpo) - Rename DEFAULT_SPAN to MINIMUM_SPAN to reflect its new purpose. (Ilpo) - Do _not_ add Ilpo's Reviewed-by tag ... the patch changed too much. Changes since V1: - Ensure buffer is at least double L3 cache size. (Ilpo) - Support user override of default buffer size. (Ilpo) --- tools/testing/selftests/resctrl/fill_buf.c | 13 +++++++++++++ tools/testing/selftests/resctrl/mba_test.c | 7 ++++++- tools/testing/selftests/resctrl/mbm_test.c | 7 ++++++- tools/testing/selftests/resctrl/resctrl.h | 3 ++- tools/testing/selftests/resctrl/resctrl_tests.c | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/sel= ftests/resctrl/fill_buf.c index 380cc35f10c6..19a01a52dc1a 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -129,3 +129,16 @@ unsigned char *alloc_buffer(size_t buf_size, bool memf= lush) =20 return buf; } + +ssize_t get_fill_buf_size(int cpu_no, const char *cache_type) +{ + unsigned long cache_total_size =3D 0; + int ret; + + ret =3D get_cache_size(cpu_no, cache_type, &cache_total_size); + if (ret) + return ret; + + return cache_total_size * 2 > MINIMUM_SPAN ? + cache_total_size * 2 : MINIMUM_SPAN; +} diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/sel= ftests/resctrl/mba_test.c index 74d95c460bd0..bf37f3555660 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -182,7 +182,12 @@ static int mba_run_test(const struct resctrl_test *tes= t, const struct user_param fill_buf.memflush =3D uparams->fill_buf->memflush; param.fill_buf =3D &fill_buf; } else if (!uparams->benchmark_cmd[0]) { - fill_buf.buf_size =3D DEFAULT_SPAN; + ssize_t buf_size; + + buf_size =3D get_fill_buf_size(uparams->cpu, "L3"); + if (buf_size < 0) + return buf_size; + fill_buf.buf_size =3D buf_size; fill_buf.memflush =3D true; param.fill_buf =3D &fill_buf; } diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/sel= ftests/resctrl/mbm_test.c index 72261413c868..4224f8ce3538 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -149,7 +149,12 @@ static int mbm_run_test(const struct resctrl_test *tes= t, const struct user_param fill_buf.memflush =3D uparams->fill_buf->memflush; param.fill_buf =3D &fill_buf; } else if (!uparams->benchmark_cmd[0]) { - fill_buf.buf_size =3D DEFAULT_SPAN; + ssize_t buf_size; + + buf_size =3D get_fill_buf_size(uparams->cpu, "L3"); + if (buf_size < 0) + return buf_size; + fill_buf.buf_size =3D buf_size; fill_buf.memflush =3D true; param.fill_buf =3D &fill_buf; } diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index 032cd9ebd761..a553fe975938 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -41,7 +41,7 @@ =20 #define BENCHMARK_ARGS 64 =20 -#define DEFAULT_SPAN (250 * MB) +#define MINIMUM_SPAN (250 * MB) =20 /* * fill_buf_param: "fill_buf" benchmark parameters @@ -169,6 +169,7 @@ int perf_event_open(struct perf_event_attr *hw_event, p= id_t pid, int cpu, unsigned char *alloc_buffer(size_t buf_size, bool memflush); void mem_flush(unsigned char *buf, size_t buf_size); void fill_cache_read(unsigned char *buf, size_t buf_size, bool once); +ssize_t get_fill_buf_size(int cpu_no, const char *cache_type); int initialize_read_mem_bw_imc(void); int measure_read_mem_bw(const struct user_params *uparams, struct resctrl_val_param *param, pid_t bm_pid); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testin= g/selftests/resctrl/resctrl_tests.c index 88768f4d4961..790f4eb7871a 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -189,7 +189,7 @@ static struct fill_buf_param *alloc_fill_buf_param(stru= ct user_params *uparams) ksft_exit_skip("Unable to parse benchmark buffer size.\n"); } } else { - fill_param->buf_size =3D DEFAULT_SPAN; + fill_param->buf_size =3D MINIMUM_SPAN; } =20 if (uparams->benchmark_cmd[2]) { --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 930B7188713; Fri, 18 Oct 2024 02:22:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218168; cv=none; b=ikgFeelbP3NEsTLQZywAnxYa0cxfRHXcXuq5PLsMuhVC6J6MWQXqu9DJDDwISZjhB3lgcDyH8iLqRfj7uTCP9p41w7GSczrBv1nU2DETJQgRYPeRAxXW7NVylf6j0XQafV4bzD/zs5lJwzOk2Sa+4UrwEYns7vJY88DcOm9Cw4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218168; c=relaxed/simple; bh=vSW/xY/u5gQfdaq8Fb5zDhVy9K06adJcO87Sfqnguxo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hs7PBlF8hW6aFPgqA1QeSsaSAgo3i/8vLbtt7x8zMrv2AWZUjIvEEcFz4vLw8xQkLdTZ5pmZkpln+laIQdvBybUbt6dW+5WVysvfi1Q/K+Yq6F7qPZ6nLQdM7iknQ2fr/ive7zD02ZookfFweNeEWZKbRVBW8q7HN7tJ4EjDAWg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=g/CshZ4c; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="g/CshZ4c" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218167; x=1760754167; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vSW/xY/u5gQfdaq8Fb5zDhVy9K06adJcO87Sfqnguxo=; b=g/CshZ4cwTEiw8Yg6zaoWUhizohWTbcUIAtTMzH3KJdQ2koaE4DLgsez m1k6zOjET1vzqk/qtnhAGx/aXTHL9iHru698I1TV9Cu60J75I9Kk5iaeH xPxPVQTk0a04nHIGF5P9X5/tMKy2+Fv+OZc4eTKhBQK+Wr0p40YxXShjo LZ9NNXqrMAqxUcXrfflwVdSiTx+acn97vH6xZ8Q3nCjcVjeZWVOe2JXk7 sxAML0oUw8aM9vDKArWWcJXoffkIadrRweoEI+QNLJlj3w7c3SWU3O8T6 ufMINBXwC8qG3jPn6a2/26Ymc5N+YY0MuhlT37FBUPt/EoajW5+bCigFY w==; X-CSE-ConnectionGUID: 7SUFslUgQ+WDRNjgtydD6A== X-CSE-MsgGUID: 0wOlB5wiRoKzEV7vs00uWw== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149721" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149721" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:38 -0700 X-CSE-ConnectionGUID: MvDR+WAaTJKdlQAxE7Q/xw== X-CSE-MsgGUID: snqS7aexSLuXEefTbLjNCQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697738" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 13/15] selftests/resctrl: Do not compare performance counters and resctrl at low bandwidth Date: Thu, 17 Oct 2024 19:33:28 -0700 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The MBA test incrementally throttles memory bandwidth, each time followed by a comparison between the memory bandwidth observed by the performance counters and resctrl respectively. While a comparison between performance counters and resctrl is generally appropriate, they do not have an identical view of memory bandwidth. For example RAS features or memory performance features that generate memory traffic may drive accesses that are counted differently by performance counters and MBM respectively, for instance generating "overhead" traffic which is not counted against any specific RMID. As a ratio, this different view of memory bandwidth becomes more apparent at low memory bandwidths. It is not practical to enable/disable the various features that may generate memory bandwidth to give performance counters and resctrl an identical view. Instead, do not compare performance counters and resctrl view of memory bandwidth when the memory bandwidth is low. Bandwidth throttling behaves differently across platforms so it is not appropriate to drop measurement data simply based on the throttling level. Instead, use a threshold of 750MiB that has been observed to support adequate comparison between performance counters and resctrl. Signed-off-by: Reinette Chatre Reviewed-by: Ilpo J=C3=A4rvinen --- Changes since V2: - Add Ilpo's Reviewed-by tag. Changes since V1: - Fix code alignment and spacing. - Modify flow to use "continue" instead of "break" now that earlier changes decreases throttling. - Expand comment of define to elaborate causes of discrepancy between performance counters and MBM. --- tools/testing/selftests/resctrl/mba_test.c | 7 +++++++ tools/testing/selftests/resctrl/resctrl.h | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/sel= ftests/resctrl/mba_test.c index bf37f3555660..5b4f0aa7a3a4 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -98,6 +98,13 @@ static bool show_mba_info(unsigned long *bw_imc, unsigne= d long *bw_resc) =20 avg_bw_imc =3D sum_bw_imc / (NUM_OF_RUNS - 1); avg_bw_resc =3D sum_bw_resc / (NUM_OF_RUNS - 1); + if (avg_bw_imc < THROTTLE_THRESHOLD || avg_bw_resc < THROTTLE_THRESHOLD)= { + ksft_print_msg("Bandwidth below threshold (%d MiB). Dropping results fr= om MBA schemata %u.\n", + THROTTLE_THRESHOLD, + ALLOCATION_MIN + ALLOCATION_STEP * allocation); + continue; + } + avg_diff =3D (float)labs(avg_bw_resc - avg_bw_imc) / avg_bw_imc; avg_diff_per =3D (int)(avg_diff * 100); =20 diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index a553fe975938..dab1953fc7a0 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -43,6 +43,16 @@ =20 #define MINIMUM_SPAN (250 * MB) =20 +/* + * Memory bandwidth (in MiB) below which the bandwidth comparisons + * between iMC and resctrl are considered unreliable. For example RAS + * features or memory performance features that generate memory traffic + * may drive accesses that are counted differently by performance counters + * and MBM respectively, for instance generating "overhead" traffic which + * is not counted against any specific RMID. + */ +#define THROTTLE_THRESHOLD 750 + /* * fill_buf_param: "fill_buf" benchmark parameters * @buf_size: Size (in bytes) of buffer used in benchmark. --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AC72188912; Fri, 18 Oct 2024 02:22:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218170; cv=none; b=TnJjlOPQFEfyOaEcMcYNeXXGINHgkiNeyiYoPL4lJrSaFfEixRGq/iCzzV3ihWC8bMWRqFwzJ96br16zQdskOvYnEqLORU1qabTlpFf1yQS5HteAEb0/3IXbhdRTvRLIF419oPnF3xTAfedKgHMr6DAL1XdJsja4w/ESVT79GFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218170; c=relaxed/simple; bh=rekm5nk2Fa51gQ2WkClGucC0pLS1nGxBhoPpHZmLRyc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nl4pyLFxhPBZHvzSAthRvC/BV9LTMGPjMwFSsuBFYg8LFuldryLnI6gUPl4FM9Eg+DctCh/8hPHL8eTmLI//T/zk8pkrHKmX3O9nhQHNMPnmFwgk7glHTXPXZUbX0drgVralCtTeXPGnYnUb3md/A+3g2WfVk9tqAa+/KR82Nic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=EnZfhGMW; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="EnZfhGMW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218168; x=1760754168; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rekm5nk2Fa51gQ2WkClGucC0pLS1nGxBhoPpHZmLRyc=; b=EnZfhGMWVCBJNQTyiaYqqIX8Jl79R48prh6R3cPiTFS3VWxHXi5IAmg/ OIDVTpb53U806tgmJup+37X8r3oSCz/uaV3acNvlV6DqRr58nWczdsPfR sdy0Y5riZByFw8UvIVY+H1nUqlpOkf2dtS3UZ0zqOkFwPzJ9RxXdgwp/8 zPFaDBcobSsNF0PtkFo3TWzdDDniS2070os597cYRGePHPcOxqKezQ67N SC69V1c0F2DIsxaXqyaUZ4dK3GO2/O1YCEcPQTpmuOcOJKZCbF/szTgTi jQYvTTLAog0gAH6x9oHwELJ5HRBSvwHiZBLg+n1oBqnGfuZMIdk2QhUxe A==; X-CSE-ConnectionGUID: a4pXeyhQSjiWxSg4Ys3emA== X-CSE-MsgGUID: FJHZSlRjTQiGg/tZyDZvpw== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149723" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149723" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:38 -0700 X-CSE-ConnectionGUID: lxWic12KTw6q1wyiR/Urfw== X-CSE-MsgGUID: zABcuXEWT8mRPMEyECy0jA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697741" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 14/15] selftests/resctrl: Keep results from first test run Date: Thu, 17 Oct 2024 19:33:29 -0700 Message-ID: <48201899f58835fca850913fe32a07940b394e8c.1729218182.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The resctrl selftests drop the results from every first test run to avoid (per comment) "inaccurate due to monitoring setup transition phase" data. Previously inaccurate data resulted from workloads needing some time to "settle" and also the measurements themselves to account for earlier measurements to measure across needed timeframe. commit da50de0a92f3 ("selftests/resctrl: Calculate resctrl FS derived mem bw over sleep(1) only") ensured that measurements accurately measure just the time frame of interest. The default "fill_buf" benchmark since separated the buffer prepare phase from the benchmark run phase reducing the need for the tests themselves to accommodate the benchmark's "settle" time. With these enhancements there are no remaining portions needing to "settle" and the first test run can contribute to measurements. Signed-off-by: Reinette Chatre Reviewed-by: Ilpo J=C3=A4rvinen --- Changes since V2: - Separate patch addresses Ilpo's observation about magic number in adjacent code. - Add Ilpo's Reviewed-by tag. Changes since V1: - Remove comment about needing results from first run removed. - Fix existing incorrect spacing while changing line. --- tools/testing/selftests/resctrl/cmt_test.c | 5 ++--- tools/testing/selftests/resctrl/mba_test.c | 10 +++------- tools/testing/selftests/resctrl/mbm_test.c | 10 +++------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/sel= ftests/resctrl/cmt_test.c index 4c3cf2c25a38..3bbf3042fb06 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -99,14 +99,13 @@ static int check_results(struct resctrl_val_param *para= m, size_t span, int no_of } =20 /* Field 3 is llc occ resc value */ - if (runs > 0) - sum_llc_occu_resc +=3D strtoul(token_array[3], NULL, 0); + sum_llc_occu_resc +=3D strtoul(token_array[3], NULL, 0); runs++; } fclose(fp); =20 return show_results_info(sum_llc_occu_resc, no_of_bits, span, - MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, true); + MAX_DIFF, MAX_DIFF_PERCENT, runs, true); } =20 static void cmt_test_cleanup(void) diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/sel= ftests/resctrl/mba_test.c index 5b4f0aa7a3a4..4e6645b172e3 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -86,18 +86,14 @@ static bool show_mba_info(unsigned long *bw_imc, unsign= ed long *bw_resc) int avg_diff_per; float avg_diff; =20 - /* - * The first run is discarded due to inaccurate value from - * phase transition. - */ - for (runs =3D NUM_OF_RUNS * allocation + 1; + for (runs =3D NUM_OF_RUNS * allocation; runs < NUM_OF_RUNS * allocation + NUM_OF_RUNS ; runs++) { sum_bw_imc +=3D bw_imc[runs]; sum_bw_resc +=3D bw_resc[runs]; } =20 - avg_bw_imc =3D sum_bw_imc / (NUM_OF_RUNS - 1); - avg_bw_resc =3D sum_bw_resc / (NUM_OF_RUNS - 1); + avg_bw_imc =3D sum_bw_imc / NUM_OF_RUNS; + avg_bw_resc =3D sum_bw_resc / NUM_OF_RUNS; if (avg_bw_imc < THROTTLE_THRESHOLD || avg_bw_resc < THROTTLE_THRESHOLD)= { ksft_print_msg("Bandwidth below threshold (%d MiB). Dropping results fr= om MBA schemata %u.\n", THROTTLE_THRESHOLD, diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/sel= ftests/resctrl/mbm_test.c index 4224f8ce3538..315b2ef3b3bc 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -22,17 +22,13 @@ show_bw_info(unsigned long *bw_imc, unsigned long *bw_r= esc, size_t span) int runs, ret, avg_diff_per; float avg_diff =3D 0; =20 - /* - * Discard the first value which is inaccurate due to monitoring setup - * transition phase. - */ - for (runs =3D 1; runs < NUM_OF_RUNS ; runs++) { + for (runs =3D 0; runs < NUM_OF_RUNS; runs++) { sum_bw_imc +=3D bw_imc[runs]; sum_bw_resc +=3D bw_resc[runs]; } =20 - avg_bw_imc =3D sum_bw_imc / 4; - avg_bw_resc =3D sum_bw_resc / 4; + avg_bw_imc =3D sum_bw_imc / NUM_OF_RUNS; + avg_bw_resc =3D sum_bw_resc / NUM_OF_RUNS; avg_diff =3D (float)labs(avg_bw_resc - avg_bw_imc) / avg_bw_imc; avg_diff_per =3D (int)(avg_diff * 100); =20 --=20 2.46.2 From nobody Tue Nov 26 12:20:20 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A72C188A3A; Fri, 18 Oct 2024 02:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218170; cv=none; b=cKowjsNuZTAeBRLcFZzqBJcAh52iDMv+/rwUZSjGuGXpS6/omVCCaqr9L7PuSNdYuEYOf1+CVwcUAAA+QbqrvdJHtjeKmi8QuTeVU98Hz+1afkOaj8+rAv6tiEuRh9wpEhEYG68Jbz+akwJLAMcXMPNNPuB0HpGuixpSaNA8+2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729218170; c=relaxed/simple; bh=tI6VohGtESZrrT4HRmtXRzYBMdb1L8lF9wfiL0/qAqs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n54ULumjBNuHVjE6JBF31b4+aVK5jT+7zDhRPRSPM9iAiTOl/JXJ2ZGftYRIWFXKg8BQxyCTOB1nt4Y63owt5e3gSRY9PD5Ee5vZtVB1J6P6Dp64VcZXWier808xheGsDcvI4Z8mSkeYB60kb9Y8K9RPSDConekjAh+Z/eRVjcE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=I5m/kEn+; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="I5m/kEn+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729218168; x=1760754168; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tI6VohGtESZrrT4HRmtXRzYBMdb1L8lF9wfiL0/qAqs=; b=I5m/kEn+YKUi7HDpEf8nHLXmqThrNhzVG3V7XdhkYjznuNycsnk/nyTk g1iJNfjZFK5klg76Krsa24ZHYQrmuI9BA3eQpX8ImYS0Dxrw+hHYAaNcE e1aoN4qtfc11a0MSn9Jj5Nu7NdLhoTQCG23zJ/uJxEfxySPqigtzJ/coq vyq11M5W1ZXJ22KuFqBb46cvV0zvPWyoor6e5OJPeRXape4FG7eWyrTbX UTD2vCEA/yvYR7/wcDWghsyEQx1L4ldRCQ3pbHJE5q7AD0FTS6wu8P7lf Oh+bivJWyC13Y7N23aslh70trjw+F4kkqkkghVsD5gRIi9cXKJ+iSPqXE Q==; X-CSE-ConnectionGUID: jC8tIDWGSTaJCWf0TGfBLQ== X-CSE-MsgGUID: 6XWkp42QRWWrvxgEXM4Pig== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="54149722" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="54149722" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:38 -0700 X-CSE-ConnectionGUID: GrBDgQ+GRG6SZMN4ZY7MLQ== X-CSE-MsgGUID: gJquDY6pSuixK+ky74CPTQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="78697744" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 19:22:37 -0700 From: Reinette Chatre To: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com, peternewman@google.com, babu.moger@amd.com, ilpo.jarvinen@linux.intel.com Cc: maciej.wieczor-retman@intel.com, reinette.chatre@intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 15/15] selftests/resctrl: Replace magic constants used as array size Date: Thu, 17 Oct 2024 19:33:30 -0700 Message-ID: <4d4887b0359bfd4094871f34aa8b06e2efee6043.1729218182.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The Memory Bandwidth Allocation (MBA) test iterates through all possible MBA allocations, from 10% (ALLOCATION_MIN) to 100% (ALLOCATION_MAX) with increments of 10% (ALLOCATION_STEP) at each iteration. During each iteration the test measures the actual memory bandwidth NUM_OF_RUNS times to determine the impact of MBA on actual memory bandwidth. After the MBA test completes all the memory bandwidth measurements are parsed into an array. One array for resctrl Memory Bandwidth Monitoring (MBM) measurements and one array for the Integrated Memory Controller (iMC) measurements. Each array has a hardcoded size of 1024 that is large enough to hold the current test data, but this hardcoded value makes the implementation difficult to understand. It will not be clear that this array needs to be reconsidered if any of the test parameters are changed. Replace the magic constant as array size with the test parameters the array size depends on. Reported-by: Ilpo J=C3=A4rvinen Closes: https://lore.kernel.org/all/45af2a8c-517d-8f0d-137d-ad0f3f6a3c68@li= nux.intel.com/ Signed-off-by: Reinette Chatre --- Changes since V2: - New patch. --- tools/testing/selftests/resctrl/mba_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/sel= ftests/resctrl/mba_test.c index 4e6645b172e3..536d9089d2f6 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -127,8 +127,9 @@ static bool show_mba_info(unsigned long *bw_imc, unsign= ed long *bw_resc) =20 static int check_results(void) { + unsigned long bw_resc[NUM_OF_RUNS * ALLOCATION_MAX / ALLOCATION_STEP]; + unsigned long bw_imc[NUM_OF_RUNS * ALLOCATION_MAX / ALLOCATION_STEP]; char *token_array[8], output[] =3D RESULT_FILE_NAME, temp[512]; - unsigned long bw_imc[1024], bw_resc[1024]; int runs; FILE *fp; =20 --=20 2.46.2