From patchwork Mon Aug 21 01:27:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Jihong X-Patchwork-Id: 136354 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp2876870vqi; Mon, 21 Aug 2023 02:12:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGywEzgTc01fwods5rpjGNnB1Oagj7tYy8tHuCtLk8K5hTmdJh9PV5+9w0r77he2FEbkZIE X-Received: by 2002:a17:907:2bec:b0:99b:6687:6107 with SMTP id gv44-20020a1709072bec00b0099b66876107mr4466834ejc.5.1692609158683; Mon, 21 Aug 2023 02:12:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692609158; cv=none; d=google.com; s=arc-20160816; b=TJnCYba/owDotvzL2N3yIPKw5Ew1uICCkJZOaq74W3JrYFyZZ9Wz6SIVldjipNhioN 2zPf/0ri+yOkL/hrAsuCQslapvQhm/qabaLYEO0jbI6m8ecWdrUQ0h66H1gJMon2VuQ7 m2E15eWTyRzcg52yykt69mMIRc7rO9dh0gZ99eRFmwNJLyQ+F6bakCBOnx0Bjfh0unee e61lDHpYI9yTc9FvnmyKXt1fwmt3fZdbQ8A0Brg9re9X40bEGUpP6J5M80qef38xm7Ci cKVJEAyOq7StmNcz9ICVIA+HG1qjCmgPinHS3A/YZUG/Ls+RevIu4UNHady1GYZ+NBvc IgEw== 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=nMSTfxhFgTBueV4KmmxTm1dfLVOIgFeFUynLJzHV0UA=; fh=Ib1wi7jRbo+eNDLEErvWCJx+cnUm87PkGFthhdFf08Y=; b=vKkSqmp6C7xyy5SlAkU/KHxARsCogTVhtOLgYcuSKdsEsovoBibF1qItAUg4KTjlhw 4FQg7UGQH/wbz0F/kJV52L1Iftdjcu9Wih4yCwa94YQsIp8tWwfa7TM0x3q5XdAncgdQ 5LpvEhVvOG9xmATycFkOQKQk2A8cG+vY8/eDA6TCaouQIZqPiohudHwj2aiAs/ymNOoh kEi3U+h5KteDPTZ7XSiNWf8m88Uey3Q1nuS9LESAImIWhvPf+u9fGWGz/0WYjlA9ZZGl Pit5eN90113XdHhdrAz8xTPXpIeCP3qk5eNatTod61HkW96ul3w6z6HQDlCKHMq5gJG4 sTnQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ec9-20020a170906b6c900b00993150e5327si4996165ejb.341.2023.08.21.02.12.13; Mon, 21 Aug 2023 02:12:38 -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 S232412AbjHUBah (ORCPT + 99 others); Sun, 20 Aug 2023 21:30:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232363AbjHUBad (ORCPT ); Sun, 20 Aug 2023 21:30:33 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B784AC; Sun, 20 Aug 2023 18:30:30 -0700 (PDT) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RTZd93T6wzrSTp; Mon, 21 Aug 2023 09:29:01 +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; Mon, 21 Aug 2023 09:30:27 +0800 From: Yang Jihong To: , , , , , , , , , , , , , , , CC: Subject: [PATCH v6 2/7] perf evlist: Add evlist__findnew_tracking_event() helper Date: Mon, 21 Aug 2023 01:27:29 +0000 Message-ID: <20230821012734.18241-3-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT In-Reply-To: <20230821012734.18241-1-yangjihong1@huawei.com> References: <20230821012734.18241-1-yangjihong1@huawei.com> MIME-Version: 1.0 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=-2.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774829341481323732 X-GMAIL-MSGID: 1774829341481323732 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. evlist__findnew_tracking_event() also deal with system_wide maps if system_wide is true. 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);