From nobody Tue Dec 16 23:41:17 2025 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 D3570C7EE43 for ; Thu, 24 Aug 2023 12:42:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238933AbjHXMl7 (ORCPT ); Thu, 24 Aug 2023 08:41:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239008AbjHXMlk (ORCPT ); Thu, 24 Aug 2023 08:41:40 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38415170C for ; Thu, 24 Aug 2023 05:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692880899; x=1724416899; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V2Qi3HynsFYuFtwYDS/n5b/APFqDC8AVlZGUMZGGet8=; b=SZMEhIguSq0v9DAk2ZDEZG4TD6SUZQc2Rj3/EtYRKWdWNBE3ZM/eu2eO YsvGKu+eKRkE7wCeiDkFHwq+Mr4rFoiY3GgQzRVN7ksFpp+SOf47PZxaS VIHvDq3toqX6+4WKKUtDFdWoAWIrkp0I/jkxJ/1GhGlTfPFs6blkUbN79 FU5jqPBXivxq216pkM47Z/wPFPhr0xXUCP05cS7MmVrsoT1RQi6WybEPr kQ8uJXtPpOjm8o+DxxnkIA5onBAXJR4dIFme4ArSHJSUDg/cxjkhi54US 9ou9CAqEHv1Svftk2NuwMe/GNHuoj2YRoT4ZERIn0BNAycO9L8Z8W1Brz g==; X-IronPort-AV: E=McAfee;i="6600,9927,10811"; a="460783942" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="460783942" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 05:41:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10811"; a="740161412" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="740161412" Received: from mdziurdx-mobl1.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.11.127]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 05:41:37 -0700 From: "Wieczor-Retman, Maciej" To: linux-kernel@vger.kernel.org, reinette.chatre@intel.com, fenghua.yu@intel.com Cc: ilpo.jarvinen@linux.intel.com Subject: [PATCH 1/3] selftests/resctrl: Fix schemata write error check Date: Thu, 24 Aug 2023 14:41:24 +0200 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Writing bitmasks to the schemata can fail when the bitmask doesn't adhere to some constraints defined by what a particular CPU supports. Some example of constraints are max length or being having contiguous bits. The driver should properly return errors when any rule concerning bitmask format is broken. Resctrl FS returns error codes from fprintf() only when fclose() is called. Current error checking scheme allows invalid bitmasks to be written into schemata file and the selftest doesn't notice because the fclose() error code isn't checked. Add error check to the fclose() call. Add perror() just after fprintf so a proper error message can be seen. Signed-off-by: Wieczor-Retman, Maciej --- tools/testing/selftests/resctrl/resctrlfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/se= lftests/resctrl/resctrlfs.c index bd36ee206602..a6d0b632cbc6 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -532,13 +532,17 @@ int write_schemata(char *ctrlgrp, char *schemata, int= cpu_no, char *resctrl_val) } =20 if (fprintf(fp, "%s\n", schema) < 0) { - sprintf(reason, "Failed to write schemata in control group"); + sprintf(reason, "fprintf() failed with error : %s", + strerror(errno)); fclose(fp); ret =3D -1; =20 goto out; } - fclose(fp); + ret =3D fclose(fp); + if (ret) + sprintf(reason, "Failed to write schemata in control group : %s", + strerror(errno)); =20 out: ksft_print_msg("Write schema \"%s\" to resctrl FS%s%s\n", --=20 2.42.0 From nobody Tue Dec 16 23:41:17 2025 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 E511FC71145 for ; Thu, 24 Aug 2023 12:42:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239280AbjHXMmA (ORCPT ); Thu, 24 Aug 2023 08:42:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239010AbjHXMlm (ORCPT ); Thu, 24 Aug 2023 08:41:42 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9232170C for ; Thu, 24 Aug 2023 05:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692880900; x=1724416900; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mW1/XHCL8jo5nLcGLbs562k5Z2uxGCBaekuKIwJh7Cg=; b=OVPFwutXec1RDRIWEyu7pZgxY8wez7x7amG0jZywVxrQGu6wITexIq+j 7T+GMMCRuWVgnJYurhkCT94TllMmrMnmjqqmHceH4GceAXua/VrMUati/ DLDZPtU1uGoVrqSlozVyTDZ9IWG5v9r0cgQJ51BDtF5EDO9IoHwUYcRGh 6rTZEsEj5q00uUpMeeFic3RUc4vztXKDzATzepiq1izxhAfXbAJDZagvY 1DKQqRJvSahrl3j43ynjRShJdtc2Hms/E6NQ7T3UngA/hZG3Bk3onboh5 Ava4SSqqY1PDbH/4P9JdnVsw6XJDxDoh7YT5FFA+sYuDQXeaiY5br5YSS g==; X-IronPort-AV: E=McAfee;i="6600,9927,10811"; a="460783945" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="460783945" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 05:41:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10811"; a="740161418" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="740161418" Received: from mdziurdx-mobl1.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.11.127]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 05:41:39 -0700 From: "Wieczor-Retman, Maciej" To: linux-kernel@vger.kernel.org, reinette.chatre@intel.com, fenghua.yu@intel.com Cc: ilpo.jarvinen@linux.intel.com Subject: [PATCH 2/3] selftests/resctrl: Move run_benchmark() to a more fitting file Date: Thu, 24 Aug 2023 14:41:25 +0200 Message-ID: <69a1ed7c06c3c34a2e39b50ffcceb9774967203a.1692880423.git.maciej.wieczor-retman@intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Resctrlfs.c file contains mostly functions that interact in some way with resctrl FS entries while functions inside resctrl_val.c deal with measurements and benchmarking Run_benchmark() function is located in resctrlfs.c file even though it's purpose is not interacting with the resctrl FS but to execute cache checking logic Move run_benchmark() to resctrl_val.c just before resctrl_val() function that makes use of run_benchmark() Signed-off-by: Wieczor-Retman, Maciej --- tools/testing/selftests/resctrl/resctrl_val.c | 52 +++++++++++++++++++ tools/testing/selftests/resctrl/resctrlfs.c | 52 ------------------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index f0f6c5f6e98b..667542c084eb 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -621,6 +621,58 @@ measure_vals(struct resctrl_val_param *param, unsigned= long *bw_resc_start) return 0; } =20 +/* + * run_benchmark - Run a specified benchmark or fill_buf (default benchmar= k) + * in specified signal. Direct benchmark stdio to /dev/null. + * @signum: signal number + * @info: signal info + * @ucontext: user context in signal handling + * + * Return: void + */ +void run_benchmark(int signum, siginfo_t *info, void *ucontext) +{ + int operation, ret, memflush; + char **benchmark_cmd; + size_t span; + bool once; + FILE *fp; + + benchmark_cmd =3D info->si_ptr; + + /* + * Direct stdio of child to /dev/null, so that only parent writes to + * stdio (console) + */ + fp =3D freopen("/dev/null", "w", stdout); + if (!fp) + PARENT_EXIT("Unable to direct benchmark status to /dev/null"); + + if (strcmp(benchmark_cmd[0], "fill_buf") =3D=3D 0) { + /* Execute default fill_buf benchmark */ + span =3D strtoul(benchmark_cmd[1], NULL, 10); + memflush =3D atoi(benchmark_cmd[2]); + operation =3D atoi(benchmark_cmd[3]); + if (!strcmp(benchmark_cmd[4], "true")) + once =3D true; + else if (!strcmp(benchmark_cmd[4], "false")) + once =3D false; + else + PARENT_EXIT("Invalid once parameter"); + + if (run_fill_buf(span, memflush, operation, once)) + fprintf(stderr, "Error in running fill buffer\n"); + } else { + /* Execute specified benchmark */ + ret =3D execvp(benchmark_cmd[0], benchmark_cmd); + if (ret) + perror("wrong\n"); + } + + fclose(stdout); + PARENT_EXIT("Unable to run specified benchmark"); +} + /* * resctrl_val: execute benchmark and measure memory bandwidth on * the benchmark diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/se= lftests/resctrl/resctrlfs.c index a6d0b632cbc6..e3c94614c086 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -291,58 +291,6 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no) return 0; } =20 -/* - * run_benchmark - Run a specified benchmark or fill_buf (default benchmar= k) - * in specified signal. Direct benchmark stdio to /dev/null. - * @signum: signal number - * @info: signal info - * @ucontext: user context in signal handling - * - * Return: void - */ -void run_benchmark(int signum, siginfo_t *info, void *ucontext) -{ - int operation, ret, memflush; - char **benchmark_cmd; - size_t span; - bool once; - FILE *fp; - - benchmark_cmd =3D info->si_ptr; - - /* - * Direct stdio of child to /dev/null, so that only parent writes to - * stdio (console) - */ - fp =3D freopen("/dev/null", "w", stdout); - if (!fp) - PARENT_EXIT("Unable to direct benchmark status to /dev/null"); - - if (strcmp(benchmark_cmd[0], "fill_buf") =3D=3D 0) { - /* Execute default fill_buf benchmark */ - span =3D strtoul(benchmark_cmd[1], NULL, 10); - memflush =3D atoi(benchmark_cmd[2]); - operation =3D atoi(benchmark_cmd[3]); - if (!strcmp(benchmark_cmd[4], "true")) - once =3D true; - else if (!strcmp(benchmark_cmd[4], "false")) - once =3D false; - else - PARENT_EXIT("Invalid once parameter"); - - if (run_fill_buf(span, memflush, operation, once)) - fprintf(stderr, "Error in running fill buffer\n"); - } else { - /* Execute specified benchmark */ - ret =3D execvp(benchmark_cmd[0], benchmark_cmd); - if (ret) - perror("wrong\n"); - } - - fclose(stdout); - PARENT_EXIT("Unable to run specified benchmark"); -} - /* * create_grp - Create a group only if one doesn't exist * @grp_name: Name of the group --=20 2.42.0 From nobody Tue Dec 16 23:41:18 2025 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 01A4AC88CB2 for ; Thu, 24 Aug 2023 12:42:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239358AbjHXMmB (ORCPT ); Thu, 24 Aug 2023 08:42:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239107AbjHXMlo (ORCPT ); Thu, 24 Aug 2023 08:41:44 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 611C0170C for ; Thu, 24 Aug 2023 05:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692880902; x=1724416902; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e8TDYWiMwooDPLL+j1EknxHChiy/ycRSty3NIGB478Y=; b=bgJv3B2OkSn33xq7/PBIyYv1ZDKGemXuTM9Qcb+6eycfiJK5oh85ax6t 0lqlQ/Vn9yDDGiINAcy1qEy7VIDu0xxYyhaCR+1qjHkiIpf+ZN7+wDzef 5Ol1bPjqonZ2QqJVhlqT9ImqDAec15WzL+Mb2Cw4Zb4fgN8qCxVPfA/aR FHV9crKL2z1E5fkW6MzbLNGhSH6QV1BMBvmkjxDIJ+hc38ciSzImrdPQp poPGZk/BCIuatV+FXq3VlOA6KTZF+C19343DUjmAqjOMdRnFtxHNSiA67 3W9OuFg2htm4ast+/5I6/436WJiRhI+McR54mtThf8BHI9eWaMVei+Awx w==; X-IronPort-AV: E=McAfee;i="6600,9927,10811"; a="460783951" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="460783951" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 05:41:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10811"; a="740161426" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="740161426" Received: from mdziurdx-mobl1.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.11.127]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 05:41:40 -0700 From: "Wieczor-Retman, Maciej" To: linux-kernel@vger.kernel.org, reinette.chatre@intel.com, fenghua.yu@intel.com Cc: ilpo.jarvinen@linux.intel.com Subject: [PATCH 3/3] selftests: Add printf attribute to ksefltest prints Date: Thu, 24 Aug 2023 14:41:26 +0200 Message-ID: <9adfc58deb5c7df43f6a8701d4e15821f4c42dc7.1692880423.git.maciej.wieczor-retman@intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Kselftest header defines multiple variadic function that use printf along with other logic There is no format checking for the variadic functions that use printing inside kselftest.h. Because of this the compiler won't be able to catch instances of mismatched print formats and debugging tests might be more difficult Add the common __printf attribute macro to kselftest.h Add __printf attribute to every function using formatted printing with variadic arguments Signed-off-by: Wieczor-Retman, Maciej Reviewed-by: Ilpo J=C3=A4rvinen --- tools/testing/selftests/kselftest.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/= kselftest.h index 829be379545a..ff47ed711879 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -77,6 +77,8 @@ #define KSFT_XPASS 3 #define KSFT_SKIP 4 =20 +#define __printf(a, b) __attribute__((format(printf, a, b))) + /* counters */ struct ksft_count { unsigned int ksft_pass; @@ -134,7 +136,7 @@ static inline void ksft_print_cnts(void) ksft_cnt.ksft_xskip, ksft_cnt.ksft_error); } =20 -static inline void ksft_print_msg(const char *msg, ...) +static inline __printf(1, 2) void ksft_print_msg(const char *msg, ...) { int saved_errno =3D errno; va_list args; @@ -146,7 +148,7 @@ static inline void ksft_print_msg(const char *msg, ...) va_end(args); } =20 -static inline void ksft_test_result_pass(const char *msg, ...) +static inline __printf(1, 2) void ksft_test_result_pass(const char *msg, .= ..) { int saved_errno =3D errno; va_list args; @@ -160,7 +162,7 @@ static inline void ksft_test_result_pass(const char *ms= g, ...) va_end(args); } =20 -static inline void ksft_test_result_fail(const char *msg, ...) +static inline __printf(1, 2) void ksft_test_result_fail(const char *msg, .= ..) { int saved_errno =3D errno; va_list args; @@ -186,7 +188,7 @@ static inline void ksft_test_result_fail(const char *ms= g, ...) ksft_test_result_fail(fmt, ##__VA_ARGS__);\ } while (0) =20 -static inline void ksft_test_result_xfail(const char *msg, ...) +static inline __printf(1, 2) void ksft_test_result_xfail(const char *msg, = ...) { int saved_errno =3D errno; va_list args; @@ -200,7 +202,7 @@ static inline void ksft_test_result_xfail(const char *m= sg, ...) va_end(args); } =20 -static inline void ksft_test_result_skip(const char *msg, ...) +static inline __printf(1, 2) void ksft_test_result_skip(const char *msg, .= ..) { int saved_errno =3D errno; va_list args; @@ -215,7 +217,7 @@ static inline void ksft_test_result_skip(const char *ms= g, ...) } =20 /* TODO: how does "error" differ from "fail" or "skip"? */ -static inline void ksft_test_result_error(const char *msg, ...) +static inline __printf(1, 2) void ksft_test_result_error(const char *msg, = ...) { int saved_errno =3D errno; va_list args; @@ -262,7 +264,7 @@ static inline int ksft_exit_fail(void) ksft_cnt.ksft_xfail + \ ksft_cnt.ksft_xskip) =20 -static inline int ksft_exit_fail_msg(const char *msg, ...) +static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...) { int saved_errno =3D errno; va_list args; @@ -289,7 +291,7 @@ static inline int ksft_exit_xpass(void) exit(KSFT_XPASS); } =20 -static inline int ksft_exit_skip(const char *msg, ...) +static inline __printf(1, 2) int ksft_exit_skip(const char *msg, ...) { int saved_errno =3D errno; va_list args; --=20 2.42.0