Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp1547039rdb; Sat, 26 Aug 2023 07:06:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGr0y2ds6oMp8FznocdOForLHDtKf0gjgorGMqqT0wVQ558XmhHcq6X9ZHcTJ+Hr9daQjoS X-Received: by 2002:a05:6a20:9155:b0:126:8b2d:4462 with SMTP id x21-20020a056a20915500b001268b2d4462mr29703734pzc.24.1693058778405; Sat, 26 Aug 2023 07:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693058778; cv=none; d=google.com; s=arc-20160816; b=oBdgTFip0g4NO0/2zvqoJNqVEKZVyYOvn2NyjpNn3wvdSlr3vs44RrOobJmpY8GIDC Bmj1Usdl1O+J8lj/1u/DZWz4fWXPF9nCoDcGnyt3ptt3xl96sc4fmWRiDKIKu8mNJ3hr Gb0XeD5dYeaXjyn1HIsCnmBERX0qqWTfjh/uqV6BTgsZEwf9PEkUWLxKQqYd4gE5Pe8K iwxSjpHH3MFyGXL1BSb7HC0P1XmHuU8cw18t6O3qBGlbCcqKoHNDU6q+DbjHJc/a4XJ1 GcdKD0IeVb/8gef1c81ZqQxyoXTbMoMgyi15IR4MVyeFVlK8CUTOqdN7zChXTNWqalKn raVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lbunSUlYHN4XSqlpqGLHYfVVSMmVb4ijlh+Wev58uBg=; fh=+V2NJRwYYldEteK9NYuSkp4iZMVHSlTgEsLCPEY32o0=; b=n7G7InB0PpEW5qTfbrd1pLY4ULX2yXsjd1TW1QpNt+ya1DAfX6aMvBA8m5qEu0Bs0n 6GZmrrdTAAM7w+DiDc86GadnAtj0J0jTgGtcEh6XC3oVVBUwfVx08lGqKpJMnOCV/wjg bvwB2p11BwoCpFo+dH1bCxr+ILDX+Yyhc4YNOlcMzYt7S7mI/GGHQxV2nJv2sy+CWJqS g9T+nIplqh0TQAxQJzttN1PeO0KsSJvX1aM5ksWceQDzTS2mJYw8SL2+xHSxYI8A3GGP Vo0zEc+FM8ZUAe2MCkkL26cCstHQz3Um30TJj11yuyO7wi6bKaPr/cfNgOAduhGi6hh2 5maQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l184-20020a6388c1000000b00565fb7714a5si3754585pgd.800.2023.08.26.07.05.56; Sat, 26 Aug 2023 07:06:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231777AbjHZD3v (ORCPT + 99 others); Fri, 25 Aug 2023 23:29:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231299AbjHZD3N (ORCPT ); Fri, 25 Aug 2023 23:29:13 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 447632137; Fri, 25 Aug 2023 20:29:09 -0700 (PDT) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RXhz41BLcztSLw; Sat, 26 Aug 2023 11:25:20 +0800 (CST) Received: from localhost.localdomain (10.67.174.95) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 26 Aug 2023 11:29:06 +0800 From: Yang Jihong To: , , , , , , , , , , , , , , , CC: Subject: [PATCH v7 2/6] perf evlist: Add evlist__findnew_tracking_event() helper Date: Sat, 26 Aug 2023 03:26:04 +0000 Message-ID: <20230826032608.107261-3-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT In-Reply-To: <20230826032608.107261-1-yangjihong1@huawei.com> References: <20230826032608.107261-1-yangjihong1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.95] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, intel-bts, intel-pt, and arm-spe may add tracking event to the evlist. We may need to search for the tracking event for some settings. Therefore, add evlist__findnew_tracking_event() helper. If system_wide is true, evlist__findnew_tracking_event() set the cpu map of the evsel to all online CPUs. Signed-off-by: Yang Jihong Acked-by: Adrian Hunter --- tools/perf/builtin-record.c | 11 +++-------- tools/perf/util/evlist.c | 18 ++++++++++++++++++ tools/perf/util/evlist.h | 1 + 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 34bb31f08bb5..12edad8392cc 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1293,14 +1293,9 @@ static int record__open(struct record *rec) */ if (opts->target.initial_delay || target__has_cpu(&opts->target) || perf_pmus__num_core_pmus() > 1) { - pos = evlist__get_tracking_event(evlist); - if (!evsel__is_dummy_event(pos)) { - /* Set up dummy event. */ - if (evlist__add_dummy(evlist)) - return -ENOMEM; - pos = evlist__last(evlist); - evlist__set_tracking_event(evlist, pos); - } + pos = evlist__findnew_tracking_event(evlist, false); + if (!pos) + return -ENOMEM; /* * Enable the dummy event when the process is forked for diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 7ef43f72098e..25c3ebe2c2f5 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1694,6 +1694,24 @@ void evlist__set_tracking_event(struct evlist *evlist, struct evsel *tracking_ev tracking_evsel->tracking = true; } +struct evsel *evlist__findnew_tracking_event(struct evlist *evlist, bool system_wide) +{ + struct evsel *evsel; + + evsel = evlist__get_tracking_event(evlist); + if (!evsel__is_dummy_event(evsel)) { + evsel = evlist__add_aux_dummy(evlist, system_wide); + if (!evsel) + return NULL; + + evlist__set_tracking_event(evlist, evsel); + } else if (system_wide) { + perf_evlist__go_system_wide(&evlist->core, &evsel->core); + } + + return evsel; +} + struct evsel *evlist__find_evsel_by_str(struct evlist *evlist, const char *str) { struct evsel *evsel; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 664c6bf7b3e0..98e7ddb2bd30 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -387,6 +387,7 @@ bool evlist_cpu_iterator__end(const struct evlist_cpu_iterator *evlist_cpu_itr); struct evsel *evlist__get_tracking_event(struct evlist *evlist); void evlist__set_tracking_event(struct evlist *evlist, struct evsel *tracking_evsel); +struct evsel *evlist__findnew_tracking_event(struct evlist *evlist, bool system_wide); struct evsel *evlist__find_evsel_by_str(struct evlist *evlist, const char *str); -- 2.30.GIT