From patchwork Mon Apr 24 13:47:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 87064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2775167vqo; Mon, 24 Apr 2023 07:12:25 -0700 (PDT) X-Google-Smtp-Source: AKy350ZQVD6dlHAQRBROSJQ35GIxJT7OoVpJgK56tVCS+A5k3/aF6R4bg2DioCgSIKjy/v43ZXvK X-Received: by 2002:a05:6a21:3286:b0:f2:6fc6:9ca3 with SMTP id yt6-20020a056a21328600b000f26fc69ca3mr14009150pzb.43.1682345545049; Mon, 24 Apr 2023 07:12:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682345545; cv=none; d=google.com; s=arc-20160816; b=QiB+JyPjLbEbJtP2znPk9gKU3jOKTVRuqk9TeCtZksCJnrgprDlzJ27wnzC227GwzU ArRSDw506ETr/66v9PNlwS2NC0fl4KIboXeZ1pLNrqXkHlKyrdU6hZo0afZbITeKRh6R DenzodA3Gnn4ajiERfo99Z7+9qHqv1itXEsl6vVBOMf+6lSEqi0WBne3E+nTxnw5l2fg 775pqeyVMGIkwUX8AXRBVFszWQI/9bK5kQrhuhgLTlXV8O7EtXsn5qtiRiJGjlB4XQUg V4dBvgG2Wdb2MFERY8qRIcT7hXQMjdaFXsrx+HgDeERhC0cPR1wFTxw+DmYnxMtCi8ju QImQ== 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=Qar4S/g0xzUFataIzlxayhEmro1eQzBB8L8IQmxasV0=; b=h0C41VDp1LeLlyE1DWBgchSeYhOQ2y4UBVEeaoNV2VlYiNK360m494t2QKIBDFqhlv c4dsMMn2PNgWKTOffjbMzp7jEGPqiFiyRDI6aSJlfFOea28xis7sCjpzSUem/tKCR9cW 7A/VAIh5SU4sxRcHMoHixZLPao+olLDHZVGro1ZJpBBvKZVGWbiJ79y4Sfuj+hzYaIpl Ubo919acpborKTaLUvsqJEGOxpQruXEm3nZWmWbSWOkPnpW270bNfiMwEjXjS/2Q3iso 9leqrS4guzyrhyoy68WD9kdXDwKyYCUkSTjybMTqrBqOlXeUrrUzksUqqIXZdsO4D1HA f80w== 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=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o189-20020a6341c6000000b004fbf520c66bsi11099033pga.247.2023.04.24.07.12.12; Mon, 24 Apr 2023 07:12:25 -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=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232546AbjDXNsW (ORCPT + 99 others); Mon, 24 Apr 2023 09:48:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232793AbjDXNsN (ORCPT ); Mon, 24 Apr 2023 09:48:13 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 041318682; Mon, 24 Apr 2023 06:48:08 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7726ED75; Mon, 24 Apr 2023 06:48:52 -0700 (PDT) Received: from e127643.arm.com (unknown [10.57.58.229]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5D20D3F64C; Mon, 24 Apr 2023 06:48:05 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, coresight@lists.linaro.org, shy828301@gmail.com Cc: denik@google.com, James Clark , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] perf tools: Add util function for overriding user set config values Date: Mon, 24 Apr 2023 14:47:42 +0100 Message-Id: <20230424134748.228137-3-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230424134748.228137-1-james.clark@arm.com> References: <20230424134748.228137-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764067162318893434?= X-GMAIL-MSGID: =?utf-8?q?1764067162318893434?= There is some duplicated code to only override config values if they haven't already been set by the user so make a util function for this. Signed-off-by: James Clark Acked-by: Adrian Hunter --- tools/perf/arch/arm64/util/arm-spe.c | 26 ++----------------------- tools/perf/arch/x86/util/intel-pt.c | 22 ++------------------- tools/perf/util/evsel.c | 29 ++++++++++++++++++++++++++++ tools/perf/util/evsel.h | 3 +++ 4 files changed, 36 insertions(+), 44 deletions(-) diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c index ef497a29e814..3b1676ff03f9 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -36,29 +36,6 @@ struct arm_spe_recording { bool *wrapped; }; -static void arm_spe_set_timestamp(struct auxtrace_record *itr, - struct evsel *evsel) -{ - struct arm_spe_recording *ptr; - struct perf_pmu *arm_spe_pmu; - struct evsel_config_term *term = evsel__get_config_term(evsel, CFG_CHG); - u64 user_bits = 0, bit; - - ptr = container_of(itr, struct arm_spe_recording, itr); - arm_spe_pmu = ptr->arm_spe_pmu; - - if (term) - user_bits = term->val.cfg_chg; - - bit = perf_pmu__format_bits(&arm_spe_pmu->format, "ts_enable"); - - /* Skip if user has set it */ - if (bit & user_bits) - return; - - evsel->core.attr.config |= bit; -} - static size_t arm_spe_info_priv_size(struct auxtrace_record *itr __maybe_unused, struct evlist *evlist __maybe_unused) @@ -238,7 +215,8 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, */ if (!perf_cpu_map__empty(cpus)) { evsel__set_sample_bit(arm_spe_evsel, CPU); - arm_spe_set_timestamp(itr, arm_spe_evsel); + evsel__set_config_if_unset(arm_spe_pmu, arm_spe_evsel, + "ts_enable", 1); } /* diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c index 2cff11de9d8a..17336da08b58 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -576,25 +576,6 @@ static int intel_pt_validate_config(struct perf_pmu *intel_pt_pmu, return err; } -static void intel_pt_config_sample_mode(struct perf_pmu *intel_pt_pmu, - struct evsel *evsel) -{ - u64 user_bits = 0, bits; - struct evsel_config_term *term = evsel__get_config_term(evsel, CFG_CHG); - - if (term) - user_bits = term->val.cfg_chg; - - bits = perf_pmu__format_bits(&intel_pt_pmu->format, "psb_period"); - - /* Did user change psb_period */ - if (bits & user_bits) - return; - - /* Set psb_period to 0 */ - evsel->core.attr.config &= ~bits; -} - static void intel_pt_min_max_sample_sz(struct evlist *evlist, size_t *min_sz, size_t *max_sz) { @@ -686,7 +667,8 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, return 0; if (opts->auxtrace_sample_mode) - intel_pt_config_sample_mode(intel_pt_pmu, intel_pt_evsel); + evsel__set_config_if_unset(intel_pt_pmu, intel_pt_evsel, + "psb_period", 0); err = intel_pt_validate_config(intel_pt_pmu, intel_pt_evsel); if (err) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index a85a987128aa..cdf1445136ad 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3216,3 +3216,32 @@ void evsel__remove_from_group(struct evsel *evsel, struct evsel *leader) leader->core.nr_members--; } } + +/* + * Set @config_name to @val as long as the user hasn't already set or cleared it + * by passing a config term on the command line. + * + * @val is the value to put into the bits specified by @config_name rather than + * the bit pattern. It is shifted into position by this function, so to set + * something to true, pass 1 for val rather than a pre shifted value. + */ +#define field_prep(_mask, _val) (((_val) << (ffsll(_mask) - 1)) & (_mask)) +void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel, + const char *config_name, u64 val) +{ + u64 user_bits = 0, bits; + struct evsel_config_term *term = evsel__get_config_term(evsel, CFG_CHG); + + if (term) + user_bits = term->val.cfg_chg; + + bits = perf_pmu__format_bits(&pmu->format, config_name); + + /* Do nothing if the user changed the value */ + if (bits & user_bits) + return; + + /* Otherwise replace it */ + evsel->core.attr.config &= ~bits; + evsel->core.attr.config |= field_prep(bits, val); +} diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 68072ec655ce..4120f5ff673d 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -529,4 +529,7 @@ bool arch_evsel__must_be_in_group(const struct evsel *evsel); ((((src) >> (pos)) & ((1ull << (size)) - 1)) << (63 - ((pos) + (size) - 1))) u64 evsel__bitfield_swap_branch_flags(u64 value); +void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel, + const char *config_name, u64 val); + #endif /* __PERF_EVSEL_H */