Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp3765176rwi; Wed, 2 Nov 2022 02:54:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7nxwIQynq5+iz4T1LDj3wwYARx7q8TpRBUMRCLPDtXCkraFODAfM70oE0utQqT8seMrh9q X-Received: by 2002:a17:906:5dce:b0:78d:ec48:6a58 with SMTP id p14-20020a1709065dce00b0078dec486a58mr22889928ejv.209.1667382850056; Wed, 02 Nov 2022 02:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667382850; cv=none; d=google.com; s=arc-20160816; b=chXsqIG7zMNchfA1RKdy1KhGdoFhiM7ZXFEQibJYyKOxLv/MmFcWHaFqzkALJ/Qxrt /tsEyWMmru/voP9as9GB0B3nZ8Bp0ORcYDQ1LevmVfwoi+aG6WJeIsLADC1+rpqoNDn1 p6FevpqvRXCAabkdBtvScq+cIwPChKAhKncpk9CsZC80tpPZ3fmkh8H8ELFYqQCvQKsZ CU70uXmL9Em1qLNqYRyAIXo7Y1IkxjYrgcs8EyY1sXNTcLQyihi41yclu3i5toz70Gpx fBlUlNQC+7iLEU/gOzlpE92O7xQu5U4BQDncIFXNEE0mJ4eydFhAp5OfO8epLqaNgXeM D50w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=ZZjjsfhVpVmcKXTEAXNtkm7mljVLUHPV6/kXC2ILvLk=; b=MP7UmyPMyo/z5kwJeq7zgpJiKT1UqIMH9ANhOgiV7bDyYg0j6WUkwFbUF/hSVcJlju uEsTnDM9kLixoY1kdYwbisz37hfeIavJGvp58bpL3hsF9oN42DNTSZSoLu2RYm58ZbUF fD65o2dJ2lVl1KBR3x3KQ+Zf5C64EQ5xN9ixL/0zWZTGjaAjpmEMKAqaikgqzThWMgOW J2TJB5oss9W0TKWdvHhJQl3c2rMsdIiEkGzwSibC1dz+L2V+rDL9F7t/h6k/gTjzZBuX LYnUsaaRrYToebNucI+I4x4JgkxyuQYT92zcjILspzjCSlX1zvtSQNj8pwXA/QLMht3K WVZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=adDXi8Yo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k1-20020a05640212c100b004602df03e36si13520422edx.486.2022.11.02.02.53.46; Wed, 02 Nov 2022 02:54:10 -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; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=adDXi8Yo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230353AbiKBJl6 (ORCPT + 97 others); Wed, 2 Nov 2022 05:41:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230153AbiKBJlx (ORCPT ); Wed, 2 Nov 2022 05:41:53 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5778222B28 for ; Wed, 2 Nov 2022 02:41:52 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id q1-20020a17090a750100b002139ec1e999so1426724pjk.1 for ; Wed, 02 Nov 2022 02:41:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ZZjjsfhVpVmcKXTEAXNtkm7mljVLUHPV6/kXC2ILvLk=; b=adDXi8Yok5j/QS1Hd0PWyyALEH6R9tJTsIbSAWlQ/AXtawOjzK452sQCf1g9NHbd0t X93cZ4qPH//xgANbOAwuONnYWtpVmnhQJ2cAGZy0NpekfVrFZpOLpdsmzbX/It4MCQ3f bsWrjcjWIHmzlMmOeRWYWhBzs/1dZCD3V+xs4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZZjjsfhVpVmcKXTEAXNtkm7mljVLUHPV6/kXC2ILvLk=; b=YuP3czmFmQ6Six0BxHk7CCrnmYL+rviw7qFVHijwTSEi/zyTsOdO3btuqNZEe+CeA2 GOJVJ21ljEHPW/CXDkeUaWrb66NAIHFHdZbzIBR04XcwaAoqxd7ZRhDclrAzgs7Mibsw hWCIQtNBW0x1SFw5gr8QPDg2LgafntKz7f6CFCs1BIRSyFzXfU5RMAwE9t54TbSvCdXT 31KldklxFMOwlDzsvVQc7YP3ddzoTQL79kMXzKwCvoFZEoC4XZPMddtnkOnbEnTnZWos NAWbkx2C2MczPTK/pSA3E0tIcRuViy0R9DWaP2eNgvydUJmBSfiMD9MdWojf5fdTZiMF cbYQ== X-Gm-Message-State: ACrzQf2deMuxKG6+fou0joTrqrhgjlJF2wtrbCIx8iDvROpeUOK3OXBv ih26eXHndyhRUgs4yvNusXG47g== X-Received: by 2002:a17:90a:e545:b0:213:9c27:cded with SMTP id ei5-20020a17090ae54500b002139c27cdedmr7680602pjb.208.1667382111831; Wed, 02 Nov 2022 02:41:51 -0700 (PDT) Received: from [192.168.0.168] ([103.99.10.63]) by smtp.gmail.com with ESMTPSA id 3-20020a620403000000b0056da2bf607csm4326244pfe.214.2022.11.02.02.41.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Nov 2022 02:41:51 -0700 (PDT) Message-ID: <39586b57-aad2-d9ca-df12-67f1dfe60258@linuxfoundation.org> Date: Wed, 2 Nov 2022 03:41:47 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH v3 4/5] selftests/resctrl: Cleanup properly when an error occurs in CAT test Content-Language: en-US To: Shaopeng Tan , Fenghua Yu , Reinette Chatre , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Shuah Khan References: <20221101094341.3383073-1-tan.shaopeng@jp.fujitsu.com> <20221101094341.3383073-5-tan.shaopeng@jp.fujitsu.com> From: Shuah Khan In-Reply-To: <20221101094341.3383073-5-tan.shaopeng@jp.fujitsu.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 On 11/1/22 03:43, Shaopeng Tan wrote: > After creating a child process with fork() in CAT test, if there is > an error occurs or such as a SIGINT signal is received, the parent > process will be terminated immediately, but the child process will not > be killed and also umount_resctrlfs() will not be called. > > Add a signal handler like other tests to kill child process, umount > resctrlfs, cleanup result files, etc. when an error occurs. > > Signed-off-by: Shaopeng Tan > --- > tools/testing/selftests/resctrl/cat_test.c | 28 +++++++++++++++------- > 1 file changed, 19 insertions(+), 9 deletions(-) > > diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c > index 6a8306b0a109..5f81817f4366 100644 > --- a/tools/testing/selftests/resctrl/cat_test.c > +++ b/tools/testing/selftests/resctrl/cat_test.c > @@ -98,12 +98,21 @@ void cat_test_cleanup(void) > remove(RESULT_FILE_NAME2); > } > > +static void ctrl_handler(int signo) > +{ > + kill(bm_pid, SIGKILL); > + umount_resctrlfs(); > + tests_cleanup(); > + ksft_print_msg("Ending\n\n"); Is there a reason to print this message? Remove it unless it serves a purpose. > + > + exit(EXIT_SUCCESS); > +} > + > 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; Odd. bm_pid is used below - why remove it here? > > cache_size = 0; > > @@ -181,17 +190,19 @@ 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 { > + /* set up ctrl-c handler */ > + if (signal(SIGINT, ctrl_handler) == SIG_ERR || > + signal(SIGHUP, ctrl_handler) == SIG_ERR || > + signal(SIGTERM, ctrl_handler) == SIG_ERR) > + printf("Failed to catch SIGNAL!\n"); Is perror() more appropriate here? > } > > 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); Why not use a goto in error case to do umount_resctrlfs() instead of changing the conditionals? > > if (bm_pid == 0) { > /* Tell parent that child is ready */ > @@ -201,7 +212,6 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) > sizeof(pipe_message)) { > close(pipefd[1]); > perror("# failed signaling parent process"); > - return errno; > } > > close(pipefd[1]); > @@ -226,5 +236,5 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) > if (bm_pid) > umount_resctrlfs(); > > - return 0; > + return ret; > } With these changes made: Reviewed-by: Shuah Khan thanks, -- Shuah