From patchwork Mon Feb 13 06:24:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 56050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2199880wrn; Sun, 12 Feb 2023 22:29:05 -0800 (PST) X-Google-Smtp-Source: AK7set+6/UOr5DLcIN3SSlWWkjPvlvsWHaWC/dD3pFDL3CwZ8eG03ZLPJvpjHRxPf9BBlVgBKu8w X-Received: by 2002:a05:6a20:3c92:b0:c0:be63:75e5 with SMTP id b18-20020a056a203c9200b000c0be6375e5mr27336040pzj.33.1676269745429; Sun, 12 Feb 2023 22:29:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676269745; cv=none; d=google.com; s=arc-20160816; b=ft5F+WngMUYBl9XTeOdXF1dSC14tksFD0DN2qoI1XumZ6JX7FWk5XtQcPBn9rYvfbj cjybWacOVol0xQ8uBy0F1k9vJKzE2r+2o/s3ICP4bSIbxd6J0he79ernZf2vY/LTZXyi bMIdYpkApiI4tpm3j6uxH5fMwAFZIxs33DX/il4niDE0XlD6/NVZzsmo1/64MCpFkyNK c3CmnBByY1eRk82kvxzMgAzgSF4cf/g1Y6xjtXaX0uoAq4FWIjUTkiAXujdTNaOIe+St c2tHIOO5gUprBsfz2oHHakesMGEWRMhlb2hvjkTyM9Mj1CA270blCf5z2dby/JqfcYTE KfUQ== 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=ihxnyg1F0ToZKzlV1GUlStqtPrYAIyB/l1HLOq6J97JZ72rHTrw1bdde5JYihqnm0D iKnWr1jmyUJwIsS3U5QbQ4wq2mKRx+Ud5NnMlUsYDKYGW6mzz1Io767rIjORUf/dJB8Q kfEQ/zlL+CC0KcbhKLbh+3/w0DrLPWBOpJZySZ/oJ+coMxWFnpk0DXvYZT1TTQVyWoVl 8NnRXnuNJVSseimJFpvekVNSbun8Jk3jYgmmOhoMYZPe2jKczniBhRekhuRCDgrB+nP9 HWiyjPU/8bx9f10wGJwCXHENIe2gpDlE6LzS0DZLHVlOMUEfTxZToWkD26o1Lv11fBKM 3rpA== 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 v190-20020a6389c7000000b004fb92fca7d2si3989674pgd.88.2023.02.12.22.28.52; Sun, 12 Feb 2023 22:29:05 -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 S229760AbjBMG2i (ORCPT + 99 others); Mon, 13 Feb 2023 01:28:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbjBMG2g (ORCPT ); Mon, 13 Feb 2023 01:28:36 -0500 Received: from esa4.hc1455-7.c3s2.iphmx.com (esa4.hc1455-7.c3s2.iphmx.com [68.232.139.117]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5384C10418; Sun, 12 Feb 2023 22:28:31 -0800 (PST) X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="106380955" X-IronPort-AV: E=Sophos;i="5.97,293,1669042800"; d="scan'208";a="106380955" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa4.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 15:28:29 +0900 Received: from yto-m1.gw.nic.fujitsu.com (yto-nat-yto-m1.gw.nic.fujitsu.com [192.168.83.64]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id D21B4DE50C; Mon, 13 Feb 2023 15:28:26 +0900 (JST) Received: from yto-om1.fujitsu.com (yto-om1.o.css.fujitsu.com [10.128.89.162]) by yto-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id 3A4BCCFBA3; Mon, 13 Feb 2023 15:28:26 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om1.fujitsu.com (Postfix) with ESMTP id 16F2E40418617; Mon, 13 Feb 2023 15:28:26 +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 v7 1/6] selftests/resctrl: Fix set up schemata with 100% allocation on first run in MBM test Date: Mon, 13 Feb 2023 15:24:23 +0900 Message-Id: <20230213062428.1721572-2-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230213062428.1721572-1-tan.shaopeng@jp.fujitsu.com> References: <20230213062428.1721572-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?1757696224748142687?= X-GMAIL-MSGID: =?utf-8?q?1757696224748142687?= 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 Mon Feb 13 06:24:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 56054 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2202348wrn; Sun, 12 Feb 2023 22:37:42 -0800 (PST) X-Google-Smtp-Source: AK7set84au8eFseFtIYt31MXC1LWdl/wOkt4BnBCytvmZ4YnfACmSiF0hMc0+SeCyEk5WmM2RtDe X-Received: by 2002:a05:6a20:3cab:b0:bc:47a0:f5a9 with SMTP id b43-20020a056a203cab00b000bc47a0f5a9mr28204363pzj.16.1676270261939; Sun, 12 Feb 2023 22:37:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676270261; cv=none; d=google.com; s=arc-20160816; b=DRrKbj6GL8CRPZsxra9zApfDaiBNXDVnmvPEuNSQjJiDCg0mV3iJkIyCRChkstcfFY Wb6IfiPwc6nzwscdOngY0GSXCGHrLQLYoQJVw8Xbcjd+X9/c7PkPGKv+DCCC6Uikkf5Q koogRb91o6eD5pXE+Z2i+l2v4Hri3cCHpbPUD/5W/HbKPKob/RjYouWbjsSTYz3es23p K3wYNrhOPNW6y2KYexXJngFMBRVUQjMKHcdY0pogfWWoU2JBGGiagd80+SKPlW815yJf ePCcNnxNAgk/hupDLSSeg5iG+l+xfn+DAEjKfTqUvrS1SspnQc4Ttw5RZds4wyoXMH+j 5tJQ== 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=d7Zq1vjvl9nzPfdyRhHfiAmUaGHsd8x8hj1wwEAT4mkxQJNWJDo6OtasiwzUn07AZC kMWI2S1c+0cqtorlqnY2IginDeDjsb/xz77lxQegYCAP3gVuRsU8T7nORk1VyNw9rKgd vqgO49NaQwCoOmeyIR0qGiTXN147ajukqFFvTluu2byAWs0Bo6uV/qYNJXfxpGfivk6F 8cZ8wcFELS9P0BdoUcMVdN6E5AYyul8isg7+wdA5hoYVkUSU5t0j6gxswwYC/AvqMfNh rQ1oFf7IpRogRUMdiWUZUIRxPWfgc2yRYLtYzRaJImkpkU0WPsbimUqTRGXjp6OjdoHU ZJNA== 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 a29-20020aa795bd000000b0059d1764718dsi10790804pfk.133.2023.02.12.22.37.28; Sun, 12 Feb 2023 22:37:41 -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 S229841AbjBMG2t (ORCPT + 99 others); Mon, 13 Feb 2023 01:28:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbjBMG2n (ORCPT ); Mon, 13 Feb 2023 01:28:43 -0500 Received: from esa8.hc1455-7.c3s2.iphmx.com (esa8.hc1455-7.c3s2.iphmx.com [139.138.61.253]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EE62EB5B; Sun, 12 Feb 2023 22:28:32 -0800 (PST) X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="94505871" X-IronPort-AV: E=Sophos;i="5.97,293,1669042800"; d="scan'208";a="94505871" Received: from unknown (HELO yto-r4.gw.nic.fujitsu.com) ([218.44.52.220]) by esa8.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 15:28:29 +0900 Received: from yto-m1.gw.nic.fujitsu.com (yto-nat-yto-m1.gw.nic.fujitsu.com [192.168.83.64]) by yto-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id D4A85D3EA3; Mon, 13 Feb 2023 15:28:27 +0900 (JST) Received: from yto-om1.fujitsu.com (yto-om1.o.css.fujitsu.com [10.128.89.162]) by yto-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id 366ADCFBAF; Mon, 13 Feb 2023 15:28:27 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om1.fujitsu.com (Postfix) with ESMTP id 074E440418617; Mon, 13 Feb 2023 15:28:27 +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 v7 2/6] selftests/resctrl: Return MBA check result and make it to output message Date: Mon, 13 Feb 2023 15:24:24 +0900 Message-Id: <20230213062428.1721572-3-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230213062428.1721572-1-tan.shaopeng@jp.fujitsu.com> References: <20230213062428.1721572-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?1757696766025504396?= X-GMAIL-MSGID: =?utf-8?q?1757696766025504396?= 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 Mon Feb 13 06:24:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 56052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2200852wrn; Sun, 12 Feb 2023 22:32:08 -0800 (PST) X-Google-Smtp-Source: AK7set+/GffskZeX5Z3vJTqqN3Zh7QeOKt1ksOEVocAI2aDAkRVNeiI/881IVtTHuw6K2vHUi69p X-Received: by 2002:a17:902:da8b:b0:199:bd4:9fbb with SMTP id j11-20020a170902da8b00b001990bd49fbbmr29031161plx.43.1676269928607; Sun, 12 Feb 2023 22:32:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676269928; cv=none; d=google.com; s=arc-20160816; b=FYpusVonSvExMzPdibi87BUj4z7fll5r/5yZN336gWfcQ5/jdO+i5/x4JJ/01tJsXf vNE+fXsFd53yRNbMIaGI5RrazI1vZQxxVmDdkDI6Rx06Y0HTrCLCqYzKVqqI4YE0wczw JNHMVlz3TBwxCXcPXJjHzzGeZm2pdpTv04E1HAhcwNS0bzfHJ7eqAQTdTarIZnEbi/MS NfkcuMHSQDhlDkGqTB1YiiuUPjReNRDLUGwdmbbHvjJL8/1vT1y4NJZPZJcyCjyjpIGq dlVWTr5BItNB+U63/bglNQbNr6RVyuLnl92G/wAJhXJXDbN6CJf2OmaEmx7QUFqznYNS TPMQ== 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=hYdp0QwEyctI1mNru8g4LBTJV5wYds/ocQ9hYftSOZYHw9t5hIPUzOGi+42RTrAK7Z Y8oLe2xEnSPsyz5fSPdyrNKJb7lDrmxKG7ogWfMJULMdyWbfaA1oKJfpsxXnYa4UyJsv nHGmQl/B3wTFHVtb6YoURr2jFbPhh+xKj+3hKWwL6ulwlgFN/e0Th/Zb2hAOPY/83fHb vUMu54RpzS/85edGW3FUKtGtsDdhv3ScWyEt0QhBnxs7seFJF7fUeq+PMqMLGELv+j+1 2+h9hmt//hNYe1McRkZFcV4dondxIPYUgCvEYqV3UUI/iB5OR5PctzKO4BlKERJ6Vz93 yNvg== 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 m11-20020a170902db0b00b00199213a3c67si12200500plx.606.2023.02.12.22.31.56; Sun, 12 Feb 2023 22:32:08 -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 S229863AbjBMG2w (ORCPT + 99 others); Mon, 13 Feb 2023 01:28:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229754AbjBMG2o (ORCPT ); Mon, 13 Feb 2023 01:28:44 -0500 Received: from esa9.hc1455-7.c3s2.iphmx.com (esa9.hc1455-7.c3s2.iphmx.com [139.138.36.223]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD29C1117D; Sun, 12 Feb 2023 22:28:33 -0800 (PST) X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="94675138" X-IronPort-AV: E=Sophos;i="5.97,293,1669042800"; d="scan'208";a="94675138" Received: from unknown (HELO yto-r3.gw.nic.fujitsu.com) ([218.44.52.219]) by esa9.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 15:28:31 +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 D2C55E4459; Mon, 13 Feb 2023 15:28:28 +0900 (JST) Received: from yto-om1.fujitsu.com (yto-om1.o.css.fujitsu.com [10.128.89.162]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 393EDD3F06; Mon, 13 Feb 2023 15:28:28 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om1.fujitsu.com (Postfix) with ESMTP id 0B0D7404AF893; Mon, 13 Feb 2023 15:28: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 v7 3/6] selftests/resctrl: Flush stdout file buffer before executing fork() Date: Mon, 13 Feb 2023 15:24:25 +0900 Message-Id: <20230213062428.1721572-4-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230213062428.1721572-1-tan.shaopeng@jp.fujitsu.com> References: <20230213062428.1721572-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?1757696416571711360?= X-GMAIL-MSGID: =?utf-8?q?1757696416571711360?= 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 Mon Feb 13 06:24:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 56051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2199898wrn; Sun, 12 Feb 2023 22:29:09 -0800 (PST) X-Google-Smtp-Source: AK7set9VrmoeQ7+L5N7ZqxtzjJXAIN9XLDPrpmB94o966UDzBgNDn9ULw3ytHSHU+SciCmir3dYG X-Received: by 2002:a17:902:e185:b0:19a:a647:1891 with SMTP id y5-20020a170902e18500b0019aa6471891mr1009987pla.67.1676269748973; Sun, 12 Feb 2023 22:29:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676269748; cv=none; d=google.com; s=arc-20160816; b=ecTvpv6oqYzwZOlo9ez7swPVIxea5wA+yjamzQgWBGSjgQ+KpQtPwH2wuCTYqyJMru +7T+Axn6xcjtzhD3nTS/UBp4iDyjJfnlleVjZx6a+1UCMOQF5rDUmgQHPs+Mm3DMOL9V smJ35HLjqeIlt5dG8Q/QD3lcyWQ4VYBlBjyc5KtbnLve7292uXXvmcBuTuJYbncrtJqp z1oPO71Bh4adztOrToAoKqNPvbVlPN/emm4Nsd4wuZKVaoFAUMmEI+W9fnoZge/pwVnn n/hyURjmznhj/YRs2aKTJFHqfpZOyEmPBtkS22r32YtNogqiKPgvfosYO9IdNE/6aWTT 5Lzw== 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=wJaQCw3Hll6T505oOvhfRHzwxUA0PZt+L+qFP1+c3Fc=; b=aEJEaMbIzATbkKbbsY/GvaGhwD2tgY2zSWQk6pz7ohH4NBSNs8ffRbDpes3Xily4I8 9j4/ZVugFJ/Udvjd/TACwjEnVHnNR/q12ef4y/lY6YwXvzt4rCMKW+D0/JrXI1TmVYR4 yXjutX7wFxGec3QDKC/2JYpb7XNOIxvBTuV6eCU63w4UEXNow0T6Zk6EydLN0dXeaHva FLPb0dhENRupm9QMyJV4RWiAswIOjtqqsWPqv9r98+7IxhYykWJfqINbk4uOyDYT1y/v BEdVvxXZh8pz1+qAceACdbNZ0FL3L6lM99PJA55aZGJrVZh2aeaoQMVwpR0co6/5Ai2r OZcA== 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 e21-20020a170902ed9500b0019a997e5675si2730573plj.197.2023.02.12.22.28.56; Sun, 12 Feb 2023 22:29:08 -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 S229756AbjBMG2q (ORCPT + 99 others); Mon, 13 Feb 2023 01:28:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbjBMG2o (ORCPT ); Mon, 13 Feb 2023 01:28:44 -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 921FFEB42; Sun, 12 Feb 2023 22:28:34 -0800 (PST) X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="106341812" X-IronPort-AV: E=Sophos;i="5.97,293,1669042800"; d="scan'208";a="106341812" Received: from unknown (HELO oym-r1.gw.nic.fujitsu.com) ([210.162.30.89]) by esa1.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 15:28:32 +0900 Received: from oym-m1.gw.nic.fujitsu.com (oym-nat-oym-m1.gw.nic.fujitsu.com [192.168.87.58]) by oym-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id E9E18DF10F; Mon, 13 Feb 2023 15:28:29 +0900 (JST) Received: from yto-om1.fujitsu.com (yto-om1.o.css.fujitsu.com [10.128.89.162]) by oym-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id 35179D88B4; Mon, 13 Feb 2023 15:28:29 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om1.fujitsu.com (Postfix) with ESMTP id 007D6404AF8A3; Mon, 13 Feb 2023 15:28: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 Subject: [PATCH v7 4/6] selftests/resctrl: Cleanup properly when an error occurs in CAT test Date: Mon, 13 Feb 2023 15:24:26 +0900 Message-Id: <20230213062428.1721572-5-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230213062428.1721572-1-tan.shaopeng@jp.fujitsu.com> References: <20230213062428.1721572-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?1757696228149928973?= X-GMAIL-MSGID: =?utf-8?q?1757696228149928973?= 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 child process is returned, but the parent process will wait pipe message from child. Synchronize the exits between the parent and child. An error occurs whether in parents process or child process, the parents process always kills child process and runs umount_resctrlfs(), and the child process always waits to be killed by the parent process. Signed-off-by: Shaopeng Tan Reviewed-by: Reinette Chatre --- 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 6a8306b0a109..477b62dac546 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 Mon Feb 13 06:24:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 56056 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2203622wrn; Sun, 12 Feb 2023 22:42:58 -0800 (PST) X-Google-Smtp-Source: AK7set+NgTgDC3oS4oFy47XCuUbH4dBJCr76E6A0BeaUVkZ1QpKVrWlW2rtQDD+lAyeBMx3Nid4V X-Received: by 2002:a05:6a20:4299:b0:b8:bcfb:7ae6 with SMTP id o25-20020a056a20429900b000b8bcfb7ae6mr15707326pzj.23.1676270577761; Sun, 12 Feb 2023 22:42:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676270577; cv=none; d=google.com; s=arc-20160816; b=njCbuGPmZfvRPGqgbxffmlkn409ZoIuVrbBA4bDxZpZdJ/aaCfedn4WwVZtNcJkRp+ ZXoWGSWBPhnbfpJbc2wzj9hCIccqqyEvk1xFdQ6ZXeLPtMnFZtBi1MNAJLDT2yB6mIIf 4N9imaILLrnmqJflN7vfYYfZSamEeyashH6xLcWwRAukRKcmwJ71vOFJlCU3ol2oNUYn VzvenSsNIr9pEjxs0uIrjCk72niq9oAH4qXfZG3KRjO4heCgPV6m7obQogKcvsoSwzC+ lKqwm/QsBj8yMnqptVSCNwFoCYsIwGxtUGRoBBWSFTuIHh9/iqHp+Kkb6gVB4O2Q4A+I 3pqA== 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=2gJf84+T4hep2GluoNbURphTD5iQU0i7OCb/vC/5HHI=; b=wE/oxjDOQviExEE+WoHrr9cLt6AF8/983q7XY1yT+wCPhKflUrd9iJVEIySDbjsTCw wP4Cl7VBWZptz1AIZFHsOEHrhwXQ5ZD4pnhNSnjFUbgjqBvQ2PJLx0GJrIKoX1O63FAH JAVMZ0FdJQ63taNKfPVi5iAmPCyJP+L2IfKR0laqNCpTkNAYIlABl3Mks1yfU/v2yIHy B9IvhaiVeycyz0onnSe1VxAKUQ+J6RKfZ0o3/JgNaABwhg6S8o0x9PWk14Q4Jy+2woKI jpIDLmlWjWJLc0V6+QRWpyuQnfTNlLDbj4AegP4iJKh5gdOnTo0S9cKkbcqaYVcj/HYs TiRw== 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 l14-20020a63be0e000000b004eca5c9c85fsi10684907pgf.282.2023.02.12.22.42.45; Sun, 12 Feb 2023 22:42:57 -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 S229875AbjBMG2y (ORCPT + 99 others); Mon, 13 Feb 2023 01:28:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbjBMG2o (ORCPT ); Mon, 13 Feb 2023 01:28:44 -0500 Received: from esa3.hc1455-7.c3s2.iphmx.com (esa3.hc1455-7.c3s2.iphmx.com [207.54.90.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAA6D11151; Sun, 12 Feb 2023 22:28:35 -0800 (PST) X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="106426588" X-IronPort-AV: E=Sophos;i="5.97,293,1669042800"; d="scan'208";a="106426588" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa3.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 15:28:33 +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 AEC87D6248; Mon, 13 Feb 2023 15:28:30 +0900 (JST) Received: from yto-om1.fujitsu.com (yto-om1.o.css.fujitsu.com [10.128.89.162]) by yto-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id 0B12DD67AC; Mon, 13 Feb 2023 15:28:30 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om1.fujitsu.com (Postfix) with ESMTP id DBBF6404AF8A5; Mon, 13 Feb 2023 15:28:29 +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 v7 5/6] selftests/resctrl: Commonize the signal handler register/unregister for all tests Date: Mon, 13 Feb 2023 15:24:27 +0900 Message-Id: <20230213062428.1721572-6-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230213062428.1721572-1-tan.shaopeng@jp.fujitsu.com> References: <20230213062428.1721572-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?1757697097577355314?= X-GMAIL-MSGID: =?utf-8?q?1757697097577355314?= 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 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. 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. Signed-off-by: Shaopeng Tan Reviewed-by: Ilpo Järvinen Reviewed-by: Reinette Chatre --- 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 477b62dac546..0bdf0305a506 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 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..92b59d2f603d 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); +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 6948843bf995..7c8d5c25e6da 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 */ @@ -761,6 +789,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 Mon Feb 13 06:24:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 56053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2200960wrn; Sun, 12 Feb 2023 22:32:33 -0800 (PST) X-Google-Smtp-Source: AK7set/0yVLP7RoEZwupRVkz53e1bVv5iK0DWI0P49+VAMpySdHwZtVi8M/Dmzi8NUk6wwOlEekp X-Received: by 2002:a17:90b:4c4d:b0:22c:9217:68b6 with SMTP id np13-20020a17090b4c4d00b0022c921768b6mr25290209pjb.14.1676269953065; Sun, 12 Feb 2023 22:32:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676269953; cv=none; d=google.com; s=arc-20160816; b=fdNp0x5LfepNnFLr36dM6gukdeVREx8wUa2FjUNnR/LNQUNqAFnobCncJex4ZNFmBj ifat3FSv1ZtH9AesGPRYuqiqo1UeZ+0nq8tXaX9QZztyIsJdiSYgdl4QBow7EkVDmNC4 YOv42z6W1Aw3JdcW9dx49uk3fyP4KOi1fZW/9WTEuERTLx7IvNp/BN7vdLJosu3zYtFB WUMasdwZDsGARCdEoM1RqMZKmHv8zkJkb52wgcM/VptWcVsFuI6XCzq+4/JsvOmVl/nf IyI6bsx5etVlwgJzjzDUBERNn2YAgGVBFETPRvsZLXn9RL8zF6TEz5bbTY3sAPygTVNf MGoA== 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=isSw9VGWDcL3zUZtkrKJ50bAy52g/5AlUcYM5IBiM6uLav5zda4b/9+/uZaI0l0Xdb Jkd6WJKWL44KH9/RsE0JagE+1feEmhL1e8w6qVnDH9/5gPl8E6lXg/nUnWyT5E0E6Ui5 2cva4qvg+iBppoStpBcglCzG+yseab+rRwbDSSNlgBJz1FWO4wiPtwkMwoC3qpq0ulyS OmAQBCkt+WSFY+rUGxhYjqAOLsoDx/1LMKpy6B8dve5So8bPovlvQrYLiavglXd0iRQs yahqgDwEz//BJp/aLZLckGCEttEWXnJDmJo3BPPzi0gkx/BHHjHGQri14cJbCPsf+2A7 Lu9w== 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 il17-20020a17090b165100b002340f617c58si532307pjb.125.2023.02.12.22.32.20; Sun, 12 Feb 2023 22:32:33 -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 S229771AbjBMG25 (ORCPT + 99 others); Mon, 13 Feb 2023 01:28:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229795AbjBMG2p (ORCPT ); Mon, 13 Feb 2023 01:28:45 -0500 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 417C411670; Sun, 12 Feb 2023 22:28:37 -0800 (PST) X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="94158594" X-IronPort-AV: E=Sophos;i="5.97,293,1669042800"; d="scan'208";a="94158594" 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 Feb 2023 15:28:34 +0900 Received: from yto-m1.gw.nic.fujitsu.com (yto-nat-yto-m1.gw.nic.fujitsu.com [192.168.83.64]) by yto-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id 70FB1C3F8B; Mon, 13 Feb 2023 15:28:32 +0900 (JST) Received: from yto-om1.fujitsu.com (yto-om1.o.css.fujitsu.com [10.128.89.162]) by yto-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id BDC49CFBA3; Mon, 13 Feb 2023 15:28:31 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by yto-om1.fujitsu.com (Postfix) with ESMTP id 9711C404AF8A3; Mon, 13 Feb 2023 15:28:31 +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 v7 6/6] selftests/resctrl: Remove duplicate codes that clear each test result file Date: Mon, 13 Feb 2023 15:24:28 +0900 Message-Id: <20230213062428.1721572-7-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230213062428.1721572-1-tan.shaopeng@jp.fujitsu.com> References: <20230213062428.1721572-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?1757696442500926987?= X-GMAIL-MSGID: =?utf-8?q?1757696442500926987?= 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)