Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp27312329rwd; Tue, 4 Jul 2023 00:52:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlGQUqnZnLIAqJKo10npppt71P+p744RriZz6LhO5gYDUlyWB7a0Xxm07WouQyKYDJMPxRz5 X-Received: by 2002:a05:6a00:139f:b0:682:713e:e510 with SMTP id t31-20020a056a00139f00b00682713ee510mr14097467pfg.27.1688457177446; Tue, 04 Jul 2023 00:52:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688457177; cv=none; d=google.com; s=arc-20160816; b=XUEJLlvveA+8aR9jg6FxDccTgxuh7/Vx3yi+XOgx03xNYimnLPUbimSZRdphLTKReK 2c9qo3gnMXVXAJrx3DeWoagJ3j7KoskZ/uqNCnFPz2JT3zo1WaGJ/d6iyoi10dDIYZ2f mWPnZCILT8tViyg6Gs7YWTuZ5Rvc9alLAD69jBCMzXIpx/fDGMIxNk3iTDthendVen6h vp6FG1Sq199+0lgRt0Pu0HaZz8GBGKj5lQeBGJm1yfnY4lN3pHbZdZs6DMQnlJ2GqPTT sbmbIG1FPGcVV2Ui9IWcbSZNgh3xd/yEHbC0Y7fmwsHjP/RiqnYi7jH2Nb4Ga/RLD84G 5pog== 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=pFWuk9CQgB53mYDiTiy+lICk6MCGHxzRe0lIgvhuc8E=; fh=td1tWwqmzXUMurl83U4wnxYbX8ZMZukrMraSvbRxzQ0=; b=fXJkvDvIo4aDPDm1AvSSy+K90m/QOyf/NbCXzZlgnZBIPwxWqoIdFnIMx2AsTPlwBK tLlofSkEy6HzGI4omlBQlRJkJst8Yii4lzwzec5E1IpG9Z73BnEMaJhoGuNfLZwCn5j8 v5UB9j5MF3s4f4Yuu4V0yS0NQyJM9FLBjKFvQL/xWINgmiCySBLhubys3WmJW5t7G/sV +wvbtVQ8wHATeuYuyl5sc0901mptjVlev4eMJpPt+wSfagNIsDA4G3V5hrn7rX9zVuyZ Yc2ChW105lZ3dvZXnX1onSSHe3RDwvxuBsecPo8D5jpxRe3LTn2cgKLsQ5/jCUHIewWy NZTg== 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 ea10-20020a056a004c0a00b006543a5c8fb7si6094227pfb.286.2023.07.04.00.52.43; Tue, 04 Jul 2023 00:52:57 -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 S231358AbjGDHog (ORCPT + 99 others); Tue, 4 Jul 2023 03:44:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231345AbjGDHoa (ORCPT ); Tue, 4 Jul 2023 03:44:30 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A3DAE71; Tue, 4 Jul 2023 00:44:23 -0700 (PDT) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QwF8g56ttzMqK1; Tue, 4 Jul 2023 15:41:07 +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.27; Tue, 4 Jul 2023 15:44:20 +0800 From: Yang Jihong To: , , , , , , , , , , , CC: Subject: [PATCH 2/5] perf evlist: Add evlist__findnew_tracking_event() helper Date: Tue, 4 Jul 2023 07:42:14 +0000 Message-ID: <20230704074217.240939-3-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT In-Reply-To: <20230704074217.240939-1-yangjihong1@huawei.com> References: <20230704074217.240939-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: dggems704-chm.china.huawei.com (10.3.19.181) 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, T_SCC_BODY_TEXT_LINE 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 a dummy event for tracking to the evlist. We may need to search for the dummy event for some settings. Therefore, add evlist__findnew_tracking_event() helper. Signed-off-by: Yang Jihong --- tools/perf/builtin-record.c | 11 +++-------- tools/perf/util/evlist.c | 17 +++++++++++++++++ tools/perf/util/evlist.h | 1 + 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index aec18db7ff23..8872cd037f2c 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1295,14 +1295,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); + 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..4621ddaeb8f3 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1694,6 +1694,23 @@ 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) +{ + struct evsel *evsel; + + evsel = evlist__get_tracking_event(evlist); + if (!evsel__is_dummy_event(evsel)) { + /* Set up dummy event. */ + if (evlist__add_dummy(evlist)) + return NULL; + + evsel = evlist__last(evlist); + evlist__set_tracking_event(evlist, evsel); + } + + 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..4d28c50ba842 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); struct evsel *evlist__find_evsel_by_str(struct evlist *evlist, const char *str); -- 2.30.GIT