From nobody Tue Feb 10 01:59:55 2026 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 0249F17592; Mon, 5 Feb 2024 10:51:16 +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=1707130279; cv=none; b=GZK/gnUDzufdSHaeVkw94t3lxcC1kUVcX2M8tg9vm6sbxSsEl4OhEAwCjOKYwfArLroJBcc/Zin8wHUGjKWBNyXduZWmWDg4d1u5vLwqZ3Yzhq+yfHXwD84IHC/bohMXPeF0q+4R/CFdgLfS11xU8M4KgGJ/WRITHvVjW1ASO5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707130279; c=relaxed/simple; bh=DoB2mUJR1wZPUsVzLJzgRS7J/E0RabBNUzGJ8kWAyao=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UkvoByI9BSS3UvcPZS6sCZLneFb59kMA/dc8iTip0dl0A+L7m9KCHA+e3Poni7jbCSsG28vmIsYzSOaTQU3sJIRoYtaFau7vUPcMHQj/XOUf8dH2mNqLKsKNWUinnbvXd2C6H69JSuFbg7qZSfig7NWOgW75QAmzpPp0iUst/TM= 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 4TT3673tzZz1gy2M; Mon, 5 Feb 2024 18:49:19 +0800 (CST) Received: from kwepemm600003.china.huawei.com (unknown [7.193.23.202]) by mail.maildlp.com (Postfix) with ESMTPS id 315371A0178; Mon, 5 Feb 2024 18:51:14 +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; Mon, 5 Feb 2024 18:51:13 +0800 From: Yang Jihong To: , , , , , , , , , , CC: Subject: [PATCH 3/5] perf sched: Move curr_thread initialization to perf_sched__map() Date: Mon, 5 Feb 2024 10:46:14 +0000 Message-ID: <20240205104616.132417-4-yangjihong1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240205104616.132417-1-yangjihong1@huawei.com> References: <20240205104616.132417-1-yangjihong1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600003.china.huawei.com (7.193.23.202) Content-Type: text/plain; charset="utf-8" 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 =3D=3D 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 45126= 4.532445 secs A0 =3D> migration/0:15 *. 45126= 4.532468 secs . =3D> swapper:0 . *B0 45126= 4.532537 secs B0 =3D> migration/1:21 . *. 45126= 4.532560 secs . . *C0 45126= 4.532644 secs C0 =3D> migration/2:27 . . *. 45126= 4.532668 secs . . . *D0 45126= 4.532753 secs D0 =3D> migration/3:33 . . . *. 45126= 4.532778 secs . . . . *E0 45126= 4.532861 secs E0 =3D> migration/4:39 . . . . *. 45126= 4.532886 secs . . . . . *F0 45126= 4.532973 secs F0 =3D> migration/5:45 A7 A7 A7 A7 A7 *A7 . . . . . . . . . . 45126= 4.790785 secs A7 A7 A7 A7 A7 A7 *A7 . . . . . . . . . 45126= 4.790858 secs A7 A7 A7 A7 A7 A7 A7 *A7 . . . . . . . . 45126= 4.790934 secs A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . . . . . 45126= 4.791004 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . . . . 45126= 4.791075 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . . . 45126= 4.791143 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . . 45126= 4.791232 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . 45126= 4.791336 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . 45126= 4.791407 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . 45126= 4.791484 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 45126= 4.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 26dbfa4aab61..54d79e560617 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 =3D -1; =20 - if (setup_map_cpus(sched)) + sched->curr_thread =3D calloc(MAX_CPUS, sizeof(*(sched->curr_thread))); + if (!sched->curr_thread) return rc; =20 + if (setup_map_cpus(sched)) + goto out_free_curr_thread; + if (setup_color_pids(sched)) goto out_free_map_cpus; =20 @@ -3291,6 +3295,9 @@ static int perf_sched__map(struct perf_sched *sched) out_free_map_cpus: free(sched->map.comp_cpus); perf_cpu_map__put(sched->map.cpus); + +out_free_curr_thread: + free(sched->curr_thread); return rc; } =20 @@ -3576,11 +3583,6 @@ int cmd_sched(int argc, const char **argv) unsigned int i; int ret =3D 0; =20 - sched.curr_thread =3D calloc(MAX_CPUS, sizeof(*sched.curr_thread)); - if (!sched.curr_thread) { - ret =3D -ENOMEM; - goto out; - } sched.cpu_last_switched =3D calloc(MAX_CPUS, sizeof(*sched.cpu_last_switc= hed)); if (!sched.cpu_last_switched) { ret =3D -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); =20 return ret; } --=20 2.34.1