From patchwork Wed Jan 11 07:57:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 41806 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3187000wrt; Wed, 11 Jan 2023 00:01:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXt2px5oZJwaoOe0RGHhWZ1JJE4PmIlf7MK8ITGuolTj9ZR3cLOQHYdqajauTHYr95ySQiKZ X-Received: by 2002:a17:906:c18d:b0:843:770e:777d with SMTP id g13-20020a170906c18d00b00843770e777dmr59568020ejz.11.1673424106827; Wed, 11 Jan 2023 00:01:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673424106; cv=none; d=google.com; s=arc-20160816; b=QtwjI13W9fC59+gEMAvQs6dXe9IcCEtCHtZZ1mYEu5zVfLUISe8SkKhEOMUrq3zUbr W3zX6SRhr1wbpu5Wu9puuvWuTJ/Ghnf7ygUW2nUBoTJctDPI+LEJ2Mr7mwa2F7NJWvVi yy6GW96SQMv2iJqFQ7dkPQ0d/RSFwSUPkHeCk17UtL8GULuuCCSvjS6vjsTVe4ESrGV+ 6lnrZvY36KLgiSJ9iPF/7bwBnasjoLvbBAd72nhUxsqnzJUNAGbe65N4mR7cLWWDdGFt VFWI5QTku6dEAjZ/GUil8PnEapc6FWcqqgymnAmlxsDBLVHYEi9IV0ENI+G0AGTo3zxp gDKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DYA4/xfV6gdF5efekXUd3A2FwgLkRnn02fG7LKFB6rk=; b=bFW6GaWJh6snkP0LfqpB2uC9qiB2KXjQjq8e5XH73lS8hgnZUas95yF2RQs3C/gmcI vGOQ+uozL8oIx10L/8tclk2HFdf/L7gdzWa9LIzWCWhDT5HXECO1+S9ORY3ZO3R4tZ68 D5zjZGAhrUgHLSsMbAwZqXLZiLUVxC7L/WqnqAftwc39mJKAXWMtGBFrr7q/GLyNos+0 E4GNIlwxLBfcYpjqdZvqgGkYz9sx42M3Kvm16MnKRATvzXMJk40l59mBe+rYMYHzhdSd ShKwRinh0aYf8HPyV0MBoYqFFs8YjXDXD72YIBab081yheWLywxQ1OH0AsI8C0e32Ow6 hQEQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb9-20020a170907160900b008546dff75e0si4606117ejc.901.2023.01.11.00.01.23; Wed, 11 Jan 2023 00:01:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231788AbjAKIAg (ORCPT + 99 others); Wed, 11 Jan 2023 03:00:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231294AbjAKIAc (ORCPT ); Wed, 11 Jan 2023 03:00:32 -0500 X-Greylist: delayed 63 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 11 Jan 2023 00:00:30 PST Received: from esa2.hc1455-7.c3s2.iphmx.com (esa2.hc1455-7.c3s2.iphmx.com [207.54.90.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DACB5E25 for ; Wed, 11 Jan 2023 00:00:30 -0800 (PST) X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="102721171" X-IronPort-AV: E=Sophos;i="5.96,315,1665414000"; d="scan'208";a="102721171" Received: from unknown (HELO oym-r3.gw.nic.fujitsu.com) ([210.162.30.91]) by esa2.hc1455-7.c3s2.iphmx.com with ESMTP; 11 Jan 2023 16:59:24 +0900 Received: from oym-m1.gw.nic.fujitsu.com (oym-nat-oym-m1.gw.nic.fujitsu.com [192.168.87.58]) by oym-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id B7A4CCA1E3; Wed, 11 Jan 2023 16:59:23 +0900 (JST) Received: from yto-om4.fujitsu.com (yto-om4.o.css.fujitsu.com [10.128.89.165]) by oym-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id EDE57D8C14; Wed, 11 Jan 2023 16:59:22 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om4.fujitsu.com (Postfix) with ESMTP id AEF624007AF34; Wed, 11 Jan 2023 16:59:22 +0900 (JST) From: Shaopeng Tan To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, tan.shaopeng@jp.fujitsu.com Subject: [PATCH v5 1/5] selftests/resctrl: Fix set up schemata with 100% allocation on first run in MBM test Date: Wed, 11 Jan 2023 16:57:58 +0900 Message-Id: <20230111075802.3556803-2-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230111075802.3556803-1-tan.shaopeng@jp.fujitsu.com> References: <20230111075802.3556803-1-tan.shaopeng@jp.fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754712356205336181?= X-GMAIL-MSGID: =?utf-8?q?1754712356205336181?= There is a comment "Set up shemata with 100% allocation on the first run" in function mbm_setup(), but there is an increment bug and the condition "num_of_runs == 0" will never be met and write_schemata() will never be called to set schemata to 100%. Even if write_schemata() is called in MBM test, since it is not supported for MBM test it does not set the schemata. This is currently fine because resctrl_val_parm->mum_resctrlfs is always 1 and umount/mount will be run in each test to set the schemata to 100%. To support the usage when MBM test does not unmount/remount resctrl filesystem before the test starts, fix to call write_schemata() and set schemata properly when the function is called for the first time. Also, remove static local variable 'num_of_runs' because this is not needed as there is resctrl_val_param->num_of_runs which should be used instead like in cat_setup(). Reviewed-by: Reinette Chatre Signed-off-by: Shaopeng Tan --- tools/testing/selftests/resctrl/mbm_test.c | 13 +++++++------ tools/testing/selftests/resctrl/resctrlfs.c | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index 8392e5c55ed0..6d550f012829 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -89,23 +89,24 @@ static int check_results(int span) static int mbm_setup(int num, ...) { 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); + /* Run NUM_OF_RUNS times */ + if (p->num_of_runs >= NUM_OF_RUNS) + return -1; + /* Set up shemata with 100% allocation on the first run. */ - if (num_of_runs == 0) + if (p->num_of_runs == 0) ret = write_schemata(p->ctrlgrp, "100", p->cpu_no, p->resctrl_val); + p->num_of_runs++; + return ret; } diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 6f543e470ad4..8546bc9f1786 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -498,6 +498,7 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) FILE *fp; if (strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) && + strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) && strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)) && strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) return -ENOENT; @@ -523,7 +524,8 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)) || !strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) sprintf(schema, "%s%d%c%s", "L3:", resource_id, '=', schemata); - if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) + if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) || + !strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) sprintf(schema, "%s%d%c%s", "MB:", resource_id, '=', schemata); fp = fopen(controlgroup, "w"); From patchwork Wed Jan 11 07:57:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 41807 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3187440wrt; Wed, 11 Jan 2023 00:02:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXv4EJuqGMpsIl3LI8nGSra1iPXH1Ru7RZ1QcrleGzmGyRwa+zzq36kzDp93HcnstSHlExfw X-Received: by 2002:a05:6402:d9:b0:48e:c83d:a935 with SMTP id i25-20020a05640200d900b0048ec83da935mr25060935edu.29.1673424156301; Wed, 11 Jan 2023 00:02:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673424156; cv=none; d=google.com; s=arc-20160816; b=ab3ifrdgqz/cLtEvzLPAPkcXwsx/W+lVir8+3rLRNBo2GhpbT6PFpdz8K5TqHTd/B3 DjD0XcVOz040MY++Cle8oMBtVer8ph3pHvjcvLuzvk95Yr7+Lj/En22IMMWtT5QvAsW8 zk4TqYF01DoX0mY1uBD4jLCCk+5Gv92qPrghDcJowsWbk4raYompK4tjERmmQJLMqIpM CtTHGX+DnzD7+nwvm9iSwgJFNOr5YBHDIGDfsFVO0iwN070+ykeaTrd+G/28FuQO40Pi EElGH3s1IuNuqjqhbxb/ZnhDcKVkQHUfHqcRwjXWxEtNJrPPK4TM8dwgDzRHMgYdR5vt GBow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=8vB7wSoHkVQdDBEgWvv4iIcFC9Fe76TYmbSGIUh7/DA=; b=cvjOEwOJ500HNuQHwsWgQ6/atAVF45pmYuZxPRIbR9EfnMlDsDpNKWCiV35ckydZpT kDZ42N27C8ub/NoEFnM7sy71cGL81hxVOl9dgnaauQL/RSc1mU7mvR6RPvAVhIWImrN1 tkKO1YGuLTavJoSGbVhi2AkNSfqkzva5rVhm4MqxkcMuL9Inrgb2CkHs4+UGVnzkY8ZO cGlAtcyVnpkl21AmcHehCMJuaHO76Z8Zf3Y0WWLENAb/GyOO9lfoJLxxmskDBkPzXtoH u0jfW1WlNQL4khDEz3i/q7wXGjwf9gNuHbgtq8HGsyJmyDTI6sLz5qMnqTicJX5Y1WZk 3u0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q11-20020aa7d44b000000b004974f256f48si10970054edr.576.2023.01.11.00.02.12; Wed, 11 Jan 2023 00:02:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231644AbjAKIAq (ORCPT + 99 others); Wed, 11 Jan 2023 03:00:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231610AbjAKIAe (ORCPT ); Wed, 11 Jan 2023 03:00:34 -0500 Received: from esa1.hc1455-7.c3s2.iphmx.com (esa1.hc1455-7.c3s2.iphmx.com [207.54.90.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46654C74 for ; Wed, 11 Jan 2023 00:00:32 -0800 (PST) X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="102719473" X-IronPort-AV: E=Sophos;i="5.96,315,1665414000"; d="scan'208";a="102719473" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa1.hc1455-7.c3s2.iphmx.com with ESMTP; 11 Jan 2023 16:59:27 +0900 Received: from yto-m3.gw.nic.fujitsu.com (yto-nat-yto-m3.gw.nic.fujitsu.com [192.168.83.66]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 8B5A0DE50F; Wed, 11 Jan 2023 16:59:26 +0900 (JST) Received: from yto-om4.fujitsu.com (yto-om4.o.css.fujitsu.com [10.128.89.165]) by yto-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id DD9AD16E22; Wed, 11 Jan 2023 16:59:25 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om4.fujitsu.com (Postfix) with ESMTP id B36284007B0E8; Wed, 11 Jan 2023 16:59:25 +0900 (JST) From: Shaopeng Tan To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, tan.shaopeng@jp.fujitsu.com, Shuah Khan Subject: [PATCH v5 2/5] selftests/resctrl: Return MBA check result and make it to output message Date: Wed, 11 Jan 2023 16:57:59 +0900 Message-Id: <20230111075802.3556803-3-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230111075802.3556803-1-tan.shaopeng@jp.fujitsu.com> References: <20230111075802.3556803-1-tan.shaopeng@jp.fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754712408070808629?= X-GMAIL-MSGID: =?utf-8?q?1754712408070808629?= Since MBA check result is not returned, the MBA test result message is always output as "ok" regardless of whether the MBA check result is true or false. Make output message to be "not ok" if MBA check result is failed. Reviewed-by: Shuah Khan Reviewed-by: Reinette Chatre Signed-off-by: Shaopeng Tan --- tools/testing/selftests/resctrl/mba_test.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index 1a1bdb6180cf..e3a473976d74 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -51,10 +51,10 @@ static int mba_setup(int num, ...) return 0; } -static void show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc) +static bool show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc) { int allocation, runs; - bool failed = false; + bool ret = false; ksft_print_msg("Results are displayed in (MB)\n"); /* Memory bandwidth from 100% down to 10% */ @@ -90,13 +90,15 @@ static void show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc) ksft_print_msg("avg_bw_imc: %lu\n", avg_bw_imc); ksft_print_msg("avg_bw_resc: %lu\n", avg_bw_resc); if (avg_diff_per > MAX_DIFF_PERCENT) - failed = true; + ret = true; } ksft_print_msg("%s Check schemata change using MBA\n", - failed ? "Fail:" : "Pass:"); - if (failed) + ret ? "Fail:" : "Pass:"); + if (ret) ksft_print_msg("At least one test failed\n"); + + return ret; } static int check_results(void) @@ -132,9 +134,7 @@ static int check_results(void) fclose(fp); - show_mba_info(bw_imc, bw_resc); - - return 0; + return show_mba_info(bw_imc, bw_resc); } void mba_test_cleanup(void) From patchwork Wed Jan 11 07:58:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 41808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3187572wrt; Wed, 11 Jan 2023 00:02:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXsgbIszZaOYWz4wy3E7JHacM9G+WUGP6h6G9zvZTofk4C/b3q9ZinEcr+FmD8zYL18NvDoA X-Received: by 2002:a17:906:910:b0:7ad:aed7:a5da with SMTP id i16-20020a170906091000b007adaed7a5damr74438144ejd.28.1673424173618; Wed, 11 Jan 2023 00:02:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673424173; cv=none; d=google.com; s=arc-20160816; b=ZsYO9n7MNjcQ+KO5NG+YMeFwsQ21Oj12DcWPgWol7cHVC3M2mr0peOtIsOVwck3bqn vH0+FP6ZSz9b6Tqod0IlmIy5rLUBEbF+ZpRjW4q6f3fExId0qTZv5m4ZyPOIVzuNijDn jz+ewtbMMvcSFhuHHLaKVP0VCvCJfvI4H6V6hC13Q8UYAp272x5nHUuxrLkhQXiUX5xW KMgiNgMXBDzIza2gvlkrVwWXweEN5hvT9UJZtFmBqNvNpgKDJS++cRLZFfbS4Uu5wwbk 5ijsmbyrW/zo7CnXhqFtQMahPsOdsgxzXD4pR39LQ1AOf9NVElyGYp1+Ve+YSGCKZagG HLaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=RjAUSPDbrjqL+ZLCB8tfzB84CWFLe7V4Zlb51S559KY=; b=J0w4468Wi9V0DiE0lbhonwSNCbMyDDB9gf80MoDOdFLYGEkC30UBoE08UCd6LYxUgR /PnIRNwQbVuhuWCnE8bbDhng86/ORcZIJOJ408RZAEsB9JWy5jfnmz2Vn3EwgnyhXaRV IQ7ivSNtMUudbg7BT4yOGz38cXn7geMZxgdQxsd4M6ydH0tQE2IvkV502V4xUBhWKqO3 Pw4m+DCNHuIFdjq/0b2+ge63QcaE90pb8sFxvcKWiYCx+fg24CQ5Gc+1g/IYztnEdbT+ y5rLqiSI8CeVSPneeiwMlw62CRzXbr1+rfuJg9/0WieDcfvUhvfBYDXuuNYiHAJI3bAn bYkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xe10-20020a170907318a00b007c0a7286bc3si3271109ejb.741.2023.01.11.00.02.30; Wed, 11 Jan 2023 00:02:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232323AbjAKIAt (ORCPT + 99 others); Wed, 11 Jan 2023 03:00:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232055AbjAKIAi (ORCPT ); Wed, 11 Jan 2023 03:00:38 -0500 X-Greylist: delayed 64 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 11 Jan 2023 00:00:36 PST Received: from esa5.hc1455-7.c3s2.iphmx.com (esa5.hc1455-7.c3s2.iphmx.com [68.232.139.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9C4C312 for ; Wed, 11 Jan 2023 00:00:36 -0800 (PST) X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="102257766" X-IronPort-AV: E=Sophos;i="5.96,315,1665414000"; d="scan'208";a="102257766" Received: from unknown (HELO yto-r1.gw.nic.fujitsu.com) ([218.44.52.217]) by esa5.hc1455-7.c3s2.iphmx.com with ESMTP; 11 Jan 2023 16:59:30 +0900 Received: from yto-m3.gw.nic.fujitsu.com (yto-nat-yto-m3.gw.nic.fujitsu.com [192.168.83.66]) by yto-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id 5DC1CD66A0; Wed, 11 Jan 2023 16:59:29 +0900 (JST) Received: from yto-om4.fujitsu.com (yto-om4.o.css.fujitsu.com [10.128.89.165]) by yto-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id BB47C16E53; Wed, 11 Jan 2023 16:59:28 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om4.fujitsu.com (Postfix) with ESMTP id 940854007B0E5; Wed, 11 Jan 2023 16:59:28 +0900 (JST) From: Shaopeng Tan To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, tan.shaopeng@jp.fujitsu.com, Shuah Khan Subject: [PATCH v5 3/5] selftests/resctrl: Flush stdout file buffer before executing fork() Date: Wed, 11 Jan 2023 16:58:00 +0900 Message-Id: <20230111075802.3556803-4-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230111075802.3556803-1-tan.shaopeng@jp.fujitsu.com> References: <20230111075802.3556803-1-tan.shaopeng@jp.fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754712426362189422?= X-GMAIL-MSGID: =?utf-8?q?1754712426362189422?= When a process has buffered output, a child process created by fork() will also copy buffered output. When using kselftest framework, the output (resctrl test result message) will be printed multiple times. Add fflush() to flush out the buffered output before executing fork(). Reviewed-by: Shuah Khan Reviewed-by: Reinette Chatre Signed-off-by: Shaopeng Tan --- tools/testing/selftests/resctrl/cat_test.c | 1 + tools/testing/selftests/resctrl/resctrl_val.c | 1 + tools/testing/selftests/resctrl/resctrlfs.c | 1 + 3 files changed, 3 insertions(+) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 1c5e90c63254..6a8306b0a109 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -167,6 +167,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) return errno; } + fflush(stdout); bm_pid = fork(); /* Set param values for child thread which will be allocated bitmask diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index b32b96356ec7..6948843bf995 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -629,6 +629,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) * Fork to start benchmark, save child's pid so that it can be killed * when needed */ + fflush(stdout); bm_pid = fork(); if (bm_pid == -1) { perror("# Unable to fork"); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 8546bc9f1786..d95688298469 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -678,6 +678,7 @@ int filter_dmesg(void) perror("pipe"); return ret; } + fflush(stdout); pid = fork(); if (pid == 0) { close(pipefds[0]); From patchwork Wed Jan 11 07:58:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 41804 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3186666wrt; Wed, 11 Jan 2023 00:01:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXsdh8ClwDrAiVMv+W/WMk0/Hrw2o3mmNDCUjpA5A5Sh6KhvujC6xy+F1Vhjcsf+9hOrBV/r X-Received: by 2002:a17:906:a186:b0:803:4549:300b with SMTP id s6-20020a170906a18600b008034549300bmr82377348ejy.19.1673424069951; Wed, 11 Jan 2023 00:01:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673424069; cv=none; d=google.com; s=arc-20160816; b=FfM3b1nFfuzCTDbztxANDEaGYMd59KfAm/PQHB1uChoZUplR5BM53jNKauTNACPUGx Kg3T+r/cTvuuUfv4Ce0uLk3AYW1iDh86S6UN5unDsFv9SSW+HzO4Rr8rCUPsYlCW6l/I 7Z5dPAwW3N2sYSoV+rgK9ucv1C0BmeqmFlCyPQlVC4Y5ecT4WY8HhTA6ofy8C9gTtnCg w3mJAt8X5rmxNvbH0/fzl9qjof0nsd7C245W6A3g7cxoFAkcwYP7kiXPDfZQrYw/47q2 B9zf3JFRb79Rn0O/7IlYcACLu8gVTCcqVhg9RNjuOWH9aguAWn72Hy9hXBJEKH/ccU/N zhMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eWnt2cdYQQcfStBaPUR5i3kJ05esykfw6w/lLf8IhDc=; b=RgO8PZBMRsO7AjevG4LktFdAEXO9W8dTGoCAFaIv5R3pdHCLkYNWS/y4IzhR5EJxvI 4SrWqo/wtbu2l7x6X3mWfvXdLRvaeP//xGO8clkTIgNFQHvSTrV0TvwuYY2c1VTA3oz+ U9fr+IqvZD1FfEiL3UKZfxVayLBatwfS+UBy2O3KblZUDYl4ZZlwZxP/YEHm4fXXy3g8 XBR8wGNZmltzskQtQt/O8yM8jiLrnvJBYa7uL7g7umfwmJ7Q7k8Pi3ikMc4YQwlN/WN4 1CEiwtWMXx6fj+nQ6CA6tbFGm+FOWpDji7LtD44PMHeyVcS5EZu9kAWVObWjNcNSjRMg 09aA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wt2-20020a170906ee8200b0084d3a7b6a04si10627706ejb.576.2023.01.11.00.00.45; Wed, 11 Jan 2023 00:01:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229793AbjAKH7j (ORCPT + 99 others); Wed, 11 Jan 2023 02:59:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbjAKH7g (ORCPT ); Wed, 11 Jan 2023 02:59:36 -0500 Received: from esa6.hc1455-7.c3s2.iphmx.com (esa6.hc1455-7.c3s2.iphmx.com [68.232.139.139]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB0C6BE4; Tue, 10 Jan 2023 23:59:34 -0800 (PST) X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="103632564" X-IronPort-AV: E=Sophos;i="5.96,315,1665414000"; d="scan'208";a="103632564" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa6.hc1455-7.c3s2.iphmx.com with ESMTP; 11 Jan 2023 16:59:32 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 63E34DE50E; Wed, 11 Jan 2023 16:59:31 +0900 (JST) Received: from yto-om4.fujitsu.com (yto-om4.o.css.fujitsu.com [10.128.89.165]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id B2335D507A; Wed, 11 Jan 2023 16:59:30 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om4.fujitsu.com (Postfix) with ESMTP id 8F1824007B0E9; Wed, 11 Jan 2023 16:59:30 +0900 (JST) From: Shaopeng Tan To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, tan.shaopeng@jp.fujitsu.com Subject: [PATCH v5 4/5] selftests/resctrl: Cleanup properly when an error occurs in CAT test Date: Wed, 11 Jan 2023 16:58:01 +0900 Message-Id: <20230111075802.3556803-5-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230111075802.3556803-1-tan.shaopeng@jp.fujitsu.com> References: <20230111075802.3556803-1-tan.shaopeng@jp.fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754712317733441812?= X-GMAIL-MSGID: =?utf-8?q?1754712317733441812?= After creating a child process with fork() in CAT test, if there is an error occurs or a signal such as SIGINT is received, the parent process will be terminated immediately, and therefor the child process will not be killed and also resctrlfs is not unmounted. There is a signal handler registered in CMT/MBM/MBA tests, which kills child process, unmount resctrlfs, cleanups result files, etc., if a signal such as SIGINT is received. Commonize the signal handler registered for CMT/MBM/MBA tests and reuse it in CAT too. To reuse the signal handler, make the child process in CAT wait to be killed by parent process in any case (an error occurred or a signal was received), and when killing child process use global bm_pid instead of local bm_pid. Also, since the MBA/MBA/CMT/CAT are run in order, unregister the signal handler at the end of each test so that the signal handler cannot be inherited by other tests. Signed-off-by: Shaopeng Tan --- tools/testing/selftests/resctrl/cat_test.c | 26 +++++---- tools/testing/selftests/resctrl/fill_buf.c | 14 ----- tools/testing/selftests/resctrl/resctrl.h | 2 + tools/testing/selftests/resctrl/resctrl_val.c | 56 ++++++++++++++----- 4 files changed, 59 insertions(+), 39 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 6a8306b0a109..87302b882929 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -103,7 +103,6 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) unsigned long l_mask, l_mask_1; int ret, pipefd[2], sibling_cpu_no; char pipe_message; - pid_t bm_pid; cache_size = 0; @@ -181,28 +180,29 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) strcpy(param.filename, RESULT_FILE_NAME1); param.num_of_runs = 0; param.cpu_no = sibling_cpu_no; + } else { + ret = signal_handler_register(); + if (ret) + goto out; } remove(param.filename); ret = cat_val(¶m); - if (ret) - return ret; - - ret = check_results(¶m); - if (ret) - return ret; + if (ret == 0) + ret = check_results(¶m); 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]); + sizeof(pipe_message)) + /* + * Just print the error message. + * Let while(1) run and wait for itself to be killed. + */ perror("# failed signaling parent process"); - return errno; - } close(pipefd[1]); while (1) @@ -226,5 +226,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) if (bm_pid) umount_resctrlfs(); - return 0; +out: + ret = signal_handler_unregister(); + return ret; } diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 56ccbeae0638..322c6812e15c 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -33,14 +33,6 @@ static void sb(void) #endif } -static void ctrl_handler(int signo) -{ - free(startptr); - printf("\nEnding\n"); - sb(); - exit(EXIT_SUCCESS); -} - static void cl_flush(void *p) { #if defined(__i386) || defined(__x86_64) @@ -198,12 +190,6 @@ int run_fill_buf(unsigned long span, int malloc_and_init_memory, unsigned long long cache_size = span; int ret; - /* set up ctrl-c handler */ - if (signal(SIGINT, ctrl_handler) == SIG_ERR) - printf("Failed to catch SIGINT!\n"); - 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); if (ret) { diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index f0ded31fb3c7..14a5e21497e1 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -107,6 +107,8 @@ void mba_test_cleanup(void); int get_cbm_mask(char *cache_type, char *cbm_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 signal_handler_register(void); +int signal_handler_unregister(void); int cat_val(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); diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 6948843bf995..91a3cf8b308b 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -476,6 +476,46 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr) exit(EXIT_SUCCESS); } +struct sigaction sigact; + +/* + * Register CTRL-C handler for parent, as it has to kill + * child process before exiting + */ +int signal_handler_register(void) +{ + int ret = 0; + struct sigaction sigact; + + sigact.sa_sigaction = ctrlc_handler; + sigemptyset(&sigact.sa_mask); + sigact.sa_flags = SA_SIGINFO; + if (sigaction(SIGINT, &sigact, NULL) || + sigaction(SIGTERM, &sigact, NULL) || + sigaction(SIGHUP, &sigact, NULL)) { + perror("# sigaction"); + ret = errno; + } + return ret; +} + +/* reset signal handler to SIG_DFL. */ +int signal_handler_unregister(void) +{ + int ret = 0; + struct sigaction sigact; + + sigact.sa_handler = SIG_DFL; + sigemptyset(&sigact.sa_mask); + if (sigaction(SIGINT, &sigact, NULL) || + sigaction(SIGTERM, &sigact, NULL) || + sigaction(SIGHUP, &sigact, NULL)) { + perror("# sigaction"); + ret = errno; + } + return ret; +} + /* * print_results_bw: the memory bandwidth results are stored in a file * @filename: file that stores the results @@ -671,20 +711,9 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) ksft_print_msg("Benchmark PID: %d\n", bm_pid); - /* - * Register CTRL-C handler for parent, as it has to kill benchmark - * before exiting - */ - sigact.sa_sigaction = ctrlc_handler; - sigemptyset(&sigact.sa_mask); - sigact.sa_flags = SA_SIGINFO; - if (sigaction(SIGINT, &sigact, NULL) || - sigaction(SIGTERM, &sigact, NULL) || - sigaction(SIGHUP, &sigact, NULL)) { - perror("# sigaction"); - ret = errno; + ret = signal_handler_register(); + if (ret) goto out; - } value.sival_ptr = benchmark_cmd; @@ -764,6 +793,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) out: kill(bm_pid, SIGKILL); umount_resctrlfs(); + ret = signal_handler_unregister(); return ret; } From patchwork Wed Jan 11 07:58:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 41805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3186682wrt; Wed, 11 Jan 2023 00:01:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXsptq09x3snkuGW1I8UlDA17pl/LnG6lTw08w+Zt+kvXKvXa89ZNM1NrbyQS+ChrbFm/sUW X-Received: by 2002:a17:906:9399:b0:7ac:2db9:6f4d with SMTP id l25-20020a170906939900b007ac2db96f4dmr66420660ejx.8.1673424071190; Wed, 11 Jan 2023 00:01:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673424071; cv=none; d=google.com; s=arc-20160816; b=QfVHVZUQemHpuLFimLzbuYFSbzEr6bwqBSuWLwflwiRk2/d1cCjNDW9LKGLGYjby0i o0/1fo8BkWlY4uxG/AXpRfPAusVj1j/CYlqpIfcE3wbOyYQXpcsXnl2AGvYuByq77Xxp 70EX4hJ2ie8IeZ0xL5w0saXHOdkjcnRXniLKkRA4thMhfnYIqltPQHg7AFXJt3sGwfdn tHhwy6PP1CrKIYZj/3/+JTvalVMAuj49oA915uFdeIShuvbnuw2HGlw7+gnFiWOF39nS UogexuZWH0Jgbxwm7ji3DxyjbFO3af1UEXktHNPeLgnejKAqbhfY1HoPZb/VV1shBUxo 24yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Do3RbqcOrnC9pJTHhjTg+G5DtBbBpxiHZwyUW2BGYiI=; b=znWmydAsXlDEBsOxsicOR/bR6MKTJe2rSjKrPuBcp8f/hAVt3coO1HJTExrC2ge6yH kr1osu9BRLP5Lq7SZTHf7D4cSjuGA1i6ul5HuYTcTbeg5v38McMxJxYX8SBRYWyCP1oE MnNCdX2TLNVBiSEFAl6dKXuxHznqR2NKD6v37lNvD1bPED6nPCnobP7FZxazsJ4xTUHT IOtR57A2/06gFOYUM4lAopGAhfCTp1j2SvIJVscTcHV/27dh7dnfYXEywB2Qrpg8/YlE THAji6MNLyDQyeUddG0ycupC2VzYfP9t5SNxKLIeS9pGwH5lsV9qDhZvdOlfxyEfsz0j INVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sz15-20020a1709078b0f00b007c16fb7f164si11537134ejc.943.2023.01.11.00.00.47; Wed, 11 Jan 2023 00:01:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231321AbjAKH7o (ORCPT + 99 others); Wed, 11 Jan 2023 02:59:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229986AbjAKH7i (ORCPT ); Wed, 11 Jan 2023 02:59:38 -0500 Received: from esa6.hc1455-7.c3s2.iphmx.com (esa6.hc1455-7.c3s2.iphmx.com [68.232.139.139]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D562D237; Tue, 10 Jan 2023 23:59:36 -0800 (PST) X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="103632565" X-IronPort-AV: E=Sophos;i="5.96,315,1665414000"; d="scan'208";a="103632565" Received: from unknown (HELO yto-r4.gw.nic.fujitsu.com) ([218.44.52.220]) by esa6.hc1455-7.c3s2.iphmx.com with ESMTP; 11 Jan 2023 16:59:34 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id 7D85CD7724; Wed, 11 Jan 2023 16:59:33 +0900 (JST) Received: from yto-om4.fujitsu.com (yto-om4.o.css.fujitsu.com [10.128.89.165]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id CD675D5077; Wed, 11 Jan 2023 16:59:32 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om4.fujitsu.com (Postfix) with ESMTP id A80AF4007B0E5; Wed, 11 Jan 2023 16:59:32 +0900 (JST) From: Shaopeng Tan To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, tan.shaopeng@jp.fujitsu.com Subject: [PATCH v5 5/5] selftests/resctrl: Remove duplicate codes that clear each test result file Date: Wed, 11 Jan 2023 16:58:02 +0900 Message-Id: <20230111075802.3556803-6-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230111075802.3556803-1-tan.shaopeng@jp.fujitsu.com> References: <20230111075802.3556803-1-tan.shaopeng@jp.fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754712319185871383?= X-GMAIL-MSGID: =?utf-8?q?1754712319185871383?= Before exiting each test function(run_cmt/cat/mbm/mba_test()), test results("ok","not ok") are printed by ksft_test_result() and then temporary result files are cleaned by function cmt/cat/mbm/mba_test_cleanup(). However, before running ksft_test_result(), function cmt/cat/mbm/mba_test_cleanup() has been run in each test function as follows: cmt_resctrl_val() cat_perf_miss_val() mba_schemata_change() mbm_bw_change() Remove duplicate codes that clear each test result file, while ensuring cleanup properly even when errors occur in each test. Reviewed-by: Reinette Chatre Signed-off-by: Shaopeng Tan --- tools/testing/selftests/resctrl/cmt_test.c | 7 +++---- tools/testing/selftests/resctrl/mba_test.c | 7 +++---- tools/testing/selftests/resctrl/mbm_test.c | 7 +++---- tools/testing/selftests/resctrl/resctrl_tests.c | 4 ---- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index 8968e36db99d..617ee95d272d 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -133,13 +133,12 @@ int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd) ret = resctrl_val(benchmark_cmd, ¶m); if (ret) - return ret; + goto out; ret = check_results(¶m, n); - if (ret) - return ret; +out: cmt_test_cleanup(); - return 0; + return ret; } diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index e3a473976d74..b948938a3b4d 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -160,13 +160,12 @@ int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd) ret = resctrl_val(benchmark_cmd, ¶m); if (ret) - return ret; + goto out; ret = check_results(); - if (ret) - return ret; +out: mba_test_cleanup(); - return 0; + return ret; } diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index 6d550f012829..040ca1f9c173 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -134,13 +134,12 @@ int mbm_bw_change(int span, int cpu_no, char *bw_report, char **benchmark_cmd) ret = resctrl_val(benchmark_cmd, ¶m); if (ret) - return ret; + goto out; ret = check_results(span); - if (ret) - return ret; +out: mbm_test_cleanup(); - return 0; + return ret; } diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index df0d8d8526fc..8732cf736528 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -88,7 +88,6 @@ 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"); - mbm_test_cleanup(); } static void run_mba_test(bool has_ben, char **benchmark_cmd, int span, @@ -107,7 +106,6 @@ static void run_mba_test(bool has_ben, char **benchmark_cmd, int span, sprintf(benchmark_cmd[1], "%d", span); res = mba_schemata_change(cpu_no, bw_report, benchmark_cmd); ksft_test_result(!res, "MBA: schemata change\n"); - mba_test_cleanup(); } static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no) @@ -126,7 +124,6 @@ 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"); - cmt_test_cleanup(); } static void run_cat_test(int cpu_no, int no_of_bits) @@ -142,7 +139,6 @@ static void run_cat_test(int cpu_no, int no_of_bits) res = cat_perf_miss_val(cpu_no, no_of_bits, "L3"); ksft_test_result(!res, "CAT: test\n"); - cat_test_cleanup(); } int main(int argc, char **argv)