From patchwork Thu Apr 13 07:22:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 82840 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp851884vqo; Thu, 13 Apr 2023 00:35:57 -0700 (PDT) X-Google-Smtp-Source: AKy350YuDfjahfApbK7dvek3cQn3NsLuFXOHsjdRGfKxxitjUA1wv3CAXzjaME5VDSHnSNwdCcZk X-Received: by 2002:a05:6a00:1949:b0:625:e77b:93b2 with SMTP id s9-20020a056a00194900b00625e77b93b2mr2548746pfk.5.1681371356877; Thu, 13 Apr 2023 00:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681371356; cv=none; d=google.com; s=arc-20160816; b=YhFMONqZs9/5Ck1Y00USH9+ihE8aMewXfoZHEmwSpJATSg7CKU3z60tAN0SZkGwLqU ha9yjZUPHhORHi28N8uLb9Ud93ooIzaiIuqyPNjnRiszwSt6lmooB+LVJlXCwuYtGAGC KMvuBtB5daENFXQ+/LWzDY3kXOVyFPkqr2IVBc4mr0oNRkVozwqIgg02LdTts7SrTSQR 2+XrEiXiHMPK6T89bMcT4AEKFFXgQCiUfE7RcVOUhIlhrjgcPNc1UjH3dkeFTHJMVOZ/ AV3MZkjr3d6p4YapFb0BP3hBUsdDIuHCUoYM0XrtJVcmKUJBN5841dhRKlYyO2ws4vOa d6bQ== 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=CXnzZkI7kQvFh7h//w1RHuMcs6gWcTQVsY/J3egB3N8=; b=FbMHtHVL6gsxmDJiUrandgsYySaE8DxxkKqziyCmFPZ39nfVsMMtgt85lDYfA/Zamk wJCnv1nYvJ1qElye74SxBWV3M5qlY9tT+vPfnywnJ16gJNd4acvVvew0sDfkuBTx2wMC BccR77Sao4DvmiuQgS842eJzazqDw8SJzClAKzpfVYm///ZiWKym+RTV4qgbkYoT9k9Z B8Q+C6PIgKq2QMZoxQ/oCrUtb5AryNsH1JG76d+ucbiAOyqKqCU3aql/kik68KgV1PPC auRoOsRzUgYGgQ91QfYEQP35bbeXorz5zce4J7FyCX+xS00ZuOPOe08dbt5mIml7PX+4 FKNg== 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 c6-20020a6566c6000000b0051b4f4f3f51si883702pgw.865.2023.04.13.00.35.44; Thu, 13 Apr 2023 00:35:56 -0700 (PDT) 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 S229845AbjDMHXH (ORCPT + 99 others); Thu, 13 Apr 2023 03:23:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229720AbjDMHXF (ORCPT ); Thu, 13 Apr 2023 03:23:05 -0400 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 0668B1BE6; Thu, 13 Apr 2023 00:23:03 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10678"; a="114304608" X-IronPort-AV: E=Sophos;i="5.98,339,1673881200"; d="scan'208";a="114304608" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa6.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2023 16:23:02 +0900 Received: from yto-m2.gw.nic.fujitsu.com (yto-nat-yto-m2.gw.nic.fujitsu.com [192.168.83.65]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 09185DE50D; Thu, 13 Apr 2023 16:22:59 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by yto-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id 533FFD35F5; Thu, 13 Apr 2023 16:22:58 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om3.fujitsu.com (Postfix) with ESMTP id 1E4FC40007204; Thu, 13 Apr 2023 16:22:58 +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 v9 1/6] selftests/resctrl: Fix set up schemata with 100% allocation on first run in MBM test Date: Thu, 13 Apr 2023 16:22:54 +0900 Message-Id: <20230413072259.2089348-2-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230413072259.2089348-1-tan.shaopeng@jp.fujitsu.com> References: <20230413072259.2089348-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?1763045651974545107?= X-GMAIL-MSGID: =?utf-8?q?1763045651974545107?= 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 Reviewed-by: Ilpo Järvinen --- 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 c9dfa54af42f..9b591c35310f 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 END_OF_TESTS; - 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 cc6cf49e3129..b31b1d9e41d1 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 Thu Apr 13 07:22:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 82842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp853335vqo; Thu, 13 Apr 2023 00:39:43 -0700 (PDT) X-Google-Smtp-Source: AKy350byO0zTNRb5n7ZS3ZPbnYNvtzQCG4bGN8vMtsH02iDkx8cLx4/4jlRL67hj4oZlkFIg0lLr X-Received: by 2002:aa7:d947:0:b0:501:cf67:97f3 with SMTP id l7-20020aa7d947000000b00501cf6797f3mr1624657eds.25.1681371583109; Thu, 13 Apr 2023 00:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681371583; cv=none; d=google.com; s=arc-20160816; b=tfzXaSGHc9FOpWWpU2qSxtgm1tB9FFuvWMw5mIKjr0flcyM14yi1zdpifIzLsGuHyH uWeiP788g++8kWjZI1ZjxRhfkXVP70m7x2AUN/w6J+uHjiUUXaUZGd2twyOzfEFYeDbz GvJVi/RvyLs53i3wxIKHOyErebOO3Ti0K/LACGDUnAtO1J3ZU6gvQnAXRjx6s4AdKDqr tqXxkW8mx6Z+8EWr90mZg0CXf/uCNTI6gzut715ieNH0tal68uEUJ5cn9YZbH/2/kr9k iJKJKJE8P4EW3a8mdqAkxKCO8t54gCrTENUZbdVmtKpyeTznyMjScp7osYRIdpPc6o8a UEDA== 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=O+WJWAQ0BmO1ECK6VY4SdovF4wD5Em/IsyaZUyWekYE=; b=iAuxoo1y+HM8Bv68WqEXbpDg+23Q5oUBNWPffGwC8KltdkzYkMlMi3nuqGroMSOo3s jHxG3eIkIyeieKM8pQOot6lxCnNc19yB8b3fYL8qJjniTIBPz0Fq4HOgkeID6Bp3oDev VatoPmvGnnrPt+m6Vm1YkH3IO/Yo31yDhI/BUf8SSaF9f/HW31hQyip8RdLxeMIWTiJL 9pwvSqDz/cF0MyQbHMKoa/gHTj/aDo8imde4pabRe4rRhbfx1AyvViESHSA5/f1insw6 QbuXfExU6aGSy4ud8EcqOkyTXbNKGsqH6Zpp5vqJ9jxzE53MG+ANljZ0CNAbnBYwEQRw CfnQ== 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 b24-20020aa7dc18000000b005050849e4adsi1248244edu.456.2023.04.13.00.39.19; Thu, 13 Apr 2023 00:39:43 -0700 (PDT) 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 S229605AbjDMHYV (ORCPT + 99 others); Thu, 13 Apr 2023 03:24:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229724AbjDMHYR (ORCPT ); Thu, 13 Apr 2023 03:24:17 -0400 X-Greylist: delayed 63 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 13 Apr 2023 00:24:08 PDT Received: from esa11.hc1455-7.c3s2.iphmx.com (esa11.hc1455-7.c3s2.iphmx.com [207.54.90.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02A478681; Thu, 13 Apr 2023 00:24:08 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10678"; a="92663591" X-IronPort-AV: E=Sophos;i="5.98,339,1673881200"; d="scan'208";a="92663591" Received: from unknown (HELO oym-r1.gw.nic.fujitsu.com) ([210.162.30.89]) by esa11.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2023 16:23:03 +0900 Received: from oym-m3.gw.nic.fujitsu.com (oym-nat-oym-m3.gw.nic.fujitsu.com [192.168.87.60]) by oym-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id 81625DF1BD; Thu, 13 Apr 2023 16:23:00 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by oym-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id C2C22D9497; Thu, 13 Apr 2023 16:22:59 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om3.fujitsu.com (Postfix) with ESMTP id 6E65C400C0319; Thu, 13 Apr 2023 16:22:59 +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 v9 2/6] selftests/resctrl: Return MBA check result and make it to output message Date: Thu, 13 Apr 2023 16:22:55 +0900 Message-Id: <20230413072259.2089348-3-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230413072259.2089348-1-tan.shaopeng@jp.fujitsu.com> References: <20230413072259.2089348-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?1763045889244557715?= X-GMAIL-MSGID: =?utf-8?q?1763045889244557715?= 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 7defb32ad0de..2a5d43f3c142 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -56,10 +56,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% */ @@ -95,13 +95,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) @@ -137,9 +139,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 Thu Apr 13 07:22:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 82836 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp847750vqo; Thu, 13 Apr 2023 00:25:59 -0700 (PDT) X-Google-Smtp-Source: AKy350bpcquD65x83X/RILDCxm016kLNoNRr0ahBodtcJnHU5REhs8SmxPJIpwKn1xvqJUbEQmU3 X-Received: by 2002:a17:906:7f98:b0:87b:6bbb:11ac with SMTP id f24-20020a1709067f9800b0087b6bbb11acmr1510759ejr.60.1681370759168; Thu, 13 Apr 2023 00:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681370759; cv=none; d=google.com; s=arc-20160816; b=O/81rDGjAi5zt3qYyhbZNoZNv+m4zrjbElx3JXaePpcScDtJ7f5vWPTNcfqSznG+00 K4mpgIhSJ3GqL4QWU99TfxE92BGO6flNKTJtUkA4orAoINA54EMvnVP5c9XYhxzcuNRB 60edXiH8wdkdnBv34HHF/LuLUaxstNLM3MM760MAmlc77iWd8h53n7IqD1y/EYGbts5N bQmcPBO8n72TsfWiNGi9ZkrigvsggpbGPVcau+XcFJXEq++Tm2AzT7LLCpo7q919NthV iwjVji7KD0sGni8532fnJb53uvVQ/rMukPJhqShsTucVrJNflWce8DkpZyh7jrWpJP8A id0g== 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=z9EN6EGd1MyzSHaTq+/3nqK06YP72xXEZjHitcANOYU=; b=Kz5j/HJw+U2sHiHuhV26cVw8nLHtZg5/6wSsX6A54D8XUJn6Rys/RY/lJ5nJHi4yxx iZ2Kx3UnT8MUo/e1vJXFTSoPFzN779P3GI7QkYAKLB4CZyVOKxYOH8CQvPp3i4GEA867 0cNPJQg25M8nwRJdVD0aeoDosXTC5r86Li0BRTfzcIQsaGUlf3g4h2rHF/4ZU40n8pee 2j77KnmeGpvvhThxchvpX7cPRM0h4ExzNlK2N9kI26M1yGWcEcVyo+cQh391XyZMDtNY 5s2fNK0DE0zXfhMKhDgKjNa2lhbjExf+rLbCHpWszgQepjY8RgbTrFEGEspBAEWBSKDH j68A== 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 o11-20020a1709062e8b00b0094e89de648asi1065150eji.778.2023.04.13.00.25.34; Thu, 13 Apr 2023 00:25:59 -0700 (PDT) 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 S229866AbjDMHXK (ORCPT + 99 others); Thu, 13 Apr 2023 03:23:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbjDMHXH (ORCPT ); Thu, 13 Apr 2023 03:23:07 -0400 Received: from esa7.hc1455-7.c3s2.iphmx.com (esa7.hc1455-7.c3s2.iphmx.com [139.138.61.252]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8262A4C3C; Thu, 13 Apr 2023 00:23:06 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10678"; a="91996438" X-IronPort-AV: E=Sophos;i="5.98,339,1673881200"; d="scan'208";a="91996438" Received: from unknown (HELO yto-r1.gw.nic.fujitsu.com) ([218.44.52.217]) by esa7.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2023 16:23:03 +0900 Received: from yto-m2.gw.nic.fujitsu.com (yto-nat-yto-m2.gw.nic.fujitsu.com [192.168.83.65]) by yto-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id 7DCBCD66A1; Thu, 13 Apr 2023 16:23:01 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by yto-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id C6F9FD35F7; Thu, 13 Apr 2023 16:23:00 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om3.fujitsu.com (Postfix) with ESMTP id 8BBF840007204; Thu, 13 Apr 2023 16:23:00 +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 v9 3/6] selftests/resctrl: Flush stdout file buffer before executing fork() Date: Thu, 13 Apr 2023 16:22:56 +0900 Message-Id: <20230413072259.2089348-4-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230413072259.2089348-1-tan.shaopeng@jp.fujitsu.com> References: <20230413072259.2089348-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?1763045024940081333?= X-GMAIL-MSGID: =?utf-8?q?1763045024940081333?= 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 08070d4fa735..38c10a8c1814 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 00864242d76c..e632657995c7 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 b31b1d9e41d1..fb00245dee92 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 Thu Apr 13 07:22:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 82837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp848166vqo; Thu, 13 Apr 2023 00:27:05 -0700 (PDT) X-Google-Smtp-Source: AKy350b2ismU2AAVCaZHSCBtRN9IN7oWUCzi4mhL/ZBh5wZv/HonCcH7bAVS4SBkkN80nWYZp6Oe X-Received: by 2002:a05:6402:202f:b0:504:b324:9ec3 with SMTP id ay15-20020a056402202f00b00504b3249ec3mr1464769edb.1.1681370825032; Thu, 13 Apr 2023 00:27:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681370825; cv=none; d=google.com; s=arc-20160816; b=Yx3dRjfsrjVxvzC9h9z5KIBPL6bHylc1IEtfBMt07w+z63WI/0t8dFRzFkAcnNg0U2 X9mhYj3wgEFcaVTP/zwo2TYRFznaNrMWKvn8A71WqewPOnJdKlRGRLrq5wWJ3DdBSb6a 3Xk03ynHGTBH9nDb52tjD74B7w+agoPj/XtVkOhd+1o9vOYBDlcZZABXkYF+JY42hsnd Eyk5QlnX4yJYJfSRYKWiSUk4QUgS3fqHyrdVf1VQL543W3jJ5/8EBerLxxs1tmYuc0Hu kHEljQe6zpjsEEBeUNd866q6Z2yMyaEW7SBhaferlF18USx5rrDLnyL26yBsiKL+byZi qLGA== 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=JHqM3cHHDkhvpOJaQfb/y/hGDqM+UYhuF/3C9EyhjEU=; b=Qe3wgCQGSyzkA1hdOpRVWctaX99IfKVYgOMMG3wF+Vn9UmgJGV/Fm2+6HLRPuR+0AY vFiX3yws+TBX3EuzKNPiMtaxRbYtzZarl5ftcBuygzjPSpXPZxJ54qW1R5nvgN90eTnm RvJV7tarzFUxqpw7P6lkhRVKDBrUgFeAWOfrHmHSDEEVW4LOzhE/RBP5fKtWg98yDQDh /tnTfTuKWDeRb64I77lR/xU3eriC1OlOdB6UtC4WBuCWcp55y1Da2YdlxfPv79eKAyd9 6YRGsG8pCngzxBRAZmCsG2GKEOgxeeqXn21uWby1cbsbcjiybXVDqB3rBJUuutOxcMDs PMxQ== 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 o13-20020a056402038d00b004bf5fd5d860si1161214edv.606.2023.04.13.00.26.40; Thu, 13 Apr 2023 00:27:05 -0700 (PDT) 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 S229733AbjDMHY3 (ORCPT + 99 others); Thu, 13 Apr 2023 03:24:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbjDMHYV (ORCPT ); Thu, 13 Apr 2023 03:24:21 -0400 Received: from esa11.hc1455-7.c3s2.iphmx.com (esa11.hc1455-7.c3s2.iphmx.com [207.54.90.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 211754C19; Thu, 13 Apr 2023 00:24:17 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10678"; a="92663594" X-IronPort-AV: E=Sophos;i="5.98,339,1673881200"; d="scan'208";a="92663594" Received: from unknown (HELO oym-r1.gw.nic.fujitsu.com) ([210.162.30.89]) by esa11.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2023 16:23:05 +0900 Received: from oym-m3.gw.nic.fujitsu.com (oym-nat-oym-m3.gw.nic.fujitsu.com [192.168.87.60]) by oym-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id CD97ADF1B6; Thu, 13 Apr 2023 16:23:02 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by oym-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id 083E0D94A9; Thu, 13 Apr 2023 16:23:02 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om3.fujitsu.com (Postfix) with ESMTP id B123B400C07D1; Thu, 13 Apr 2023 16:23:01 +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 v9 4/6] selftests/resctrl: Cleanup properly when an error occurs in CAT test Date: Thu, 13 Apr 2023 16:22:57 +0900 Message-Id: <20230413072259.2089348-5-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230413072259.2089348-1-tan.shaopeng@jp.fujitsu.com> References: <20230413072259.2089348-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?1763045093913048304?= X-GMAIL-MSGID: =?utf-8?q?1763045093913048304?= After creating a child process with fork() in CAT test, if an error occurs when parent process runs cat_val() or check_results(), the child process will not be killed and also resctrlfs is not unmounted. Also if an error occurs when child process runs cat_val() or check_results(), the parent process will wait for the pipe message from the child process which will never be sent by the child process and the parent process cannot proceed to unmount resctrlfs. Synchronize the exits between the parent and child. An error could occur whether in parent process or child process. The parent process always kills the child process and runs umount_resctrlfs(). The child process always waits to be killed by the parent process. Reviewed-by: Reinette Chatre Signed-off-by: Shaopeng Tan --- tools/testing/selftests/resctrl/cat_test.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 38c10a8c1814..0880575840f9 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -186,23 +186,20 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) 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 +223,5 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) if (bm_pid) umount_resctrlfs(); - return 0; + return ret; } From patchwork Thu Apr 13 07:22: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: 82841 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp852767vqo; Thu, 13 Apr 2023 00:38:04 -0700 (PDT) X-Google-Smtp-Source: AKy350YsxTbY21q8x6un2D+OA3AhWxSUi4LnEpLV62oLxqdWS39jPy8jT1bz1suHX4ddRp0k/unl X-Received: by 2002:a17:906:4f91:b0:932:83fa:d2fe with SMTP id o17-20020a1709064f9100b0093283fad2femr1957217eju.12.1681371483796; Thu, 13 Apr 2023 00:38:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681371483; cv=none; d=google.com; s=arc-20160816; b=Jk1FhwyPHBv6QrRLnoFatRMXChHpBu2K/+Eid6LuCbfxAHvAeqayrf016fkJSqrtNj nBUnDXk9LdQsQcoae6qXWIS+j2gaNsz8Y8ZyrApQDdqqaRGc0itXn8GznDrZwVWM7m3W kah31slh4cfFFBF5L9Mz8CSUhzz6SnnbXT4yVfoLxFE5EOyBLJdpxJM+vfUvRVKamZ1S SNBmTttLhsoKhCfdWVO4h2TtFD8Iv3/uLbC/uWf16XzeMDswv1QyXRfK+Zy+3PjItmQd Lesrqin3XY3c4W9gG3h0RnMXFE6BjbUmKyzNPlqAjK6pGzxZT6YUWJhACdC8cQaddDCY DI3A== 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=1Sity6i4pE+bh0/EMKlkv10diThT3L/551g+8zGfgdI=; b=G5pS5D/Ql1g79mZUXMEFSTCUaxBFmIYSqIXTKIsNF5PQemvk5+FIwPQTgNeqpQ31Pk /QKg7vgCW6a7TTUWVrUwB7uLXNYm2thxqWQQS7GU2dq2dh6is/magwHtBf+I6zM8aJiT 3xL9EwX9G+uHXN3B8kgQC4DFgTu88td3IwYYtKgmiNq8+7BvJQAcdoCG7HXsXz7MYVUr 7HY5ddoRddEJkbHZx4Bs1SVELjrDX+wpkyWEglPIai9Fd33OBthhaHKq6iwdVteDYDs8 jHhkLF2Rmfl+bc7tjsLsDYcITOsIygGdvVeJ/LKQh+JzGqhoCuE3uyyLyUTbvSU+EdxQ 6FMA== 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 x1-20020a170906296100b0094aa492a5d0si1278697ejd.956.2023.04.13.00.37.39; Thu, 13 Apr 2023 00:38:03 -0700 (PDT) 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 S229873AbjDMHY1 (ORCPT + 99 others); Thu, 13 Apr 2023 03:24:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229871AbjDMHYT (ORCPT ); Thu, 13 Apr 2023 03:24:19 -0400 X-Greylist: delayed 64 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 13 Apr 2023 00:24:12 PDT Received: from esa12.hc1455-7.c3s2.iphmx.com (esa12.hc1455-7.c3s2.iphmx.com [139.138.37.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5BB38A62; Thu, 13 Apr 2023 00:24:12 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10678"; a="92736996" X-IronPort-AV: E=Sophos;i="5.98,339,1673881200"; d="scan'208";a="92736996" Received: from unknown (HELO oym-r4.gw.nic.fujitsu.com) ([210.162.30.92]) by esa12.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2023 16:23:05 +0900 Received: from oym-m1.gw.nic.fujitsu.com (oym-nat-oym-m1.gw.nic.fujitsu.com [192.168.87.58]) by oym-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id 0E944DD9AA; Thu, 13 Apr 2023 16:23:04 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by oym-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id 4629C15FDD8; Thu, 13 Apr 2023 16:23:03 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om3.fujitsu.com (Postfix) with ESMTP id ED9C3400C07D0; Thu, 13 Apr 2023 16:23:02 +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, Ilpo Jarvinen Subject: [PATCH v9 5/6] selftests/resctrl: Commonize the signal handler register/unregister for all tests Date: Thu, 13 Apr 2023 16:22:58 +0900 Message-Id: <20230413072259.2089348-6-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230413072259.2089348-1-tan.shaopeng@jp.fujitsu.com> References: <20230413072259.2089348-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?1763045785235685460?= X-GMAIL-MSGID: =?utf-8?q?1763045785235685460?= After creating a child process with fork() in CAT test, if a signal such as SIGINT is received, the parent process will be terminated immediately, and therefore 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. To reuse the signal handler to kill 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. Reviewed-by: Ilpo Jarvinen Reviewed-by: Reinette Chatre Signed-off-by: Shaopeng Tan --- tools/testing/selftests/resctrl/cat_test.c | 9 ++- tools/testing/selftests/resctrl/fill_buf.c | 14 ---- tools/testing/selftests/resctrl/resctrl.h | 2 + tools/testing/selftests/resctrl/resctrl_val.c | 66 ++++++++++++++----- 4 files changed, 58 insertions(+), 33 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 0880575840f9..fb1443f888c4 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,6 +180,12 @@ 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) { + kill(bm_pid, SIGKILL); + goto out; + } } remove(param.filename); @@ -217,8 +222,10 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) } close(pipefd[0]); kill(bm_pid, SIGKILL); + signal_handler_unregister(); } +out: cat_test_cleanup(); if (bm_pid) umount_resctrlfs(); diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 3cd0b337eae5..341cc93ca84c 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -32,14 +32,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) @@ -201,12 +193,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 9555a6f683f7..87e39456dee0 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -109,6 +109,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); +void 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 e632657995c7..ab1eab1e7ff6 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -476,6 +476,45 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr) exit(EXIT_SUCCESS); } +/* + * Register CTRL-C handler for parent, as it has to kill + * child process before exiting. + */ +int signal_handler_register(void) +{ + struct sigaction sigact; + int ret = 0; + + 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 = -1; + } + return ret; +} + +/* + * Reset signal handler to SIG_DFL. + * Non-Value return because the caller should keep + * the error code of other path even if sigaction fails. + */ +void signal_handler_unregister(void) +{ + 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"); + } +} + /* * print_results_bw: the memory bandwidth results are stored in a file * @filename: file that stores the results @@ -671,39 +710,28 @@ 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; /* Taskset benchmark to specified cpu */ ret = taskset_benchmark(bm_pid, param->cpu_no); if (ret) - goto out; + goto unregister; /* Write benchmark to specified control&monitoring grp in resctrl FS */ ret = write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp, resctrl_val); if (ret) - goto out; + goto unregister; if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) || !strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) { ret = initialize_mem_bw_imc(); if (ret) - goto out; + goto unregister; initialize_mem_bw_resctrl(param->ctrlgrp, param->mongrp, param->cpu_no, resctrl_val); @@ -718,7 +746,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) sizeof(pipe_message)) { perror("# failed reading message from child process"); close(pipefd[0]); - goto out; + goto unregister; } } close(pipefd[0]); @@ -727,7 +755,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) if (sigqueue(bm_pid, SIGUSR1, value) == -1) { perror("# sigqueue SIGUSR1 to child"); ret = errno; - goto out; + goto unregister; } /* Give benchmark enough time to fully run */ @@ -756,6 +784,8 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) } } +unregister: + signal_handler_unregister(); out: kill(bm_pid, SIGKILL); umount_resctrlfs(); From patchwork Thu Apr 13 07:22: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: 82838 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp848587vqo; Thu, 13 Apr 2023 00:28:13 -0700 (PDT) X-Google-Smtp-Source: AKy350bFPDs6fp+v+0bY8oMrNlzVaNIRyLLsqgvvIDPNTusfZE3QbnPYm/unUFhBPojMBGiM9b4Q X-Received: by 2002:a17:906:7f9a:b0:94e:772d:1b7c with SMTP id f26-20020a1709067f9a00b0094e772d1b7cmr1881111ejr.40.1681370893600; Thu, 13 Apr 2023 00:28:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681370893; cv=none; d=google.com; s=arc-20160816; b=Imoey+MNFKCWbsSuJFyu+N7uivhnZAnbaebe6A2O8krXV0j/Pg3WCp/XBimF/hYaMk 4rtqbLsfErDRjev6F/PBd3ZgspK13GRBRIAuiOvUIJaz5qGyiUEb4w3YhpdNx3y4mxHV YpkYdPZP5vYp6eTosLZaYONCAkGzrBTeiokd/Bhm+vezpc1hiTcyX/XJfJgTBZFAxyw3 eDDdLeEnKfxG9C8bx/0wDy7PcV5HnAMnNIe7FA5nafH581Z60VUIzQJaQ8jT0+/D9sA1 NGXBvs2tpPui1QiXyhA+aus2LVu0tw/EKP+NVmhr9O2+1Lnqy3wm7QZxPyi1IXyXouvM /jLQ== 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=M6As8rkxvQtEYXC2L2tnZvPM2HpXM7YKjNIpQRv20Es=; b=dlEAnlAppNsbktuuCzRLRVmJxeaORfRy0lD41OgM++vLVpR6k0V3LX3cWzHbvBA27l ClF967PbECbr4fDh5FsFY+vrwMVz4tq6O22cRaq+ATuaHlN6M1PtK07D9JWsXOp/vSYh JRihIyE44Ooyhf2TTYqRB3mAX0xqrmEdcEfo/utowjvvbxC49tjHJhiF9s3qyc2HU6X+ /Tq0t5Mr9t+9EgW1mCHnooccMpo/JKktS6T15G8H1YXujRIDd3B8yet26cyYxQ3er2Gj hrHAewpK2oMO8aYLU3Mll7jmwAaX+6cdH8dBsdrZz32w35+1oTSfiO4jqhVhMrJ8oCBE Zxyg== 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 eq16-20020a170907291000b009497c0571b4si1026597ejc.26.2023.04.13.00.27.49; Thu, 13 Apr 2023 00:28:13 -0700 (PDT) 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 S229924AbjDMHXU (ORCPT + 99 others); Thu, 13 Apr 2023 03:23:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbjDMHXN (ORCPT ); Thu, 13 Apr 2023 03:23:13 -0400 Received: from esa10.hc1455-7.c3s2.iphmx.com (esa10.hc1455-7.c3s2.iphmx.com [139.138.36.225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0772386B5; Thu, 13 Apr 2023 00:23:09 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10678"; a="100985214" X-IronPort-AV: E=Sophos;i="5.98,339,1673881200"; d="scan'208";a="100985214" Received: from unknown (HELO yto-r3.gw.nic.fujitsu.com) ([218.44.52.219]) by esa10.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2023 16:23:07 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id 1BFCDE8523; Thu, 13 Apr 2023 16:23:05 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 53019D3F33; Thu, 13 Apr 2023 16:23:04 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om3.fujitsu.com (Postfix) with ESMTP id 1AB20400C07D1; Thu, 13 Apr 2023 16:23:04 +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 v9 6/6] selftests/resctrl: Remove duplicate codes that clear each test result file Date: Thu, 13 Apr 2023 16:22:59 +0900 Message-Id: <20230413072259.2089348-7-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230413072259.2089348-1-tan.shaopeng@jp.fujitsu.com> References: <20230413072259.2089348-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?1763045165998548905?= X-GMAIL-MSGID: =?utf-8?q?1763045165998548905?= 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 47cde5c02b7f..af71b2141271 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -132,13 +132,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 2a5d43f3c142..cde3781a9ab0 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -165,13 +165,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 9b591c35310f..146132fa986d 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)