From nobody Mon Apr 6 18:44:16 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 7A0F7ECAAD4 for ; Sat, 3 Sep 2022 06:51:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231799AbiICGvK (ORCPT ); Sat, 3 Sep 2022 02:51:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231666AbiICGvC (ORCPT ); Sat, 3 Sep 2022 02:51:02 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FB22481C0; Fri, 2 Sep 2022 23:51:01 -0700 (PDT) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MKQKv12F6zWfBL; Sat, 3 Sep 2022 14:46:27 +0800 (CST) Received: from kwepemm600008.china.huawei.com (7.193.23.88) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 3 Sep 2022 14:50:53 +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; Sat, 3 Sep 2022 14:50:52 +0800 From: Shang XiaoJing To: , , , , , , , , CC: Subject: [PATCH 1/3] perf clean: Add same_cmd_with_prefix helper Date: Sat, 3 Sep 2022 15:25:40 +0800 Message-ID: <20220903072542.27678-2-shangxiaojing@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220903072542.27678-1-shangxiaojing@huawei.com> References: <20220903072542.27678-1-shangxiaojing@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.100.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 function same_cmd_with_prefix for more clearly. Signed-off-by: Shang XiaoJing --- tools/perf/perf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/perf/perf.c b/tools/perf/perf.c index c21b3973641a..7af135dea1cd 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -99,10 +99,16 @@ struct pager_config { int val; }; =20 +static bool same_cmd_with_prefix(const char *var, struct pager_config *c, + const char *header) +{ + return (strstarts(var, header) && !strcmp(var + strlen(header), c->cmd)); +} + static int pager_command_config(const char *var, const char *value, void *= data) { struct pager_config *c =3D data; - if (strstarts(var, "pager.") && !strcmp(var + 6, c->cmd)) + if (same_cmd_with_prefix(var, c, "pager.")) c->val =3D perf_config_bool(var, value); return 0; } @@ -121,9 +127,9 @@ static int check_pager_config(const char *cmd) static int browser_command_config(const char *var, const char *value, void= *data) { struct pager_config *c =3D data; - if (strstarts(var, "tui.") && !strcmp(var + 4, c->cmd)) + if (same_cmd_with_prefix(var, c, "tui.")) c->val =3D perf_config_bool(var, value); - if (strstarts(var, "gtk.") && !strcmp(var + 4, c->cmd)) + if (same_cmd_with_prefix(var, c, "gtk.")) c->val =3D perf_config_bool(var, value) ? 2 : 0; return 0; } --=20 2.17.1 From nobody Mon Apr 6 18:44:16 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 0FA7CECAAD4 for ; Sat, 3 Sep 2022 06:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232712AbiICGvH (ORCPT ); Sat, 3 Sep 2022 02:51:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232291AbiICGu6 (ORCPT ); Sat, 3 Sep 2022 02:50:58 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F309549B56; Fri, 2 Sep 2022 23:50:56 -0700 (PDT) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MKQLk6ntfzkWJq; Sat, 3 Sep 2022 14:47:10 +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; Sat, 3 Sep 2022 14:50:54 +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; Sat, 3 Sep 2022 14:50:53 +0800 From: Shang XiaoJing To: , , , , , , , , CC: Subject: [PATCH 2/3] perf c2c: Add helpers to get counts of loads or stores Date: Sat, 3 Sep 2022 15:25:41 +0800 Message-ID: <20220903072542.27678-3-shangxiaojing@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220903072542.27678-1-shangxiaojing@huawei.com> References: <20220903072542.27678-1-shangxiaojing@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.100.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 get_load_llc_misses, get_load_cache_hits. For consistence, helper function get_stores is wraped as well. Signed-off-by: Shang XiaoJing --- tools/perf/builtin-c2c.c | 65 +++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 653e13b5037e..12f272811487 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -673,28 +673,35 @@ STAT_FN(ld_l2hit) STAT_FN(ld_llchit) STAT_FN(rmt_hit) =20 -static uint64_t total_records(struct c2c_stats *stats) +static uint64_t get_load_llc_misses(struct c2c_stats *stats) { - uint64_t lclmiss, ldcnt, total; - - lclmiss =3D stats->lcl_dram + - stats->rmt_dram + - stats->rmt_hitm + - stats->rmt_hit; + return stats->lcl_dram + + stats->rmt_dram + + stats->rmt_hitm + + stats->rmt_hit; +} =20 - ldcnt =3D lclmiss + - stats->ld_fbhit + - stats->ld_l1hit + - stats->ld_l2hit + - stats->ld_llchit + - stats->lcl_hitm; +static uint64_t get_load_cache_hits(struct c2c_stats *stats) +{ + return stats->ld_fbhit + + stats->ld_l1hit + + stats->ld_l2hit + + stats->ld_llchit + + stats->lcl_hitm; +} =20 - total =3D ldcnt + - stats->st_l1hit + - stats->st_l1miss + - stats->st_na; +static uint64_t get_stores(struct c2c_stats *stats) +{ + return stats->st_l1hit + + stats->st_l1miss + + stats->st_na; +} =20 - return total; +static uint64_t total_records(struct c2c_stats *stats) +{ + return get_load_llc_misses(stats) + + get_load_cache_hits(stats) + + get_stores(stats); } =20 static int @@ -731,21 +738,8 @@ tot_recs_cmp(struct perf_hpp_fmt *fmt __maybe_unused, =20 static uint64_t total_loads(struct c2c_stats *stats) { - uint64_t lclmiss, ldcnt; - - lclmiss =3D stats->lcl_dram + - stats->rmt_dram + - stats->rmt_hitm + - stats->rmt_hit; - - ldcnt =3D lclmiss + - stats->ld_fbhit + - stats->ld_l1hit + - stats->ld_l2hit + - stats->ld_llchit + - stats->lcl_hitm; - - return ldcnt; + return get_load_llc_misses(stats) + + get_load_cache_hits(stats); } =20 static int @@ -2370,10 +2364,7 @@ static void print_c2c__display_stats(FILE *out) int llc_misses; struct c2c_stats *stats =3D &c2c.hists.stats; =20 - llc_misses =3D stats->lcl_dram + - stats->rmt_dram + - stats->rmt_hit + - stats->rmt_hitm; + llc_misses =3D get_load_llc_misses(stats); =20 fprintf(out, "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D\n"); fprintf(out, " Trace Event Information \n"); --=20 2.17.1 From nobody Mon Apr 6 18:44:16 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 16DE9ECAAD4 for ; Sat, 3 Sep 2022 06:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232654AbiICGvE (ORCPT ); Sat, 3 Sep 2022 02:51:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231938AbiICGu6 (ORCPT ); Sat, 3 Sep 2022 02:50:58 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E0287E33A; Fri, 2 Sep 2022 23:50:57 -0700 (PDT) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4MKQNw4x5CzrS34; Sat, 3 Sep 2022 14:49:04 +0800 (CST) Received: from kwepemm600008.china.huawei.com (7.193.23.88) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 3 Sep 2022 14:50:54 +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; Sat, 3 Sep 2022 14:50:53 +0800 From: Shang XiaoJing To: , , , , , , , , CC: Subject: [PATCH 3/3] perf c2c: Prevent potential memory leak in c2c_he_zalloc Date: Sat, 3 Sep 2022 15:25:42 +0800 Message-ID: <20220903072542.27678-4-shangxiaojing@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220903072542.27678-1-shangxiaojing@huawei.com> References: <20220903072542.27678-1-shangxiaojing@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.100.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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" Free allocated resources when zalloc is failed for members in c2c_he, to prevent potential memory leak in c2c_he_zalloc. Signed-off-by: Shang XiaoJing Acked-by: Jiri Olsa --- tools/perf/builtin-c2c.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 12f272811487..5530433eda80 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -146,15 +146,15 @@ static void *c2c_he_zalloc(size_t size) =20 c2c_he->cpuset =3D bitmap_zalloc(c2c.cpus_cnt); if (!c2c_he->cpuset) - return NULL; + goto out_free_he; =20 c2c_he->nodeset =3D bitmap_zalloc(c2c.nodes_cnt); if (!c2c_he->nodeset) - return NULL; + goto out_free_cpuset; =20 c2c_he->node_stats =3D zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats)= ); if (!c2c_he->node_stats) - return NULL; + goto out_free_nodeset; =20 init_stats(&c2c_he->cstats.lcl_hitm); init_stats(&c2c_he->cstats.rmt_hitm); @@ -163,6 +163,14 @@ static void *c2c_he_zalloc(size_t size) init_stats(&c2c_he->cstats.load); =20 return &c2c_he->he; + +out_free_nodeset: + free(c2c_he->nodeset); +out_free_cpuset: + free(c2c_he->cpuset); +out_free_he: + free(c2c_he); + return NULL; } =20 static void c2c_he_free(void *he) --=20 2.17.1