From nobody Mon Apr 6 12:33:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A81B8C38145 for ; Thu, 8 Sep 2022 01:37:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbiIHBhT (ORCPT ); Wed, 7 Sep 2022 21:37:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbiIHBhH (ORCPT ); Wed, 7 Sep 2022 21:37:07 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A4E8C6CF5; Wed, 7 Sep 2022 18:37:05 -0700 (PDT) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MNM8B6HHfz1P6jw; Thu, 8 Sep 2022 09:33:14 +0800 (CST) Received: from kwepemm600008.china.huawei.com (7.193.23.88) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 8 Sep 2022 09:37:04 +0800 Received: from huawei.com (10.175.100.227) by kwepemm600008.china.huawei.com (7.193.23.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 8 Sep 2022 09:37:02 +0800 From: Shang XiaoJing To: , , , , , , , , CC: Subject: [PATCH 4/4] perf timechart: Add p_state_end helper Date: Thu, 8 Sep 2022 10:11:41 +0800 Message-ID: <20220908021141.27134-5-shangxiaojing@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220908021141.27134-1-shangxiaojing@huawei.com> References: <20220908021141.27134-1-shangxiaojing@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.100.227] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600008.china.huawei.com (7.193.23.88) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Wrap repeated code in helper functions p_state_end, which alloc a new power_event recording last pstate, and insert to the head of tchart->power_events. Signed-off-by: Shang XiaoJing --- tools/perf/builtin-timechart.c | 37 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 667a94d45493..c36296bb7637 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -376,16 +376,13 @@ static void c_state_end(struct timechart *tchart, int= cpu, u64 timestamp) tchart->power_events =3D pwr; } =20 -static void p_state_change(struct timechart *tchart, int cpu, u64 timestam= p, u64 new_freq) +static struct power_event *p_state_end(struct timechart *tchart, int cpu, + u64 timestamp) { - struct power_event *pwr; - - if (new_freq > 8000000) /* detect invalid data */ - return; + struct power_event *pwr =3D zalloc(sizeof(*pwr)); =20 - pwr =3D zalloc(sizeof(*pwr)); if (!pwr) - return; + return NULL; =20 pwr->state =3D cpus_pstate_state[cpu]; pwr->start_time =3D cpus_pstate_start_times[cpu]; @@ -393,11 +390,23 @@ static void p_state_change(struct timechart *tchart, = int cpu, u64 timestamp, u64 pwr->cpu =3D cpu; pwr->type =3D PSTATE; pwr->next =3D tchart->power_events; - if (!pwr->start_time) pwr->start_time =3D tchart->first_time; =20 tchart->power_events =3D pwr; + return pwr; +} + +static void p_state_change(struct timechart *tchart, int cpu, u64 timestam= p, u64 new_freq) +{ + struct power_event *pwr; + + if (new_freq > 8000000) /* detect invalid data */ + return; + + pwr =3D p_state_end(tchart, cpu, timestamp); + if (!pwr) + return; =20 cpus_pstate_state[cpu] =3D new_freq; cpus_pstate_start_times[cpu] =3D timestamp; @@ -705,22 +714,12 @@ static void end_sample_processing(struct timechart *t= chart) #endif /* P state */ =20 - pwr =3D zalloc(sizeof(*pwr)); + pwr =3D p_state_end(tchart, cpu, tchart->last_time); if (!pwr) return; =20 - pwr->state =3D cpus_pstate_state[cpu]; - pwr->start_time =3D cpus_pstate_start_times[cpu]; - pwr->end_time =3D tchart->last_time; - pwr->cpu =3D cpu; - pwr->type =3D PSTATE; - pwr->next =3D tchart->power_events; - - if (!pwr->start_time) - pwr->start_time =3D tchart->first_time; if (!pwr->state) pwr->state =3D tchart->min_freq; - tchart->power_events =3D pwr; } } =20 --=20 2.17.1