From patchwork Thu Jul 13 13:19:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 702575 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF4EDC001E0 for ; Thu, 13 Jul 2023 13:20:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234851AbjGMNUo (ORCPT ); Thu, 13 Jul 2023 09:20:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234797AbjGMNUa (ORCPT ); Thu, 13 Jul 2023 09:20:30 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 553572D7D; Thu, 13 Jul 2023 06:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689254423; x=1720790423; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eyfFQOIKAZuYYHklcPqdTE2gmRhrKpH4qZtrSJz6apA=; b=dfi3BudECKBmEr/Ori08aoyjCFjc9CciZYn/IlKMbXY717cJXuBMErzh rfgWVfavlAU9ldNMgjHDB05cRSzbpJnb8XFGoS6Y7DalpXNX0bqjtkW4x NGGw+SD6RqZM8OH+U1euXqvurBeqBN166rxoC7iyq2uU5GR67QM43KKsi +433hXBrDhmCksx+D9Y0bEfzg0Do05v+NypgOJ4/sqb4Hwuwj+wyvVMlj pvufA+mRf0+Iyd2g5wH3gOPfjN8umvzdLHpKslkK5dky0yNiwtvHmBtN0 dQNsNstcqNgEE5EFU5CHuJ0GTLWF4KH/NancnkDsObwfkImE4xiQ1Jz8j g==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="345496538" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="345496538" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="968615700" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="968615700" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.222.39]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:20 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , Colin Ian King , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v4 02/19] selftests/resctrl: Don't leak buffer in fill_cache() Date: Thu, 13 Jul 2023 16:19:15 +0300 Message-Id: <20230713131932.133258-3-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The error path in fill_cache() does return before the allocated buffer is freed leaking the buffer. The leak was introduced when fill_cache_read() started to return errors in c7b607fa9325 ("selftests/resctrl: Fix null pointer dereference on open failed"), before that both fill functions always returned 0. Move free() earlier to prevent the mem leak. Fixes: c7b607fa9325 ("selftests/resctrl: Fix null pointer dereference on open failed") Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/fill_buf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 341cc93ca84c..3b328c844896 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -177,12 +177,13 @@ fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush, else ret = fill_cache_write(start_ptr, end_ptr, resctrl_val); + free(startptr); + if (ret) { printf("\n Error in fill cache read/write...\n"); return -1; } - free(startptr); return 0; } From patchwork Thu Jul 13 13:19:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 702574 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9880DEB64DD for ; Thu, 13 Jul 2023 13:21:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234213AbjGMNVF (ORCPT ); Thu, 13 Jul 2023 09:21:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230514AbjGMNUl (ORCPT ); Thu, 13 Jul 2023 09:20:41 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72DC1213B; Thu, 13 Jul 2023 06:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689254431; x=1720790431; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SfPvkmzWJcJdc6LqGPirAEzeqOxBh6wxev3IG7Dp8Fo=; b=hO1C6B0lLC21mJUarCQLpq/Uts2FxsxdaUfGgLbXibQdG8ciS/IlZzfV XXprmbV2RzWpSy2EoBhloYz440l/XnqnnUVB4IHesSF79IlxpCm7j1IKg hVG3WtxKowpmtpuvoxxBlNj7U2i60Z+zC8yCj77jN/WXxRw4e1yJXARD5 vC5SsCYpxYDHLWdQIu1gmYkIxC08W0TyUJycymX8kQJo0DEGTbUkraBu0 ACvcLo2xwkZWf9lcyYy/WmnVhr5HTA7SXbbMia/iMKtZgCwurFZZ5183n BZjP2VII5LLHHiH/WnS5jNxrwZJnxR/fr0yo/Pp0ZWcB45wrCLSlB2bS+ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="345496593" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="345496593" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="968615770" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="968615770" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.222.39]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:28 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , Sai Praneeth Prakhya , Babu Moger , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v4 04/19] selftests/resctrl: Close perf value read fd on errors Date: Thu, 13 Jul 2023 16:19:17 +0300 Message-Id: <20230713131932.133258-5-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Perf event fd (fd_lm) is not closed on some error paths. Always close fd_lm in get_llc_perf() and add close into an error handling block in cat_val(). Fixes: 790bf585b0ee ("selftests/resctrl: Add Cache Allocation Technology (CAT) selftest") Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index 8a4fe8693be6..ced47b445d1e 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -87,21 +87,20 @@ static int reset_enable_llc_perf(pid_t pid, int cpu_no) static int get_llc_perf(unsigned long *llc_perf_miss) { __u64 total_misses; + int ret; /* Stop counters after one span to get miss rate */ ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0); - if (read(fd_lm, &rf_cqm, sizeof(struct read_format)) == -1) { + ret = read(fd_lm, &rf_cqm, sizeof(struct read_format)); + close(fd_lm); + if (ret == -1) { perror("Could not get llc misses through perf"); - return -1; } total_misses = rf_cqm.values[0].value; - - close(fd_lm); - *llc_perf_miss = total_misses; return 0; @@ -253,6 +252,7 @@ int cat_val(struct resctrl_val_param *param) memflush, operation, resctrl_val)) { fprintf(stderr, "Error-running fill buffer\n"); ret = -1; + close(fd_lm); break; } From patchwork Thu Jul 13 13:19:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 702573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4BC0C001DD for ; Thu, 13 Jul 2023 13:21:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231537AbjGMNVJ (ORCPT ); Thu, 13 Jul 2023 09:21:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234495AbjGMNUo (ORCPT ); Thu, 13 Jul 2023 09:20:44 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8CA72721; Thu, 13 Jul 2023 06:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689254434; x=1720790434; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Hn0fYehjq6FV6t/LfA0e2GwEyK8XmldiekSokujXnRI=; b=TkKRkp6OFw7a7CyfCqDPaxrYgI6Z8DKzZLRzZa2oHJhSJLnkO5oUMCAE wN0u6UPB27Dky6CgkIcv01CiDU8GmjzQmrwd5ndnafgAlVDklbSIDfCDE /eTUiUn9CG34ncpTH7eky8luDvsZTK2XQNH+jWNc2jfOQTmZCuiazOXro bVSJvUCdpktJVtGVw8e+pYMZR1Ly2kHi/UxmJ3JX+RppqaypPnlyDcqSS NUa4v3iDFAGaWq7C1hQV5m8KM8UNTg94THaOHzpCk1SK3LCC17OISt0Ja /2nzopszEQh9l869vaQAIQpl0YUi9kouUxGnMqxEyAaXTflZ+Gkw/ccn7 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="345496617" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="345496617" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="968615793" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="968615793" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.222.39]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:32 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v4 05/19] selftests/resctrl: Unmount resctrl FS before starting the first test Date: Thu, 13 Jul 2023 16:19:18 +0300 Message-Id: <20230713131932.133258-6-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Resctrl FS mount/remount/umount code is hard to track. Better approach is to use mount/umount pair for each test but that assumes resctrl FS is not mounted beforehand. Change umount_resctrlfs() so that it can unmount resctrl FS from any path, and enable further simplifications into mount/remount/umount logic by unmounting resctrl FS at the start if a pre-existing mountpoint is found. Suggested-by: Reinette Chatre Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/resctrl_tests.c | 2 ++ tools/testing/selftests/resctrl/resctrlfs.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 9b9751206e1c..b1b2d28b52f7 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -250,6 +250,8 @@ int main(int argc, char **argv) if (!check_resctrlfs_support()) return ksft_exit_skip("resctrl FS does not exist. Enable X86_CPU_RESCTRL config option.\n"); + umount_resctrlfs(); + filter_dmesg(); ksft_set_plan(tests ? : 4); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index fb00245dee92..23f75aeaa198 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -82,10 +82,12 @@ int remount_resctrlfs(bool mum_resctrlfs) int umount_resctrlfs(void) { - if (find_resctrl_mount(NULL)) + char mountpoint[256]; + + if (find_resctrl_mount(mountpoint)) return 0; - if (umount(RESCTRL_PATH)) { + if (umount(mountpoint)) { perror("# Unable to umount resctrl"); return errno; From patchwork Thu Jul 13 13:19:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 702572 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBBF3EB64DD for ; Thu, 13 Jul 2023 13:21:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234908AbjGMNVS (ORCPT ); Thu, 13 Jul 2023 09:21:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234927AbjGMNUq (ORCPT ); Thu, 13 Jul 2023 09:20:46 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B4D22728; Thu, 13 Jul 2023 06:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689254438; x=1720790438; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fFkFFFd2y2jKWl+2aoiMWCfgfLwLB1Qvo1uHm4CoT5M=; b=kjqjlRg+EWGYo+oUpsQCp1jZ4+I5PP3xnjQ4stO1K7Huni+FjCWxTC3+ j//vLa/z2nLSs+s5OsFDmfdecku27nMNPMGF/3knv+VL+NHzXcGn60Tth aZcjpP+7POi5OnskqayWYYSPr5vUX/KavQ9UR6M2sjuXiApa7umd+lSrX UXAI3j0TuOyZNk9J8I/HAML3+GPbdA0SXbcq/e9k6xRY+NxnxHHdONw4p YqQlHshxAPHn8pQK/EBmlK8eJhwuOHaMNKVXZeR3gQf0ELfJ8Ophk0Owv XxH3+MVF7se+QNOzpKwZ1xTizuc5euGjQnxAyiM9IprYKrgtB5rc58LKH Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="345496637" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="345496637" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="968615811" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="968615811" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.222.39]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:35 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v4 06/19] selftests/resctrl: Move resctrl FS mount/umount to higher level Date: Thu, 13 Jul 2023 16:19:19 +0300 Message-Id: <20230713131932.133258-7-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org A few places currently lack umounting resctrl FS on error paths: - cmt_resctrl_val() has multiple error paths with direct return. - cat_perf_miss_val() has multiple error paths with direct return. In addition, validate_resctrl_feature_request() is called by run_mbm_test() and run_mba_test(). Neither MBA nor MBM test tries to umount resctrl FS. Each and every test does require resctrl FS to be present already for feature check. Thus, it makes sense to just mount it on higher level in resctrl_tests.c and properly pair it with umount. Move resctrl FS (re)mount/unmount into each test function in resctrl_tests.c. Make feature validation to simply check that resctrl FS is mounted. Fixes: 91db4fd9019a ("selftests/resctrl: Remove duplicate codes that clear each test result file") Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cat_test.c | 6 --- tools/testing/selftests/resctrl/cmt_test.c | 4 -- .../testing/selftests/resctrl/resctrl_tests.c | 47 ++++++++++++++++--- tools/testing/selftests/resctrl/resctrl_val.c | 5 -- tools/testing/selftests/resctrl/resctrlfs.c | 7 ++- 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index fb1443f888c4..e1c071dec1b0 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -106,10 +106,6 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) cache_size = 0; - ret = remount_resctrlfs(true); - if (ret) - return ret; - /* Get default cbm mask for L3/L2 cache */ ret = get_cbm_mask(cache_type, cbm_mask); if (ret) @@ -227,8 +223,6 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) out: cat_test_cleanup(); - if (bm_pid) - umount_resctrlfs(); return ret; } diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index af71b2141271..426d11189a99 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -86,10 +86,6 @@ int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd) cache_size = 0; - ret = remount_resctrlfs(true); - if (ret) - return ret; - if (!validate_resctrl_feature_request(CMT_STR)) return -1; diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index b1b2d28b52f7..a421d045de08 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -77,9 +77,15 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, int span, ksft_print_msg("Starting MBM BW change ...\n"); + res = remount_resctrlfs(true); + if (res) { + ksft_exit_fail_msg("Failed to mount resctrl FS\n"); + return; + } + if (!validate_resctrl_feature_request(MBM_STR) || (get_vendor() != ARCH_INTEL)) { ksft_test_result_skip("Hardware does not support MBM or MBM is disabled\n"); - return; + goto umount; } if (!has_ben) @@ -88,6 +94,9 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, int span, ksft_test_result(!res, "MBM: bw change\n"); if ((get_vendor() == ARCH_INTEL) && res) ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n"); + +umount: + umount_resctrlfs(); } static void run_mba_test(bool has_ben, char **benchmark_cmd, int span, @@ -97,15 +106,24 @@ static void run_mba_test(bool has_ben, char **benchmark_cmd, int span, ksft_print_msg("Starting MBA Schemata change ...\n"); + res = remount_resctrlfs(true); + if (res) { + ksft_exit_fail_msg("Failed to mount resctrl FS\n"); + return; + } + if (!validate_resctrl_feature_request(MBA_STR) || (get_vendor() != ARCH_INTEL)) { ksft_test_result_skip("Hardware does not support MBA or MBA is disabled\n"); - return; + goto umount; } if (!has_ben) sprintf(benchmark_cmd[1], "%d", span); res = mba_schemata_change(cpu_no, bw_report, benchmark_cmd); ksft_test_result(!res, "MBA: schemata change\n"); + +umount: + umount_resctrlfs(); } static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no) @@ -113,9 +131,16 @@ static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no) int res; ksft_print_msg("Starting CMT test ...\n"); + + res = remount_resctrlfs(true); + if (res) { + ksft_exit_fail_msg("Failed to mount resctrl FS\n"); + return; + } + if (!validate_resctrl_feature_request(CMT_STR)) { ksft_test_result_skip("Hardware does not support CMT or CMT is disabled\n"); - return; + goto umount; } if (!has_ben) @@ -124,6 +149,9 @@ static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no) ksft_test_result(!res, "CMT: test\n"); if ((get_vendor() == ARCH_INTEL) && res) ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n"); + +umount: + umount_resctrlfs(); } static void run_cat_test(int cpu_no, int no_of_bits) @@ -132,13 +160,22 @@ static void run_cat_test(int cpu_no, int no_of_bits) ksft_print_msg("Starting CAT test ...\n"); + res = remount_resctrlfs(true); + if (res) { + ksft_exit_fail_msg("Failed to mount resctrl FS\n"); + return; + } + if (!validate_resctrl_feature_request(CAT_STR)) { ksft_test_result_skip("Hardware does not support CAT or CAT is disabled\n"); - return; + goto umount; } res = cat_perf_miss_val(cpu_no, no_of_bits, "L3"); ksft_test_result(!res, "CAT: test\n"); + +umount: + umount_resctrlfs(); } int main(int argc, char **argv) @@ -268,7 +305,5 @@ int main(int argc, char **argv) if (cat_test) run_cat_test(cpu_no, no_of_bits); - umount_resctrlfs(); - ksft_finished(); } diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index ab1eab1e7ff6..e8f1e6a59f4a 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -648,10 +648,6 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) return ret; } - ret = remount_resctrlfs(param->mum_resctrlfs); - if (ret) - return ret; - /* * If benchmark wasn't successfully started by child, then child should * kill parent, so save parent's pid @@ -788,7 +784,6 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) signal_handler_unregister(); out: kill(bm_pid, SIGKILL); - umount_resctrlfs(); return ret; } diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 23f75aeaa198..b3a05488d360 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -613,7 +613,8 @@ char *fgrep(FILE *inf, const char *str) * validate_resctrl_feature_request - Check if requested feature is valid. * @resctrl_val: Requested feature * - * Return: True if the feature is supported, else false + * Return: True if the feature is supported, else false. False is also + * returned if resctrl FS is not mounted. */ bool validate_resctrl_feature_request(const char *resctrl_val) { @@ -621,11 +622,13 @@ bool validate_resctrl_feature_request(const char *resctrl_val) bool found = false; char *res; FILE *inf; + int ret; if (!resctrl_val) return false; - if (remount_resctrlfs(false)) + ret = find_resctrl_mount(NULL); + if (ret) return false; if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) { From patchwork Thu Jul 13 13:19:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 702571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99202C0015E for ; Thu, 13 Jul 2023 13:21:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235168AbjGMNV0 (ORCPT ); Thu, 13 Jul 2023 09:21:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234513AbjGMNUy (ORCPT ); Thu, 13 Jul 2023 09:20:54 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09B712D48; Thu, 13 Jul 2023 06:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689254447; x=1720790447; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e4ibwDjlAb+ZjhQ1AfFhannM0naGZnGDFIvVBzF6V0E=; b=KD9pu+h2bBpgF0TToczU3XXHfFRGVQKK0J0iB+rTAqX+mR2KqxcPJoxL /ycCGEeD/ubM4slf4jQ2v7OtdspoCoavc19CZ/YAHo6m2iLTnEnv7Z3hh /Yk7nBo6Env7irD1SDC81iNrPpEaczn8kHYW9QGso37igcmiQE6vkbVRn /rjoRNUT8tiI+C0kiJU5RDqVryzvQGc1ouOGFzPtsditXRcycXHMWV7+H zfDK0ZnZTe2sFaQ4T3MZTOM4wIstEoUE8EZI1Wf0qRjKTZd3EmgDb4sVk OVSO1kmc/DpCMw+GOEg+55XsmO89H+ohChyGG5SrTuytaHXzE87mhhdee w==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="345496707" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="345496707" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="968615827" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="968615827" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.222.39]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:38 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v4 07/19] selftests/resctrl: Refactor remount_resctrl(bool mum_resctrlfs) to mount_resctrl() Date: Thu, 13 Jul 2023 16:19:20 +0300 Message-Id: <20230713131932.133258-8-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Mount/umount of the resctrl FS is now paired nicely per test. Rename remount_resctrl(bool mum_resctrlfs) to mount_resctrl(). Make it unconditionally try to mount the resctrl FS and return error if resctrl FS was mounted already. While at it, group the mount/umount prototypes in the header. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/resctrl.h | 2 +- .../testing/selftests/resctrl/resctrl_tests.c | 8 ++++---- tools/testing/selftests/resctrl/resctrlfs.c | 20 +++++-------------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index f455f0b7e314..23af3fb73cb4 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -85,8 +85,8 @@ extern char llc_occup_path[1024]; int get_vendor(void); bool check_resctrlfs_support(void); int filter_dmesg(void); -int remount_resctrlfs(bool mum_resctrlfs); int get_resource_id(int cpu_no, int *resource_id); +int mount_resctrlfs(void); int umount_resctrlfs(void); int validate_bw_report_request(char *bw_report); bool validate_resctrl_feature_request(const char *resctrl_val); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index a421d045de08..3f26d2279f75 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -77,7 +77,7 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, int span, ksft_print_msg("Starting MBM BW change ...\n"); - res = remount_resctrlfs(true); + res = mount_resctrlfs(); if (res) { ksft_exit_fail_msg("Failed to mount resctrl FS\n"); return; @@ -106,7 +106,7 @@ static void run_mba_test(bool has_ben, char **benchmark_cmd, int span, ksft_print_msg("Starting MBA Schemata change ...\n"); - res = remount_resctrlfs(true); + res = mount_resctrlfs(); if (res) { ksft_exit_fail_msg("Failed to mount resctrl FS\n"); return; @@ -132,7 +132,7 @@ static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no) ksft_print_msg("Starting CMT test ...\n"); - res = remount_resctrlfs(true); + res = mount_resctrlfs(); if (res) { ksft_exit_fail_msg("Failed to mount resctrl FS\n"); return; @@ -160,7 +160,7 @@ static void run_cat_test(int cpu_no, int no_of_bits) ksft_print_msg("Starting CAT test ...\n"); - res = remount_resctrlfs(true); + res = mount_resctrlfs(); if (res) { ksft_exit_fail_msg("Failed to mount resctrl FS\n"); return; diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index b3a05488d360..f622245adafe 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -48,29 +48,19 @@ static int find_resctrl_mount(char *buffer) } /* - * remount_resctrlfs - Remount resctrl FS at /sys/fs/resctrl - * @mum_resctrlfs: Should the resctrl FS be remounted? + * mount_resctrlfs - Mount resctrl FS at /sys/fs/resctrl * * If not mounted, mount it. - * If mounted and mum_resctrlfs then remount resctrl FS. - * If mounted and !mum_resctrlfs then noop * * Return: 0 on success, non-zero on failure */ -int remount_resctrlfs(bool mum_resctrlfs) +int mount_resctrlfs(void) { - char mountpoint[256]; int ret; - ret = find_resctrl_mount(mountpoint); - if (ret) - strcpy(mountpoint, RESCTRL_PATH); - - if (!ret && mum_resctrlfs && umount(mountpoint)) - ksft_print_msg("Fail: unmounting \"%s\"\n", mountpoint); - - if (!ret && !mum_resctrlfs) - return 0; + ret = find_resctrl_mount(NULL); + if (!ret) + return -1; ksft_print_msg("Mounting resctrl to \"%s\"\n", RESCTRL_PATH); ret = mount("resctrl", RESCTRL_PATH, "resctrl", 0, NULL); From patchwork Thu Jul 13 13:19:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 702569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32296C0015E for ; Thu, 13 Jul 2023 13:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235228AbjGMNVs (ORCPT ); Thu, 13 Jul 2023 09:21:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234894AbjGMNVS (ORCPT ); Thu, 13 Jul 2023 09:21:18 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD5B13588; Thu, 13 Jul 2023 06:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689254454; x=1720790454; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1Z6XtgfnkLNnOa77rczS1AMCmK7GDgGUepg6zaFzaNk=; b=Pqlk6al1iqtG4Ow/6f9hOBV8Dac7GyFkXb785AiKPKzmmgL07vEuoBmv 1ffLIonQCyrE2NqBeUd0QSuGeuSsKfrDxfFrBvyJ1GkNcPYgrhfjjpW93 WHvMZslJ0wYS+Jk2/8/fWls/rFWCNxuW509WcpBy8/OMewXMhJZ1BCuy6 TXU+chg3ZO5PuracCywOYNWO5lT8UJiyxfcJ/E2GIDCBvuRvevZ6L3nI8 W6wYAHcAoJHUqZGOaceua0J3OHPSwV+bghphzYg1SZ5gG6+MNVk9sRG22 oh53BjuNF1FnGLz8RlfS986wQRkFLsDhD0JdRg4QRnkDR/OIWT8A16c9O A==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="345496756" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="345496756" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="968615862" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="968615862" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.222.39]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:49 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v4 10/19] selftests/resctrl: Express span internally in bytes Date: Thu, 13 Jul 2023 16:19:23 +0300 Message-Id: <20230713131932.133258-11-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org MBA and MBM tests to use megabytes to represent span. CMT test uses bytes. The difference requires run_benchmark() to size the buffer differently based on the test name, which in turn requires passing the test name into run_benchmark(). Convert MBA and MBM tests to use internally bytes like CMT test to remove the internal inconsistency between the tests. Remove the test dependent buffer sizing from run_benchmark(). This change eliminates one of the reasons why the test name has to be passed around but there are still other users too so the test name passing cannot yet be removed. Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/mbm_test.c | 2 +- tools/testing/selftests/resctrl/resctrl_tests.c | 2 +- tools/testing/selftests/resctrl/resctrlfs.c | 9 ++------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index fd116158d008..2d58d4b8a918 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -40,7 +40,7 @@ show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, size_t span) ksft_print_msg("%s Check MBM diff within %d%%\n", ret ? "Fail:" : "Pass:", MAX_DIFF_PERCENT); ksft_print_msg("avg_diff_per: %d%%\n", avg_diff_per); - ksft_print_msg("Span (MB): %zu\n", span); + ksft_print_msg("Span (MB): %zu\n", span / MB); ksft_print_msg("avg_bw_imc: %lu\n", avg_bw_imc); ksft_print_msg("avg_bw_resc: %lu\n", avg_bw_resc); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 6b2ca1b4744f..5205a13ed250 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -185,8 +185,8 @@ int main(int argc, char **argv) char benchmark_cmd_area[BENCHMARK_ARGS][BENCHMARK_ARG_SIZE]; int c, cpu_no = 1, argc_new = argc, i, no_of_bits = 0; int ben_ind, ben_count, tests = 0; + size_t span = 250 * MB; bool cat_test = true; - size_t span = 250; for (i = 0; i < argc; i++) { if (strcmp(argv[i], "-b") == 0) { diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 8be5b745226d..847e0a80c6cd 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -298,9 +298,9 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no) void run_benchmark(int signum, siginfo_t *info, void *ucontext) { int operation, ret, malloc_and_init_memory, memflush; - size_t span, buffer_span; char **benchmark_cmd; char resctrl_val[64]; + size_t span; FILE *fp; benchmark_cmd = info->si_ptr; @@ -321,12 +321,7 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext) operation = atoi(benchmark_cmd[4]); sprintf(resctrl_val, "%s", benchmark_cmd[5]); - if (strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) - buffer_span = span * MB; - else - buffer_span = span; - - if (run_fill_buf(buffer_span, malloc_and_init_memory, memflush, + if (run_fill_buf(span, malloc_and_init_memory, memflush, operation, resctrl_val)) fprintf(stderr, "Error in running fill buffer\n"); } else { From patchwork Thu Jul 13 13:19:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 702568 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92DA8C0015E for ; Thu, 13 Jul 2023 13:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235201AbjGMNV4 (ORCPT ); Thu, 13 Jul 2023 09:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234839AbjGMNV1 (ORCPT ); Thu, 13 Jul 2023 09:21:27 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27A8035AD; Thu, 13 Jul 2023 06:21:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689254461; x=1720790461; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/q4GY8rhp2G88sSlAlKWw7Agjaw1iIMrjHxhCLVPXWA=; b=KpIZ/UCsakfhSsNc9tsIzcG7EqNc3GxmknsexERIFtoA2J+BPh7UkyU1 0VFLwOse8jAM9P68ieTkhDHqKIy8666/95vPSJbeTbqf5iwDbI7NGpjAf IbbGnT3btdFkTpEI0Z127roONC5dT/SeoIeWDvvPtPMc6kLItB4TdJdJg MZoY0SLtrRQQO5CitzTeciTwPwQUJkm+JIxuoba13Oth8Ao3CV+JW9GPh SpprhK2fgiNNBLKm/NK16cjHz+Dl3mw+ONJ9zr3X9M9v0AYxl5xHQqdtc 23joolTZKl9HU6PLtX1bN1eo1F7lASKENE6Jjr95k7zUxTxvMbVvbsHPQ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="345496837" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="345496837" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="968615885" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="968615885" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.222.39]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:55 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v4 12/19] selftests/resctrl: Remove "malloc_and_init_memory" param from run_fill_buf() Date: Thu, 13 Jul 2023 16:19:25 +0300 Message-Id: <20230713131932.133258-13-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org run_fill_buf()'s malloc_and_init_memory parameter is always 1. There's also duplicated memory init code for malloc_and_init_memory == 0 case in fill_buf() which is unused. Remove the malloc_and_init_memory parameter and the duplicated mem init code. While at it, fix also a typo in run_fill_buf() prototype's argument. Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 6 ++-- tools/testing/selftests/resctrl/fill_buf.c | 28 +++---------------- tools/testing/selftests/resctrl/resctrl.h | 3 +- .../testing/selftests/resctrl/resctrl_tests.c | 13 ++++----- tools/testing/selftests/resctrl/resctrlfs.c | 12 ++++---- 5 files changed, 19 insertions(+), 43 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index f2c7d322bd76..0db97b6a542f 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -211,7 +211,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid) */ int cat_val(struct resctrl_val_param *param) { - int malloc_and_init_memory = 1, memflush = 1, operation = 0, ret = 0; + int memflush = 1, operation = 0, ret = 0; char *resctrl_val = param->resctrl_val; pid_t bm_pid; @@ -248,8 +248,8 @@ int cat_val(struct resctrl_val_param *param) if (ret) break; - if (run_fill_buf(param->span, malloc_and_init_memory, - memflush, operation, resctrl_val)) { + if (run_fill_buf(param->span, memflush, operation, + resctrl_val)) { fprintf(stderr, "Error-running fill buffer\n"); ret = -1; close(fd_lm); diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 785cbd8d0148..d8f5505eb9e6 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -138,36 +138,18 @@ static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr, return 0; } -static int -fill_cache(size_t buf_size, int malloc_and_init, int memflush, - int op, char *resctrl_val) +static int fill_cache(size_t buf_size, int memflush, int op, char *resctrl_val) { 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); - + start_ptr = malloc_and_init_memory(buf_size); if (!start_ptr) return -1; startptr = start_ptr; end_ptr = start_ptr + buf_size; - /* - * It's better to touch the memory once to avoid any compiler - * optimizations - */ - if (!malloc_and_init) { - for (i = 0; i < buf_size; i++) - *start_ptr++ = (unsigned char)rand(); - } - - start_ptr = startptr; - /* Flush the memory before using to avoid "cache hot pages" effect */ if (memflush) mem_flush(start_ptr, buf_size); @@ -188,14 +170,12 @@ fill_cache(size_t buf_size, int malloc_and_init, int memflush, return 0; } -int run_fill_buf(size_t span, int malloc_and_init_memory, int memflush, int op, - char *resctrl_val) +int run_fill_buf(size_t span, int memflush, int op, char *resctrl_val) { size_t cache_size = span; int ret; - ret = fill_cache(cache_size, malloc_and_init_memory, memflush, op, - resctrl_val); + ret = fill_cache(cache_size, memflush, op, resctrl_val); 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 52068ceea956..3054cc4ef0e3 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -97,8 +97,7 @@ 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 run_fill_buf(size_t span, int malloc_and_init_memory, int memflush, int op, - char *resctrl_va); +int run_fill_buf(size_t span, int memflush, int op, char *resctrl_val); int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param); int mbm_bw_change(size_t 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 6e693f381a6e..0c313054326d 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -89,7 +89,7 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, size_t span, } if (!has_ben) - sprintf(benchmark_cmd[5], "%s", MBA_STR); + sprintf(benchmark_cmd[4], "%s", MBA_STR); res = mbm_bw_change(span, cpu_no, bw_report, benchmark_cmd); ksft_test_result(!res, "MBM: bw change\n"); if ((get_vendor() == ARCH_INTEL) && res) @@ -141,7 +141,7 @@ static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no) } if (!has_ben) - sprintf(benchmark_cmd[5], "%s", CMT_STR); + sprintf(benchmark_cmd[4], "%s", CMT_STR); res = cmt_resctrl_val(cpu_no, 5, benchmark_cmd); ksft_test_result(!res, "CMT: test\n"); if ((get_vendor() == ARCH_INTEL) && res) @@ -267,16 +267,15 @@ 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"); sprintf(benchmark_cmd[1], "%zu", span); strcpy(benchmark_cmd[2], "1"); - strcpy(benchmark_cmd[3], "1"); - strcpy(benchmark_cmd[4], "0"); - strcpy(benchmark_cmd[5], ""); - benchmark_cmd[6] = NULL; + strcpy(benchmark_cmd[3], "0"); + strcpy(benchmark_cmd[4], ""); + benchmark_cmd[5] = NULL; } sprintf(bw_report, "reads"); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 847e0a80c6cd..5f41ce03c470 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -297,7 +297,7 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no) */ void run_benchmark(int signum, siginfo_t *info, void *ucontext) { - int operation, ret, malloc_and_init_memory, memflush; + int operation, ret, memflush; char **benchmark_cmd; char resctrl_val[64]; size_t span; @@ -316,13 +316,11 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext) if (strcmp(benchmark_cmd[0], "fill_buf") == 0) { /* Execute default fill_buf benchmark */ span = strtoul(benchmark_cmd[1], NULL, 10); - 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]); + memflush = atoi(benchmark_cmd[2]); + operation = atoi(benchmark_cmd[3]); + sprintf(resctrl_val, "%s", benchmark_cmd[4]); - if (run_fill_buf(span, malloc_and_init_memory, memflush, - operation, resctrl_val)) + if (run_fill_buf(span, memflush, operation, resctrl_val)) fprintf(stderr, "Error in running fill buffer\n"); } else { /* Execute specified benchmark */ From patchwork Thu Jul 13 13:19:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 702567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E084DEB64DD for ; Thu, 13 Jul 2023 13:22:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234120AbjGMNWk (ORCPT ); Thu, 13 Jul 2023 09:22:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234601AbjGMNVx (ORCPT ); Thu, 13 Jul 2023 09:21:53 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1715D3A9E; Thu, 13 Jul 2023 06:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689254473; x=1720790473; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Vd7tzwpfv1b8Vdm5xf009cWmFKxKtbsLKfgak3lNYlg=; b=lu4H+LI3fFyCfJzuuLZeE7LYvo8hDBOxV7xl1I1VyK4PFyTk0f1BTuNt ULOgrINoms2KH9g6jKTkaybwGmdWMb+rLZwtdQIWiXP6J9fdlAduMAHOU qhHTVVnvyQEQGZgW8sm+obFlx7MXtxy80pekV593P2XQxXkM4GRm+Eij6 +jK1W029R7f9YXTl1Ub5i0/D4SNGMKLmUYGG+JHH1bF84ZNIvgqUGmB9T 95nfvYirwW8lQU82Nd4gQPXdQUDKrTHFm5tMoWAGh/8hbRW6quimyuFqG /NjZX8/soyIdZ8PN4G2LaT63Xv2B2LFfeiLYWZVL/V3anx2Jj6YF+0Tqf Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="345496912" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="345496912" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:21:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="968615921" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="968615921" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.222.39]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:21:01 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v4 14/19] selftests/resctrl: Improve parameter consistency in fill_buf Date: Thu, 13 Jul 2023 16:19:27 +0300 Message-Id: <20230713131932.133258-15-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org fill_buf's arguments can be improved in multiple ways: - Multiple functions in fill_buf have start_ptr as one of their argument which is a bit long and the extra "start" is pretty obvious when it comes to pointers. - Some of the functions take end_ptr and others size_t to indicate the end of the buffer. - Some arguments meaning buffer size are called just 's' - mem_flush() takes void * but immediately converts it to char * Cleanup the parameters to make things simpler and more consistent: - Rename start_ptr to simply buf as it's shorter. - Replace end_ptr and s parameters with buf_size and only calculate end_ptr in the functions that truly use it. - Make mem_flush() parameters to follow the same convention as the other functions in fill_buf. - convert mem_flush() char * to unsigned char *. While at it, fix also a typo in a comment. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/fill_buf.c | 49 +++++++++++----------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index a5ec9c82a960..5f16c4f5dfbf 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -38,32 +38,32 @@ static void cl_flush(void *p) #endif } -static void mem_flush(void *p, size_t s) +static void mem_flush(unsigned char *buf, size_t buf_size) { - char *cp = (char *)p; + unsigned char *cp = buf; size_t i = 0; - s = s / CL_SIZE; /* mem size in cache llines */ + buf_size = buf_size / CL_SIZE; /* mem size in cache lines */ - for (i = 0; i < s; i++) + for (i = 0; i < buf_size; i++) cl_flush(&cp[i * CL_SIZE]); sb(); } -static void *malloc_and_init_memory(size_t s) +static void *malloc_and_init_memory(size_t buf_size) { void *p = NULL; uint64_t *p64; size_t s64; int ret; - ret = posix_memalign(&p, PAGE_SIZE, s); + ret = posix_memalign(&p, PAGE_SIZE, buf_size); if (ret < 0) return NULL; p64 = (uint64_t *)p; - s64 = s / sizeof(uint64_t); + s64 = buf_size / sizeof(uint64_t); while (s64 > 0) { *p64 = (uint64_t)rand(); @@ -74,12 +74,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(unsigned char *buf, size_t buf_size) { + unsigned char *end_ptr = buf + buf_size; unsigned char sum, *p; sum = 0; - p = start_ptr; + p = buf; while (p < end_ptr) { sum += *p; p += (CL_SIZE / 2); @@ -88,26 +89,26 @@ 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(unsigned char *buf, size_t buf_size) { + unsigned char *end_ptr = buf + buf_size; unsigned char *p; - p = start_ptr; + p = buf; while (p < end_ptr) { *p = '1'; p += (CL_SIZE / 2); } } -static int fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr, +static int fill_cache_read(unsigned char *buf, size_t buf_size, char *resctrl_val) { int ret = 0; FILE *fp; while (1) { - ret = fill_one_span_read(start_ptr, end_ptr); + ret = fill_one_span_read(buf, buf_size); if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) break; } @@ -124,11 +125,11 @@ 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, +static int fill_cache_write(unsigned char *buf, size_t buf_size, char *resctrl_val) { while (1) { - fill_one_span_write(start_ptr, end_ptr); + fill_one_span_write(buf, buf_size); if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) break; } @@ -138,25 +139,23 @@ static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr, static int fill_cache(size_t buf_size, int memflush, int op, char *resctrl_val) { - unsigned char *start_ptr, *end_ptr; + unsigned char *buf; int ret; - start_ptr = malloc_and_init_memory(buf_size); - if (!start_ptr) + buf = malloc_and_init_memory(buf_size); + if (!buf) return -1; - end_ptr = start_ptr + buf_size; - /* Flush the memory before using to avoid "cache hot pages" effect */ if (memflush) - mem_flush(start_ptr, buf_size); + mem_flush(buf, buf_size); if (op == 0) - ret = fill_cache_read(start_ptr, end_ptr, resctrl_val); + ret = fill_cache_read(buf, buf_size, resctrl_val); else - ret = fill_cache_write(start_ptr, end_ptr, resctrl_val); + ret = fill_cache_write(buf, buf_size, resctrl_val); - free(start_ptr); + free(buf); if (ret) { printf("\n Error in fill cache read/write...\n"); From patchwork Thu Jul 13 13:19:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 702566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82CCDC0015E for ; Thu, 13 Jul 2023 13:22:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233120AbjGMNW4 (ORCPT ); Thu, 13 Jul 2023 09:22:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235254AbjGMNWd (ORCPT ); Thu, 13 Jul 2023 09:22:33 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C2582D74; Thu, 13 Jul 2023 06:21:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689254488; x=1720790488; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=adWz9KGhV5KjAo3m22fwN6bZ55XBth7V+DQufUxY6uk=; b=X/T1HpIb4m42c8hLpruGyBQlOc6ybA24WoZv3PfsQVAkhEK0TkYSYt1A Vua+FSTHGgiMDurg7Sv4myCuUxSIHlACO80xL5QFkSjuCTw6pmBYlJls5 gyh4YuECB+VecBeK/IifQBNb+f2XjD9r3ApJi9mA+3O6D8sVJBcTiSaON /AW8SAJ2GYdoank+5aR7A/nMSnh4Y8gtqBYC6B7fatwMfe9vewYjAG0dk w+eBok8FSgGA4rn4SPcN1spdObqgWrAXRcqGYtGtf3VsJWSVlw9E2dqqL AtpU7zye+NpywC6hjLCXQWXGGaziENPrW6sPVMsrmw0mXNc1S3DKeMU6F A==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="345497027" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="345497027" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:21:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="968616029" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="968616029" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.222.39]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:21:08 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v4 16/19] selftests/resctrl: Don't use variable argument list for ->setup() Date: Thu, 13 Jul 2023 16:19:29 +0300 Message-Id: <20230713131932.133258-17-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org struct resctrl_val_param has ->setup() function that accepts variable argument list. All test cases use only 1 argument as input and it's the struct resctrl_val_param pointer. Instead of variable argument list, directly pass struct resctrl_val_param pointer as the only parameter to ->setup(). Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 2 +- tools/testing/selftests/resctrl/cat_test.c | 8 +------- tools/testing/selftests/resctrl/cmt_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 | 3 +-- tools/testing/selftests/resctrl/resctrl_val.c | 2 +- 7 files changed, 7 insertions(+), 33 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index bf758f2e5578..385c01dd3ec6 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -237,7 +237,7 @@ int cat_val(struct resctrl_val_param *param) /* Test runs until the callback setup() tells the test to stop. */ while (1) { if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) { - ret = param->setup(1, param); + ret = param->setup(param); if (ret == END_OF_TESTS) { ret = 0; break; diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 480db0dc4e0e..42e35269d8b6 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -27,17 +27,11 @@ static 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 END_OF_TESTS; diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index beb0f0687c6d..7214aefb55ed 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -21,15 +21,8 @@ static char cbm_mask[256]; static unsigned long long_mask; static unsigned long cache_size; -static int cmt_setup(int num, ...) +static int cmt_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 END_OF_TESTS; diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index 3d53c6c9b9ce..4d2f145804b8 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -22,18 +22,12 @@ * 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; int ret; - 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 2d58d4b8a918..c7de6f5977f6 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -86,16 +86,10 @@ static int check_results(size_t span) return ret; } -static int mbm_setup(int num, ...) +static int mbm_setup(struct resctrl_val_param *p) { - struct resctrl_val_param *p; - 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 END_OF_TESTS; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 645ad407bd8d..838d1a438f33 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -3,7 +3,6 @@ #ifndef RESCTRL_H #define RESCTRL_H #include -#include #include #include #include @@ -68,7 +67,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); }; #define MBM_STR "mbm" diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index e8f1e6a59f4a..f0f6c5f6e98b 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -759,7 +759,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) /* Test runs until the callback setup() tells the test to stop. */ while (1) { - ret = param->setup(1, param); + ret = param->setup(param); if (ret == END_OF_TESTS) { ret = 0; break; From patchwork Thu Jul 13 13:19:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 702565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01188C001DF for ; Thu, 13 Jul 2023 13:23:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234555AbjGMNXh (ORCPT ); Thu, 13 Jul 2023 09:23:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235253AbjGMNW4 (ORCPT ); Thu, 13 Jul 2023 09:22:56 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52E583591; Thu, 13 Jul 2023 06:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689254510; x=1720790510; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B1zmj95tGIdII2SZaOFKFZ8yIm0cMc8pTOJH7ndgiGQ=; b=QBCmt7QLb72LpgCVMagKNsIVbWdfGAifz2X6QYBGO+B2CtiUP2/cTuy3 Ehm2bZx+k+1Y76R3YUghKlINaTX1F731XtCemeYDlYIjesEq8ZScfAwUd IgwS4ZPaS8xKX78ODrDDuf+dVBVRi9/FD9mJbJoMPj2sR61qV5cKJTBKz XxecS74cSzO1a7ATgJnL7a34M7cn/8a2UgT5v88jV9QMd+kOkEGDZVZKj w3fgQd2GcocFCROq8GjUVMnLox+yV9r9ndsCBFfDi3UnEFp5tCW8mEpox W9RTy6TONWki/kNiNZwQW3DHC97oW5oX7syb97EkiLnNC+RvygG0gosfh A==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="345497143" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="345497143" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:21:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="968616062" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="968616062" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.222.39]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:21:18 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v4 19/19] selftests/resctrl: Remove test type checks from cat_val() Date: Thu, 13 Jul 2023 16:19:32 +0300 Message-Id: <20230713131932.133258-20-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org cat_val() is only used during CAT test but it checks for test type. Remove test type checks and the unused else branch from cat_val(). Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 47 +++++++++++-------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index 5aa112e5fdd3..2758e1a3b255 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -231,37 +231,32 @@ int cat_val(struct resctrl_val_param *param) if (ret) return ret; - if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) - initialize_llc_perf(); + initialize_llc_perf(); /* Test runs until the callback setup() tells the test to stop. */ while (1) { - if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) { - ret = param->setup(param); - if (ret == END_OF_TESTS) { - ret = 0; - break; - } - if (ret < 0) - break; - ret = reset_enable_llc_perf(bm_pid, param->cpu_no); - if (ret) - break; - - if (run_fill_buf(param->span, memflush, operation, true)) { - fprintf(stderr, "Error-running fill buffer\n"); - ret = -1; - close(fd_lm); - break; - } - - sleep(1); - ret = measure_cache_vals(param, bm_pid); - if (ret) - break; - } else { + ret = param->setup(param); + if (ret == END_OF_TESTS) { + ret = 0; break; } + if (ret < 0) + break; + ret = reset_enable_llc_perf(bm_pid, param->cpu_no); + if (ret) + break; + + if (run_fill_buf(param->span, memflush, operation, true)) { + fprintf(stderr, "Error-running fill buffer\n"); + ret = -1; + close(fd_lm); + break; + } + + sleep(1); + ret = measure_cache_vals(param, bm_pid); + if (ret) + break; } return ret;