Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp85701rdh; Sat, 23 Sep 2023 02:33:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMi5/oKhRF6vdAo8HMVT8AToIBpixb3nrfGRpyHa3YD4eZbjqEI/GqUtyLp0tVM8CdzwTq X-Received: by 2002:a05:6808:2096:b0:3a9:9ce5:83a9 with SMTP id s22-20020a056808209600b003a99ce583a9mr2559193oiw.50.1695461620883; Sat, 23 Sep 2023 02:33:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695461620; cv=none; d=google.com; s=arc-20160816; b=zmwiHJtHj1TpwuYlA7dq+sEWHfGIczlmtBY/Wzn25UTH2LwX9OTfdB8yN72cs88hYQ ActFjIemJK8Nqfg4FjBuCZEnAJ1zTAMkPQPp9n7jyQ92ExFV1u7C9Dv6UUW+Ojp9zt3I QQUI9xoLb33epl/bA7ANk02XByEbJVaaCogSXdtvjroQkhWFdIdHkOIGX01amgCNHzy0 NTv1C8CRNhSkeVzk6CrM98wYFqk7DmfayVhSCpkKSR6R3c7zwmBr9cxKVJa4BTV1ad6U hLp91RCwsO0rWOelkDYNeMygaEfcGybAPlqD7zKtjCatkNVpEcyOIBSEoB5LcFLF1wZL YONA== 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=HybSFhU2w0PY+hVqZWhLWFKqDaI2kOyz9uVMdJG6/rE=; fh=JXx1mv1fB650HoTkc5GIgpDQ5Ey550GcDyaNZ/s6bYc=; b=A553b3lo5AqHRY/0menkGfB+1Wc79zbJi14oaXyHeCfRyaYfvbOtRU4G2wjUSchVK8 bqBJREx1KmsOxgR6GCtPngK1Md4Il0ISlG2NsdY5RJ6XN8k5s1/Hbccar2qkWsLulF+0 G2tkOXBK6k5hrq1tJ/WjOzwG/3MqZ8Rmxbuz0Wq7cPqk2bbGzrJEO8Jm5cWrArUQhjGX TvC43oY8L9W3GF9xq/6a3a73PAVgq1mnfdZZ+mdZliYkDdYHUzrbMoBo+ExxTlIg9i87 Sqh+MZjgrNlSKyL16tmRbjyvK1aSSdWawnr6acRqmyjOTXfvpLur6NuN6J+f2YxgC9NW 3gWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id s14-20020a65644e000000b00578c1c576acsi5190835pgv.370.2023.09.23.02.33.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 02:33:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 77D1B8183249; Sat, 23 Sep 2023 02:32:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231320AbjIWJcb (ORCPT + 99 others); Sat, 23 Sep 2023 05:32:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231271AbjIWJcT (ORCPT ); Sat, 23 Sep 2023 05:32:19 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58EFA136; Sat, 23 Sep 2023 02:32:12 -0700 (PDT) Received: from kwepemm000003.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Rt3jB6BFHzMljc; Sat, 23 Sep 2023 17:28:30 +0800 (CST) Received: from ubuntu2204.huawei.com (10.67.174.22) by kwepemm000003.china.huawei.com (7.193.23.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 23 Sep 2023 17:32:08 +0800 From: Yang Jihong To: , , , , , , , , , , CC: Subject: [PATCH 4/4] perf bench messaging: Kill child processes when exit abnormally in process mode Date: Sat, 23 Sep 2023 09:30:37 +0000 Message-ID: <20230923093037.961232-5-yangjihong1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230923093037.961232-1-yangjihong1@huawei.com> References: <20230923093037.961232-1-yangjihong1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.22] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm000003.china.huawei.com (7.193.23.66) X-CFilter-Loop: Reflected X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sat, 23 Sep 2023 02:32:39 -0700 (PDT) X-Spam-Level: ** When exit abnormally in process mode, customize SIGINT and SIGTERM signal handler to kill the forked child processes. Before: # perf bench sched messaging -l 1000000 -g 1 & [1] 8519 # # Running 'sched/messaging' benchmark: # pgrep sched-messaging | wc -l 41 # kill -15 8519 [1]+ Terminated perf bench sched messaging -l 1000000 -g 1 # pgrep sched-messaging | wc -l 40 After: # perf bench sched messaging -l 1000000 -g 1 & [1] 8472 # # Running 'sched/messaging' benchmark: # pgrep sched-messaging | wc -l 41 # kill -15 8472 [1]+ Exit 1 perf bench sched messaging -l 1000000 -g 1 # pgrep sched-messaging | wc -l 0 Signed-off-by: Yang Jihong --- tools/perf/bench/sched-messaging.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c index 04ffaabdd45b..e2b8938b7dc3 100644 --- a/tools/perf/bench/sched-messaging.c +++ b/tools/perf/bench/sched-messaging.c @@ -36,6 +36,7 @@ static bool use_pipes = false; static unsigned int nr_loops = 100; static bool thread_mode = false; static unsigned int num_groups = 10; +static unsigned int total_children = 0; static struct list_head sender_contexts = LIST_HEAD_INIT(sender_contexts); static struct list_head receiver_contexts = LIST_HEAD_INIT(receiver_contexts); @@ -60,6 +61,8 @@ union messaging_worker { pid_t pid; }; +static union messaging_worker *worker_tab; + static void fdpair(int fds[2]) { if (use_pipes) { @@ -260,6 +263,17 @@ static unsigned int group(union messaging_worker *worker, return num_fds * 2; } +static void sig_handler(int sig __maybe_unused) +{ + unsigned int i; + + /* + * When exit abnormally, kill all forked child processes. + */ + for (i = 0; i < total_children; i++) + kill(worker_tab[i].pid, SIGKILL); +} + static const struct option options[] = { OPT_BOOLEAN('p', "pipe", &use_pipes, "Use pipe() instead of socketpair()"), @@ -277,12 +291,11 @@ static const char * const bench_sched_message_usage[] = { int bench_sched_messaging(int argc, const char **argv) { - unsigned int i, total_children; + unsigned int i; struct timeval start, stop, diff; unsigned int num_fds = 20; int readyfds[2], wakefds[2]; char dummy; - union messaging_worker *worker_tab; struct sender_context *pos, *n; argc = parse_options(argc, argv, options, @@ -295,7 +308,11 @@ int bench_sched_messaging(int argc, const char **argv) fdpair(readyfds); fdpair(wakefds); - total_children = 0; + if (!thread_mode) { + signal(SIGINT, sig_handler); + signal(SIGTERM, sig_handler); + } + for (i = 0; i < num_groups; i++) total_children += group(worker_tab + total_children, num_fds, readyfds[1], wakefds[0]); -- 2.34.1