From patchwork Tue Feb 6 08:32:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Jihong X-Patchwork-Id: 197251 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1401205dyb; Tue, 6 Feb 2024 00:39:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvEnpdJl/Rf8WPwBVwlwDeA1B6WJyCgH/AxWqlRYNWqgegHlinwsjH+E1WpE1ihcFNZGr6 X-Received: by 2002:a05:6214:509b:b0:68c:8ff0:7a15 with SMTP id kk27-20020a056214509b00b0068c8ff07a15mr1975956qvb.36.1707208784469; Tue, 06 Feb 2024 00:39:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707208784; cv=pass; d=google.com; s=arc-20160816; b=snwNxL1RNmrcZ2RVBrOhU1h3eS+mIFswk7edu2geCA8MhNrObfCwjDC715YfOYbdJ5 /wLsGwMLyJlKJrGv2yz7pv59zsCz78073wQnGgrP/WKfY/q/HxkTk7y5qPRBf/7EyNuX yEOYN5e2UT8q7QNkhxBHwXZecu3Evz2aqSPtdfzoaba1RDAPfrSdxhkdPx0mzUMcQM6A 3zukJPoKofaNeM2R5fy50OU7RJRuFi8YOv54HXDgXKT8yrYhPdgwoMODiRhFz9SmMCWp MAw0NTfomEHU3JflloE654v3B9OUdga6dtmjaGXbMqb5anAZAEmdDBY9LufXyQTLHBp3 By2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=0rZ7Mn40zs8ZL6JMCWiuhTnESZ8O9HDi4L//V5dsRs4=; fh=kE8VHT7fvLBMM8mCsVkZsaCwLLE4Fjp+PXsNB8N2l4U=; b=dPTrVyj0i6MszjTXGAFdtNEYGVOnWMieDtIgAuR2HdahoYoXq0NX4k7F5zkUMxu7O1 h4NcgJS4cM4MkklVsFXscBTOKHALMP5oGG32GCbx7tdLzgXHRonK7aBXz1ZZ9JJEmZe1 XPr6PNaG5DsJbh2P3G/7Mmd8AdmiIB4v1O0/jpI9TwlCmyuIqIvf0uyRRT7a8QRxc4+e hcaHadMmYUDoIKOfxxs4wDBQSaQ7EnkK3nl4Hud6aD9io717CFr6xw6cTyELwJpWK6kS ygVlpT/sf/uRViK11CxMBWpw5Uxh/Ok1+aKuiczLVnHoesqTL/Y9L/3DcGRSUq+pYC1e CPBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-54506-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54506-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com X-Forwarded-Encrypted: i=1; AJvYcCXdLQ63NZ5LCHV/nZOVYpHmLMJFSU6iMcFUUZPhcZwwwDj4TXoT6ljnuixIg2Acv31RhDw1a0vCHrHnt4lRJhQQWyCcUQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d23-20020a05620a205700b0078534dabe45si1839057qka.282.2024.02.06.00.39.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 00:39:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54506-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-54506-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54506-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3333B1C245ED for ; Tue, 6 Feb 2024 08:39:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB76412D749; Tue, 6 Feb 2024 08:37:34 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4362831A60; Tue, 6 Feb 2024 08:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707208652; cv=none; b=mcjaSYjlLiYnCD6LbC6dJeYKxdjoPTXwAZRn619ofQXGvNt4Rdr45tPg9RqvAdZoDi2/4glLgqA/Gt74OkUuk0WT+GH02/UUVQQCwOQF0YosGBMG3sTkT69LwpHWne1Q/Uc3dg6gOQ4XNkYaAfNAvHrgASSb5MIX2eJ8slRhcfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707208652; c=relaxed/simple; bh=akxPEgyMnsMulfBbKHAmf+qbvnaNRYhrNfJ8MDEIybA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tZ8OcjLKhPrQkoWFzgBsdcX01A1dNxF3Yxf2wtxwBVh9X67C5iRZdCeKc+pBvVut9Afa7aW8mIopYKW4DfSnLREErfniDK1FIwQHNBBiicquuVvN+fY+aGuU3nCRwffeZUxuoqbq+KOpCxY66y4NebB8XR0sevWKJDhwZKXSVls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4TTc6x19cRzLnZ9; Tue, 6 Feb 2024 16:36:57 +0800 (CST) Received: from kwepemm600003.china.huawei.com (unknown [7.193.23.202]) by mail.maildlp.com (Postfix) with ESMTPS id 33EE11400DA; Tue, 6 Feb 2024 16:37:26 +0800 (CST) Received: from ubuntu2204.huawei.com (10.67.174.22) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 6 Feb 2024 16:37:25 +0800 From: Yang Jihong To: , , , , , , , , , , CC: Subject: [PATCH v2 1/5] perf sched: Move start_work_mutex and work_done_wait_mutex initialization to perf_sched__replay() Date: Tue, 6 Feb 2024 08:32:24 +0000 Message-ID: <20240206083228.172607-2-yangjihong1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240206083228.172607-1-yangjihong1@huawei.com> References: <20240206083228.172607-1-yangjihong1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600003.china.huawei.com (7.193.23.202) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790138158767600788 X-GMAIL-MSGID: 1790138158767600788 The start_work_mutex and work_done_wait_mutex are used only for the 'perf sched replay'. Put their initialization in perf_sched__replay () to reduce unnecessary actions in other commands. Simple functional testing: # perf sched record perf bench sched messaging # Running 'sched/messaging' benchmark: # 20 sender and receiver processes per group # 10 groups == 400 processes run Total time: 0.197 [sec] [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 14.952 MB perf.data (134165 samples) ] # perf sched replay run measurement overhead: 108 nsecs sleep measurement overhead: 65658 nsecs the run test took 999991 nsecs the sleep test took 1079324 nsecs nr_run_events: 42378 nr_sleep_events: 43102 nr_wakeup_events: 31852 target-less wakeups: 17 multi-target wakeups: 712 task 0 ( swapper: 0), nr_events: 10451 task 1 ( swapper: 1), nr_events: 3 task 2 ( swapper: 2), nr_events: 1 task 717 ( sched-messaging: 74483), nr_events: 152 task 718 ( sched-messaging: 74484), nr_events: 1944 task 719 ( sched-messaging: 74485), nr_events: 73 task 720 ( sched-messaging: 74486), nr_events: 163 task 721 ( sched-messaging: 74487), nr_events: 942 task 722 ( sched-messaging: 74488), nr_events: 78 task 723 ( sched-messaging: 74489), nr_events: 1090 ------------------------------------------------------------ #1 : 1366.507, ravg: 1366.51, cpu: 7682.70 / 7682.70 #2 : 1410.072, ravg: 1370.86, cpu: 7723.88 / 7686.82 #3 : 1396.296, ravg: 1373.41, cpu: 7568.20 / 7674.96 #4 : 1381.019, ravg: 1374.17, cpu: 7531.81 / 7660.64 #5 : 1393.826, ravg: 1376.13, cpu: 7725.25 / 7667.11 #6 : 1401.581, ravg: 1378.68, cpu: 7594.82 / 7659.88 #7 : 1381.337, ravg: 1378.94, cpu: 7371.22 / 7631.01 #8 : 1373.842, ravg: 1378.43, cpu: 7894.92 / 7657.40 #9 : 1364.697, ravg: 1377.06, cpu: 7324.91 / 7624.15 #10 : 1363.613, ravg: 1375.72, cpu: 7209.55 / 7582.69 # echo $? 0 Signed-off-by: Yang Jihong --- tools/perf/builtin-sched.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 42d5fc5d6b7b..08dec557e6be 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -3285,15 +3285,20 @@ static int perf_sched__map(struct perf_sched *sched) static int perf_sched__replay(struct perf_sched *sched) { + int ret; unsigned long i; + mutex_init(&sched->start_work_mutex); + mutex_init(&sched->work_done_wait_mutex); + calibrate_run_measurement_overhead(sched); calibrate_sleep_measurement_overhead(sched); test_calibrations(sched); - if (perf_sched__read_events(sched)) - return -1; + ret = perf_sched__read_events(sched); + if (ret) + goto out_mutex_destroy; printf("nr_run_events: %ld\n", sched->nr_run_events); printf("nr_sleep_events: %ld\n", sched->nr_sleep_events); @@ -3318,7 +3323,11 @@ static int perf_sched__replay(struct perf_sched *sched) sched->thread_funcs_exit = true; destroy_tasks(sched); - return 0; + +out_mutex_destroy: + mutex_destroy(&sched->start_work_mutex); + mutex_destroy(&sched->work_done_wait_mutex); + return ret; } static void setup_sorting(struct perf_sched *sched, const struct option *options, @@ -3556,8 +3565,6 @@ int cmd_sched(int argc, const char **argv) unsigned int i; int ret = 0; - mutex_init(&sched.start_work_mutex); - mutex_init(&sched.work_done_wait_mutex); sched.curr_thread = calloc(MAX_CPUS, sizeof(*sched.curr_thread)); if (!sched.curr_thread) { ret = -ENOMEM; @@ -3645,8 +3652,6 @@ int cmd_sched(int argc, const char **argv) free(sched.curr_pid); free(sched.cpu_last_switched); free(sched.curr_thread); - mutex_destroy(&sched.start_work_mutex); - mutex_destroy(&sched.work_done_wait_mutex); return ret; }