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; } From patchwork Tue Feb 6 08:32:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Jihong X-Patchwork-Id: 197253 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1401833dyb; Tue, 6 Feb 2024 00:41:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2XzKZVoVdmNxEobOurO1yfP3jOC9oZFYuqSAaazhhLBYEvQugVoKOHrZGmdpAkJ9z25y4 X-Received: by 2002:a50:ee12:0:b0:55f:63ac:2425 with SMTP id g18-20020a50ee12000000b0055f63ac2425mr970068eds.41.1707208898535; Tue, 06 Feb 2024 00:41:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707208898; cv=pass; d=google.com; s=arc-20160816; b=ZC2Rd3DAFhFCAB6ESF+uNL+ZJLX5dimJj2WNPlyK9oVLmxJ5uI3bB6fBCuGa42D7Xi w/BfkAk6I7Rz57QFY6et+8lEQmbmyiQS4mGKcNceBzQVRLOerB4ETi4hZAx1TDFDL/8C UxCRBtuWFOD9Sb/DHu5eRPGBiJb0lNQo2fs2xRLGNcB9CfJfTqzerGTcB9IlpE/jn4j/ zMDRCfxL9YSYoqinMWJ38ic1JyoufOWZFFoVErEyqUJd+BkZQplmU3sf75END+Qgox75 WcchKBNecdEFAGMBWsclywlnOFGBYPn1g4pBWww+k7X4iWNRuD84HZ67/6Rm2Ve/iH2B QxdA== 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=txm05IxhM6kALSPYkeA2RcR8yTJqfkpB5Bizzp5qP18=; fh=jPKyLtQEHeL+z1v6YbIP2uDnqnabwfy5kW9aEPQ2/1U=; b=tZY0dZruM3G/CLlLtumBWRUp9dXWKrmIc1RvNbCwEhJathgOJsCupkGBPiliGMoUMx 1/IHJc3lIqd0LODkZAwoX6MHjIFAFZo5mweuE/9KokvHQH1UE1thw8m3krNbk7SSgeLS JWoHrpYZ0/JEp/RO7y80vgEe0ZAuKJ11/pZVJ+QAsZyvYH4wKHD2a6UvrrrZzjMYi3dS GZjG6+//Em/BNaIb5qwI/0t+dzxq/5W/92q49+BNEYmovHag3ddMbeHNDiWlVfq9YoH6 j+UYyOzXKtMU3orRxGuboGcK6DdevLUsW+BarbkXBH/wOnstKeDcJ1BjMmlo8E71q0lT 45VQ==; 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-54508-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54508-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com X-Forwarded-Encrypted: i=1; AJvYcCX4DNJph+9KnCrof4zMUxdX18Ipvd2MBM4dGxEjIL323pz3jVvxXn0lYYqLyGgqy+MGZycLSTcvi9IfVb011oXMIRggYQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b99-20020a509f6c000000b0055ef0580007si894139edf.527.2024.02.06.00.41.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 00:41:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54508-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-54508-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54508-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0F0F31F21D28 for ; Tue, 6 Feb 2024 08:41:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18FA412DDA3; Tue, 6 Feb 2024 08:37:38 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 9ACCE12D17F; Tue, 6 Feb 2024 08:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707208656; cv=none; b=dP9hAw2f+DJy2RK6WhSXaeNS14KPcPtd5eObLMa2BYagY7GJjh8a0NricBUm8X2/n7XlDwqINJbgC3cCLYjbMx80VEvdalXCH8ojKItFfyTSAFBgVLtVqOpQCenc2EQ2KGdy3CVw+Ct54/s6cv/M74PQq+GGfQ/bL905OrP6L8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707208656; c=relaxed/simple; bh=KD6XdYRpKTdS6+uyeil6KtGFbsdwckMxsTa/vEY6iDM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JtT2RM6JlcoD2jpQPrGpX+V+ifIspRmw6d4dFUR32KmUA9kkIOeGXaUi7SGqTlovakKXqHLx60Z3K8Jz/R0GA63IIQuDtpAArMSGcesMVMyKF4rr6B9eO0Bi5X+/1w5HeAB2Ahv4RbkfSF459LGSnbX8Evua0Zn2R/4fKZlw21w= 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.187 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.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4TTc5y6WZKzsWk2; Tue, 6 Feb 2024 16:36:06 +0800 (CST) Received: from kwepemm600003.china.huawei.com (unknown [7.193.23.202]) by mail.maildlp.com (Postfix) with ESMTPS id ADF9018006C; 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:26 +0800 From: Yang Jihong To: , , , , , , , , , , CC: Subject: [PATCH v2 2/5] perf sched: Fix memory leak in perf_sched__map() Date: Tue, 6 Feb 2024 08:32:25 +0000 Message-ID: <20240206083228.172607-3-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: 1790138277611837161 X-GMAIL-MSGID: 1790138277611837161 perf_sched__map() needs to free memory of map_cpus, color_pids and color_cpus in normal path and rollback allocated memory in error path. Signed-off-by: Yang Jihong --- tools/perf/builtin-sched.c | 41 ++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 08dec557e6be..1513e87ce4f2 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -3208,8 +3208,6 @@ static int perf_sched__lat(struct perf_sched *sched) static int setup_map_cpus(struct perf_sched *sched) { - struct perf_cpu_map *map; - sched->max_cpu.cpu = sysconf(_SC_NPROCESSORS_CONF); if (sched->map.comp) { @@ -3218,16 +3216,15 @@ static int setup_map_cpus(struct perf_sched *sched) return -1; } - if (!sched->map.cpus_str) - return 0; - - map = perf_cpu_map__new(sched->map.cpus_str); - if (!map) { - pr_err("failed to get cpus map from %s\n", sched->map.cpus_str); - return -1; + if (sched->map.cpus_str) { + sched->map.cpus = perf_cpu_map__new(sched->map.cpus_str); + if (!sched->map.cpus) { + pr_err("failed to get cpus map from %s\n", sched->map.cpus_str); + zfree(&sched->map.comp_cpus); + return -1; + } } - sched->map.cpus = map; return 0; } @@ -3267,20 +3264,34 @@ static int setup_color_cpus(struct perf_sched *sched) static int perf_sched__map(struct perf_sched *sched) { + int rc = -1; + if (setup_map_cpus(sched)) - return -1; + return rc; if (setup_color_pids(sched)) - return -1; + goto out_put_map_cpus; if (setup_color_cpus(sched)) - return -1; + goto out_put_color_pids; setup_pager(); if (perf_sched__read_events(sched)) - return -1; + goto out_put_color_cpus; + + rc = 0; print_bad_events(sched); - return 0; + +out_put_color_cpus: + perf_cpu_map__put(sched->map.color_cpus); + +out_put_color_pids: + perf_thread_map__put(sched->map.color_pids); + +out_put_map_cpus: + zfree(&sched->map.comp_cpus); + perf_cpu_map__put(sched->map.cpus); + return rc; } static int perf_sched__replay(struct perf_sched *sched) From patchwork Tue Feb 6 08:32:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Jihong X-Patchwork-Id: 197250 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1401146dyb; Tue, 6 Feb 2024 00:39:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWy236whZa9V6JP7/Gwu2C+ibTgtBLFLOXE/OKQkWS8sL/5UwGgjSeWCP5WqUM0Iib2mKh X-Received: by 2002:a05:6122:2a1:b0:4c0:2416:6fba with SMTP id 1-20020a05612202a100b004c024166fbamr1263249vkq.7.1707208774301; Tue, 06 Feb 2024 00:39:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707208774; cv=pass; d=google.com; s=arc-20160816; b=RlkKTIWWO5KwQvteuwSbJDVeC+Q3qKWZIa/msYFJCKp69M6KkbD7E+TxjQDTBm6kln dCRZXQZ2J5514lm2kZIhAymLmHTbidB64rPO8RJnA1QprkB6chjMZIbL0mXi987BruN3 qZE938RMcbk3qbu4mnlvEA5XLewSvnCvadJw8fQ//cdrxee6MtVDDNzHyAhbHuHh03sI Eo8AvbiFqQwS7YRvtKyelyV0gJGPEMnwKdT5s9mwv5/zLNg2RpuMAdJRWFWflbTK4dQ5 OwB3TcHtiTnwrubge/KMUV+ANfwsPKEKwvouHhUcUS7gBhXDhIeV5oU/ohNzXjKvfS3H Dkyg== 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=IvArJuM1zFmcrU4fyyTURSVcLPsm8Ztgf3ct5iyPIFU=; fh=CmTlhpy0PtHwRDeZ6BIcR005QHuz5SEYO7zJCXHg3B0=; b=GTik8f4oiIbTukuRtB3nAP7HVrqqCR+XoMYjCN40ooHiIn4/w3Vjzp80qzKDywmKsH eoFkQ3oRN8mclDU8nE8jSFsyHDmQI8/yzWsizUil1mBbebRJm3a05Eenk5070smXiKRB k3/Ess0vO73SGvHPwz31Yxj9mJQEJPFDRDStolzgT7urKYAdBaHoJIudJ0p57hGhrE2H uWeQMoTkZJQqkggY+HkWbmrsQsR11Ehm4QCQri3Q/PFaxMruysJBrpKk4QAzN7JbBH7K PbiLhw5y2jx38+wsHRrDmHpP3psCbHu+mOwgBaQt/JLJxhlBzr0QJoHiuD5Q/CzRnNwz d8LQ==; 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-54504-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54504-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com X-Forwarded-Encrypted: i=1; AJvYcCVDJGR2Z6tZVSWi1qWS/v8Hr162Psy8q+LGmydIaMLF7nOJ1CdUT3zRAspeHs6fB4DTvaQ6M0IjuIIuF08T744uzGL+1g== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l14-20020ad4452e000000b0068c8aa49aefsi1876176qvu.166.2024.02.06.00.39.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 00:39:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54504-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-54504-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54504-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 0A2391C245E2 for ; Tue, 6 Feb 2024 08:39:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 62B2312D170; Tue, 6 Feb 2024 08:37:34 +0000 (UTC) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 6B70612BEBE; Tue, 6 Feb 2024 08:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707208652; cv=none; b=WFsajuHjMuhVWkMcCmrDyPoRxvtk/shGX+pS9OcnGDI+EMzFfOXaBUC1V1p+cPfO7a8TcIaG4OfL8gSBXz4ShaoFJ5Ubkjl9GnpJVXVnv7avXpE92/GeK4cDaz4uHfiTuUiYo/Eg7dD0UmY2nI19EPF7pUCZrKgGnG/nCRDju0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707208652; c=relaxed/simple; bh=pGKy0/JDwlucTovijWCK5UFwzkM9x2dYOV+LQPogVlE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RCXn07qZuEphKfM+R1NA2e1tLYlDFB64XKhkXxhahP8K9iL5BbqIqT9j2BgYfb66h1Ju9vuxsGzeeqZbLxZ6P6+BuOtLwOmfaMX+AoqLKdZGO3j7Mt6GsygWA9dY0TAT32Jhr79MBmJFx5jjLlfWoy1J7/qjVzmpCtOoN2uWfmc= 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.191 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.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TTc2C5FVdz1FKN3; Tue, 6 Feb 2024 16:32:51 +0800 (CST) Received: from kwepemm600003.china.huawei.com (unknown [7.193.23.202]) by mail.maildlp.com (Postfix) with ESMTPS id 2E5791A0178; Tue, 6 Feb 2024 16:37:27 +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:26 +0800 From: Yang Jihong To: , , , , , , , , , , CC: Subject: [PATCH v2 3/5] perf sched: Move curr_thread initialization to perf_sched__map() Date: Tue, 6 Feb 2024 08:32:26 +0000 Message-ID: <20240206083228.172607-4-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: 1790138148066560057 X-GMAIL-MSGID: 1790138148066560057 The curr_thread is used only for the 'perf sched map'. Put initialization in perf_sched__map() 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 15.526 MB perf.data (140095 samples) ] # perf sched map *A0 451264.532445 secs A0 => migration/0:15 *. 451264.532468 secs . => swapper:0 . *B0 451264.532537 secs B0 => migration/1:21 . *. 451264.532560 secs . . *C0 451264.532644 secs C0 => migration/2:27 . . *. 451264.532668 secs . . . *D0 451264.532753 secs D0 => migration/3:33 . . . *. 451264.532778 secs . . . . *E0 451264.532861 secs E0 => migration/4:39 . . . . *. 451264.532886 secs . . . . . *F0 451264.532973 secs F0 => migration/5:45 A7 A7 A7 A7 A7 *A7 . . . . . . . . . . 451264.790785 secs A7 A7 A7 A7 A7 A7 *A7 . . . . . . . . . 451264.790858 secs A7 A7 A7 A7 A7 A7 A7 *A7 . . . . . . . . 451264.790934 secs A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . . . . . 451264.791004 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . . . . 451264.791075 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . . . 451264.791143 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . . 451264.791232 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . 451264.791336 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . 451264.791407 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . 451264.791484 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 451264.791553 secs # echo $? 0 Signed-off-by: Yang Jihong --- tools/perf/builtin-sched.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 1513e87ce4f2..b56a573ed06c 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -3266,9 +3266,13 @@ static int perf_sched__map(struct perf_sched *sched) { int rc = -1; - if (setup_map_cpus(sched)) + sched->curr_thread = calloc(MAX_CPUS, sizeof(*(sched->curr_thread))); + if (!sched->curr_thread) return rc; + if (setup_map_cpus(sched)) + goto out_free_curr_thread; + if (setup_color_pids(sched)) goto out_put_map_cpus; @@ -3291,6 +3295,9 @@ static int perf_sched__map(struct perf_sched *sched) out_put_map_cpus: zfree(&sched->map.comp_cpus); perf_cpu_map__put(sched->map.cpus); + +out_free_curr_thread: + zfree(&sched->curr_thread); return rc; } @@ -3576,11 +3583,6 @@ int cmd_sched(int argc, const char **argv) unsigned int i; int ret = 0; - sched.curr_thread = calloc(MAX_CPUS, sizeof(*sched.curr_thread)); - if (!sched.curr_thread) { - ret = -ENOMEM; - goto out; - } sched.cpu_last_switched = calloc(MAX_CPUS, sizeof(*sched.cpu_last_switched)); if (!sched.cpu_last_switched) { ret = -ENOMEM; @@ -3662,7 +3664,6 @@ int cmd_sched(int argc, const char **argv) out: free(sched.curr_pid); free(sched.cpu_last_switched); - free(sched.curr_thread); return ret; } From patchwork Tue Feb 6 08:32:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Jihong X-Patchwork-Id: 197252 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1401439dyb; Tue, 6 Feb 2024 00:40:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrJC07YMyAXuJRkHDRWlq5BLiQjwbsdLatb82HyO5bv51NmXnIosveZZmkqzPXgFJlR/EL X-Received: by 2002:a05:620a:98f:b0:785:8c17:dfa1 with SMTP id x15-20020a05620a098f00b007858c17dfa1mr1683163qkx.61.1707208828672; Tue, 06 Feb 2024 00:40:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707208828; cv=pass; d=google.com; s=arc-20160816; b=KidMXFkhchLPwfORckDs1NsPPtFHO+58DUw7Jo6OffDGtbMTsCOCL9LH5VS/BHDSiT f4992nAUQhKdcEaLoeIME92QqrOaokRvjyue1+3ZAzIs0NNMSxDkUupBmQWnnZ7XrRIF gAoXL4XgCmgvYaxdYqCjIKSw1NzsupAgNfL7lqwDCKi8MHRVWUaBidahHn5kXrj+V2uV 0f3ZtRPdmFugL8u8FEt9U4zn2bJ7jMvcNpbyDOQ9oPAuskHIfvSRcQomUeWhK1xSFD3Y g9yl6GHubh/6nSASxOjYiiFNGpJsZktrRVMlA67OjVIaKJQlmSs45g5xq87fyghYHtLa udug== 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=nKBYEtS/inY9d0ZtRXeFh/IgwFlyQTq235PW778P/tY=; fh=56NRUEJkwMmxI43ByaBn6poJuxX5E+Uxp/5faKlrpvU=; b=mNcFxDEh7eV1ovK7gD07S5iwmMpeSWAcyamBrTpn8cLW77IgVnMG8bWhAlkQgHo9J6 8f6qKqSNFAUm1I5jJ49ssvjWpspzvydDdfVbN1+cH4ATM5tHLObNf42IB56djObhj+vG mDPw04u4fEUTsWYkqYLU8HuR8aJ6yvymbRy7rpB+leA+QQ7n80Th+emO5svqh4DxIQeP zX7p3LSVxUbM3pu79/PP7v66KpFnHzbsPnijVZMgm6NQJYKRoT28wHUwXqqg22EBh9Kx BOvfjKmiURc1sSvTnNTiAF12izPqXNGHuPRF+tZyArGDPC1XPyaSBQcFlDIb0vkBuhP/ 1L6A==; 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-54505-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54505-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com X-Forwarded-Encrypted: i=1; AJvYcCVBVXL2HZ0pK+dW7W7o6p+IK2AWx7ykPHY6RNgjzY2ybchkZ3j7nXzXRJRjxpjcM9fuqJNmeHf7neXDiV2OAGZqe+iEbA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id qs15-20020a05620a394f00b00785752e87e0si2076661qkn.694.2024.02.06.00.40.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 00:40:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54505-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-54505-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54505-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 AE1521C245E7 for ; Tue, 6 Feb 2024 08:40:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F170012D779; Tue, 6 Feb 2024 08:37:35 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 BAD7B12BF0F; Tue, 6 Feb 2024 08:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707208652; cv=none; b=ZE3Ty9Py6tGF2SKR4dQGgI2hZzK/d/KkStcqCe15Bsg+UzpHPlbU+3WB+bKeHPJrR7wx545Ipwnm6ZfX683Yju1ZUUd91KqBEJqlWtTg/2honQtE7O+xaqcVaTHi7y3b5STT8fX0J0rJ/D2ngCmMDM/MAHSbRtw+wnEzH+JTd3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707208652; c=relaxed/simple; bh=zdWxmqTwFrfRIDgAj0sfZeAbu8v57sL5+EShC9x6of8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gWWuRudfE0NHDPGUTvMq74ncv6LYCawIlvKt9BN6BMG1eGG/+Zfa4gLnrbJGWxWOX1sOxD7i79ZLfCy1ptApqjHaG7ESXq/Z0tZfDfnLuBcD5teWtkRATIPiVwa1hM4rKARZZ0IRZkyP4dya5mH+aIBXDa8z4g4qmNdz3vIrQgA= 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.190 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.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TTc6F23Nzz1xmt7; Tue, 6 Feb 2024 16:36:21 +0800 (CST) Received: from kwepemm600003.china.huawei.com (unknown [7.193.23.202]) by mail.maildlp.com (Postfix) with ESMTPS id 9C31F140382; Tue, 6 Feb 2024 16:37:27 +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:27 +0800 From: Yang Jihong To: , , , , , , , , , , CC: Subject: [PATCH v2 4/5] perf sched: Move curr_pid and cpu_last_switched initialization to perf_sched__{lat|map|replay}() Date: Tue, 6 Feb 2024 08:32:27 +0000 Message-ID: <20240206083228.172607-5-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: 1790138204594206802 X-GMAIL-MSGID: 1790138204594206802 The curr_pid and cpu_last_switched are used only for the 'perf sched replay/latency/map'. Put their initialization in perf_sched__{lat|map|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.209 [sec] [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 16.456 MB perf.data (147907 samples) ] # perf sched lat ------------------------------------------------------------------------------------------------------------------------------------------- Task | Runtime ms | Switches | Avg delay ms | Max delay ms | Max delay start | Max delay end | ------------------------------------------------------------------------------------------------------------------------------------------- sched-messaging:(401) | 2990.699 ms | 38705 | avg: 0.661 ms | max: 67.046 ms | max start: 456532.624830 s | max end: 456532.691876 s qemu-system-x86:(7) | 179.764 ms | 2191 | avg: 0.152 ms | max: 21.857 ms | max start: 456532.576434 s | max end: 456532.598291 s sshd:48125 | 0.522 ms | 2 | avg: 0.037 ms | max: 0.046 ms | max start: 456532.514610 s | max end: 456532.514656 s ksoftirqd/11:82 | 0.063 ms | 1 | avg: 0.005 ms | max: 0.005 ms | max start: 456532.769366 s | max end: 456532.769371 s kworker/9:0-mm_:34624 | 0.233 ms | 20 | avg: 0.004 ms | max: 0.007 ms | max start: 456532.690804 s | max end: 456532.690812 s migration/13:93 | 0.000 ms | 1 | avg: 0.004 ms | max: 0.004 ms | max start: 456532.512669 s | max end: 456532.512674 s ----------------------------------------------------------------------------------------------------------------- TOTAL: | 3180.750 ms | 41368 | --------------------------------------------------- # echo $? 0 # perf sched map *A0 456532.510141 secs A0 => migration/0:15 *. 456532.510171 secs . => swapper:0 . *B0 456532.510261 secs B0 => migration/1:21 . *. 456532.510279 secs L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 *L7 . . . . 456532.785979 secs L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 *L7 . . . 456532.786054 secs L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 *L7 . . 456532.786127 secs L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 *L7 . 456532.786197 secs L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 L7 *L7 456532.786270 secs # echo $? 0 # perf sched replay run measurement overhead: 108 nsecs sleep measurement overhead: 66473 nsecs the run test took 1000002 nsecs the sleep test took 1082686 nsecs nr_run_events: 49334 nr_sleep_events: 50054 nr_wakeup_events: 34701 target-less wakeups: 165 multi-target wakeups: 766 task 0 ( swapper: 0), nr_events: 15419 task 1 ( swapper: 1), nr_events: 1 task 2 ( swapper: 2), nr_events: 1 task 715 ( sched-messaging: 110248), nr_events: 1438 task 716 ( sched-messaging: 110249), nr_events: 512 task 717 ( sched-messaging: 110250), nr_events: 500 task 718 ( sched-messaging: 110251), nr_events: 537 task 719 ( sched-messaging: 110252), nr_events: 823 ------------------------------------------------------------ #1 : 1325.288, ravg: 1325.29, cpu: 7823.35 / 7823.35 #2 : 1363.606, ravg: 1329.12, cpu: 7655.53 / 7806.56 #3 : 1349.494, ravg: 1331.16, cpu: 7544.80 / 7780.39 #4 : 1311.488, ravg: 1329.19, cpu: 7495.13 / 7751.86 #5 : 1309.902, ravg: 1327.26, cpu: 7266.65 / 7703.34 #6 : 1309.535, ravg: 1325.49, cpu: 7843.86 / 7717.39 #7 : 1316.482, ravg: 1324.59, cpu: 7854.41 / 7731.09 #8 : 1366.604, ravg: 1328.79, cpu: 7955.81 / 7753.57 #9 : 1326.286, ravg: 1328.54, cpu: 7466.86 / 7724.90 #10 : 1356.653, ravg: 1331.35, cpu: 7566.60 / 7709.07 # echo $? 0 Signed-off-by: Yang Jihong --- tools/perf/builtin-sched.c | 94 +++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 33 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index b56a573ed06c..b248c433529a 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -3167,14 +3167,44 @@ static void perf_sched__merge_lat(struct perf_sched *sched) } } +static int setup_cpus_switch_event(struct perf_sched *sched) +{ + unsigned int i; + + sched->cpu_last_switched = calloc(MAX_CPUS, sizeof(*(sched->cpu_last_switched))); + if (!sched->cpu_last_switched) + return -1; + + sched->curr_pid = malloc(MAX_CPUS * sizeof(*(sched->curr_pid))); + if (!sched->curr_pid) { + zfree(&sched->cpu_last_switched); + return -1; + } + + for (i = 0; i < MAX_CPUS; i++) + sched->curr_pid[i] = -1; + + return 0; +} + +static void free_cpus_switch_event(struct perf_sched *sched) +{ + zfree(&sched->curr_pid); + zfree(&sched->cpu_last_switched); +} + static int perf_sched__lat(struct perf_sched *sched) { + int rc = -1; struct rb_node *next; setup_pager(); + if (setup_cpus_switch_event(sched)) + return rc; + if (perf_sched__read_events(sched)) - return -1; + goto out_free_cpus_switch_event; perf_sched__merge_lat(sched); perf_sched__sort_lat(sched); @@ -3203,7 +3233,11 @@ static int perf_sched__lat(struct perf_sched *sched) print_bad_events(sched); printf("\n"); - return 0; + rc = 0; + +out_free_cpus_switch_event: + free_cpus_switch_event(sched); + return rc; } static int setup_map_cpus(struct perf_sched *sched) @@ -3270,9 +3304,12 @@ static int perf_sched__map(struct perf_sched *sched) if (!sched->curr_thread) return rc; - if (setup_map_cpus(sched)) + if (setup_cpus_switch_event(sched)) goto out_free_curr_thread; + if (setup_map_cpus(sched)) + goto out_free_cpus_switch_event; + if (setup_color_pids(sched)) goto out_put_map_cpus; @@ -3296,6 +3333,9 @@ static int perf_sched__map(struct perf_sched *sched) zfree(&sched->map.comp_cpus); perf_cpu_map__put(sched->map.cpus); +out_free_cpus_switch_event: + free_cpus_switch_event(sched); + out_free_curr_thread: zfree(&sched->curr_thread); return rc; @@ -3309,6 +3349,10 @@ static int perf_sched__replay(struct perf_sched *sched) mutex_init(&sched->start_work_mutex); mutex_init(&sched->work_done_wait_mutex); + ret = setup_cpus_switch_event(sched); + if (ret) + goto out_mutex_destroy; + calibrate_run_measurement_overhead(sched); calibrate_sleep_measurement_overhead(sched); @@ -3316,7 +3360,7 @@ static int perf_sched__replay(struct perf_sched *sched) ret = perf_sched__read_events(sched); if (ret) - goto out_mutex_destroy; + goto out_free_cpus_switch_event; printf("nr_run_events: %ld\n", sched->nr_run_events); printf("nr_sleep_events: %ld\n", sched->nr_sleep_events); @@ -3342,6 +3386,9 @@ static int perf_sched__replay(struct perf_sched *sched) sched->thread_funcs_exit = true; destroy_tasks(sched); +out_free_cpus_switch_event: + free_cpus_switch_event(sched); + out_mutex_destroy: mutex_destroy(&sched->start_work_mutex); mutex_destroy(&sched->work_done_wait_mutex); @@ -3580,21 +3627,7 @@ int cmd_sched(int argc, const char **argv) .switch_event = replay_switch_event, .fork_event = replay_fork_event, }; - unsigned int i; - int ret = 0; - - sched.cpu_last_switched = calloc(MAX_CPUS, sizeof(*sched.cpu_last_switched)); - if (!sched.cpu_last_switched) { - ret = -ENOMEM; - goto out; - } - sched.curr_pid = malloc(MAX_CPUS * sizeof(*sched.curr_pid)); - if (!sched.curr_pid) { - ret = -ENOMEM; - goto out; - } - for (i = 0; i < MAX_CPUS; i++) - sched.curr_pid[i] = -1; + int ret; argc = parse_options_subcommand(argc, argv, sched_options, sched_subcommands, sched_usage, PARSE_OPT_STOP_AT_NON_OPTION); @@ -3605,9 +3638,9 @@ int cmd_sched(int argc, const char **argv) * Aliased to 'perf script' for now: */ if (!strcmp(argv[0], "script")) { - ret = cmd_script(argc, argv); + return cmd_script(argc, argv); } else if (strlen(argv[0]) > 2 && strstarts("record", argv[0])) { - ret = __cmd_record(argc, argv); + return __cmd_record(argc, argv); } else if (strlen(argv[0]) > 2 && strstarts("latency", argv[0])) { sched.tp_handler = &lat_ops; if (argc > 1) { @@ -3616,7 +3649,7 @@ int cmd_sched(int argc, const char **argv) usage_with_options(latency_usage, latency_options); } setup_sorting(&sched, latency_options, latency_usage); - ret = perf_sched__lat(&sched); + return perf_sched__lat(&sched); } else if (!strcmp(argv[0], "map")) { if (argc) { argc = parse_options(argc, argv, map_options, map_usage, 0); @@ -3625,7 +3658,7 @@ int cmd_sched(int argc, const char **argv) } sched.tp_handler = &map_ops; setup_sorting(&sched, latency_options, latency_usage); - ret = perf_sched__map(&sched); + return perf_sched__map(&sched); } else if (strlen(argv[0]) > 2 && strstarts("replay", argv[0])) { sched.tp_handler = &replay_ops; if (argc) { @@ -3633,7 +3666,7 @@ int cmd_sched(int argc, const char **argv) if (argc) usage_with_options(replay_usage, replay_options); } - ret = perf_sched__replay(&sched); + return perf_sched__replay(&sched); } else if (!strcmp(argv[0], "timehist")) { if (argc) { argc = parse_options(argc, argv, timehist_options, @@ -3649,21 +3682,16 @@ int cmd_sched(int argc, const char **argv) parse_options_usage(NULL, timehist_options, "w", true); if (sched.show_next) parse_options_usage(NULL, timehist_options, "n", true); - ret = -EINVAL; - goto out; + return -EINVAL; } ret = symbol__validate_sym_arguments(); if (ret) - goto out; + return ret; - ret = perf_sched__timehist(&sched); + return perf_sched__timehist(&sched); } else { usage_with_options(sched_usage, sched_options); } -out: - free(sched.curr_pid); - free(sched.cpu_last_switched); - - return ret; + return 0; } From patchwork Tue Feb 6 08:32:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Jihong X-Patchwork-Id: 197249 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1401082dyb; Tue, 6 Feb 2024 00:39:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IH4Eu3bMKrxFCN/QNwpAcUcPAqV047BaxBG4RO/SuwKskOMGp0i1U/CUXbQJEndrw+NNF9B X-Received: by 2002:a2e:7c07:0:b0:2cf:425b:59ee with SMTP id x7-20020a2e7c07000000b002cf425b59eemr1306139ljc.24.1707208761292; Tue, 06 Feb 2024 00:39:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707208761; cv=pass; d=google.com; s=arc-20160816; b=McWiicwXt6VJ4ol7zJfXV0/X/+mK7lV8jDXgcuS3hKNRM3aykpBlEx+/d6by4auKo3 MEjXEONjXiEzdxOWXuRy5StUFFc0kVSSD0a8o6oWHAfjT33mL6QLTxX8yssvINO2vzJp oMCFUMEp/6ViqoyE1n7qB147kFVFCGTMQy6HUI2zTkd6+QHozPN1TtZNcQ9nZbCMFXcG B5Ib1uEot2DGEb7MdQ7xLV7K/VT9qb1Pc2xab1xULnvMqFVMhgUnpZOAou3asgU8Fznl aRPcm+iwYmYu9nG1eoiVXUb6XIUIDI8B9UD8vqbrPqkR3YziqSoxqYRLg+2UVmIyJ14e tdBw== 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=SyPhNS/N/Z8iH+Hbr0qv7AmqfEsTMPkvb4mWs/7kn6Q=; fh=e2+TC3/3CW6q+BrlheQxA2Prq9JQK9GgcqHJcDHYSek=; b=xfUOHxz3ZqFmUia0WE8ChGUotX4/d8GrOf++Ep9+aPMDqNwdDRJ+gifYH3wWGaAdqS IPjZdGfw+EdxmazDi2G1wMGDrQze6qKgYOjFG+2UhSKw+OB8ONdwg8eOEJTXqN0DULZq pWE4bOehTY03RuyaP4U+oLNleYzsc/8PjQXXcesSJqVOGTtA/A8fN7ffYDL1phPtXrKd Fdi9fIL+8KB+ANrr5LLB9VEx3unJ9GyXY/7xFm0nw2OLXOda0xDQlvelwJxF19JikP2V 2BKEXZ5lUgqpC/c5UHKOKUU6sqwVjWG8XbUr+rzo2Oym+6ihNLPfMbIqwWv3JEo2zAhz TODA==; 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-54503-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54503-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com X-Forwarded-Encrypted: i=1; AJvYcCVzz5rtsExBl0vySHcauDUBGB4qKDDgog6zhCCiv9bE1VM5mEq4305/sM4xJTQTofKoj/Jm4R54bYmmuWCyO/FkKwiHMQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y23-20020aa7ccd7000000b0055ed0e8eef0si886148edt.516.2024.02.06.00.39.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 00:39:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54503-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-54503-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54503-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 am.mirrors.kernel.org (Postfix) with ESMTPS id CD7A61F22E3F for ; Tue, 6 Feb 2024 08:39:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 09FF712D15E; Tue, 6 Feb 2024 08:37:34 +0000 (UTC) Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (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 6051A12BEB7; Tue, 6 Feb 2024 08:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707208652; cv=none; b=UvlrWof64JJvIqcb0eB7p0y91fSfAkgBMiYGMxsz7xymCuwBDUMJ5rJIyw6arGpucBWxNbG1IX1q4iLlIcA6kioy/3PrSIPLFkujwhKkXQM+3oAo7O3ya+aNPaVnpnDs9t3BbVwWUW16K3U/fcM+T/kR/yN8Wc2cW+2WPQ+SW7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707208652; c=relaxed/simple; bh=/xpATSrVpRUAb/2rTYqzEK+C8mbseixibxzL286QETI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YcyvtcHoM+yKFvqNNJ61zlA46iGlJGh4ju3bUXtTSH8a2XgnZNKFZg+3o0AKTl2CixMwR6kg+HR1/V9BReskV/558Qw2+PS9Jue/opcDUOm7/Hd8tkRTP8iaVZOqVkNc1tOs5vSY/Osc1HcSIol3Znt8yeQv1RXbbD5adbEqVpk= 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.32 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.162.112]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4TTc703Mnqz1vtCj; Tue, 6 Feb 2024 16:37:00 +0800 (CST) Received: from kwepemm600003.china.huawei.com (unknown [7.193.23.202]) by mail.maildlp.com (Postfix) with ESMTPS id 200C6140390; Tue, 6 Feb 2024 16:37:28 +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:27 +0800 From: Yang Jihong To: , , , , , , , , , , CC: Subject: [PATCH v2 5/5] perf thread_map: Free strlist on normal path in thread_map__new_by_tid_str() Date: Tue, 6 Feb 2024 08:32:28 +0000 Message-ID: <20240206083228.172607-6-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: 1790138133779703413 X-GMAIL-MSGID: 1790138133779703413 slist needs to be freed in both error path and normal path in thread_map__new_by_tid_str(). Fixes: b52956c961be3a04 ("perf tools: Allow multiple threads or processes in record, stat, top") Reviewed-by: Arnaldo Carvalho de Melo Signed-off-by: Yang Jihong --- tools/perf/util/thread_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index e848579e61a8..ea3b431b9783 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c @@ -280,13 +280,13 @@ struct perf_thread_map *thread_map__new_by_tid_str(const char *tid_str) threads->nr = ntasks; } out: + strlist__delete(slist); if (threads) refcount_set(&threads->refcnt, 1); return threads; out_free_threads: zfree(&threads); - strlist__delete(slist); goto out; }