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; }