From nobody Thu Apr 2 13:32:40 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 F24F3C32771 for ; Sat, 24 Sep 2022 16:57:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229662AbiIXQ5q (ORCPT ); Sat, 24 Sep 2022 12:57:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231770AbiIXQ5m (ORCPT ); Sat, 24 Sep 2022 12:57:42 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 960DA3FA27; Sat, 24 Sep 2022 09:57:41 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id jm5so2724276plb.13; Sat, 24 Sep 2022 09:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date; bh=KLe1rhG2jyFxMjNRfJfVKi4UTDqQ8WJWgu9o/n99gQM=; b=Y7CXU6iNdPkcsRL/SPx0ZSGbxyT3GSS9kG6O5u+YuInrdNhYoQDFDryLtXGRWEVe46 4+4Vs7AP80fdJGizBhlx0BVcHZnj08eJrk6dvzErxNJf0qPJPBgPXhqIl1CrjblJ/ugM B/hnERzz20ZimSeFghjKqEt+gZsyj2JC94hxU7bUz2JiAuwVEXXROc1I7gDxELOmcGfD Abe2zrkrQNfx+Dlqio1k30aSVJoQyhpzsCUFKw+gLptPyX0WpnHsKCzHDoZR5UgRjx/E +Njdg8pafrw9sW+pZ9DcrJoltqFetw6Oy0UQ8Y5FYWtFjIZh9XFIemCuImoKHsK0QxCB OGCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date; bh=KLe1rhG2jyFxMjNRfJfVKi4UTDqQ8WJWgu9o/n99gQM=; b=v4FAvI4GousDAMhbILAxWL+pmFC2D4c78RVD6dg83S6bdrIOXU8rzqktvmTP7rOStE I2OQyE5s5vfa6qr6rue2wnCXvqVPiwAaA/9k03wudX50Op+InuwHSquvREMt9wQkjDHn lFs2O+QumfXJo9dQRSFaRaFmhriEwdjwOGODpdbqHhSMfFcxm5/aSU8Nyu4iB8YeC0OV 0nxHMWeGOYUvIj66ONqZQ1QGq1YwislGqAonEr5IGSUfFf7aLqOJQYX4qA6WW3IIo5Ae +a2RmIe77qhpKeZ5QXWEZNQSF3GvdwTY0+QTWYfH/64DMHpUV1virwB+IARLiHPCXk3e jkPA== X-Gm-Message-State: ACrzQf3EpShsYRYuuUWyK8BLPBMoWk7kTHWdPnVFMMF4mZ3LyIS7B6dG E6z+0Xr5CUfBFLC5nYnMIPY= X-Google-Smtp-Source: AMsMyM709bRyaS417ZlIXlxiOSAsiF+vTQwqdwvpXBfHOzblFPLXa2JKj3Vb0zj2Y84svDFMpJT33Q== X-Received: by 2002:a17:90b:110a:b0:203:6f0c:9b66 with SMTP id gi10-20020a17090b110a00b002036f0c9b66mr16220873pjb.104.1664038660991; Sat, 24 Sep 2022 09:57:40 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:20c0:42d3:7ef1:1f3]) by smtp.gmail.com with ESMTPSA id m12-20020a170902f20c00b00176675adbe1sm7960082plc.208.2022.09.24.09.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Sep 2022 09:57:40 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Leo Yan Subject: [PATCH 1/5] libperf: Populate system-wide evsel maps Date: Sat, 24 Sep 2022 09:57:33 -0700 Message-Id: <20220924165737.956428-2-namhyung@kernel.org> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220924165737.956428-1-namhyung@kernel.org> References: <20220924165737.956428-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Setting proper cpu and thread maps for system wide evsels regardless of user requested cpu in __perf_evlist__propagate_maps(). Those evsels need to be active on all cpus always. Do it in the libperf so that we can guarantee it has proper maps. Signed-off-by: Namhyung Kim Reviewed-by: Adrian Hunter --- tools/lib/perf/evlist.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 6b1bafe267a4..187129652ab6 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -40,11 +40,11 @@ static void __perf_evlist__propagate_maps(struct perf_e= vlist *evlist, * We already have cpus for evsel (via PMU sysfs) so * keep it, if there's no target cpu list defined. */ - if (!evsel->own_cpus || - (!evsel->system_wide && evlist->has_user_cpus) || - (!evsel->system_wide && - !evsel->requires_cpu && - perf_cpu_map__empty(evlist->user_requested_cpus))) { + if (evsel->system_wide) { + perf_cpu_map__put(evsel->cpus); + evsel->cpus =3D perf_cpu_map__new(NULL); + } else if (!evsel->own_cpus || evlist->has_user_cpus || + (!evsel->requires_cpu && perf_cpu_map__empty(evlist->user_requested_c= pus))) { perf_cpu_map__put(evsel->cpus); evsel->cpus =3D perf_cpu_map__get(evlist->user_requested_cpus); } else if (evsel->cpus !=3D evsel->own_cpus) { @@ -52,7 +52,10 @@ static void __perf_evlist__propagate_maps(struct perf_ev= list *evlist, evsel->cpus =3D perf_cpu_map__get(evsel->own_cpus); } =20 - if (!evsel->system_wide) { + if (evsel->system_wide) { + perf_thread_map__put(evsel->threads); + evsel->threads =3D perf_thread_map__new_dummy(); + } else { perf_thread_map__put(evsel->threads); evsel->threads =3D perf_thread_map__get(evlist->threads); } --=20 2.37.3.998.g577e59143f-goog From nobody Thu Apr 2 13:32:40 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 9FE7FC07E9D for ; Sat, 24 Sep 2022 16:57:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233923AbiIXQ5t (ORCPT ); Sat, 24 Sep 2022 12:57:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233549AbiIXQ5n (ORCPT ); Sat, 24 Sep 2022 12:57:43 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCC57857E6; Sat, 24 Sep 2022 09:57:42 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id l10so2737493plb.10; Sat, 24 Sep 2022 09:57:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date; bh=MCPAXhDCQc742dpZ+x6jNLqv2PyH1MjeNNepu11/jbY=; b=NwJ4cizpRMzHOznKzS3FE/SMKkxdMFrkvvIyEfcdzdTWpU3aAogaAYRoetonnMJ+OT BSrMt0UnTU9ScsMhYjc8CQBDm2RMvr1xhLvjBqsNDN9TmHBUMS0Z3J3hfat0+m+PTyOb bMHb/IgoyLnztzS/5nsQBWbYwyB3ua36LirW0LkL1Ee9cELyCBYvw/dUvGCsKTSYFHpm zjZFDYfovVlCDfSHBveeeMmTESDumbhaUZGcIEYJ0EkAIiwtDp925DercUvIqmuKi71U fVFIGvYk68K3jjwWK7WykZR7cnjS3Em4xFGAZngdYzo5JFNTjjAQne0t/z1O65mRVn93 /yig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date; bh=MCPAXhDCQc742dpZ+x6jNLqv2PyH1MjeNNepu11/jbY=; b=PESyPBl5rCjZ33N6qWpsv5mpApxE/ou5zWot84UDcTmpH7RrtNqY30PK9MG7qZY4DM fhDB+JxwRNau1NjQUgAp9mMfWFbTzBwjVBEFXt8sbRNeiFEmkJ7ZPLqVXa8dhTkhYkH3 rkc8avA8jLMaMfA/tLpStc6uYwRKnA2xfNaNuiDA/9yuvHjEB6m1wB2bwqmYzE1zziEe pp3JUd6K2Msyntj/hqvDp+hWzumiyyIRjd+nSr6xOSM2DfMLWXywEKL1kS5TGq/nqoxT O5fiOgCcEnREXaGxmF1WhXj6tsyqLVFg5bd7mV9p0iK3DUY0ooWwH2fsCF0a5KC+7ckp XJnA== X-Gm-Message-State: ACrzQf1Vd4kSMN6xAj1xbTZJwEISE3E9beFBf4SClyUKX4hghCZJ090b T6wcZdu1pDlamZJFEZaWZ9c= X-Google-Smtp-Source: AMsMyM6UQ05a2tPF8vUMZ9lpxHlKt2jcdrs+U21k72SAK5yyrcIcygqryAgVol3RQvFWaz11uDtVDw== X-Received: by 2002:a17:902:e5c9:b0:178:5a6f:6eb8 with SMTP id u9-20020a170902e5c900b001785a6f6eb8mr14435456plf.42.1664038662284; Sat, 24 Sep 2022 09:57:42 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:20c0:42d3:7ef1:1f3]) by smtp.gmail.com with ESMTPSA id m12-20020a170902f20c00b00176675adbe1sm7960082plc.208.2022.09.24.09.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Sep 2022 09:57:41 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Leo Yan Subject: [PATCH 2/5] libperf: Propagate maps only if necessary Date: Sat, 24 Sep 2022 09:57:34 -0700 Message-Id: <20220924165737.956428-3-namhyung@kernel.org> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220924165737.956428-1-namhyung@kernel.org> References: <20220924165737.956428-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The current code propagate evsel's cpu map settings to evlist when it's added to an evlist. But the evlist->all_cpus and each evsel's cpus will be updated in perf_evlist__set_maps() later. No need to do it before evlist's cpus are set actually. Actually we discarded this intermediate all_cpus maps at the beginning of perf_evlist__set_maps(). Let's not do this. It's only needed when an evsel is added after the evlist cpu maps are set. Signed-off-by: Namhyung Kim --- tools/lib/perf/evlist.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 187129652ab6..cc070c3a134d 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -67,10 +67,6 @@ static void perf_evlist__propagate_maps(struct perf_evli= st *evlist) { struct perf_evsel *evsel; =20 - /* Recomputing all_cpus, so start with a blank slate. */ - perf_cpu_map__put(evlist->all_cpus); - evlist->all_cpus =3D NULL; - perf_evlist__for_each_evsel(evlist, evsel) __perf_evlist__propagate_maps(evlist, evsel); } @@ -81,7 +77,9 @@ void perf_evlist__add(struct perf_evlist *evlist, evsel->idx =3D evlist->nr_entries; list_add_tail(&evsel->node, &evlist->entries); evlist->nr_entries +=3D 1; - __perf_evlist__propagate_maps(evlist, evsel); + + if (evlist->all_cpus) + __perf_evlist__propagate_maps(evlist, evsel); } =20 void perf_evlist__remove(struct perf_evlist *evlist, --=20 2.37.3.998.g577e59143f-goog From nobody Thu Apr 2 13:32:40 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 251A1C32771 for ; Sat, 24 Sep 2022 16:57:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233964AbiIXQ5w (ORCPT ); Sat, 24 Sep 2022 12:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233921AbiIXQ5q (ORCPT ); Sat, 24 Sep 2022 12:57:46 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51290883F0; Sat, 24 Sep 2022 09:57:44 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d24so2762034pls.4; Sat, 24 Sep 2022 09:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date; bh=uEB7eOXWTpeJuzDn8ZjWWedlCXtJw6M1+lr3Jy5UZrA=; b=XJmkoQDLfZvXbETKGEySQdmjNidTmwB3cjF5/g7eRWSYmKCo6wzXI17hyGRTzXN/2j TAeJQD8VoEtDn/1XlT6iyRw/YQESrnj6ZpFqkGY0vHj5ri7vyJsVPZUupyg8TlHAAayo 1tUpD2/uwG38Xhv4jEwzkai4mZTMOK0z3VyXdH1gL3iZvybS7Nvu46dpn/klMk6pVrJu vgV3Qntn07ELErBO/pqW0jaV80Ch98i+911Qo+SPok/zWgbiQxYljdPjfW7VkLyXPZLb sB5CtpU1beRSLRJAl+nUsXfp5mDwAltEnGO/ygrncEc6oHHxI4P7y0vhyGyVPG/MrP11 WpSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date; bh=uEB7eOXWTpeJuzDn8ZjWWedlCXtJw6M1+lr3Jy5UZrA=; b=Rlo4kPOZA6FYRsPD+WAk70Gc+Tn6CNviRbCRx/2xjKWi/AGVFWeC6O5TkfpULnmlbu aJC6iwWc0M/5/2LVyXqyOs3NZIlkab/JfPaBsNsntJfhfIgcmWsjbWP4e8YE36CEJQK5 /gVWTkNp3VFxEq1wTwNFEEFqBSZYhH/piP/D98yqOIzBvAOxqpzbK9O/2Tutosi8b+iF PHQJN0PDpl9lnVI5Nd/jH5QmzGHr/KuC/NMMCIsULybMTPQO3//+9OVnsVjZtSj0U8si iw1qhF2k3JKG6sud7zN95+DBUsJxuO4MK4DifcS0yUi2vWa4Rm8JMF9LOvGO/qnUrPIN IOVA== X-Gm-Message-State: ACrzQf1Y6vYn43Iqg71erzmnOLPZ2TnxQeHtl2LnXYFV0SMLBHLh3Kud nkGPms8HQzJzKTsfe3sPrh0= X-Google-Smtp-Source: AMsMyM54wbIiHOBUMK7x36JF9iw9rmAgY6qObJNUvPA8zNX+ljP/plQUsMDJHq9H/+jvxpoNcogNtQ== X-Received: by 2002:a17:90b:1c07:b0:202:8ad0:3210 with SMTP id oc7-20020a17090b1c0700b002028ad03210mr28369036pjb.193.1664038663587; Sat, 24 Sep 2022 09:57:43 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:20c0:42d3:7ef1:1f3]) by smtp.gmail.com with ESMTPSA id m12-20020a170902f20c00b00176675adbe1sm7960082plc.208.2022.09.24.09.57.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Sep 2022 09:57:43 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Leo Yan Subject: [PATCH 3/5] perf tools: Get rid of evlist__add_on_all_cpus() Date: Sat, 24 Sep 2022 09:57:35 -0700 Message-Id: <20220924165737.956428-4-namhyung@kernel.org> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220924165737.956428-1-namhyung@kernel.org> References: <20220924165737.956428-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The cpu and thread maps are properly handled in libperf now. No need to do it in the perf tools anymore. Let's remove the logic. Signed-off-by: Namhyung Kim Reviewed-by: Adrian Hunter --- tools/perf/util/evlist.c | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index fcfe5bcc0bcf..dcf57b271ff1 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -268,28 +268,6 @@ int evlist__add_dummy(struct evlist *evlist) return 0; } =20 -static void evlist__add_on_all_cpus(struct evlist *evlist, struct evsel *e= vsel) -{ - evsel->core.system_wide =3D true; - - /* - * All CPUs. - * - * Note perf_event_open() does not accept CPUs that are not online, so - * in fact this CPU list will include only all online CPUs. - */ - perf_cpu_map__put(evsel->core.own_cpus); - evsel->core.own_cpus =3D perf_cpu_map__new(NULL); - perf_cpu_map__put(evsel->core.cpus); - evsel->core.cpus =3D perf_cpu_map__get(evsel->core.own_cpus); - - /* No threads */ - perf_thread_map__put(evsel->core.threads); - evsel->core.threads =3D perf_thread_map__new_dummy(); - - evlist__add(evlist, evsel); -} - struct evsel *evlist__add_aux_dummy(struct evlist *evlist, bool system_wid= e) { struct evsel *evsel =3D evlist__dummy_event(evlist); @@ -302,14 +280,11 @@ struct evsel *evlist__add_aux_dummy(struct evlist *ev= list, bool system_wide) evsel->core.attr.exclude_hv =3D 1; evsel->core.attr.freq =3D 0; evsel->core.attr.sample_period =3D 1; + evsel->core.system_wide =3D system_wide; evsel->no_aux_samples =3D true; evsel->name =3D strdup("dummy:u"); =20 - if (system_wide) - evlist__add_on_all_cpus(evlist, evsel); - else - evlist__add(evlist, evsel); - + evlist__add(evlist, evsel); return evsel; } =20 --=20 2.37.3.998.g577e59143f-goog From nobody Thu Apr 2 13:32:40 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 271C7C07E9D for ; Sat, 24 Sep 2022 16:58:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229915AbiIXQ6K (ORCPT ); Sat, 24 Sep 2022 12:58:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233930AbiIXQ5r (ORCPT ); Sat, 24 Sep 2022 12:57:47 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFFA68B2CC; Sat, 24 Sep 2022 09:57:45 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id s90-20020a17090a2f6300b00203a685a1aaso3091955pjd.1; Sat, 24 Sep 2022 09:57:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date; bh=a8E584MihiKhrfPuBohiQk7ujLHrncMgdIyW+Lv5p9E=; b=pDyguElPLfm2FUgIbSAlVJVNX0tPTsOjM/ZASm55g97xmRQsYeY4X6Z/QiqhiC6LNy eMMAnYSjtyMg8/10AOdPOJBgZGmnsHaHFJ4M8WC45ONr95jp9Y6BDVwQ4aF4x8XWV54F eL8wAYPxJVDZCTown19NL1q5bgnqqwtlRB755AIx+dhMXtYLfJVX32CSR3+uarK9xacx X6nXx6K/POtKN4YI4gmhSBwZNF9fKcpvn4Ta4g7PMbj6HHDtrJi+HQ3QXM4cio5OrxmC UMb+XE1dJ/NKRsro/WWSm+yZuP7x5v7Z3RWxFMzptu7T1g60UOyuDOA/EygfMSWzRtw8 pUbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date; bh=a8E584MihiKhrfPuBohiQk7ujLHrncMgdIyW+Lv5p9E=; b=pIx5MWwpuDGLI1wO8vzxZdTUVr3Vf3ujpy5uT53uawCdXeN8Mof2Thnk0h/ZqI/D6g GAJNilH6Na7cl4hKid9Vc5EDuL7yBQSnkOWAOIUryJQe9J9pli0yfV1RynlN3F0GoKMV 8Mjovz3z6Nb9KqPu7XBCehrXhCKPNyyH1o3XjdKLjTgKWijQOek2ZtjGOnHGF5R91mbJ jzfJGd/qaaAs8zMNsfek+SpYwoIstR7oGfTRSs/71HbgTlcBSq9io7h8NNeHNE9s8dyI JIwpJ3iYHPDdkASRSiJUee6NDSO2Sv2/x4/IUuLbkve3lW+c9CLnKW2UDPrbPhuEQiH/ MpnQ== X-Gm-Message-State: ACrzQf0HLArf7HH1G1fFqsEEFE5vkihXhCafQpxOxRzqbRUYLhSFXDg2 LUf68bE8vxwRuC/z9QKWZnpEFUQlf8Y= X-Google-Smtp-Source: AMsMyM4d4/WzlSFWilGf7cobCWuRXC5dd1QxXso3ZgtR2ZADj6hDysA8ijj3BBySt8ozXd0vs8d+Mg== X-Received: by 2002:a17:902:d34a:b0:176:b8ad:ba76 with SMTP id l10-20020a170902d34a00b00176b8adba76mr14545411plk.139.1664038664920; Sat, 24 Sep 2022 09:57:44 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:20c0:42d3:7ef1:1f3]) by smtp.gmail.com with ESMTPSA id m12-20020a170902f20c00b00176675adbe1sm7960082plc.208.2022.09.24.09.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Sep 2022 09:57:44 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Leo Yan Subject: [PATCH 4/5] perf tools: Add evlist__add_sched_switch() Date: Sat, 24 Sep 2022 09:57:36 -0700 Message-Id: <20220924165737.956428-5-namhyung@kernel.org> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220924165737.956428-1-namhyung@kernel.org> References: <20220924165737.956428-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a help to create a system-wide sched_switch event. One merit is that it sets the system-wide bit before adding it to evlist so that the libperf can handle the cpu and thread maps correctly. Signed-off-by: Namhyung Kim Reviewed-by: Adrian Hunter --- tools/perf/arch/x86/util/intel-pt.c | 15 +++++---------- tools/perf/tests/switch-tracking.c | 15 +++++---------- tools/perf/util/evlist.c | 17 +++++++++++++++++ tools/perf/util/evlist.h | 1 + 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util= /intel-pt.c index 13933020a79e..793b35f2221a 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -11,6 +11,7 @@ #include #include #include +#include #include =20 #include "../../../util/session.h" @@ -426,20 +427,14 @@ static int intel_pt_track_switches(struct evlist *evl= ist) if (!evlist__can_select_event(evlist, sched_switch)) return -EPERM; =20 - err =3D parse_event(evlist, sched_switch); - if (err) { - pr_debug2("%s: failed to parse %s, error %d\n", + evsel =3D evlist__add_sched_switch(evlist, true); + if (IS_ERR(evsel)) { + err =3D PTR_ERR(evsel); + pr_debug2("%s: failed to create %s, error =3D %d\n", __func__, sched_switch, err); return err; } =20 - evsel =3D evlist__last(evlist); - - evsel__set_sample_bit(evsel, CPU); - evsel__set_sample_bit(evsel, TIME); - - evsel->core.system_wide =3D true; - evsel->no_aux_samples =3D true; evsel->immediate =3D true; =20 return 0; diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-t= racking.c index 2d46af9ef935..87f565c7f650 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -398,19 +399,13 @@ static int test__switch_tracking(struct test_suite *t= est __maybe_unused, int sub goto out; } =20 - err =3D parse_event(evlist, sched_switch); - if (err) { - pr_debug("Failed to parse event %s\n", sched_switch); + switch_evsel =3D evlist__add_sched_switch(evlist, true); + if (IS_ERR(switch_evsel)) { + err =3D PTR_ERR(switch_evsel); + pr_debug("Failed to create event %s\n", sched_switch); goto out_err; } =20 - switch_evsel =3D evlist__last(evlist); - - evsel__set_sample_bit(switch_evsel, CPU); - evsel__set_sample_bit(switch_evsel, TIME); - - switch_evsel->core.system_wide =3D true; - switch_evsel->no_aux_samples =3D true; switch_evsel->immediate =3D true; =20 /* Test moving an event to the front */ diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index dcf57b271ff1..6612b00949e7 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -288,6 +288,23 @@ struct evsel *evlist__add_aux_dummy(struct evlist *evl= ist, bool system_wide) return evsel; } =20 +struct evsel *evlist__add_sched_switch(struct evlist *evlist, bool system_= wide) +{ + struct evsel *evsel =3D evsel__newtp_idx("sched", "sched_switch", 0); + + if (IS_ERR(evsel)) + return evsel; + + evsel__set_sample_bit(evsel, CPU); + evsel__set_sample_bit(evsel, TIME); + + evsel->core.system_wide =3D system_wide; + evsel->no_aux_samples =3D true; + + evlist__add(evlist, evsel); + return evsel; +}; + int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs= , size_t nr_attrs) { struct evsel *evsel, *n; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 9d967fe3953a..16734c6756b3 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -127,6 +127,7 @@ static inline struct evsel *evlist__add_dummy_on_all_cp= us(struct evlist *evlist) { return evlist__add_aux_dummy(evlist, true); } +struct evsel *evlist__add_sched_switch(struct evlist *evlist, bool system_= wide); =20 int evlist__add_sb_event(struct evlist *evlist, struct perf_event_attr *at= tr, evsel__sb_cb_t cb, void *data); --=20 2.37.3.998.g577e59143f-goog From nobody Thu Apr 2 13:32:40 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 5C267C32771 for ; Sat, 24 Sep 2022 16:58:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231970AbiIXQ6P (ORCPT ); Sat, 24 Sep 2022 12:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233939AbiIXQ5s (ORCPT ); Sat, 24 Sep 2022 12:57:48 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 397428FD5E; Sat, 24 Sep 2022 09:57:46 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id t190so2950608pgd.9; Sat, 24 Sep 2022 09:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date; bh=pBF4ZzTbmSSf3D3u0dSQ0dRvqjp81c7kDio+V9o09V4=; b=GPgSOwj8gg3MLAl25L5V+/YfmaBwz8OIMSUembZ/4dgveavNrGxKC8CHwSRVz8z9jH dZtN7BfH0Hqu9ND3293o6ayYTR5VBSaez28su8AirlqYs4Wjpwd6J6KKAJJ9+A0iN9AK bSuNkMiGifrYpq/DPApbgdQKBo4lAutonHjagmSEKLi10Bey3OUC3tLkWUVbeamDq4CC XyBNkG4eI5AhnQ9cqVHIeGJIJ54mvD2U498PcvOAFwepefgEcYHM/cCnJrjL3/SJ/R3a s6+Dcq/HQrTYToG3Vy36gA924LA8PYmtiWrdN1yM4vnzMX9Vwnn1mj5DhAzh6v9ncjOg k9vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date; bh=pBF4ZzTbmSSf3D3u0dSQ0dRvqjp81c7kDio+V9o09V4=; b=iOUTCJuujfHrSSBw7j1KHuQlDfI4kaGxSalNNPmd9XoiAxM8Gm3o4I4cT1mG29FP1C sUyr0YtAB7D6oSOyMwjBuToCcqG+D6uVCqfvQsg6KJiFEidoiVSVn+1N97O/OYkpjXVY BGVMsAMKNCLos5Q6Ro/zFHKdipXn7GveRGpWI0zpeXCp/fb1v/cDVvKGehdw2WeQ+6f3 h+VTzg5Fgb3ebIkKYy48byMKqmQk8NtcFldsNZEemjsd2x5p+eGqc3i7QXe8ikYkpzV8 T9Hkv0Q35Q9lS00peZWdvtEHU+0AhU3xb1Hw4UWbL8t/6RMBxUCHqJakhJLFx3tNziK7 /+8A== X-Gm-Message-State: ACrzQf1BRd/oKsnZ14I0ip8Vxn7vQ8Mjg+3xDfoTB0/ZLN56ef/VkaDM J4IUNb1e2iVAmhD8EFR7H0E= X-Google-Smtp-Source: AMsMyM53GVkc2Cy683BypENlfHcF58Gw5tykq4EfpnnWckONGuemFtLPWnEhUZIh6oM6QnrgxUyu7w== X-Received: by 2002:a63:4243:0:b0:439:2031:be87 with SMTP id p64-20020a634243000000b004392031be87mr12801448pga.592.1664038666190; Sat, 24 Sep 2022 09:57:46 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:20c0:42d3:7ef1:1f3]) by smtp.gmail.com with ESMTPSA id m12-20020a170902f20c00b00176675adbe1sm7960082plc.208.2022.09.24.09.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Sep 2022 09:57:45 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Leo Yan Subject: [PATCH 5/5] perf tools: Remove special handling of system-wide evsel Date: Sat, 24 Sep 2022 09:57:37 -0700 Message-Id: <20220924165737.956428-6-namhyung@kernel.org> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220924165737.956428-1-namhyung@kernel.org> References: <20220924165737.956428-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" For system-wide evsels, the thread map should be dummy - i.e. it has a single entry of -1. But the code guarantees such a thread map, so no need to handle it specially. No functional change intended. Signed-off-by: Namhyung Kim Reviewed-by: Adrian Hunter --- tools/lib/perf/evsel.c | 3 --- tools/perf/builtin-script.c | 3 --- tools/perf/util/evsel.c | 12 ++---------- tools/perf/util/stat.c | 3 --- 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index 8ce5bbd09666..8b51b008a81f 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -515,9 +515,6 @@ int perf_evsel__alloc_id(struct perf_evsel *evsel, int = ncpus, int nthreads) if (ncpus =3D=3D 0 || nthreads =3D=3D 0) return 0; =20 - if (evsel->system_wide) - nthreads =3D 1; - evsel->sample_id =3D xyarray__new(ncpus, nthreads, sizeof(struct perf_sam= ple_id)); if (evsel->sample_id =3D=3D NULL) return -ENOMEM; diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 886f53cfa257..7fa467ed91dc 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2243,9 +2243,6 @@ static void __process_stat(struct evsel *counter, u64= tstamp) struct perf_cpu cpu; static int header_printed; =20 - if (counter->core.system_wide) - nthreads =3D 1; - if (!header_printed) { printf("%3s %8s %15s %15s %15s %15s %s\n", "CPU", "THREAD", "VAL", "ENA", "RUN", "TIME", "EVENT"); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 5776bfa70f11..e319bb17d10d 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1813,7 +1813,7 @@ static struct perf_thread_map *empty_thread_map; static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map = *cpus, struct perf_thread_map *threads) { - int nthreads; + int nthreads =3D perf_thread_map__nr(threads); =20 if ((perf_missing_features.write_backward && evsel->core.attr.write_backw= ard) || (perf_missing_features.aux_output && evsel->core.attr.aux_output)) @@ -1839,11 +1839,6 @@ static int __evsel__prepare_open(struct evsel *evsel= , struct perf_cpu_map *cpus, threads =3D empty_thread_map; } =20 - if (evsel->core.system_wide) - nthreads =3D 1; - else - nthreads =3D threads->nr; - if (evsel->core.fd =3D=3D NULL && perf_evsel__alloc_fd(&evsel->core, perf_cpu_map__nr(cpus), nthreads) = < 0) return -ENOMEM; @@ -2061,10 +2056,7 @@ static int evsel__open_cpu(struct evsel *evsel, stru= ct perf_cpu_map *cpus, if (threads =3D=3D NULL) threads =3D empty_thread_map; =20 - if (evsel->core.system_wide) - nthreads =3D 1; - else - nthreads =3D threads->nr; + nthreads =3D perf_thread_map__nr(threads); =20 if (evsel->cgrp) pid =3D evsel->cgrp->fd; diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index ce5e9e372fc4..cef943377ad7 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -420,9 +420,6 @@ static int process_counter_maps(struct perf_stat_config= *config, int ncpus =3D evsel__nr_cpus(counter); int idx, thread; =20 - if (counter->core.system_wide) - nthreads =3D 1; - for (thread =3D 0; thread < nthreads; thread++) { for (idx =3D 0; idx < ncpus; idx++) { if (process_counter_values(config, counter, idx, thread, --=20 2.37.3.998.g577e59143f-goog