From nobody Fri May 3 08:16:31 2024 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 0D551C433FE for ; Fri, 30 Sep 2022 17:27:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232086AbiI3R1r (ORCPT ); Fri, 30 Sep 2022 13:27:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232306AbiI3R1f (ORCPT ); Fri, 30 Sep 2022 13:27:35 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 919881D848A; Fri, 30 Sep 2022 10:27:31 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d10so4813042pfh.6; Fri, 30 Sep 2022 10:27:31 -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=mcdTg7QGTQqXsDIVRoGrzxy9JDO0zJAoCC38Nz4SgJw=; b=NDow9pY49V2nnJdhg9VfTSlgt2CoEbvxDL2bBjXqXk1n5UaunlhdOtNChnMVplVvL5 J6JH04rmKR6llzHl7ENoG76+qyJHe92XNM0BqZe23IWD3/rYTvgDgGOUqDF+J539yxEi KxVlOwz9ZBLTZMXlPIRREAix93Dh0KMbQ3TciotY96GQy6fDN2t0qAFFA+Yr6vbzNV7V guqA0/NBw/ogBcDNcr/7C0SQ+aeFMN3duhuXfycjmvveZyHLp3mEgzKesLBpipEgi9Nr qFxBN+yBlnV/jSQ2IGMti8mAdiubGwuqxkiFHnVzKye+L7TnTRXSLgQNSg1/L5lxrEAA m0RQ== 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=mcdTg7QGTQqXsDIVRoGrzxy9JDO0zJAoCC38Nz4SgJw=; b=hTzH+tTL25pwApPEbjCdPT7Sc4MWsgLgEgfg+FH8hBMCS5t+kJ458iPH2BqNhhueki kOrEcXZzR+TxjaJUkE+CyldeD/rerRUcHHTJcJT/fuDNMtWu2rds0m9P319Zt697UB6c tY/shqa6qaCm6GJpfD1gD4GYJbfS3jhaEgLlvUYniNnHzu0pipurGv70OOV4e48RE9Je ABq+W58NJTE5ArJ1279Hc+76c1NUTJnZ8e11zx97FRMDgJxBQe0d3mIWnyD0oJ8sVW8+ FTsxwkDzbcsZkLxAYTjHZnxozKTMxSRvuzphuKYIpn3cFYoDLxK90tK1Tpeqj0jQdweW CuWg== X-Gm-Message-State: ACrzQf2xjzoCqqGY95PRr1LIGvNtyu8SOcI54y1bwkdtW9LoyBpg4y14 QLT0zP1ajc3+elA9jn2Oiua5SSZeZm8= X-Google-Smtp-Source: AMsMyM4jorXdi+tWGkFGxEfc+0YcCK8xa6KmpZp0EnTTcOWyTe/FwCR9NkSPKZtUn0KaiO1RXXgf0w== X-Received: by 2002:a05:6a00:4c91:b0:543:646e:9 with SMTP id eb17-20020a056a004c9100b00543646e0009mr10370713pfb.40.1664558850728; Fri, 30 Sep 2022 10:27:30 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:4075:4245:762c:e746]) by smtp.gmail.com with ESMTPSA id e10-20020a170902b78a00b00168dadc7354sm2154762pls.78.2022.09.30.10.27.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 10:27:30 -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: Fri, 30 Sep 2022 10:27:10 -0700 Message-Id: <20220930172714.711616-2-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220930172714.711616-1-namhyung@kernel.org> References: <20220930172714.711616-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. Reviewed-by: Adrian Hunter Signed-off-by: Namhyung Kim --- 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.38.0.rc1.362.ged0d419d3c-goog From nobody Fri May 3 08:16:31 2024 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 13CAAC433FE for ; Fri, 30 Sep 2022 17:28:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232319AbiI3R1x (ORCPT ); Fri, 30 Sep 2022 13:27:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232087AbiI3R1f (ORCPT ); Fri, 30 Sep 2022 13:27:35 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CA3D1D8F05; Fri, 30 Sep 2022 10:27:32 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id e129so4696215pgc.9; Fri, 30 Sep 2022 10:27:32 -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=Dc/jbP+J01QaQor+cUjUGSbMxL2tJwx81JkUMwy36Mw=; b=k0RdZn1YaRjj8kIpVG7xyr/uMLTesVGw+P1Gsk97+gIKX8PML3gUKxkiQeTnR//vse IjQ3jtXJ8rJkPKUSKrcp86xa39bVmCEWY2Aeh5KoPYothect4D/ZOzoROKEFiCyuHQPx jZLpb3LnY4+DvDjoDg/MX16mXEWfLRgN78LzjaUWhoNViLcoCTtyVKx8Y79rEIBUqloL QSyoywHBd6TkdjMChg7YmPK7fS6l3ea5ee0YMIHCZpaPQ8mNlaJlcnsDvElIM8YbXpic th4uqrKhYiL7YDjEFPmRUGHUT0CtoUYhczAlE/WMrke320xCcP/dfRAdQbA8ZZHlrIUf wH3g== 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=Dc/jbP+J01QaQor+cUjUGSbMxL2tJwx81JkUMwy36Mw=; b=E8XZPL/MiaG4kC3tplGjBwNLjlenXDYNGcoRCfOrIRszQmuOZ923RRg0f9M30SO9WJ Dch3q+B/v4hqCex+D6wfihIbfn5sqOSRQUVZ5K4V5BJcXlqb4lmPTYkDs1RYC+PXvl8c EsTCQmTzfXTDWLgRfisRFF5br998wN759epmCYWIFYHIkhCXxTsWDGFUQ0KHzppuNAaE UfBJcPRcfGa8PzDbw7UeVwq11VSrHDIQ+0nnfKNeKcoapsE7OlMF/LtIgQLv8Q5s4Lo4 lHTRxgt6+hWJe94WyPGZegUnJpHK1ziYDVGpDS8A5v0tevr2w7OmQBtImvrvDIb6pDWe mgDA== X-Gm-Message-State: ACrzQf03nDw0VC+mkcEv3QTI61zBHnaXq4W9HVHkeb6wLZEiDcrUvIhA 65G/eYk9QP8B7mYUaYXPU6GOfgKvEck= X-Google-Smtp-Source: AMsMyM5IUZo/b73E4aEZJ1Dsr9rNdUolvG8XjHO+WYGafrLziT2XBraTbbYifqNXllLiyPO2V4kBpw== X-Received: by 2002:a05:6a00:194f:b0:54d:d12e:93aa with SMTP id s15-20020a056a00194f00b0054dd12e93aamr9750102pfk.34.1664558851825; Fri, 30 Sep 2022 10:27:31 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:4075:4245:762c:e746]) by smtp.gmail.com with ESMTPSA id e10-20020a170902b78a00b00168dadc7354sm2154762pls.78.2022.09.30.10.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 10:27:31 -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: Fri, 30 Sep 2022 10:27:11 -0700 Message-Id: <20220930172714.711616-3-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220930172714.711616-1-namhyung@kernel.org> References: <20220930172714.711616-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. In fact it discards 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/thread maps are set. Signed-off-by: Namhyung Kim Reviewed-by: Adrian Hunter --- tools/lib/perf/evlist.c | 8 ++++---- tools/lib/perf/include/internal/evlist.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 187129652ab6..c5f65b89d77a 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -67,9 +67,7 @@ static void perf_evlist__propagate_maps(struct perf_evlis= t *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; + evlist->needs_map_propagation =3D true; =20 perf_evlist__for_each_evsel(evlist, evsel) __perf_evlist__propagate_maps(evlist, evsel); @@ -81,7 +79,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->needs_map_propagation) + __perf_evlist__propagate_maps(evlist, evsel); } =20 void perf_evlist__remove(struct perf_evlist *evlist, diff --git a/tools/lib/perf/include/internal/evlist.h b/tools/lib/perf/incl= ude/internal/evlist.h index 6f89aec3e608..850f07070036 100644 --- a/tools/lib/perf/include/internal/evlist.h +++ b/tools/lib/perf/include/internal/evlist.h @@ -19,6 +19,7 @@ struct perf_evlist { int nr_entries; int nr_groups; bool has_user_cpus; + bool needs_map_propagation; /** * The cpus passed from the command line or all online CPUs by * default. --=20 2.38.0.rc1.362.ged0d419d3c-goog From nobody Fri May 3 08:16:31 2024 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 6B30AC433FE for ; Fri, 30 Sep 2022 17:28:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231744AbiI3R2N (ORCPT ); Fri, 30 Sep 2022 13:28:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232128AbiI3R1l (ORCPT ); Fri, 30 Sep 2022 13:27:41 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDBFD1D8F30; Fri, 30 Sep 2022 10:27:33 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id v186so4816166pfv.11; Fri, 30 Sep 2022 10:27:33 -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=t5TCNRTrQpQtzWyPUY1rC308ScWd7VMmiHrE+xshmOU=; b=oJfVWGxV0kuZ1YrxHJGxcX3bLRFdhuP43KryRxKuT67hW5iM3LTVn5fXmJUo3G2Bup KS+F7pwREa8G01bOZhKquE9ETT/oDIuCUmofjYmZ2BvEWHKNvk1TH0Iui1zxSljjwKgV Jl3D4MRuPuUlwb8EtlTJXgHkhOMx50dyyAFySAh7nYA60ay5fwvlQbbAyr9QHqUvDXtS sN0BrqBygo3Rr/6n0avNzyC3MhGNeSdEFdAqUF32vJlXSYj/cCjFd92U/2UNhpVF4bUE nGhKB7Smxh7oTCU/ab1RHJx6LFqCSDWhs+tS+XFay02xfBnwuY552Ig2N1qokJuHP4n6 F2SQ== 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=t5TCNRTrQpQtzWyPUY1rC308ScWd7VMmiHrE+xshmOU=; b=sM5ubwjbKgheMQY3bMre4YxXw1QWfN+gUuuerfnHfX+nVaK74SC8rdiYDhhsEZeK8l Ss4kJ/KQFpP4qHe6BlgvCIb4SOJLWfhcJJ9HNzo95l9Mzjj0Y/rYI+Gcao6Ypkx+UqWi XJE6gYJFMXr5FDHI2ibKV3PSADQEt37gz570/3sXayJp5QU/59137cX+ms9NtH3UBq8S TQIWb88KyZsephfiQ6gtuXy67KkfPMdps06jg27fnsRt9neGDQTQwwWDpq9xwVTxAEeG xDHpw7tkA/NeowycKHgY3qBLb1wHfNkHqV3qLIiXcL+SPAlnihVWvCMPMFcdwt4ScAXz tpog== X-Gm-Message-State: ACrzQf1o6Gw2ambC15lo/tDyS3cKfSct2Sc3N+TYRfxIdEziZETCMxzL /vldSh8wHroKle1H+emHN88= X-Google-Smtp-Source: AMsMyM5IQ02O46kO2hLNR+U3mgBxTK5DR4VA8sQ5TxSwHE5AhtWlrnnV0520TJJDRjX/3xsg7Y+HUg== X-Received: by 2002:a63:3c3:0:b0:441:833b:10c4 with SMTP id 186-20020a6303c3000000b00441833b10c4mr3920574pgd.573.1664558853118; Fri, 30 Sep 2022 10:27:33 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:4075:4245:762c:e746]) by smtp.gmail.com with ESMTPSA id e10-20020a170902b78a00b00168dadc7354sm2154762pls.78.2022.09.30.10.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 10:27:32 -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: Fri, 30 Sep 2022 10:27:12 -0700 Message-Id: <20220930172714.711616-4-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220930172714.711616-1-namhyung@kernel.org> References: <20220930172714.711616-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. Reviewed-by: Adrian Hunter Signed-off-by: Namhyung Kim --- 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.38.0.rc1.362.ged0d419d3c-goog From nobody Fri May 3 08:16:31 2024 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 2211EC433F5 for ; Fri, 30 Sep 2022 17:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231880AbiI3R2R (ORCPT ); Fri, 30 Sep 2022 13:28:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232312AbiI3R1m (ORCPT ); Fri, 30 Sep 2022 13:27:42 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABA261D8F31; Fri, 30 Sep 2022 10:27:34 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id u12so4871660pjj.1; Fri, 30 Sep 2022 10:27:34 -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=lB1WobpkhUf6urHo6McT5kj0otXKFdVMUG2TKkEYqg0=; b=jZ7QECLk3jxHAnEySG8oIfa0jV5Mcos+qHcxDi1XddyzrkPxUr0eTBLeweINIZf95q D92UmXqggk7ljSb+ErBVafmnNvKs+HwrP4GPq0qoLppE49A9RkkDRuKI/KKg2OnZjUVJ qxCaK5iqgqcYVFOExgRXSPMkspkrjkHk+HzLieogqnNn0g67tVc2mqrZVvD0gaqQqO2u UABGx7aASHJdnU0THOsxxRlYGSWvYz0++NTZiLrIDYg01HNkrr71zs8+RCtKu4XvGre5 A0pUmLP6FtQbrPjKBGG4Y03RTOl521Ge+lrAob1GAZTuna25xaXPkc7v0MkXIopbRC+0 1ZCw== 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=lB1WobpkhUf6urHo6McT5kj0otXKFdVMUG2TKkEYqg0=; b=yqFnomkYp9X/5dollG+04LisNMZxFuUIQqgvpHLfH6dxY5m2RkaUKIcmWqInZtaVrZ r6SPcXNAfsMCxQJoXNE5TLHTuU4TXoypeNl2cvCrbNolTz35+6WMwr49DHncdqvEyNdq t+FGT3n9AO9zeJjmvIqhd79DWt9sBbLksYKEfJxz/UmsFt4rS1AZIakJU5cR9r58D8Fd MmiaNWwiI6+Qa4Oy9rSFAUMrB4/gwwfuGJ2m+48NfHj3j4I13Lkg9wBXEtp7LWzRmTPX RpPjaxT1tY5Xb7XZgw/mmcuBcXTDRDFehqI1EBYj4hZOVaW+LbxLSkJcdOelJhw1oTf5 1c3A== X-Gm-Message-State: ACrzQf39Cyo0I5bGY50K3dxKeVupI+dY/kO4D0UnKGUq1aVp/SeBfLu0 o37iOsa0+fvYLQ1ucu9LL9E= X-Google-Smtp-Source: AMsMyM4Bu1fMhTlG4S0PHAnxdIEBVhLc19mS8ZZ+7l/U0iFeGNvvbSNjHdZ2chAAK7XJv+Ux3y/6Lw== X-Received: by 2002:a17:90b:33c5:b0:202:fa60:3765 with SMTP id lk5-20020a17090b33c500b00202fa603765mr23874242pjb.137.1664558854173; Fri, 30 Sep 2022 10:27:34 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:4075:4245:762c:e746]) by smtp.gmail.com with ESMTPSA id e10-20020a170902b78a00b00168dadc7354sm2154762pls.78.2022.09.30.10.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 10:27:33 -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: Fri, 30 Sep 2022 10:27:13 -0700 Message-Id: <20220930172714.711616-5-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220930172714.711616-1-namhyung@kernel.org> References: <20220930172714.711616-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. Reviewed-by: Adrian Hunter Signed-off-by: Namhyung Kim --- 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.38.0.rc1.362.ged0d419d3c-goog From nobody Fri May 3 08:16:31 2024 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 97D34C433FE for ; Fri, 30 Sep 2022 17:28:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232138AbiI3R2W (ORCPT ); Fri, 30 Sep 2022 13:28:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232277AbiI3R1n (ORCPT ); Fri, 30 Sep 2022 13:27:43 -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 5F69811FD24; Fri, 30 Sep 2022 10:27:36 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id b21so4542387plz.7; Fri, 30 Sep 2022 10:27:36 -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=sYSCzo/dCEHy9uom4/Q42uUwbH0+TjIpRi+wDvZ9v+M=; b=A6oyjBK3ujGB4Vjkw0+7c6QXkkKsYwASuReGkcRIxnx/bukbBl6OVSZ1GFOvYJmR/q 11jx0FFxDlO1eKDdaBkWlfJDDDJM8yey0o9WnBGyuhOo/+C6Uar/pA+2q4mEMt0Y/CQi VFp8M3YCYVPGq4ie4F5aGLUNUB/enFDBqdZL9vG/5fyvHdgurCZucNvNxb+gUiHV4Nzf w7zN/N7DOXY+OAfIc7huXnZ5v8sAXuMKdLF+NVQKJftjpsbinPJgRlhuJj6LgP0u/KNf irAtY9/i2rX7WJ/q/SEYsbm/7ibFRkv+epEYKLDaTiYrmtKTaV7i1keCSRlKfhq7msjm ZlVg== 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=sYSCzo/dCEHy9uom4/Q42uUwbH0+TjIpRi+wDvZ9v+M=; b=PQ4hBSs7xjUD98o0iqm7XAczG1M6HVFx/GZmAFyWlPv0kamX4UflAFDkSRFtNoOscX WXdgsrbKNXZIHnnmKUVdSbe9Chm7aoSD6UZnHgyuoLIEIYDfosAQ39uTsQ1PStqDIoej 2ewiizFwCyk9tfCj0VFW4IyMylZmr8UmUmuHXTj92nhfwnqWtgLP8rOalBu3KKwD8E4e mi35UvYbwyuC62rqVKTgqqxWqOfSmn/KlON4kL81DGixxSwSyYOZb58F0RVud32dZzfG SC4JKaQndzmdbLp4+xd3y/a4F7mVM3T/jXoh47E21tD0HLVKbknMD+Ooe6lCimeQhWMX VZ2Q== X-Gm-Message-State: ACrzQf0v21HR8zm0pdqEiyEMGTsZeQHr+CtaCXN4zGJunnYMJ/x+GD2q p9yRxEudzN3Sr78/kfqujIk= X-Google-Smtp-Source: AMsMyM6RUSc/dZNQniCXQYK/8cTEtNmC4JENUAgxWQEUj1kF8z0vILQ5f5f4iHdQ1ZsvVPyTPjlTkA== X-Received: by 2002:a17:90b:1c07:b0:202:ff6e:6015 with SMTP id oc7-20020a17090b1c0700b00202ff6e6015mr10994970pjb.210.1664558855318; Fri, 30 Sep 2022 10:27:35 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:4075:4245:762c:e746]) by smtp.gmail.com with ESMTPSA id e10-20020a170902b78a00b00168dadc7354sm2154762pls.78.2022.09.30.10.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 10:27:34 -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: Fri, 30 Sep 2022 10:27:14 -0700 Message-Id: <20220930172714.711616-6-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220930172714.711616-1-namhyung@kernel.org> References: <20220930172714.711616-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. Reviewed-by: Adrian Hunter Signed-off-by: Namhyung Kim --- 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.38.0.rc1.362.ged0d419d3c-goog