From patchwork Sat Mar 7 03:40:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425075 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D6CD924 for ; Sat, 7 Mar 2020 03:46:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5812C2073D for ; Sat, 7 Mar 2020 03:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbgCGDqN (ORCPT ); Fri, 6 Mar 2020 22:46:13 -0500 Received: from mga11.intel.com ([192.55.52.93]:57577 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726300AbgCGDqM (ORCPT ); Fri, 6 Mar 2020 22:46:12 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235035991" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:12 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 01/13] selftests/resctrl: Fix feature detection Date: Fri, 6 Mar 2020 19:40:42 -0800 Message-Id: <7e3e4b91f5786a489e68eecda21e1d8049b60181.1583657204.git.sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Reinette Chatre The intention of the resctrl selftests is to only run the tests associated with the feature(s) supported by the platform. Through parsing of the feature flags found in /proc/cpuinfo it is possible to learn which features are supported by the plaform. There are currently two issues with the platform feature detection that together result in tests always being run, whether the platform supports a feature or not. First, the parsing of the the feature flags loads the line containing the flags in a buffer that is too small (256 bytes) to always contain all flags. The consequence is that the flags of the features being tested for may not be present in the buffer. Second, the actual test for presence of a feature has an error in the logic, negating the test for a particular feature flag instead of testing for the presence of a particular feature flag. These two issues combined results in all tests being run on all platforms, whether the feature is supported or not. Fix these issue by (1) increasing the buffer size being used to parse the feature flags, and (2) change the logic to test for presence of the feature being tested for. Signed-off-by: Reinette Chatre Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/resctrlfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 19c0ec4045a4..226dd7fdcfb1 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -596,11 +596,11 @@ bool check_resctrlfs_support(void) char *fgrep(FILE *inf, const char *str) { - char line[256]; int slen = strlen(str); + char line[2048]; while (!feof(inf)) { - if (!fgets(line, 256, inf)) + if (!fgets(line, 2048, inf)) break; if (strncmp(line, str, slen)) continue; @@ -631,7 +631,7 @@ bool validate_resctrl_feature_request(char *resctrl_val) if (res) { char *s = strchr(res, ':'); - found = s && !strstr(s, resctrl_val); + found = s && strstr(s, resctrl_val); free(res); } fclose(inf); From patchwork Sat Mar 7 03:40:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425099 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E21C2924 for ; Sat, 7 Mar 2020 03:46:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CD6432075A for ; Sat, 7 Mar 2020 03:46:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726956AbgCGDqO (ORCPT ); Fri, 6 Mar 2020 22:46:14 -0500 Received: from mga11.intel.com ([192.55.52.93]:57577 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726300AbgCGDqN (ORCPT ); Fri, 6 Mar 2020 22:46:13 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235035997" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:13 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 02/13] selftests/resctrl: Fix typo Date: Fri, 6 Mar 2020 19:40:43 -0800 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Reinette Chatre The format "%sok" is used to print results of a test. If the test passes, the empty string is printed and if the test fails "not " is printed. This results in output of "ok" when test passes and "not ok" when test fails. Fix one instance where "not" (without a space) is printed on test failure resulting in output of "notok" on test failure. Signed-off-by: Reinette Chatre Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/cqm_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/resctrl/cqm_test.c b/tools/testing/selftests/resctrl/cqm_test.c index c8756152bd61..fb4797cfda09 100644 --- a/tools/testing/selftests/resctrl/cqm_test.c +++ b/tools/testing/selftests/resctrl/cqm_test.c @@ -58,7 +58,7 @@ static void show_cache_info(unsigned long sum_llc_occu_resc, int no_of_bits, else res = false; - printf("%sok CQM: diff within %d, %d\%%\n", res ? "" : "not", + printf("%sok CQM: diff within %d, %d\%%\n", res ? "" : "not ", MAX_DIFF, (int)MAX_DIFF_PERCENT); printf("# diff: %ld\n", avg_diff); From patchwork Sat Mar 7 03:40:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425077 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C7AA0924 for ; Sat, 7 Mar 2020 03:46:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B265F2073B for ; Sat, 7 Mar 2020 03:46:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726998AbgCGDqO (ORCPT ); Fri, 6 Mar 2020 22:46:14 -0500 Received: from mga11.intel.com ([192.55.52.93]:57577 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726982AbgCGDqO (ORCPT ); Fri, 6 Mar 2020 22:46:14 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235036001" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:14 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 03/13] selftests/resctrl: Fix typo in help text Date: Fri, 6 Mar 2020 19:40:44 -0800 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Reinette Chatre Add a missing newline to the help text printed and fixup the next line to line it up to previous line for improved readability. Signed-off-by: Reinette Chatre Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/resctrl_tests.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 425cc85ac883..f076d285d7c3 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -37,8 +37,8 @@ void detect_amd(void) static void cmd_help(void) { printf("usage: resctrl_tests [-h] [-b \"benchmark_cmd [options]\"] [-t test list] [-n no_of_bits]\n"); - printf("\t-b benchmark_cmd [options]: run specified benchmark for MBM, MBA and CQM"); - printf("\t default benchmark is builtin fill_buf\n"); + printf("\t-b benchmark_cmd [options]: run specified benchmark for MBM, MBA and CQM\n"); + printf("\t default benchmark is builtin fill_buf\n"); printf("\t-t test list: run tests specified in the test list, "); printf("e.g. -t mbm, mba, cqm, cat\n"); printf("\t-n no_of_bits: run cache tests using specified no of bits in cache bit mask\n"); From patchwork Sat Mar 7 03:40:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425097 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16DAE924 for ; Sat, 7 Mar 2020 03:46:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EBAB42075E for ; Sat, 7 Mar 2020 03:46:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727059AbgCGDqP (ORCPT ); Fri, 6 Mar 2020 22:46:15 -0500 Received: from mga11.intel.com ([192.55.52.93]:57577 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727052AbgCGDqP (ORCPT ); Fri, 6 Mar 2020 22:46:15 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235036005" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:15 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 04/13] selftests/resctrl: Ensure sibling CPU is not same as original CPU Date: Fri, 6 Mar 2020 19:40:45 -0800 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Reinette Chatre The resctrl tests can accept a CPU on which the tests are run and use default of CPU #1 if it is not provided. In the CAT test a "sibling CPU" is determined that is from the same package where another thread will be run. The current algorithm with which a "sibling CPU" is determined does not take the provided/default CPU into account and when that CPU is the first CPU in a package then the "sibling CPU" will be selected to be the same CPU since it starts by picking the first CPU from core_siblings_list. Fix the "sibling CPU" selection by taking the provided/default CPU into account and ensuring a sibling that is a different CPU is selected. Signed-off-by: Reinette Chatre Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/resctrlfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 226dd7fdcfb1..465faaad3239 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -268,7 +268,7 @@ int get_core_sibling(int cpu_no) while (token) { sibling_cpu_no = atoi(token); /* Skipping core 0 as we don't want to run test on core 0 */ - if (sibling_cpu_no != 0) + if (sibling_cpu_no != 0 && sibling_cpu_no != cpu_no) break; token = strtok(NULL, "-,"); } From patchwork Sat Mar 7 03:40:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425079 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EEE9492A for ; Sat, 7 Mar 2020 03:46:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D039D2073B for ; Sat, 7 Mar 2020 03:46:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727080AbgCGDqR (ORCPT ); Fri, 6 Mar 2020 22:46:17 -0500 Received: from mga11.intel.com ([192.55.52.93]:57577 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727065AbgCGDqQ (ORCPT ); Fri, 6 Mar 2020 22:46:16 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235036009" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:15 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 05/13] selftests/resctrl: Fix missing options "-n" and "-p" Date: Fri, 6 Mar 2020 19:40:46 -0800 Message-Id: <987bf946e0772c4a43a27d9162aa010e05f64a47.1583657204.git.sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Fenghua Yu Add missing options "-n" and "-p" in getopt() so that the options can take action. Other code related to the options are in place already and no change is needed. Signed-off-by: Fenghua Yu Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/resctrl_tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index f076d285d7c3..84a436e0775c 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -73,7 +73,7 @@ int main(int argc, char **argv) } } - while ((c = getopt(argc_new, argv, "ht:b:")) != -1) { + while ((c = getopt(argc_new, argv, "ht:b:n:p:")) != -1) { char *token; switch (c) { From patchwork Sat Mar 7 03:40:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425095 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 544A592A for ; Sat, 7 Mar 2020 03:46:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F3D52072D for ; Sat, 7 Mar 2020 03:46:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727076AbgCGDqR (ORCPT ); Fri, 6 Mar 2020 22:46:17 -0500 Received: from mga11.intel.com ([192.55.52.93]:57583 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727052AbgCGDqR (ORCPT ); Fri, 6 Mar 2020 22:46:17 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235036014" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:16 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 06/13] selftests/resctrl: Fix MBA/MBM results reporting format Date: Fri, 6 Mar 2020 19:40:47 -0800 Message-Id: <8179b975778fb1d365f3b5d88b69976332a2f061.1583657204.git.sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Currently MBM/MBA tests use absolute values to check results. But, iMC values and MBM resctrl values may vary on different platforms and specifically for MBA the values may vary as schemata changes. Hence, use percentage instead of absolute values to check tests result. Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/mba_test.c | 24 +++++++++++++----------- tools/testing/selftests/resctrl/mbm_test.c | 21 +++++++++++---------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index 7bf8eaa6204b..165e5123e040 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -12,7 +12,7 @@ #define RESULT_FILE_NAME "result_mba" #define NUM_OF_RUNS 5 -#define MAX_DIFF 300 +#define MAX_DIFF_PERCENT 5 #define ALLOCATION_MAX 100 #define ALLOCATION_MIN 10 #define ALLOCATION_STEP 10 @@ -62,31 +62,33 @@ static void show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc) allocation++) { unsigned long avg_bw_imc, avg_bw_resc; unsigned long sum_bw_imc = 0, sum_bw_resc = 0; - unsigned long avg_diff; + float avg_diff; + int avg_diff_per; /* * The first run is discarded due to inaccurate value from * phase transition. */ for (runs = NUM_OF_RUNS * allocation + 1; - runs < NUM_OF_RUNS * allocation + NUM_OF_RUNS ; runs++) { + runs < NUM_OF_RUNS * allocation + NUM_OF_RUNS; runs++) { sum_bw_imc += bw_imc[runs]; sum_bw_resc += bw_resc[runs]; } avg_bw_imc = sum_bw_imc / (NUM_OF_RUNS - 1); avg_bw_resc = sum_bw_resc / (NUM_OF_RUNS - 1); - avg_diff = labs((long)(avg_bw_resc - avg_bw_imc)); + avg_diff = (float)labs(avg_bw_resc - avg_bw_imc) / avg_bw_imc; + avg_diff_per = (int)(avg_diff * 100); - printf("%sok MBA schemata percentage %u smaller than %d %%\n", - avg_diff > MAX_DIFF ? "not " : "", - ALLOCATION_MAX - ALLOCATION_STEP * allocation, - MAX_DIFF); - tests_run++; - printf("# avg_diff: %lu\n", avg_diff); + printf("%sok MBA: diff within %d%% for schemata %u\n", + avg_diff_per > MAX_DIFF_PERCENT ? "not " : "", + MAX_DIFF_PERCENT, + ALLOCATION_MAX - ALLOCATION_STEP * allocation); printf("# avg_bw_imc: %lu\n", avg_bw_imc); printf("# avg_bw_resc: %lu\n", avg_bw_resc); - if (avg_diff > MAX_DIFF) + printf("# avg_diff_per: %d%%\n", avg_diff_per); + tests_run++; + if (avg_diff_per > MAX_DIFF_PERCENT) failed = true; } diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index 4700f7453f81..530ec5bec0b9 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -11,7 +11,7 @@ #include "resctrl.h" #define RESULT_FILE_NAME "result_mbm" -#define MAX_DIFF 300 +#define MAX_DIFF_PERCENT 5 #define NUM_OF_RUNS 5 static void @@ -19,29 +19,30 @@ show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, int span) { unsigned long avg_bw_imc = 0, avg_bw_resc = 0; unsigned long sum_bw_imc = 0, sum_bw_resc = 0; - long avg_diff = 0; - int runs; + float avg_diff = 0; + int runs, avg_diff_per; /* * Discard the first value which is inaccurate due to monitoring setup * transition phase. */ - for (runs = 1; runs < NUM_OF_RUNS ; runs++) { + for (runs = 1; runs < NUM_OF_RUNS; runs++) { sum_bw_imc += bw_imc[runs]; sum_bw_resc += bw_resc[runs]; } - avg_bw_imc = sum_bw_imc / 4; - avg_bw_resc = sum_bw_resc / 4; - avg_diff = avg_bw_resc - avg_bw_imc; + avg_bw_imc = sum_bw_imc / (NUM_OF_RUNS - 1); + avg_bw_resc = sum_bw_resc / (NUM_OF_RUNS - 1); + avg_diff = (float)labs(avg_bw_resc - avg_bw_imc) / avg_bw_imc; + avg_diff_per = (int)(avg_diff * 100); printf("%sok MBM: diff within %d%%\n", - labs(avg_diff) > MAX_DIFF ? "not " : "", MAX_DIFF); - tests_run++; - printf("# avg_diff: %lu\n", labs(avg_diff)); + avg_diff_per > MAX_DIFF_PERCENT ? "not " : "", MAX_DIFF_PERCENT); printf("# Span (MB): %d\n", span); printf("# avg_bw_imc: %lu\n", avg_bw_imc); printf("# avg_bw_resc: %lu\n", avg_bw_resc); + printf("# avg_diff_per: %d%%\n", avg_diff_per); + tests_run++; } static int check_results(int span) From patchwork Sat Mar 7 03:40:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425089 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B4911731 for ; Sat, 7 Mar 2020 03:46:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E9E582077B for ; Sat, 7 Mar 2020 03:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727097AbgCGDqS (ORCPT ); Fri, 6 Mar 2020 22:46:18 -0500 Received: from mga11.intel.com ([192.55.52.93]:57584 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727077AbgCGDqS (ORCPT ); Fri, 6 Mar 2020 22:46:18 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235036021" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:17 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 07/13] selftests/resctrl: Don't use variable argument list for setup function Date: Fri, 6 Mar 2020 19:40:48 -0800 Message-Id: <4d2f519c9a67d86e71f8fe6fd281f1e39cfe4e49.1583657204.git.sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org struct resctrl_val_param has setup() function that accepts variable argument list. But, presently, all the test cases use only 1 argument as input and it's struct resctrl_val_param *. So, instead of variable argument list, directly pass struct resctrl_val_param * as parameter. Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/cache.c | 2 +- tools/testing/selftests/resctrl/cat_test.c | 8 +------- tools/testing/selftests/resctrl/cqm_test.c | 9 +-------- tools/testing/selftests/resctrl/mba_test.c | 8 +------- tools/testing/selftests/resctrl/mbm_test.c | 8 +------- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrl_val.c | 4 ++-- 7 files changed, 8 insertions(+), 33 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index 38dbf4962e33..1cbcd7fbe216 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -243,7 +243,7 @@ int cat_val(struct resctrl_val_param *param) /* Test runs until the callback setup() tells the test to stop. */ while (1) { if (strcmp(resctrl_val, "cat") == 0) { - ret = param->setup(1, param); + ret = param->setup(param); if (ret) { ret = 0; break; diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 5da43767b973..046c7f285e72 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -27,17 +27,11 @@ unsigned long cache_size; * con_mon grp, mon_grp in resctrl FS. * Run 5 times in order to get average values. */ -static int cat_setup(int num, ...) +static int cat_setup(struct resctrl_val_param *p) { - struct resctrl_val_param *p; char schemata[64]; - va_list param; int ret = 0; - va_start(param, num); - p = va_arg(param, struct resctrl_val_param *); - va_end(param); - /* Run NUM_OF_RUNS times */ if (p->num_of_runs >= NUM_OF_RUNS) return -1; diff --git a/tools/testing/selftests/resctrl/cqm_test.c b/tools/testing/selftests/resctrl/cqm_test.c index fb4797cfda09..f27b0363e518 100644 --- a/tools/testing/selftests/resctrl/cqm_test.c +++ b/tools/testing/selftests/resctrl/cqm_test.c @@ -21,15 +21,8 @@ char cbm_mask[256]; unsigned long long_mask; unsigned long cache_size; -static int cqm_setup(int num, ...) +static int cqm_setup(struct resctrl_val_param *p) { - struct resctrl_val_param *p; - va_list param; - - va_start(param, num); - p = va_arg(param, struct resctrl_val_param *); - va_end(param); - /* Run NUM_OF_RUNS times */ if (p->num_of_runs >= NUM_OF_RUNS) return -1; diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index 165e5123e040..0f85e5be390d 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -22,16 +22,10 @@ * con_mon grp, mon_grp in resctrl FS. * For each allocation, run 5 times in order to get average values. */ -static int mba_setup(int num, ...) +static int mba_setup(struct resctrl_val_param *p) { static int runs_per_allocation, allocation = 100; - struct resctrl_val_param *p; char allocation_str[64]; - va_list param; - - va_start(param, num); - p = va_arg(param, struct resctrl_val_param *); - va_end(param); if (runs_per_allocation >= NUM_OF_RUNS) runs_per_allocation = 0; diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index 530ec5bec0b9..9e847641516a 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -84,21 +84,15 @@ static int check_results(int span) return 0; } -static int mbm_setup(int num, ...) +static int mbm_setup(struct resctrl_val_param *p) { - struct resctrl_val_param *p; static int num_of_runs; - va_list param; int ret = 0; /* Run NUM_OF_RUNS times */ if (num_of_runs++ >= NUM_OF_RUNS) return -1; - va_start(param, num); - p = va_arg(param, struct resctrl_val_param *); - va_end(param); - /* Set up shemata with 100% allocation on the first run. */ if (num_of_runs == 0) ret = write_schemata(p->ctrlgrp, "100", p->cpu_no, diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 39bf59c6b9c5..e320e79bc4d4 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -59,7 +59,7 @@ struct resctrl_val_param { char *bw_report; unsigned long mask; int num_of_runs; - int (*setup)(int num, ...); + int (*setup)(struct resctrl_val_param *param); }; pid_t bm_pid, ppid; diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 520fea3606d1..271cb5c976f5 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -712,7 +712,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) while (1) { if ((strcmp(resctrl_val, "mbm") == 0) || (strcmp(resctrl_val, "mba") == 0)) { - ret = param->setup(1, param); + ret = param->setup(param); if (ret) { ret = 0; break; @@ -722,7 +722,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) if (ret) break; } else if (strcmp(resctrl_val, "cqm") == 0) { - ret = param->setup(1, param); + ret = param->setup(param); if (ret) { ret = 0; break; From patchwork Sat Mar 7 03:40:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425083 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3EE1B92A for ; Sat, 7 Mar 2020 03:46:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2A50021775 for ; Sat, 7 Mar 2020 03:46:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727103AbgCGDqS (ORCPT ); Fri, 6 Mar 2020 22:46:18 -0500 Received: from mga11.intel.com ([192.55.52.93]:57584 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727089AbgCGDqS (ORCPT ); Fri, 6 Mar 2020 22:46:18 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235036027" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:18 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 08/13] selftests/resctrl: Fix typos Date: Fri, 6 Mar 2020 19:40:49 -0800 Message-Id: <4800d93350b5bdfa52cc99f2420e0d629b1dec78.1583657204.git.sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org No functional changes intended 1. Schemata is spelled wrongly in a comment in mbm_test, fix it. 2. Fix incorrect commenting style in cache.c, fill_buf.c 3. Remove extra space while initializing struct resctrl_val_param in mbm_test.c Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/cache.c | 10 +++------- tools/testing/selftests/resctrl/fill_buf.c | 3 ++- tools/testing/selftests/resctrl/mbm_test.c | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index 1cbcd7fbe216..be60d7d3f066 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -179,9 +179,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid) unsigned long llc_perf_miss = 0, llc_occu_resc = 0, llc_value = 0; int ret; - /* - * Measure cache miss from perf. - */ + /* Measure cache miss from perf */ if (!strcmp(param->resctrl_val, "cat")) { ret = get_llc_perf(&llc_perf_miss); if (ret < 0) @@ -189,9 +187,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid) llc_value = llc_perf_miss; } - /* - * Measure llc occupancy from resctrl. - */ + /* Measure llc occupancy from resctrl */ if (!strcmp(param->resctrl_val, "cqm")) { ret = get_llc_occu_resctrl(&llc_occu_resc); if (ret < 0) @@ -228,7 +224,7 @@ int cat_val(struct resctrl_val_param *param) if (ret) return ret; - /* Write benchmark to specified con_mon grp, mon_grp in resctrl FS*/ + /* Write benchmark to specified con_mon grp, mon_grp in resctrl FS */ ret = write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp, resctrl_val); if (ret) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 84d2a8b9657a..9ede7b63f059 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -54,7 +54,8 @@ static void mem_flush(void *p, size_t s) char *cp = (char *)p; size_t i = 0; - s = s / CL_SIZE; /* mem size in cache llines */ + /* mem size in cache lines */ + s = s / CL_SIZE; for (i = 0; i < s; i++) cl_flush(&cp[i * CL_SIZE]); diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index 9e847641516a..b64906f1b34f 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -93,7 +93,7 @@ static int mbm_setup(struct resctrl_val_param *p) if (num_of_runs++ >= NUM_OF_RUNS) return -1; - /* Set up shemata with 100% allocation on the first run. */ + /* Set up schemata with 100% allocation on the first run */ if (num_of_runs == 0) ret = write_schemata(p->ctrlgrp, "100", p->cpu_no, p->resctrl_val); @@ -116,7 +116,7 @@ int mbm_bw_change(int span, int cpu_no, char *bw_report, char **benchmark_cmd) .cpu_no = cpu_no, .mum_resctrlfs = 1, .filename = RESULT_FILE_NAME, - .bw_report = bw_report, + .bw_report = bw_report, .setup = mbm_setup }; int ret; From patchwork Sat Mar 7 03:40:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425081 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17FF61731 for ; Sat, 7 Mar 2020 03:46:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 032CB2075A for ; Sat, 7 Mar 2020 03:46:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727131AbgCGDqU (ORCPT ); Fri, 6 Mar 2020 22:46:20 -0500 Received: from mga11.intel.com ([192.55.52.93]:57584 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727123AbgCGDqT (ORCPT ); Fri, 6 Mar 2020 22:46:19 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235036035" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:19 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 09/13] selftests/resctrl: Modularize fill_buf for new CAT test case Date: Fri, 6 Mar 2020 19:40:50 -0800 Message-Id: <43b368952bb006ee973311d9c9ae0eb53d8e7f60.1583657204.git.sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Currently fill_buf (in-built benchmark) runs as a separate process and it runs indefinitely looping around given buffer either reading it or writing to it. But, some future test cases might want to start and stop looping around the buffer as they see fit. So, modularize fill_buf to support this use case. Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/fill_buf.c | 66 ++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 9ede7b63f059..204ae8870a32 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -23,7 +23,7 @@ #define PAGE_SIZE (4 * 1024) #define MB (1024 * 1024) -static unsigned char *startptr; +static unsigned char *startptr, *endptr; static void sb(void) { @@ -82,13 +82,13 @@ static void *malloc_and_init_memory(size_t s) return p; } -static int fill_one_span_read(unsigned char *start_ptr, unsigned char *end_ptr) +static int fill_one_span_read(void) { unsigned char sum, *p; sum = 0; - p = start_ptr; - while (p < end_ptr) { + p = startptr; + while (p < endptr) { sum += *p; p += (CL_SIZE / 2); } @@ -96,26 +96,24 @@ static int fill_one_span_read(unsigned char *start_ptr, unsigned char *end_ptr) return sum; } -static -void fill_one_span_write(unsigned char *start_ptr, unsigned char *end_ptr) +static void fill_one_span_write(void) { unsigned char *p; - p = start_ptr; - while (p < end_ptr) { + p = startptr; + while (p < endptr) { *p = '1'; p += (CL_SIZE / 2); } } -static int fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr, - char *resctrl_val) +static int fill_cache_read(char *resctrl_val) { int ret = 0; FILE *fp; while (1) { - ret = fill_one_span_read(start_ptr, end_ptr); + ret = fill_one_span_read(); if (!strcmp(resctrl_val, "cat")) break; } @@ -130,11 +128,10 @@ static int fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr, return 0; } -static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr, - char *resctrl_val) +static int fill_cache_write(char *resctrl_val) { while (1) { - fill_one_span_write(start_ptr, end_ptr); + fill_one_span_write(); if (!strcmp(resctrl_val, "cat")) break; } @@ -142,24 +139,25 @@ static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr, return 0; } -static int -fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush, - int op, char *resctrl_val) +static +int init_buffer(unsigned long long buf_size, int malloc_and_init, int memflush) { unsigned char *start_ptr, *end_ptr; unsigned long long i; - int ret; if (malloc_and_init) start_ptr = malloc_and_init_memory(buf_size); else start_ptr = malloc(buf_size); - if (!start_ptr) + if (!start_ptr) { + printf("Failed to allocate memory to buffer\n"); return -1; + } - startptr = start_ptr; end_ptr = start_ptr + buf_size; + endptr = end_ptr; + startptr = start_ptr; /* * It's better to touch the memory once to avoid any compiler @@ -176,16 +174,40 @@ fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush, if (memflush) mem_flush(start_ptr, buf_size); + return 0; +} + +static int use_buffer_forever(int op, char *resctrl_val) +{ + int ret; + if (op == 0) - ret = fill_cache_read(start_ptr, end_ptr, resctrl_val); + ret = fill_cache_read(resctrl_val); else - ret = fill_cache_write(start_ptr, end_ptr, resctrl_val); + ret = fill_cache_write(resctrl_val); if (ret) { printf("\n Errror in fill cache read/write...\n"); return -1; } + return 0; +} + +static int +fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush, + int op, char *resctrl_val) +{ + int ret; + + ret = init_buffer(buf_size, malloc_and_init, memflush); + if (ret) + return ret; + + ret = use_buffer_forever(op, resctrl_val); + if (ret) + return ret; + free(startptr); return 0; From patchwork Sat Mar 7 03:40:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425093 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C1BE92A for ; Sat, 7 Mar 2020 03:46:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2B592073B for ; Sat, 7 Mar 2020 03:46:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726751AbgCGDqq (ORCPT ); Fri, 6 Mar 2020 22:46:46 -0500 Received: from mga11.intel.com ([192.55.52.93]:57584 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727052AbgCGDqU (ORCPT ); Fri, 6 Mar 2020 22:46:20 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235036039" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:20 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 10/13] selftests/resctrl: Change Cache Allocation Technology (CAT) test Date: Fri, 6 Mar 2020 19:40:51 -0800 Message-Id: <51d0f3c928fbc310c85bac6de20745f69cbc423e.1583657204.git.sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The present CAT test case, spawns two processes that run in two different control groups with exclusive schemata and both the processes read a buffer from memory only once. Before reading the buffer, perf miss count is cleared and perf miss count is calculated for the read. Since the processes are reading through the buffer only once and initially all the buffer is in memory perf miss count will always be the same regardless of the cache size allocated by CAT to these processes. So, the test isn't testing CAT. Fix this issue by changing the CAT test case. The updated CAT test runs a "critical" process with exclusive schemata that reads a buffer (same as the size of allocated cache) multiple times there-by utilizing the allocated cache and calculates perf miss rate for every read of the buffer. The average of this perf miss rate is saved. This value indicates the critical process self induced misses. Now, the "critical" process runs besides a "noisy" neighbor that is reading a buffer that is 10 times the size of LLC and both the processes are in different control groups with exclusive schematas. The average perf miss rate for "critical" process is calculated again and compared with the earlier value. If the difference between both these values is greater than 5% it means that "noisy" neighbor does have impact on "critical" process which means CAT is not working as expected and hence the test fails. Reported-by: Reinette Chatre Suggested-by: Tony Luck Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/cache.c | 167 ++++++++----- tools/testing/selftests/resctrl/cat_test.c | 312 ++++++++++++++---------- tools/testing/selftests/resctrl/fill_buf.c | 33 ++- tools/testing/selftests/resctrl/resctrl.h | 9 +- tools/testing/selftests/resctrl/resctrl_tests.c | 2 +- tools/testing/selftests/resctrl/resctrlfs.c | 34 ++- 6 files changed, 352 insertions(+), 205 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index be60d7d3f066..e30cdd7b851c 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -10,9 +10,9 @@ struct read_format { } values[2]; }; -static struct perf_event_attr pea_llc_miss; +static struct perf_event_attr pea_llc_miss, pea_llc_access; static struct read_format rf_cqm; -static int fd_lm; +static int fd_lm, fd_la; char llc_occup_path[1024]; static void initialize_perf_event_attr(void) @@ -27,15 +27,30 @@ static void initialize_perf_event_attr(void) pea_llc_miss.inherit = 1; pea_llc_miss.exclude_guest = 1; pea_llc_miss.disabled = 1; + + pea_llc_access.type = PERF_TYPE_HARDWARE; + pea_llc_access.size = sizeof(struct perf_event_attr); + pea_llc_access.read_format = PERF_FORMAT_GROUP; + pea_llc_access.exclude_kernel = 1; + pea_llc_access.exclude_hv = 1; + pea_llc_access.exclude_idle = 1; + pea_llc_access.exclude_callchain_kernel = 1; + pea_llc_access.inherit = 1; + pea_llc_access.exclude_guest = 1; + pea_llc_access.disabled = 1; + } static void ioctl_perf_event_ioc_reset_enable(void) { ioctl(fd_lm, PERF_EVENT_IOC_RESET, 0); ioctl(fd_lm, PERF_EVENT_IOC_ENABLE, 0); + + ioctl(fd_la, PERF_EVENT_IOC_RESET, 0); + ioctl(fd_la, PERF_EVENT_IOC_ENABLE, 0); } -static int perf_event_open_llc_miss(pid_t pid, int cpu_no) +static int perf_event_open_llc_miss_rate(pid_t pid, int cpu_no) { fd_lm = perf_event_open(&pea_llc_miss, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC); @@ -45,29 +60,40 @@ static int perf_event_open_llc_miss(pid_t pid, int cpu_no) return -1; } + fd_la = perf_event_open(&pea_llc_access, pid, cpu_no, fd_lm, + PERF_FLAG_FD_CLOEXEC); + if (fd_la == -1) { + perror("Error opening member"); + ctrlc_handler(0, NULL, NULL); + return -1; + } + return 0; } -static int initialize_llc_perf(void) +static void initialize_llc_perf(void) { memset(&pea_llc_miss, 0, sizeof(struct perf_event_attr)); + memset(&pea_llc_access, 0, sizeof(struct perf_event_attr)); memset(&rf_cqm, 0, sizeof(struct read_format)); - /* Initialize perf_event_attr structures for HW_CACHE_MISSES */ + /* + * Initialize perf_event_attr structures for HW_CACHE_MISSES and + * HW_CACHE_REFERENCES + */ initialize_perf_event_attr(); pea_llc_miss.config = PERF_COUNT_HW_CACHE_MISSES; + pea_llc_access.config = PERF_COUNT_HW_CACHE_REFERENCES; - rf_cqm.nr = 1; - - return 0; + rf_cqm.nr = 2; } static int reset_enable_llc_perf(pid_t pid, int cpu_no) { int ret = 0; - ret = perf_event_open_llc_miss(pid, cpu_no); + ret = perf_event_open_llc_miss_rate(pid, cpu_no); if (ret < 0) return ret; @@ -78,21 +104,21 @@ static int reset_enable_llc_perf(pid_t pid, int cpu_no) } /* - * get_llc_perf: llc cache miss through perf events - * @cpu_no: CPU number that the benchmark PID is binded to + * get_llc_perf_miss_rate: llc cache miss rate through perf events + * @cpu_no: CPU number that the benchmark PID is binded to * - * Perf events like HW_CACHE_MISSES could be used to validate number of - * cache lines allocated. + * Perf events like HW_CACHE_MISSES and HW_CACHE_REFERENCES could be used to + * approximate LLc occupancy under controlled environment * * Return: =0 on success. <0 on failure. */ -static int get_llc_perf(unsigned long *llc_perf_miss) +static int get_llc_perf_miss_rate(float *llc_perf_miss_rate) { - __u64 total_misses; + __u64 total_misses, total_references; /* Stop counters after one span to get miss rate */ - ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0); + ioctl(fd_la, PERF_EVENT_IOC_DISABLE, 0); if (read(fd_lm, &rf_cqm, sizeof(struct read_format)) == -1) { perror("Could not get llc misses through perf"); @@ -100,11 +126,19 @@ static int get_llc_perf(unsigned long *llc_perf_miss) return -1; } + if (read(fd_la, &rf_cqm, sizeof(struct read_format)) == -1) { + perror("Could not get llc accesses through perf"); + + return -1; + } + total_misses = rf_cqm.values[0].value; + total_references = rf_cqm.values[1].value; close(fd_lm); + close(fd_la); - *llc_perf_miss = total_misses; + *llc_perf_miss_rate = ((float)total_misses / total_references) * 100; return 0; } @@ -176,15 +210,16 @@ static int print_results_cache(char *filename, int bm_pid, int measure_cache_vals(struct resctrl_val_param *param, int bm_pid) { - unsigned long llc_perf_miss = 0, llc_occu_resc = 0, llc_value = 0; + unsigned long llc_occu_resc = 0, llc_value = 0; + float llc_perf_miss_rate = 0; int ret; /* Measure cache miss from perf */ if (!strcmp(param->resctrl_val, "cat")) { - ret = get_llc_perf(&llc_perf_miss); + ret = get_llc_perf_miss_rate(&llc_perf_miss_rate); if (ret < 0) return ret; - llc_value = llc_perf_miss; + llc_value = llc_perf_miss_rate; } /* Measure llc occupancy from resctrl */ @@ -202,66 +237,72 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid) } /* - * cache_val: execute benchmark and measure LLC occupancy resctrl - * and perf cache miss for the benchmark - * @param: parameters passed to cache_val() + * setup_critical_process: Bind given pid to given cpu and write the pid + * in requested resctrl FS location, set schemata, + * initialize perf LLC counters and also initialize + * fill buffer benchmark. + * @pid: pid of the process + * @param: Parameters passed to cache_val() * - * Return: 0 on success. non-zero on failure. + * Return: 0 on success. non-zero on failure. */ -int cat_val(struct resctrl_val_param *param) +int setup_critical_process(pid_t pid, struct resctrl_val_param *param) { - int malloc_and_init_memory = 1, memflush = 1, operation = 0, ret = 0; + int ret = 0; char *resctrl_val = param->resctrl_val; - pid_t bm_pid; + char schemata[64]; - if (strcmp(param->filename, "") == 0) - sprintf(param->filename, "stdio"); + /* Taskset parent (critical process) to a specified cpu */ + ret = taskset_benchmark(pid, param->cpu_no); + if (ret) + return ret; - bm_pid = getpid(); + /* Write parent to specified con_mon grp, mon_grp in resctrl FS */ + ret = write_bm_pid_to_resctrl(pid, param->ctrlgrp, param->mongrp, + resctrl_val); + if (ret) + return ret; - /* Taskset benchmark to specified cpu */ - ret = taskset_benchmark(bm_pid, param->cpu_no); + sprintf(schemata, "%lx", param->mask); + ret = write_schemata(param->ctrlgrp, schemata, param->cpu_no, "cat"); if (ret) return ret; - /* Write benchmark to specified con_mon grp, mon_grp in resctrl FS */ - ret = write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp, - resctrl_val); + initialize_llc_perf(); + + ret = init_buffer(param->span, 1, 1); if (ret) return ret; - if ((strcmp(resctrl_val, "cat") == 0)) { - ret = initialize_llc_perf(); - if (ret) - return ret; - } + return 0; +} + +int run_critical_process(pid_t pid, struct resctrl_val_param *param) +{ + int ret = 0; - /* Test runs until the callback setup() tells the test to stop. */ + /* Test runs until the callback setup() tells the test to stop */ while (1) { - if (strcmp(resctrl_val, "cat") == 0) { - ret = param->setup(param); - if (ret) { - ret = 0; - break; - } - ret = reset_enable_llc_perf(bm_pid, param->cpu_no); - if (ret) - break; - - if (run_fill_buf(param->span, malloc_and_init_memory, - memflush, operation, resctrl_val)) { - fprintf(stderr, "Error-running fill buffer\n"); - ret = -1; - break; - } - - sleep(1); - ret = measure_cache_vals(param, bm_pid); - if (ret) - break; - } else { + ret = param->setup(param); + if (ret) { + ret = 0; + break; + } + + ret = reset_enable_llc_perf(pid, param->cpu_no); + if (ret) + break; + + /* Read buffer once */ + if (use_buffer_once(0)) { + fprintf(stderr, "Error-running fill buffer\n"); + ret = -1; break; } + + ret = measure_cache_vals(param, pid); + if (ret) + break; } return ret; diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 046c7f285e72..f7a67f005fe5 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -11,70 +11,65 @@ #include "resctrl.h" #include -#define RESULT_FILE_NAME1 "result_cat1" -#define RESULT_FILE_NAME2 "result_cat2" -#define NUM_OF_RUNS 5 -#define MAX_DIFF_PERCENT 4 -#define MAX_DIFF 1000000 +#define RESULT_FILE_NAME "result_cat" +#define NUM_OF_RUNS 10 +#define MAX_DIFF_PERCENT 5 -int count_of_bits; char cbm_mask[256]; -unsigned long long_mask; -unsigned long cache_size; -/* - * Change schemata. Write schemata to specified - * con_mon grp, mon_grp in resctrl FS. - * Run 5 times in order to get average values. - */ +static unsigned long avg_llc_perf_miss_rate_single_thread; +static unsigned long p1_mask, p2_mask; +static unsigned long cache_size; +static pid_t noisy_pid; +static int count_of_bits; + +/* Run 5 times in order to get average values */ static int cat_setup(struct resctrl_val_param *p) { - char schemata[64]; - int ret = 0; - /* Run NUM_OF_RUNS times */ if (p->num_of_runs >= NUM_OF_RUNS) return -1; - if (p->num_of_runs == 0) { - sprintf(schemata, "%lx", p->mask); - ret = write_schemata(p->ctrlgrp, schemata, p->cpu_no, - p->resctrl_val); - } p->num_of_runs++; - - return ret; + return 0; } -static void show_cache_info(unsigned long sum_llc_perf_miss, int no_of_bits, - unsigned long span) +static void show_cache_info(unsigned long sum_llc_perf_miss_rate, + int no_of_bits, unsigned long span) { - unsigned long allocated_cache_lines = span / 64; - unsigned long avg_llc_perf_miss = 0; - float diff_percent; + unsigned long avg_llc_perf_miss_rate = 0, diff_percent = 0; + + avg_llc_perf_miss_rate = sum_llc_perf_miss_rate / (NUM_OF_RUNS - 1); + if (!noisy_pid) { + avg_llc_perf_miss_rate_single_thread = avg_llc_perf_miss_rate; + return; + } - avg_llc_perf_miss = sum_llc_perf_miss / (NUM_OF_RUNS - 1); - diff_percent = ((float)allocated_cache_lines - avg_llc_perf_miss) / - allocated_cache_lines * 100; + diff_percent = labs(avg_llc_perf_miss_rate - + avg_llc_perf_miss_rate_single_thread); - printf("%sok CAT: cache miss rate within %d%%\n", - !is_amd && abs((int)diff_percent) > MAX_DIFF_PERCENT ? + printf("%sok CAT: cache miss rate difference within %d%%\n", + !is_amd && diff_percent > MAX_DIFF_PERCENT ? "not " : "", MAX_DIFF_PERCENT); - tests_run++; - printf("# Percent diff=%d\n", abs((int)diff_percent)); printf("# Number of bits: %d\n", no_of_bits); - printf("# Avg_llc_perf_miss: %lu\n", avg_llc_perf_miss); - printf("# Allocated cache lines: %lu\n", allocated_cache_lines); + printf("# Buffer size: %lu\n", span); + printf("# Avg_llc_perf_miss_rate without noisy process: %lu%%\n", + avg_llc_perf_miss_rate_single_thread); + printf("# Avg_llc_perf_miss_rate with noisy process: %lu%%\n", + avg_llc_perf_miss_rate); + printf("# Percent diff: %lu\n", diff_percent); + tests_run++; } static int check_results(struct resctrl_val_param *param) { char *token_array[8], temp[512]; - unsigned long sum_llc_perf_miss = 0; + unsigned long sum_llc_perf_miss_rate = 0; int runs = 0, no_of_bits = 0; FILE *fp; - printf("# Checking for pass/fail\n"); + if (noisy_pid) + printf("# Checking for pass/fail\n"); fp = fopen(param->filename, "r"); if (!fp) { perror("# Cannot open file"); @@ -90,37 +85,107 @@ static int check_results(struct resctrl_val_param *param) token_array[fields++] = token; token = strtok(NULL, ":\t"); } + /* * Discard the first value which is inaccurate due to monitoring * setup transition phase. */ - if (runs > 0) - sum_llc_perf_miss += strtoul(token_array[3], NULL, 0); runs++; + if (runs == 1) + continue; + + sum_llc_perf_miss_rate += strtoul(token_array[3], NULL, 0); } fclose(fp); no_of_bits = count_bits(param->mask); - - show_cache_info(sum_llc_perf_miss, no_of_bits, param->span); + show_cache_info(sum_llc_perf_miss_rate, no_of_bits, param->span); return 0; } void cat_test_cleanup(void) { - remove(RESULT_FILE_NAME1); - remove(RESULT_FILE_NAME2); + remove(RESULT_FILE_NAME); +} + +static int prepare_masks_for_two_processes(int no_of_bits, char *cache_type) +{ + int ret, i; + unsigned long long_mask, shareable_mask; + + /* Get default cbm mask for L3/L2 cache */ + ret = get_cbm_mask(cache_type); + if (ret) + return ret; + + /* Get max number of bits from default cbm mask */ + long_mask = strtoul(cbm_mask, NULL, 16); + count_of_bits = count_bits(long_mask); + + /* + * Max limit is count_of_bits - 1 because we need exclusive masks for + * the two processes. So, the last saved bit will be used by the other + * process. + */ + if (no_of_bits < 1 || no_of_bits > count_of_bits - 1) { + printf("Invalid input value for no_of_bits 'n'\n"); + printf("Please Enter value in range 1 to %d\n", + count_of_bits - 1); + return -1; + } + + ret = get_shareable_mask(cache_type, &shareable_mask); + if (ret) + return ret; + + /* Prepare cbm mask without any shareable bits */ + for (i = 0; i < no_of_bits; i++) { + p1_mask <<= 1; + p1_mask |= 1; + } + p1_mask = ~shareable_mask & p1_mask; + p2_mask = ~p1_mask & long_mask; + + return 0; } -int cat_perf_miss_val(int cpu_no, int n, char *cache_type) +static int start_noisy_process(pid_t pid, int sibling_cpu_no) { - unsigned long l_mask, l_mask_1; - int ret, pipefd[2], sibling_cpu_no; - char pipe_message; - pid_t bm_pid; + int ret; + unsigned long buf_size = cache_size * 10; - cache_size = 0; + /* Taskset noisy process to specified cpu */ + ret = taskset_benchmark(pid, sibling_cpu_no); + if (ret) + return ret; + + /* Write noisy process to root con_mon grp in resctrl FS */ + ret = write_bm_pid_to_resctrl(pid, "", "", "cat"); + if (ret) + return ret; + + /* + * Passing 'cat' will not loop around buffer forever, hence don't pass + * test name + */ + ret = run_fill_buf(buf_size, 1, 1, 0, ""); + if (ret) + return ret; + + return 0; +} + +int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type) +{ + int ret, sibling_cpu_no; + unsigned long buf_size; + pid_t critical_pid; + char schemata[64]; + + noisy_pid = 0; + critical_pid = getpid(); + printf("# critical_pid: %d\n", critical_pid); ret = remount_resctrlfs(true); if (ret) @@ -129,77 +194,43 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) if (!validate_resctrl_feature_request("cat")) return -1; - /* Get default cbm mask for L3/L2 cache */ - ret = get_cbm_mask(cache_type); + ret = prepare_masks_for_two_processes(no_of_bits, cache_type); if (ret) return ret; - long_mask = strtoul(cbm_mask, NULL, 16); + /* + * Change root con_mon grp schemata to be exclusive of critical process + * schemata to avoid any interference + */ + sprintf(schemata, "%lx", p2_mask); + ret = write_schemata("", schemata, cpu_no, "cat"); + if (ret) + return ret; /* Get L3/L2 cache size */ ret = get_cache_size(cpu_no, cache_type, &cache_size); if (ret) return ret; - printf("cache size :%lu\n", cache_size); - - /* Get max number of bits from default-cabm mask */ - count_of_bits = count_bits(long_mask); - - if (n < 1 || n > count_of_bits - 1) { - printf("Invalid input value for no_of_bits n!\n"); - printf("Please Enter value in range 1 to %d\n", - count_of_bits - 1); - return -1; - } - - /* Get core id from same socket for running another thread */ - sibling_cpu_no = get_core_sibling(cpu_no); - if (sibling_cpu_no < 0) - return -1; + printf("# cache size: %lu\n", cache_size); + buf_size = cache_size * ((float)(no_of_bits) / count_of_bits); struct resctrl_val_param param = { .resctrl_val = "cat", .cpu_no = cpu_no, .mum_resctrlfs = 0, .setup = cat_setup, + .ctrlgrp = "c1", + .filename = RESULT_FILE_NAME, + .mask = p1_mask, + .num_of_runs = 0, + .span = buf_size }; - l_mask = long_mask >> n; - l_mask_1 = ~l_mask & long_mask; - - /* Set param values for parent thread which will be allocated bitmask - * with (max_bits - n) bits - */ - param.span = cache_size * (count_of_bits - n) / count_of_bits; - strcpy(param.ctrlgrp, "c2"); - strcpy(param.mongrp, "m2"); - strcpy(param.filename, RESULT_FILE_NAME2); - param.mask = l_mask; - param.num_of_runs = 0; - - if (pipe(pipefd)) { - perror("# Unable to create pipe"); - return errno; - } - - bm_pid = fork(); - - /* Set param values for child thread which will be allocated bitmask - * with n bits - */ - if (bm_pid == 0) { - param.mask = l_mask_1; - strcpy(param.ctrlgrp, "c1"); - strcpy(param.mongrp, "m1"); - param.span = cache_size * n / count_of_bits; - strcpy(param.filename, RESULT_FILE_NAME1); - param.num_of_runs = 0; - param.cpu_no = sibling_cpu_no; - } - - remove(param.filename); + ret = setup_critical_process(critical_pid, ¶m); + if (ret) + return ret; - ret = cat_val(¶m); + ret = run_critical_process(critical_pid, ¶m); if (ret) return ret; @@ -207,38 +238,51 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) if (ret) return ret; - if (bm_pid == 0) { - /* Tell parent that child is ready */ - close(pipefd[0]); - pipe_message = 1; - if (write(pipefd[1], &pipe_message, sizeof(pipe_message)) < - sizeof(pipe_message)) { - close(pipefd[1]); - perror("# failed signaling parent process"); - return errno; - } + printf("# ran critical process without noisy process\n"); - close(pipefd[1]); - while (1) - ; + /* + * Results from first run of critical process are already calculated + * and stored in 'avg_llc_perf_miss_single_thread'. Hence, delete the + * file, so that it could be reused for second run. + */ + cat_test_cleanup(); + + /* Get core id from same socket for running noisy process */ + sibling_cpu_no = get_core_sibling(cpu_no); + if (sibling_cpu_no < 0) + return -1; + + noisy_pid = fork(); + if (noisy_pid == 0) { + /* + * Child is the noisy_process which runs in root con_mon grp by + * default and hence no need to write pid to resctrl FS. + * Schemata for root con_mon grp is also set above. + */ + printf("# noisy_pid: %d\n", getpid()); + ret = start_noisy_process(getpid(), sibling_cpu_no); + exit(EXIT_SUCCESS); + } else if (noisy_pid == -1) { + return -1; } else { - /* Parent waits for child to be ready. */ - close(pipefd[1]); - pipe_message = 0; - while (pipe_message != 1) { - if (read(pipefd[0], &pipe_message, - sizeof(pipe_message)) < sizeof(pipe_message)) { - perror("# failed reading from child process"); - break; - } - } - close(pipefd[0]); - kill(bm_pid, SIGKILL); - } + /* + * Parent runs again. Sleep for a second here so that noisy + * process gets to run before critical process + */ + sleep(1); + param.num_of_runs = 0; + ret = run_critical_process(critical_pid, ¶m); + if (ret) + return ret; - cat_test_cleanup(); - if (bm_pid) - umount_resctrlfs(); + ret = check_results(¶m); + if (ret) + return ret; + + ret = kill(noisy_pid, SIGKILL); + if (ret) + printf("Failed to kill noisy_pid\n"); + } return 0; } diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 204ae8870a32..0500dab90b2e 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -139,7 +139,6 @@ static int fill_cache_write(char *resctrl_val) return 0; } -static int init_buffer(unsigned long long buf_size, int malloc_and_init, int memflush) { unsigned char *start_ptr, *end_ptr; @@ -177,7 +176,33 @@ int init_buffer(unsigned long long buf_size, int malloc_and_init, int memflush) return 0; } -static int use_buffer_forever(int op, char *resctrl_val) +int use_buffer_once(int op) +{ + FILE *fp; + int ret = 0; + + if (op == 0) { + ret = fill_one_span_read(); + + /* Consume result so that reading memory is not optimized */ + fp = fopen("/dev/null", "w"); + if (!fp) + perror("Unable to write to /dev/null"); + fprintf(fp, "Sum: %d ", ret); + fclose(fp); + ret = 0; + } else { + fill_one_span_write(); + } + + if (ret) { + printf("\n Error in fill cache read/write...\n"); + return -1; + } + return 0; +} + +int use_buffer_forever(int op, char *resctrl_val) { int ret; @@ -187,7 +212,7 @@ static int use_buffer_forever(int op, char *resctrl_val) ret = fill_cache_write(resctrl_val); if (ret) { - printf("\n Errror in fill cache read/write...\n"); + printf("\n Error in fill cache read/write...\n"); return -1; } @@ -228,7 +253,7 @@ int run_fill_buf(unsigned long span, int malloc_and_init_memory, ret = fill_cache(cache_size, malloc_and_init_memory, memflush, op, resctrl_val); if (ret) { - printf("\n Errror in fill cache\n"); + printf("\n Error in fill cache\n"); return -1; } diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index e320e79bc4d4..79148cbbd7a4 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -27,7 +27,7 @@ #define MB (1024 * 1024) #define RESCTRL_PATH "/sys/fs/resctrl" #define PHYS_ID_PATH "/sys/devices/system/cpu/cpu" -#define CBM_MASK_PATH "/sys/fs/resctrl/info" +#define INFO_PATH "/sys/fs/resctrl/info" #define PARENT_EXIT(err_msg) \ do { \ @@ -84,6 +84,9 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, char *resctrl_val); int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags); +int init_buffer(unsigned long long buf_size, int malloc_and_init, int memflush); +int use_buffer_once(int op); +int use_buffer_forever(int op, char *resctrl_val); int run_fill_buf(unsigned long span, int malloc_and_init_memory, int memflush, int op, char *resctrl_va); int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param); @@ -93,9 +96,11 @@ void mbm_test_cleanup(void); int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd); void mba_test_cleanup(void); int get_cbm_mask(char *cache_type); +int get_shareable_mask(char *cache_type, unsigned long *shareable_mask); int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size); void ctrlc_handler(int signum, siginfo_t *info, void *ptr); -int cat_val(struct resctrl_val_param *param); +int setup_critical_process(pid_t pid, struct resctrl_val_param *param); +int run_critical_process(pid_t pid, struct resctrl_val_param *param); void cat_test_cleanup(void); int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type); int cqm_resctrl_val(int cpu_no, int n, char **benchmark_cmd); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 84a436e0775c..60db128312a6 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -192,8 +192,8 @@ int main(int argc, char **argv) printf("# Starting CAT test ...\n"); res = cat_perf_miss_val(cpu_no, no_of_bits, "L3"); printf("%sok CAT: test\n", res ? "not " : ""); - tests_run++; cat_test_cleanup(); + tests_run++; } printf("1..%d\n", tests_run); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 465faaad3239..52452bb0178a 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -215,7 +215,7 @@ int get_cbm_mask(char *cache_type) char cbm_mask_path[1024]; FILE *fp; - sprintf(cbm_mask_path, "%s/%s/cbm_mask", CBM_MASK_PATH, cache_type); + sprintf(cbm_mask_path, "%s/%s/cbm_mask", INFO_PATH, cache_type); fp = fopen(cbm_mask_path, "r"); if (!fp) { @@ -235,6 +235,38 @@ int get_cbm_mask(char *cache_type) } /* + * get_shareable_mask - Get shareable mask from shareable_bits for given cache + * @cache_type: Cache level L2/L3 + * @shareable_mask: Mask is returned as unsigned long value + * + * Return: = 0 on success, < 0 on failure. + */ +int get_shareable_mask(char *cache_type, unsigned long *shareable_mask) +{ + char shareable_bits_file[1024]; + FILE *fp; + + sprintf(shareable_bits_file, "%s/%s/shareable_bits", INFO_PATH, + cache_type); + + fp = fopen(shareable_bits_file, "r"); + if (!fp) { + perror("Failed to open shareable_bits file"); + + return -1; + } + if (fscanf(fp, "%lx", shareable_mask) <= 0) { + perror("Could not get shareable bits"); + fclose(fp); + + return -1; + } + fclose(fp); + + return 0; +} + +/* * get_core_sibling - Get sibling core id from the same socket for given CPU * @cpu_no: CPU number * From patchwork Sat Mar 7 03:40:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425091 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D99C9924 for ; Sat, 7 Mar 2020 03:46:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B3C1F2073B for ; Sat, 7 Mar 2020 03:46:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726368AbgCGDqp (ORCPT ); Fri, 6 Mar 2020 22:46:45 -0500 Received: from mga11.intel.com ([192.55.52.93]:57585 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727143AbgCGDqW (ORCPT ); Fri, 6 Mar 2020 22:46:22 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235036044" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:21 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 11/13] selftests/resctrl: Change Cache Quality Monitoring (CQM) test Date: Fri, 6 Mar 2020 19:40:52 -0800 Message-Id: <26086dda86f062bba4116878a012a553503924b2.1583657204.git.sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The present CQM test runs fill_buff continuously with some user specified buffer size and reads cqm_llc_occupancy every 1 second and tests if resctrl reported value is in 15% range of buffer that fill_buff is working on. If the difference is greater than 15% the test fails. This test assumes that the buffer fill_buff is working on will be identity mapped into cache from memory i.e. there won't be any overlap. But that might not always be true because of the way cache indexing works (two physical addresses could get indexed into the same cache line). If this happens, cqm_llc_occupancy will be less than buffer size and we cannot guarantee the percentage by which this might be less. Another issue with the test case is that, although it has 15% of guard band, the cache occupied by code (or other parts) of the process may not be within this range. While we are actively looking into approximating llc_occupancy through perf, fix this test case with the help of CAT. The new CQM test runs fill_buff continuously with a buffer size that is much greater than cache size and uses CAT to change schemata (from 1 bit to max_bits available without shareable bits). For every change in schemata, it then averages cqm_llc_occupancy and checks if it is less than allocated cache size (with 5% guard band). If the average cqm_llc_occupancy is less than allocated cache size, the test passes. Please note that there is no lower bound on the expected cqm_llc_occupancy because presently that cannot be determined. Note: The new test case assumes that 1. The system supports CAT 2. CAT is working as expected on the system Reported-by: Reinette Chatre Suggested-by: Tony Luck Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/cache.c | 4 + tools/testing/selftests/resctrl/cqm_test.c | 203 +++++++++++++++--------- tools/testing/selftests/resctrl/resctrl.h | 3 +- tools/testing/selftests/resctrl/resctrl_tests.c | 6 +- tools/testing/selftests/resctrl/resctrl_val.c | 22 +-- tools/testing/selftests/resctrl/resctrlfs.c | 6 +- 6 files changed, 143 insertions(+), 101 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index e30cdd7b851c..ca794ad6fcfc 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -224,11 +224,15 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid) /* Measure llc occupancy from resctrl */ if (!strcmp(param->resctrl_val, "cqm")) { + /* Sleep for a second so that benchmark gets to run */ + sleep(1); + ret = get_llc_occu_resctrl(&llc_occu_resc); if (ret < 0) return ret; llc_value = llc_occu_resc; } + ret = print_results_cache(param->filename, bm_pid, llc_value); if (ret) return ret; diff --git a/tools/testing/selftests/resctrl/cqm_test.c b/tools/testing/selftests/resctrl/cqm_test.c index f27b0363e518..3406c04ff110 100644 --- a/tools/testing/selftests/resctrl/cqm_test.c +++ b/tools/testing/selftests/resctrl/cqm_test.c @@ -13,73 +13,74 @@ #define RESULT_FILE_NAME "result_cqm" #define NUM_OF_RUNS 5 -#define MAX_DIFF 2000000 -#define MAX_DIFF_PERCENT 15 +#define MAX_DIFF_PERCENT 5 -int count_of_bits; char cbm_mask[256]; -unsigned long long_mask; -unsigned long cache_size; -static int cqm_setup(struct resctrl_val_param *p) -{ - /* Run NUM_OF_RUNS times */ - if (p->num_of_runs >= NUM_OF_RUNS) - return -1; - - p->num_of_runs++; - - return 0; -} +static int count_of_bits, count_of_shareable_bits; +static unsigned long cache_size, shareable_mask; -static void show_cache_info(unsigned long sum_llc_occu_resc, int no_of_bits, - unsigned long span) +static void show_cache_info(unsigned long *llc_occu_resc) { - unsigned long avg_llc_occu_resc = 0; - float diff_percent; - long avg_diff = 0; - bool res; + int bits, runs; + bool failed = false; - avg_llc_occu_resc = sum_llc_occu_resc / (NUM_OF_RUNS - 1); - avg_diff = (long)abs(span - avg_llc_occu_resc); - - diff_percent = (((float)span - avg_llc_occu_resc) / span) * 100; + printf("# Results are displayed in (Bytes)\n"); - if ((abs((int)diff_percent) <= MAX_DIFF_PERCENT) || - (abs(avg_diff) <= MAX_DIFF)) - res = true; - else - res = false; + for (bits = 0; bits < count_of_bits - count_of_shareable_bits; bits++) { + unsigned long avg_llc_occu_resc, sum_llc_occu_resc = 0; + unsigned long alloc_llc, mask = 0; + int llc_occu_diff, i; + + /* + * The first run is discarded due to inaccurate value from + * phase transition. + */ + for (runs = NUM_OF_RUNS * bits + 1; + runs < NUM_OF_RUNS * bits + NUM_OF_RUNS; runs++) + sum_llc_occu_resc += llc_occu_resc[runs]; + + avg_llc_occu_resc = sum_llc_occu_resc / (NUM_OF_RUNS - 1); + alloc_llc = cache_size * ((float)(bits + 1) / count_of_bits); + llc_occu_diff = avg_llc_occu_resc - alloc_llc; + + for (i = 0; i < bits + 1; i++) { + mask <<= 1; + mask |= 1; + } - printf("%sok CQM: diff within %d, %d\%%\n", res ? "" : "not ", - MAX_DIFF, (int)MAX_DIFF_PERCENT); + if (llc_occu_diff > 0 && + llc_occu_diff > alloc_llc * ((float)MAX_DIFF_PERCENT / 100)) + failed = true; - printf("# diff: %ld\n", avg_diff); - printf("# percent diff=%d\n", abs((int)diff_percent)); - printf("# Results are displayed in (Bytes)\n"); - printf("# Number of bits: %d\n", no_of_bits); - printf("# Avg_llc_occu_resc: %lu\n", avg_llc_occu_resc); - printf("# llc_occu_exp (span): %lu\n", span); + printf("%sok CQM: diff within %d%% for mask %lx\n", + failed ? "not " : "", MAX_DIFF_PERCENT, mask); + printf("# alloc_llc_cache_size: %lu\n", alloc_llc); + printf("# avg_llc_occu_resc: %lu\n", avg_llc_occu_resc); + tests_run++; + } + printf("%sok schemata change for CQM%s\n", failed ? "not " : "", + failed ? " # at least one test failed" : ""); tests_run++; } -static int check_results(struct resctrl_val_param *param, int no_of_bits) +static int check_results(void) { - char *token_array[8], temp[512]; - unsigned long sum_llc_occu_resc = 0; - int runs = 0; + char *token_array[8], output[] = RESULT_FILE_NAME, temp[512]; + unsigned long llc_occu_resc[count_of_bits * NUM_OF_RUNS]; + int runs; FILE *fp; - printf("# checking for pass/fail\n"); - fp = fopen(param->filename, "r"); + fp = fopen(output, "r"); if (!fp) { - perror("# Error in opening file\n"); + perror(output); return errno; } - while (fgets(temp, 1024, fp)) { + runs = 0; + while (fgets(temp, sizeof(temp), fp)) { char *token = strtok(temp, ":\t"); int fields = 0; @@ -88,13 +89,14 @@ static int check_results(struct resctrl_val_param *param, int no_of_bits) token = strtok(NULL, ":\t"); } - /* Field 3 is llc occ resc value */ - if (runs > 0) - sum_llc_occu_resc += strtoul(token_array[3], NULL, 0); + /* Field 3 is resctrl LLC occupancy value */ + llc_occu_resc[runs] = strtoul(token_array[3], NULL, 0); runs++; } + fclose(fp); - show_cache_info(sum_llc_occu_resc, no_of_bits, param->span); + + show_cache_info(llc_occu_resc); return 0; } @@ -104,62 +106,107 @@ void cqm_test_cleanup(void) remove(RESULT_FILE_NAME); } -int cqm_resctrl_val(int cpu_no, int n, char **benchmark_cmd) +/* + * Change schemata from 1 to count_of_bits - 1. Write schemata to specified + * con_mon grp, mon_grp in resctrl FS. For each allocation, run "NUM_OF_RUNS" + * times to get average values. + */ +static int cqm_setup(struct resctrl_val_param *p) { - int ret, mum_resctrlfs; + static int runs_per_allocation = 0, num_of_bits = 1; + unsigned long mask = 0; + char schemata[64]; + int i, ret; - cache_size = 0; - mum_resctrlfs = 1; + if (runs_per_allocation >= NUM_OF_RUNS) + runs_per_allocation = 0; - ret = remount_resctrlfs(mum_resctrlfs); - if (ret) - return ret; + /* Only set up schemata once every NUM_OF_RUNS of allocations */ + if (runs_per_allocation++ != 0) + return 0; - if (!validate_resctrl_feature_request("cqm")) + if (num_of_bits > count_of_bits - count_of_shareable_bits) return -1; - ret = get_cbm_mask("L3"); - if (ret) - return ret; - - long_mask = strtoul(cbm_mask, NULL, 16); + /* Prepare cbm mask without any shareable bits */ + for (i = 0; i < num_of_bits; i++) { + mask <<= 1; + mask |= 1; + } + mask = ~shareable_mask & mask; - ret = get_cache_size(cpu_no, "L3", &cache_size); + sprintf(schemata, "%lx", mask); + ret = write_schemata(p->ctrlgrp, schemata, p->cpu_no, "cat"); if (ret) return ret; - printf("cache size :%lu\n", cache_size); - count_of_bits = count_bits(long_mask); + p->mask = mask; + num_of_bits++; - if (n < 1 || n > count_of_bits) { - printf("Invalid input value for numbr_of_bits n!\n"); - printf("Please Enter value in range 1 to %d\n", count_of_bits); - return -1; - } + return 0; +} +int cqm_schemata_change(int cpu_no, int span, char *cache_type, + char **benchmark_cmd) +{ struct resctrl_val_param param = { .resctrl_val = "cqm", .ctrlgrp = "c1", .mongrp = "m1", .cpu_no = cpu_no, + .span = span, .mum_resctrlfs = 0, .filename = RESULT_FILE_NAME, - .mask = ~(long_mask << n) & long_mask, - .span = cache_size * n / count_of_bits, .num_of_runs = 0, - .setup = cqm_setup, + .setup = cqm_setup }; + int ret; + char schemata[64]; + unsigned long long_mask; - if (strcmp(benchmark_cmd[0], "fill_buf") == 0) - sprintf(benchmark_cmd[1], "%lu", param.span); + ret = remount_resctrlfs(1); + if (ret) + return ret; - remove(RESULT_FILE_NAME); + /* Check for both 'cat' and 'cqm' because CQM is validated using CAT */ + if (!validate_resctrl_feature_request("cqm")) + return -1; + + if (!validate_resctrl_feature_request("cat")) + return -1; + + ret = get_cache_size(cpu_no, cache_type, &cache_size); + if (ret) + return ret; + printf("# cache size: %lu\n", cache_size); + + ret = get_cbm_mask(cache_type); + if (ret) + return ret; + + long_mask = strtoul(cbm_mask, NULL, 16); + count_of_bits = count_bits(long_mask); + + /* + * Change root con_mon grp schemata to minimum (i.e. '1' bit) so that + * test could use all other bits + */ + sprintf(schemata, "%x", 1); + ret = write_schemata("", schemata, cpu_no, "cqm"); + if (ret) + return ret; + + ret = get_shareable_mask(cache_type, &shareable_mask); + if (ret) + return ret; + + count_of_shareable_bits = count_bits(shareable_mask); ret = resctrl_val(benchmark_cmd, ¶m); if (ret) return ret; - ret = check_results(¶m, n); + ret = check_results(); if (ret) return ret; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 79148cbbd7a4..cb67ad689475 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -103,7 +103,8 @@ int setup_critical_process(pid_t pid, struct resctrl_val_param *param); int run_critical_process(pid_t pid, struct resctrl_val_param *param); void cat_test_cleanup(void); int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type); -int cqm_resctrl_val(int cpu_no, int n, char **benchmark_cmd); +int cqm_schemata_change(int cpu_no, int span, char *cache_type, + char **benchmark_cmd); unsigned int count_bits(unsigned long n); void cqm_test_cleanup(void); int get_core_sibling(int cpu_no); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 60db128312a6..3c408c636b6d 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -180,9 +180,11 @@ int main(int argc, char **argv) if (cqm_test) { printf("# Starting CQM test ...\n"); - if (!has_ben) + if (!has_ben) { + sprintf(benchmark_cmd[1], "%d", span); sprintf(benchmark_cmd[5], "%s", "cqm"); - res = cqm_resctrl_val(cpu_no, no_of_bits, benchmark_cmd); + } + res = cqm_schemata_change(cpu_no, span, "L3", benchmark_cmd); printf("%sok CQM: test\n", res ? "not " : ""); cqm_test_cleanup(); tests_run++; diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 271cb5c976f5..c59fad6cb9b0 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -705,29 +705,21 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) goto out; } - /* Give benchmark enough time to fully run */ - sleep(1); - /* Test runs until the callback setup() tells the test to stop. */ while (1) { + ret = param->setup(param); + if (ret) { + ret = 0; + break; + } + + /* Measure vals sleeps for a second */ if ((strcmp(resctrl_val, "mbm") == 0) || (strcmp(resctrl_val, "mba") == 0)) { - ret = param->setup(param); - if (ret) { - ret = 0; - break; - } - ret = measure_vals(param, &bw_resc_start); if (ret) break; } else if (strcmp(resctrl_val, "cqm") == 0) { - ret = param->setup(param); - if (ret) { - ret = 0; - break; - } - sleep(1); ret = measure_cache_vals(param, bm_pid); if (ret) break; diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 52452bb0178a..bd81a13ff9df 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -365,11 +365,7 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext) memflush = atoi(benchmark_cmd[3]); operation = atoi(benchmark_cmd[4]); sprintf(resctrl_val, "%s", benchmark_cmd[5]); - - if (strcmp(resctrl_val, "cqm") != 0) - buffer_span = span * MB; - else - buffer_span = span; + buffer_span = span * MB; if (run_fill_buf(buffer_span, malloc_and_init_memory, memflush, operation, resctrl_val)) From patchwork Sat Mar 7 03:40:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425085 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 64EAB92A for ; Sat, 7 Mar 2020 03:46:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4FBCC2073C for ; Sat, 7 Mar 2020 03:46:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727065AbgCGDq0 (ORCPT ); Fri, 6 Mar 2020 22:46:26 -0500 Received: from mga11.intel.com ([192.55.52.93]:57586 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726533AbgCGDqW (ORCPT ); Fri, 6 Mar 2020 22:46:22 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235036048" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:21 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 12/13] selftests/resctrl: Dynamically select buffer size for CAT test Date: Fri, 6 Mar 2020 19:40:53 -0800 Message-Id: <18ab8b47d1d2b6373d7899bdf8df19fa94afcfaa.1583657204.git.sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Presently, while running CAT test case, if user hasn't given any input for '-n' option, the test defaults to 5 bits to determine the buffer size that is used during test. Instead of statically running always with 5 bits, change it such that the buffer size is always half of the cache size. Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/cat_test.c | 16 +++++++++++----- tools/testing/selftests/resctrl/resctrl.h | 3 ++- tools/testing/selftests/resctrl/resctrl_tests.c | 7 ++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index f7a67f005fe5..d1c50430ab20 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -109,7 +109,8 @@ void cat_test_cleanup(void) remove(RESULT_FILE_NAME); } -static int prepare_masks_for_two_processes(int no_of_bits, char *cache_type) +static int prepare_masks_for_two_processes(int *no_of_bits, bool user_bits, + char *cache_type) { int ret, i; unsigned long long_mask, shareable_mask; @@ -123,12 +124,15 @@ static int prepare_masks_for_two_processes(int no_of_bits, char *cache_type) long_mask = strtoul(cbm_mask, NULL, 16); count_of_bits = count_bits(long_mask); + if (!user_bits) + *no_of_bits = count_of_bits / 2; + /* * Max limit is count_of_bits - 1 because we need exclusive masks for * the two processes. So, the last saved bit will be used by the other * process. */ - if (no_of_bits < 1 || no_of_bits > count_of_bits - 1) { + if (*no_of_bits < 1 || *no_of_bits > count_of_bits - 1) { printf("Invalid input value for no_of_bits 'n'\n"); printf("Please Enter value in range 1 to %d\n", count_of_bits - 1); @@ -140,7 +144,7 @@ static int prepare_masks_for_two_processes(int no_of_bits, char *cache_type) return ret; /* Prepare cbm mask without any shareable bits */ - for (i = 0; i < no_of_bits; i++) { + for (i = 0; i < *no_of_bits; i++) { p1_mask <<= 1; p1_mask |= 1; } @@ -176,7 +180,8 @@ static int start_noisy_process(pid_t pid, int sibling_cpu_no) return 0; } -int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type) +int cat_perf_miss_val(int cpu_no, int no_of_bits, bool user_bits, + char *cache_type) { int ret, sibling_cpu_no; unsigned long buf_size; @@ -194,7 +199,8 @@ int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type) if (!validate_resctrl_feature_request("cat")) return -1; - ret = prepare_masks_for_two_processes(no_of_bits, cache_type); + ret = prepare_masks_for_two_processes(&no_of_bits, user_bits, + cache_type); if (ret) return ret; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index cb67ad689475..393f2f34ccac 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -102,7 +102,8 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr); int setup_critical_process(pid_t pid, struct resctrl_val_param *param); int run_critical_process(pid_t pid, struct resctrl_val_param *param); void cat_test_cleanup(void); -int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type); +int cat_perf_miss_val(int cpu_no, int no_of_bits, bool user_bits, + char *cache_type); int cqm_schemata_change(int cpu_no, int span, char *cache_type, char **benchmark_cmd); unsigned int count_bits(unsigned long n); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 3c408c636b6d..4461c3dc8cce 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -57,11 +57,11 @@ void tests_cleanup(void) int main(int argc, char **argv) { bool has_ben = false, mbm_test = true, mba_test = true, cqm_test = true; - int res, c, cpu_no = 1, span = 250, argc_new = argc, i, no_of_bits = 5; + int res, c, cpu_no = 1, span = 250, argc_new = argc, i, no_of_bits; char *benchmark_cmd[BENCHMARK_ARGS], bw_report[64], bm_type[64]; char benchmark_cmd_area[BENCHMARK_ARGS][BENCHMARK_ARG_SIZE]; int ben_ind, ben_count; - bool cat_test = true; + bool cat_test = true, user_bits = false; for (i = 0; i < argc; i++) { if (strcmp(argv[i], "-b") == 0) { @@ -105,6 +105,7 @@ int main(int argc, char **argv) cpu_no = atoi(optarg); break; case 'n': + user_bits = true; no_of_bits = atoi(optarg); break; case 'h': @@ -192,7 +193,7 @@ int main(int argc, char **argv) if (cat_test) { printf("# Starting CAT test ...\n"); - res = cat_perf_miss_val(cpu_no, no_of_bits, "L3"); + res = cat_perf_miss_val(cpu_no, no_of_bits, user_bits, "L3"); printf("%sok CAT: test\n", res ? "not " : ""); cat_test_cleanup(); tests_run++; From patchwork Sat Mar 7 03:40:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakhya, Sai Praneeth" X-Patchwork-Id: 11425087 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC9FC924 for ; Sat, 7 Mar 2020 03:46:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D04B2077C for ; Sat, 7 Mar 2020 03:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727179AbgCGDqZ (ORCPT ); Fri, 6 Mar 2020 22:46:25 -0500 Received: from mga11.intel.com ([192.55.52.93]:57585 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727173AbgCGDqY (ORCPT ); Fri, 6 Mar 2020 22:46:24 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 19:46:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,524,1574150400"; d="scan'208";a="235036052" Received: from sai-dev-mach.sc.intel.com ([143.183.140.153]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2020 19:46:22 -0800 From: Sai Praneeth Prakhya To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, tony.luck@intel.com, reinette.chatre@intel.com, babu.moger@amd.com, james.morse@arm.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Sai Praneeth Prakhya Subject: [PATCH V1 13/13] selftests/resctrl: Cleanup fill_buff after changing CAT test Date: Fri, 6 Mar 2020 19:40:54 -0800 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The previous CAT test reads buffer only once and hence to accomodate this use case, name of the test case (i.e. cat) was passed as an argument to "fill_buff". Ideally, "fill_buff" doesn't need to know which test invoked it, hence, cleanup "fill_buff" and code that was carrying around this extra argument. Signed-off-by: Sai Praneeth Prakhya --- tools/testing/selftests/resctrl/cat_test.c | 6 +---- tools/testing/selftests/resctrl/fill_buf.c | 29 ++++++++++--------------- tools/testing/selftests/resctrl/resctrl.h | 4 ++-- tools/testing/selftests/resctrl/resctrl_tests.c | 11 +++------- tools/testing/selftests/resctrl/resctrlfs.c | 4 +--- 5 files changed, 18 insertions(+), 36 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index d1c50430ab20..b25c8f43d29c 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -169,11 +169,7 @@ static int start_noisy_process(pid_t pid, int sibling_cpu_no) if (ret) return ret; - /* - * Passing 'cat' will not loop around buffer forever, hence don't pass - * test name - */ - ret = run_fill_buf(buf_size, 1, 1, 0, ""); + ret = run_fill_buf(buf_size, 1, 1, 0); if (ret) return ret; diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 0500dab90b2e..486e6b4c9924 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -107,16 +107,13 @@ static void fill_one_span_write(void) } } -static int fill_cache_read(char *resctrl_val) +static int fill_cache_read(void) { int ret = 0; FILE *fp; - while (1) { + while (1) ret = fill_one_span_read(); - if (!strcmp(resctrl_val, "cat")) - break; - } /* Consume read result so that reading memory is not optimized out. */ fp = fopen("/dev/null", "w"); @@ -128,13 +125,10 @@ static int fill_cache_read(char *resctrl_val) return 0; } -static int fill_cache_write(char *resctrl_val) +static int fill_cache_write(void) { - while (1) { + while (1) fill_one_span_write(); - if (!strcmp(resctrl_val, "cat")) - break; - } return 0; } @@ -202,14 +196,14 @@ int use_buffer_once(int op) return 0; } -int use_buffer_forever(int op, char *resctrl_val) +int use_buffer_forever(int op) { int ret; if (op == 0) - ret = fill_cache_read(resctrl_val); + ret = fill_cache_read(); else - ret = fill_cache_write(resctrl_val); + ret = fill_cache_write(); if (ret) { printf("\n Error in fill cache read/write...\n"); @@ -221,7 +215,7 @@ int use_buffer_forever(int op, char *resctrl_val) static int fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush, - int op, char *resctrl_val) + int op) { int ret; @@ -229,7 +223,7 @@ fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush, if (ret) return ret; - ret = use_buffer_forever(op, resctrl_val); + ret = use_buffer_forever(op); if (ret) return ret; @@ -239,7 +233,7 @@ fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush, } int run_fill_buf(unsigned long span, int malloc_and_init_memory, - int memflush, int op, char *resctrl_val) + int memflush, int op) { unsigned long long cache_size = span; int ret; @@ -250,8 +244,7 @@ int run_fill_buf(unsigned long span, int malloc_and_init_memory, if (signal(SIGHUP, ctrl_handler) == SIG_ERR) printf("Failed to catch SIGHUP!\n"); - ret = fill_cache(cache_size, malloc_and_init_memory, memflush, op, - resctrl_val); + ret = fill_cache(cache_size, malloc_and_init_memory, memflush, op); if (ret) { printf("\n Error in fill cache\n"); return -1; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 393f2f34ccac..18e27e3f71ae 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -86,9 +86,9 @@ int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags); int init_buffer(unsigned long long buf_size, int malloc_and_init, int memflush); int use_buffer_once(int op); -int use_buffer_forever(int op, char *resctrl_val); +int use_buffer_forever(int op); int run_fill_buf(unsigned long span, int malloc_and_init_memory, int memflush, - int op, char *resctrl_va); + int op); int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param); int mbm_bw_change(int span, int cpu_no, char *bw_report, char **benchmark_cmd); void tests_cleanup(void); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 4461c3dc8cce..503c68f2570f 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -141,7 +141,7 @@ int main(int argc, char **argv) benchmark_cmd[ben_count] = NULL; } else { /* If no benchmark is given by "-b" argument, use fill_buf. */ - for (i = 0; i < 6; i++) + for (i = 0; i < 5; i++) benchmark_cmd[i] = benchmark_cmd_area[i]; strcpy(benchmark_cmd[0], "fill_buf"); @@ -149,8 +149,7 @@ int main(int argc, char **argv) strcpy(benchmark_cmd[2], "1"); strcpy(benchmark_cmd[3], "1"); strcpy(benchmark_cmd[4], "0"); - strcpy(benchmark_cmd[5], ""); - benchmark_cmd[6] = NULL; + benchmark_cmd[5] = NULL; } sprintf(bw_report, "reads"); @@ -161,8 +160,6 @@ int main(int argc, char **argv) if (!is_amd && mbm_test) { printf("# Starting MBM BW change ...\n"); - if (!has_ben) - sprintf(benchmark_cmd[5], "%s", "mba"); res = mbm_bw_change(span, cpu_no, bw_report, benchmark_cmd); printf("%sok MBM: bw change\n", res ? "not " : ""); mbm_test_cleanup(); @@ -181,10 +178,8 @@ int main(int argc, char **argv) if (cqm_test) { printf("# Starting CQM test ...\n"); - if (!has_ben) { + if (!has_ben) sprintf(benchmark_cmd[1], "%d", span); - sprintf(benchmark_cmd[5], "%s", "cqm"); - } res = cqm_schemata_change(cpu_no, span, "L3", benchmark_cmd); printf("%sok CQM: test\n", res ? "not " : ""); cqm_test_cleanup(); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index bd81a13ff9df..dcc9e70cbf30 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -345,7 +345,6 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext) int operation, ret, malloc_and_init_memory, memflush; unsigned long span, buffer_span; char **benchmark_cmd; - char resctrl_val[64]; FILE *fp; benchmark_cmd = info->si_ptr; @@ -364,11 +363,10 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext) malloc_and_init_memory = atoi(benchmark_cmd[2]); memflush = atoi(benchmark_cmd[3]); operation = atoi(benchmark_cmd[4]); - sprintf(resctrl_val, "%s", benchmark_cmd[5]); buffer_span = span * MB; if (run_fill_buf(buffer_span, malloc_and_init_memory, memflush, - operation, resctrl_val)) + operation)) fprintf(stderr, "Error in running fill buffer\n"); } else { /* Execute specified benchmark */