From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5AFE9C77B61 for ; Mon, 24 Apr 2023 15:37:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Po332d8Qxv9xNHVT8ikBc/nljsGQICGgbkk8Fcx9EF8=; b=eImwR4NYRVuwUt XI3ZF+6N94LUOr5GB2sbAH8/VcFD0gWpAHL+JnrvzWXOCaxoiGxRKTG9z8MML6Qbo0X0XfenrOVJO qBBoyWb65FcFeo+Nhgw4rzBISfPeZMmrVAk5b3kCfY/QwNp9V8SuP631FYZlBoZTQpr9qAOsotIua 7CGa0spTG+UD6OCTT0lyFy+0MlrW0U6aNRKVMEtIomEYnvScAucl9m59eAd7xKUqjgbOEENo7s4n3 DLMW9XeWy3ZPk8i2kDOAPEYoOPPbVXYC9Jc3WU6Y67/golH6vuBG+MJwMkoQam+le6SX37m8LQ71X IjBXuklFqSFytgSLOkRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pqyEu-00GiFB-1d; Mon, 24 Apr 2023 15:36:28 +0000 Received: from mga09.intel.com ([134.134.136.24]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pqyEr-00GiEL-15 for linux-arm-kernel@lists.infradead.org; Mon, 24 Apr 2023 15:36:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1682350585; x=1713886585; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=/c3+7fN4hIHgLN5YbLi2NThTNwQuocvN8Q/dAhPDBSs=; b=m5LfJQKouTVCU63Ee1AzvjjbE39Uw/AAyhu1dAJ8Ls2DGnRK3wrig4vm xDZ08U8WMmGemVYlfOi0e8TbF7vOKHMBLGjD/NBLuvvDzJS1Pia4c53jX T1YJ45OD+BZI1Ha8A08Ht9fGvxXKUNW90uyLz/+OUoofp+scR/3/skPLN CHkkaZKO/+nnbgX6xCmOrdq8N2LsvIBi3i/mFSN1CdVJdRSl1JRDdCF+4 QxcYjUadpWKNCEHxYEK371Cm+9YxYcX1q5dpXPGlT+OitQjrO/w/qHTa3 sV0jF+lYXm/3K/yWLexpmZDEg0TK4m1ZoZkmDIPvjK0ZIkhZfeR5LvDJm A==; X-IronPort-AV: E=McAfee;i="6600,9927,10690"; a="348393224" X-IronPort-AV: E=Sophos;i="5.99,223,1677571200"; d="scan'208";a="348393224" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2023 08:36:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10690"; a="725734757" X-IronPort-AV: E=Sophos;i="5.99,223,1677571200"; d="scan'208";a="725734757" Received: from hschroed-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.252.33.95]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2023 08:36:18 -0700 Message-ID: Date: Mon, 24 Apr 2023 18:36:14 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.10.0 Subject: Re: [PATCH 2/7] perf tools: Add util function for overriding user set config values To: James Clark , linux-perf-users@vger.kernel.org, coresight@lists.linaro.org, shy828301@gmail.com Cc: denik@google.com, 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 References: <20230424134748.228137-1-james.clark@arm.com> <20230424134748.228137-3-james.clark@arm.com> Content-Language: en-US From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: <20230424134748.228137-3-james.clark@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230424_083625_424308_2A5D6B88 X-CRM114-Status: GOOD ( 30.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 24/04/23 16:47, James Clark wrote: > 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 One minor comment, nevertheless: 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)) I notice there is already tools/include/linux/bitfield.h so may FIELD_PREP from there could be used? > +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 */ _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel