linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: "Liang, Kan" <kan.liang@linux.intel.com>,
	Ian Rogers <irogers@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Zhengjun Xing <zhengjun.xing@linux.intel.com>,
	Ravi Bangoria <ravi.bangoria@amd.com>,
	"Steinar H. Gunderson" <sesse@google.com>,
	Kim Phillips <kim.phillips@amd.com>,
	Florian Fischer <florian.fischer@muhq.space>,
	James Clark <james.clark@arm.com>,
	Suzuki Poulouse <suzuki.poulose@arm.com>,
	Sean Christopherson <seanjc@google.com>,
	Leo Yan <leo.yan@linaro.org>,
	John Garry <john.g.garry@oracle.com>,
	Kajol Jain <kjain@linux.ibm.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH v2 03/10] perf record: Early auxtrace initialization before event parsing
Date: Mon, 6 Mar 2023 11:31:52 +0200	[thread overview]
Message-ID: <9788f0f1-087f-7f0b-048a-0146afe1f632@intel.com> (raw)
In-Reply-To: <4473367b-38e1-7c15-3937-a077d68410b7@intel.com>

On 5/03/23 10:32, Adrian Hunter wrote:
> On 3/03/23 18:40, Liang, Kan wrote:
>>
>>
>> On 2023-03-02 4:25 p.m., Ian Rogers wrote:
>>> This allows event parsing to use the evsel__is_aux_event function,
>>> which is important when determining event grouping.
>>>
>>> Signed-off-by: Ian Rogers <irogers@google.com>
>>> ---
>>>  tools/perf/arch/x86/util/auxtrace.c | 17 +++++++++++++----
>>>  tools/perf/builtin-record.c         |  6 ++++++
>>>  tools/perf/util/auxtrace.h          |  2 ++
>>>  3 files changed, 21 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/tools/perf/arch/x86/util/auxtrace.c b/tools/perf/arch/x86/util/auxtrace.c
>>> index 3da506e13f49..de1e4842ea2e 100644
>>> --- a/tools/perf/arch/x86/util/auxtrace.c
>>> +++ b/tools/perf/arch/x86/util/auxtrace.c
>>> @@ -15,6 +15,19 @@
>>>  #include "../../../util/intel-bts.h"
>>>  #include "../../../util/evlist.h"
>>>  
>>> +void auxtrace__early_init(void)
>>> +{
>>> +	struct perf_pmu *intel_pt_pmu;
>>> +	struct perf_pmu *intel_bts_pmu;
>>> +
>>> +	intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
>>> +	if (intel_pt_pmu)
>>> +		intel_pt_pmu->auxtrace = true;
>>> +	intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
>>> +	if (intel_bts_pmu)
>>> +		intel_bts_pmu->auxtrace = true;
>>> +}
>>> +
>>>  static
>>>  struct auxtrace_record *auxtrace_record__init_intel(struct evlist *evlist,
>>>  						    int *err)
>>> @@ -26,11 +39,7 @@ struct auxtrace_record *auxtrace_record__init_intel(struct evlist *evlist,
>>>  	bool found_bts = false;
>>>  
>>>  	intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
>>> -	if (intel_pt_pmu)
>>> -		intel_pt_pmu->auxtrace = true;
>>>  	intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
>>> -	if (intel_bts_pmu)
>>> -		intel_bts_pmu->auxtrace = true;
>>>  
>>>  	evlist__for_each_entry(evlist, evsel) {
>>>  		if (intel_pt_pmu && evsel->core.attr.type == intel_pt_pmu->type)
>>> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
>>> index 8374117e66f6..a0870c076dc0 100644
>>> --- a/tools/perf/builtin-record.c
>>> +++ b/tools/perf/builtin-record.c
>>> @@ -3940,6 +3940,10 @@ static int record__init_thread_masks(struct record *rec)
>>>  	return ret;
>>>  }
>>>  
>>> +__weak void auxtrace__early_init(void)
>>> +{
>>> +}
>>> +
>>>  int cmd_record(int argc, const char **argv)
>>>  {
>>>  	int err;
>>> @@ -3985,6 +3989,8 @@ int cmd_record(int argc, const char **argv)
>>>  	if (err)
>>>  		return err;
>>>  
>>> +	auxtrace__early_init();
>>
>> So the auxtrace__early_init() will be unconditionally invoked even there
>> is no PT or BTS events, right?
>>
>> Maybe we should move the auxtrace__early_init() to evsel__is_aux_event()
>> and cache the value. The initialization will only be invoked when it's
>> required.
> 
> Although perf_pmu__find() will be called unconditionally via
> record__auxtrace_init() anyway.

However auxtrace__early_init() is before parsing 'verbose' so
debug prints don't work anymore.

How about this instead:

diff --git a/tools/perf/arch/x86/util/auxtrace.c
b/tools/perf/arch/x86/util/auxtrace.c
index 3da506e13f49d..330d03216b0e6 100644
--- a/tools/perf/arch/x86/util/auxtrace.c
+++ b/tools/perf/arch/x86/util/auxtrace.c
@@ -26,11 +26,7 @@ struct auxtrace_record
*auxtrace_record__init_intel(struct evlist *evlist,
 	bool found_bts = false;

 	intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
-	if (intel_pt_pmu)
-		intel_pt_pmu->auxtrace = true;
 	intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
-	if (intel_bts_pmu)
-		intel_bts_pmu->auxtrace = true;

 	evlist__for_each_entry(evlist, evsel) {
 		if (intel_pt_pmu && evsel->core.attr.type == intel_pt_pmu->type)
diff --git a/tools/perf/arch/x86/util/pmu.c b/tools/perf/arch/x86/util/pmu.c
index 358340b342431..f73b80dcd8bdc 100644
--- a/tools/perf/arch/x86/util/pmu.c
+++ b/tools/perf/arch/x86/util/pmu.c
@@ -27,10 +27,14 @@ static bool cached_list;
 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu
*pmu __maybe_unused)
 {
 #ifdef HAVE_AUXTRACE_SUPPORT
-	if (!strcmp(pmu->name, INTEL_PT_PMU_NAME))
+	if (!strcmp(pmu->name, INTEL_PT_PMU_NAME)) {
+		pmu->auxtrace = true;
 		return intel_pt_pmu_default_config(pmu);
-	if (!strcmp(pmu->name, INTEL_BTS_PMU_NAME))
+	}
+	if (!strcmp(pmu->name, INTEL_BTS_PMU_NAME)) {
+		pmu->auxtrace = true;
 		pmu->selectable = true;
+	}
 #endif
 	return NULL;
 }



> 
>> Something as below (not tested.)
>>
>> +void auxtrace__init(void)
>> +{
>> +	struct perf_pmu *intel_pt_pmu;
>> +	struct perf_pmu *intel_bts_pmu;
>> +	static bool cached;
>> +
>> +	if (cached)
>> +		return;
>> +	intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
>> +	if (intel_pt_pmu)
>> +		intel_pt_pmu->auxtrace = true;
>> +	intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
>> +	if (intel_bts_pmu)
>> +		intel_bts_pmu->auxtrace = true;
>> +}
>>
>> bool evsel__is_aux_event(struct evsel *evsel)
>> {
>> 	struct perf_pmu *pmu = evsel__find_pmu(evsel);
>> +	auxtrace__init();
>> 	return pmu && pmu->auxtrace;
>> }
>>
>>
>>
>> Thanks,
>> Kan
>>
>>> +
>>>  	argc = parse_options(argc, argv, record_options, record_usage,
>>>  			    PARSE_OPT_STOP_AT_NON_OPTION);
>>>  	if (quiet)
>>> diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
>>> index 29eb82dff574..49a86aa6ac94 100644
>>> --- a/tools/perf/util/auxtrace.h
>>> +++ b/tools/perf/util/auxtrace.h
>>> @@ -457,6 +457,8 @@ struct addr_filters {
>>>  
>>>  struct auxtrace_cache;
>>>  
>>> +void auxtrace__early_init(void);
>>> +
>>>  #ifdef HAVE_AUXTRACE_SUPPORT
>>>  
>>>  u64 compat_auxtrace_mmap__read_head(struct auxtrace_mmap *mm);
> 


  reply	other threads:[~2023-03-06  9:32 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 21:25 [PATCH v2 00/10] Better fixes for grouping of events Ian Rogers
2023-03-02 21:25 ` [PATCH v2 01/10] libperf evlist: Avoid a use of evsel idx Ian Rogers
2023-03-02 21:25 ` [PATCH v2 02/10] perf stat: Don't remove all grouped events when CPU maps disagree Ian Rogers
2023-03-03 15:50   ` Liang, Kan
2023-03-03 16:44     ` Ian Rogers
2023-03-03 17:36       ` Liang, Kan
2023-03-02 21:25 ` [PATCH v2 03/10] perf record: Early auxtrace initialization before event parsing Ian Rogers
2023-03-03 16:40   ` Liang, Kan
2023-03-05  8:32     ` Adrian Hunter
2023-03-06  9:31       ` Adrian Hunter [this message]
2023-03-06 14:10         ` Liang, Kan
2023-03-02 21:25 ` [PATCH v2 04/10] perf stat: Modify the group test Ian Rogers
2023-03-02 21:25 ` [PATCH v2 05/10] perf evsel: Allow const evsel for certain accesses Ian Rogers
2023-03-03  0:14   ` Namhyung Kim
2023-03-03  1:40     ` Ian Rogers
2023-03-02 21:25 ` [PATCH v2 06/10] perf evsel: Add function to compute pmu_name Ian Rogers
2023-03-03  0:18   ` Namhyung Kim
2023-03-03  1:41     ` Ian Rogers
2023-03-02 21:25 ` [PATCH v2 07/10] perf parse-events: Pass ownership of the group name Ian Rogers
2023-03-02 21:25 ` [PATCH v2 08/10] perf parse-events: Sort and group parsed events Ian Rogers
2023-03-03  0:37   ` Namhyung Kim
2023-03-03  1:39     ` Ian Rogers
2023-03-04  2:22       ` Namhyung Kim
2023-03-02 21:25 ` [PATCH v2 09/10] perf evsel: Remove use_uncore_alias Ian Rogers
2023-03-02 21:25 ` [PATCH v2 10/10] perf evlist: Remove nr_groups Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9788f0f1-087f-7f0b-048a-0146afe1f632@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=florian.fischer@muhq.space \
    --cc=irogers@google.com \
    --cc=james.clark@arm.com \
    --cc=john.g.garry@oracle.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=kim.phillips@amd.com \
    --cc=kjain@linux.ibm.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=seanjc@google.com \
    --cc=sesse@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=zhengjun.xing@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).