From mboxrd@z Thu Jan 1 00:00:00 1970 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 DF102C433EF for ; Fri, 15 Jul 2022 06:39:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231129AbiGOGjd (ORCPT ); Fri, 15 Jul 2022 02:39:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231307AbiGOGiT (ORCPT ); Fri, 15 Jul 2022 02:38:19 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE8284D161 for ; Thu, 14 Jul 2022 23:37:49 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id j11-20020a05690212cb00b006454988d225so3364835ybu.10 for ; Thu, 14 Jul 2022 23:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=zRY4q8dGu1/hQr60xv0fzIHPiiQD0Rve6HsFB3hsbJk=; b=AJi1iXRo01uKEFISeKI3HajnGrt0gt02mv4Vy4WtJ1TCuImtAZAWRiloR+sTyW7HeI QQVbdkFBZ4E0v3QBE4YOBmFbwTBLl2snB12NDtrJ22TbVj8NhFzET12RHwMXYNG1Scc4 l1ueN/93t69/EIXH5G+VjObmwt6WWV1z7a85EFgtSLq355vNiM3p37CpT1BlIYFT6aDN VCCmZ2Kj/U8/P3bXH4atEWTHgLdWf8ToMX3usp9xzhgF32AqGFhPjmViPACvSYpS8Fhm BxJthOgOWyKbcF4teHyyPeWREdkbt+Uq9vW89Ni+Jwz5IoTegbw4j18bND2xvZ2Oz5gA uPGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=zRY4q8dGu1/hQr60xv0fzIHPiiQD0Rve6HsFB3hsbJk=; b=GzN53xPld6hVhKi29cyB+bngGhMUmLq/PlwQjdG+lbhz08uXjR6FaZRWyKeFklKPTW NqnLoVsg9TMCURD71noQFcO1ZQ00zeB/mTdhSg7Gu6Luute/ixp1LvgokugV7t7oZVXx UMMqQ6gmQMva93jomt9vFwfod40OmqVuPBsRJaeJlEYU3VJDW1AAyE+gL0u72D0SPFNM P5zrWBe6oXSO7PPHds/aHA/HyslfR0nxn6uphx9k79aufQzh1FimS54bc/W3Dsh1dkvp CawY6k0AZOkCtw4anyi+Sv2s4Z654e9exoahgFS/RNrZUUoNDXcHfX52x4StYL15YnJB cQLw== X-Gm-Message-State: AJIora8N2ExbeUY5K77+OM81fasi2mTcSQGvgxcHAZNtfd6d3P3qIVKf gjuFCBxIFQP33xXFGp1aHS45fVB1LtZU X-Google-Smtp-Source: AGRyM1s9U2WGZvSsdr/Y3vq4x60yOs1ZiOiNMMnYoJyQNsjTcwuj+5f84KosQYEXShYBFhmQB8yNcQKZT6RJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:e8fe:2a8e:e0f6:318d]) (user=irogers job=sendgmr) by 2002:a25:3b95:0:b0:66e:316c:159 with SMTP id i143-20020a253b95000000b0066e316c0159mr12911831yba.297.1657867068756; Thu, 14 Jul 2022 23:37:48 -0700 (PDT) Date: Thu, 14 Jul 2022 23:36:52 -0700 In-Reply-To: <20220715063653.3203761-1-irogers@google.com> Message-Id: <20220715063653.3203761-15-irogers@google.com> Mime-Version: 1.0 References: <20220715063653.3203761-1-irogers@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog Subject: [PATCH v1 14/15] perf metrics: Copy entire pmu_event in find metric From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pmu_event passed to the pmu_events_table_for_each_event is invalid after the loop. Copy the entire struct in metricgroup__find_metric. Reduce the scope of this function to static. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 33 ++++++++++++++++++--------------- tools/perf/util/metricgroup.h | 2 -- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 8ef44f4b5e9a..95f4b46dba09 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -879,6 +879,10 @@ struct metricgroup_add_iter_data { const struct pmu_events_table *table; }; +static bool metricgroup__find_metric(const char *metric, + const struct pmu_events_table *table, + struct pmu_event *pe); + static int add_metric(struct list_head *metric_list, const struct pmu_event *pe, const char *modifier, @@ -914,7 +918,7 @@ static int resolve_metric(struct list_head *metric_list, size_t bkt; struct to_resolve { /* The metric to resolve. */ - const struct pmu_event *pe; + struct pmu_event pe; /* * The key in the IDs map, this may differ from in case, * etc. from pe->metric_name. @@ -928,16 +932,15 @@ static int resolve_metric(struct list_head *metric_list, * the pending array. */ hashmap__for_each_entry(root_metric->pctx->ids, cur, bkt) { - const struct pmu_event *pe; + struct pmu_event pe; - pe = metricgroup__find_metric(cur->key, table); - if (pe) { + if (metricgroup__find_metric(cur->key, table, &pe)) { pending = realloc(pending, (pending_cnt + 1) * sizeof(struct to_resolve)); if (!pending) return -ENOMEM; - pending[pending_cnt].pe = pe; + memcpy(&pending[pending_cnt].pe, &pe, sizeof(pe)); pending[pending_cnt].key = cur->key; pending_cnt++; } @@ -952,7 +955,7 @@ static int resolve_metric(struct list_head *metric_list, * context. */ for (i = 0; i < pending_cnt; i++) { - ret = add_metric(metric_list, pending[i].pe, modifier, metric_no_group, + ret = add_metric(metric_list, &pending[i].pe, modifier, metric_no_group, root_metric, visited, table); if (ret) break; @@ -1073,7 +1076,7 @@ static int __add_metric(struct list_head *metric_list, struct metricgroup__find_metric_data { const char *metric; - const struct pmu_event *pe; + struct pmu_event *pe; }; static int metricgroup__find_metric_callback(const struct pmu_event *pe, @@ -1085,21 +1088,21 @@ static int metricgroup__find_metric_callback(const struct pmu_event *pe, if (!match_metric(pe->metric_name, data->metric)) return 0; - data->pe = pe; - return -1; + memcpy(data->pe, pe, sizeof(*pe)); + return 1; } -const struct pmu_event *metricgroup__find_metric(const char *metric, - const struct pmu_events_table *table) +static bool metricgroup__find_metric(const char *metric, + const struct pmu_events_table *table, + struct pmu_event *pe) { struct metricgroup__find_metric_data data = { .metric = metric, - .pe = NULL, + .pe = pe, }; - pmu_events_table_for_each_event(table, metricgroup__find_metric_callback, &data); - - return data.pe; + return pmu_events_table_for_each_event(table, metricgroup__find_metric_callback, &data) + ? true : false; } static int add_metric(struct list_head *metric_list, diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index f54d170043e9..016b3b1a289a 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -69,8 +69,6 @@ int metricgroup__parse_groups(const struct option *opt, bool metric_no_group, bool metric_no_merge, struct rblist *metric_events); -const struct pmu_event *metricgroup__find_metric(const char *metric, - const struct pmu_events_table *table); int metricgroup__parse_groups_test(struct evlist *evlist, const struct pmu_events_table *table, const char *str, -- 2.37.0.170.g444d1eabd0-goog From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92957C433EF for ; Fri, 15 Jul 2022 06:45:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=H6VenJWuQmAz2mZ5oSbNtiBSomieNzeGB0aJR4qorIA=; b=XCClWl3KGbrhK6Kk0+YpGMEBnG aHDPSSTpV1llRh2SQckthjQGhCbFqSn78u22I6GDNiC+V2l548PTF3X3zQGAHA9seyFP7+UEfNK+y XXh1aGUBRr2awP6J/T6OfsjwDGSv/oustEuk3jZi3MpPB2z1TkkCe4ZmCFKBzqisXjjpjiemd1AdP IeRdZ40kgmwdi5BImLY+OvDgUUBZkyCLlv+tiCAQ9lv4QsgzQPZnbMR8d3dMgq6PqP7GoKbMAZGq2 JHizGfEkraOD+gZ381LhQS6eTgme4lcjZGcRw8jeU5kTlLMvUYYzam2Y+pBmLtk3KQqm2rAk3IRwE LNtidTrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCF3R-004gYo-70; Fri, 15 Jul 2022 06:44:01 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCExb-004eDm-3h for linux-arm-kernel@bombadil.infradead.org; Fri, 15 Jul 2022 06:37:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=zRY4q8dGu1/hQr60xv0fzIHPiiQD0Rve6HsFB3hsbJk=; b=AuQT/WZyPkasMWVRwxUj8Yb5f4 3Qi/EMFptwc1sD3hGJbpB4zVJWgCRpLLdQ+zKyInXc0D3CFptAAYle0SGl+0q2010gbqoXOwOEySs IcqMo9umg5oYwcE0r3fWVIetDr/z0E40z7fHb04C3zJS3OwoUCbur3N+Hn8n8Qi4kRNHaI82T644g fE4WiDHqcS7rKNNWbGuqV+gDcMYt5tOJkBBadh96KIh1n8bMPQcDVCFNzxVAG44XfcjhvnoIVxMbx hv6PWwloWwow+GwoHh0IBHGbtfAOHLkeNmNKwOPVWdscwaUBagps97Bye+ycb2/B3cwT1Etdd5Ew9 ck5FtHVw==; Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCExS-0042PD-Q7 for linux-arm-kernel@lists.infradead.org; Fri, 15 Jul 2022 06:37:52 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31dfe25bd47so1032747b3.18 for ; Thu, 14 Jul 2022 23:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=zRY4q8dGu1/hQr60xv0fzIHPiiQD0Rve6HsFB3hsbJk=; b=AJi1iXRo01uKEFISeKI3HajnGrt0gt02mv4Vy4WtJ1TCuImtAZAWRiloR+sTyW7HeI QQVbdkFBZ4E0v3QBE4YOBmFbwTBLl2snB12NDtrJ22TbVj8NhFzET12RHwMXYNG1Scc4 l1ueN/93t69/EIXH5G+VjObmwt6WWV1z7a85EFgtSLq355vNiM3p37CpT1BlIYFT6aDN VCCmZ2Kj/U8/P3bXH4atEWTHgLdWf8ToMX3usp9xzhgF32AqGFhPjmViPACvSYpS8Fhm BxJthOgOWyKbcF4teHyyPeWREdkbt+Uq9vW89Ni+Jwz5IoTegbw4j18bND2xvZ2Oz5gA uPGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=zRY4q8dGu1/hQr60xv0fzIHPiiQD0Rve6HsFB3hsbJk=; b=AuG2Hkw8MaH7bEHqMcbPaYTaeF96p84IrJPUc8r28uMCY4R41466DBqOxKIpjU+DA+ MJlqYXsdKIEeLV6fQp/Awqw6Al/AF6UpbpKsr+s+fjnsZewoIMMcQbouXvBYFjkPFXu/ IyPhFOS4NoROhcAyo4b41ee6Fbm8fokkP5zozv0XqhCUZZ8VNPgSDJ9sDhMok541c1Kl DqSXx4H9W/cmvFXLIneGAOaK75mLzUjgDPo+ouduGurlmIn+zOONOcqnruPfHTJ+b+SC Y41/YXdRpwQVS0sVC9qu8mVA6DA690ZYGBxTpOIBgYidkK6RNkZvGHeIxwSnDygxugkJ GwEg== X-Gm-Message-State: AJIora8dyx8NW3Ylaicg+V8UDk1iHLzN/dDG1mryjvXT9QNkQwRlUFHg jZUE12M5AMoxyW7I2XyB2+jANfBwoswy X-Google-Smtp-Source: AGRyM1s9U2WGZvSsdr/Y3vq4x60yOs1ZiOiNMMnYoJyQNsjTcwuj+5f84KosQYEXShYBFhmQB8yNcQKZT6RJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:e8fe:2a8e:e0f6:318d]) (user=irogers job=sendgmr) by 2002:a25:3b95:0:b0:66e:316c:159 with SMTP id i143-20020a253b95000000b0066e316c0159mr12911831yba.297.1657867068756; Thu, 14 Jul 2022 23:37:48 -0700 (PDT) Date: Thu, 14 Jul 2022 23:36:52 -0700 In-Reply-To: <20220715063653.3203761-1-irogers@google.com> Message-Id: <20220715063653.3203761-15-irogers@google.com> Mime-Version: 1.0 References: <20220715063653.3203761-1-irogers@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog Subject: [PATCH v1 14/15] perf metrics: Copy entire pmu_event in find metric From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220715_073751_189344_E9FC7F5A X-CRM114-Status: GOOD ( 18.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The pmu_event passed to the pmu_events_table_for_each_event is invalid after the loop. Copy the entire struct in metricgroup__find_metric. Reduce the scope of this function to static. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 33 ++++++++++++++++++--------------- tools/perf/util/metricgroup.h | 2 -- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 8ef44f4b5e9a..95f4b46dba09 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -879,6 +879,10 @@ struct metricgroup_add_iter_data { const struct pmu_events_table *table; }; +static bool metricgroup__find_metric(const char *metric, + const struct pmu_events_table *table, + struct pmu_event *pe); + static int add_metric(struct list_head *metric_list, const struct pmu_event *pe, const char *modifier, @@ -914,7 +918,7 @@ static int resolve_metric(struct list_head *metric_list, size_t bkt; struct to_resolve { /* The metric to resolve. */ - const struct pmu_event *pe; + struct pmu_event pe; /* * The key in the IDs map, this may differ from in case, * etc. from pe->metric_name. @@ -928,16 +932,15 @@ static int resolve_metric(struct list_head *metric_list, * the pending array. */ hashmap__for_each_entry(root_metric->pctx->ids, cur, bkt) { - const struct pmu_event *pe; + struct pmu_event pe; - pe = metricgroup__find_metric(cur->key, table); - if (pe) { + if (metricgroup__find_metric(cur->key, table, &pe)) { pending = realloc(pending, (pending_cnt + 1) * sizeof(struct to_resolve)); if (!pending) return -ENOMEM; - pending[pending_cnt].pe = pe; + memcpy(&pending[pending_cnt].pe, &pe, sizeof(pe)); pending[pending_cnt].key = cur->key; pending_cnt++; } @@ -952,7 +955,7 @@ static int resolve_metric(struct list_head *metric_list, * context. */ for (i = 0; i < pending_cnt; i++) { - ret = add_metric(metric_list, pending[i].pe, modifier, metric_no_group, + ret = add_metric(metric_list, &pending[i].pe, modifier, metric_no_group, root_metric, visited, table); if (ret) break; @@ -1073,7 +1076,7 @@ static int __add_metric(struct list_head *metric_list, struct metricgroup__find_metric_data { const char *metric; - const struct pmu_event *pe; + struct pmu_event *pe; }; static int metricgroup__find_metric_callback(const struct pmu_event *pe, @@ -1085,21 +1088,21 @@ static int metricgroup__find_metric_callback(const struct pmu_event *pe, if (!match_metric(pe->metric_name, data->metric)) return 0; - data->pe = pe; - return -1; + memcpy(data->pe, pe, sizeof(*pe)); + return 1; } -const struct pmu_event *metricgroup__find_metric(const char *metric, - const struct pmu_events_table *table) +static bool metricgroup__find_metric(const char *metric, + const struct pmu_events_table *table, + struct pmu_event *pe) { struct metricgroup__find_metric_data data = { .metric = metric, - .pe = NULL, + .pe = pe, }; - pmu_events_table_for_each_event(table, metricgroup__find_metric_callback, &data); - - return data.pe; + return pmu_events_table_for_each_event(table, metricgroup__find_metric_callback, &data) + ? true : false; } static int add_metric(struct list_head *metric_list, diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index f54d170043e9..016b3b1a289a 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -69,8 +69,6 @@ int metricgroup__parse_groups(const struct option *opt, bool metric_no_group, bool metric_no_merge, struct rblist *metric_events); -const struct pmu_event *metricgroup__find_metric(const char *metric, - const struct pmu_events_table *table); int metricgroup__parse_groups_test(struct evlist *evlist, const struct pmu_events_table *table, const char *str, -- 2.37.0.170.g444d1eabd0-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel