diff mbox series

[v1,22/26] perf auxevent: Add explicit dummy tool initialization

Message ID 20240625172603.900667-23-irogers@google.com (mailing list archive)
State New
Headers show
Series Constify tool pointers | expand

Commit Message

Ian Rogers June 25, 2024, 5:25 p.m. UTC
Ensure tool is initialized to avoid lazy initialization pattern so
that more uses of struct perf_tool can be made const.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/arm-spe.c     | 1 +
 tools/perf/util/cs-etm.c      | 1 +
 tools/perf/util/intel-bts.c   | 1 +
 tools/perf/util/intel-pt.c    | 2 +-
 tools/perf/util/s390-cpumsf.c | 1 -
 5 files changed, 4 insertions(+), 2 deletions(-)

Comments

Adrian Hunter June 26, 2024, 6:59 a.m. UTC | #1
On 25/06/24 20:25, Ian Rogers wrote:
> Ensure tool is initialized to avoid lazy initialization pattern so
> that more uses of struct perf_tool can be made const.

This does not look necessary.

The dummy tool is not used, and is not subject to lazy initialization,
so the existing initialization to zero is fine.

> 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/arm-spe.c     | 1 +
>  tools/perf/util/cs-etm.c      | 1 +
>  tools/perf/util/intel-bts.c   | 1 +
>  tools/perf/util/intel-pt.c    | 2 +-
>  tools/perf/util/s390-cpumsf.c | 1 -
>  5 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
> index 70bad18c4a0d..06a198b2f483 100644
> --- a/tools/perf/util/arm-spe.c
> +++ b/tools/perf/util/arm-spe.c
> @@ -1097,6 +1097,7 @@ static int arm_spe_synth_event(struct perf_session *session,
>  
>  	memset(&arm_spe_synth, 0, sizeof(struct arm_spe_synth));
>  	arm_spe_synth.session = session;
> +	perf_tool__init(&arm_spe_synth.dummy_tool, /*ordered_events=*/false);
>  
>  	return perf_event__synthesize_attr(&arm_spe_synth.dummy_tool, attr, 1,
>  					   &id, arm_spe_event_synth);
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 231cd833c012..02eb5b3eed14 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
> @@ -1619,6 +1619,7 @@ static int cs_etm__synth_event(struct perf_session *session,
>  
>  	memset(&cs_etm_synth, 0, sizeof(struct cs_etm_synth));
>  	cs_etm_synth.session = session;
> +	perf_tool__init(&cs_etm_synth.dummy_tool, /*ordered_events=*/false);
>  
>  	return perf_event__synthesize_attr(&cs_etm_synth.dummy_tool, attr, 1,
>  					   &id, cs_etm__event_synth);
> diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
> index 779982c478e0..ae97109542be 100644
> --- a/tools/perf/util/intel-bts.c
> +++ b/tools/perf/util/intel-bts.c
> @@ -761,6 +761,7 @@ static int intel_bts_synth_event(struct perf_session *session,
>  
>  	memset(&intel_bts_synth, 0, sizeof(struct intel_bts_synth));
>  	intel_bts_synth.session = session;
> +	perf_tool__init(&intel_bts_synth.dummy_tool, /*ordered_events=*/false);
>  
>  	return perf_event__synthesize_attr(&intel_bts_synth.dummy_tool, attr, 1,
>  					   &id, intel_bts_event_synth);
> diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
> index bed35029e1f6..48ed60e521ed 100644
> --- a/tools/perf/util/intel-pt.c
> +++ b/tools/perf/util/intel-pt.c
> @@ -3687,7 +3687,7 @@ static int intel_pt_synth_event(struct perf_session *session, const char *name,
>  
>  	memset(&intel_pt_synth, 0, sizeof(struct intel_pt_synth));
>  	intel_pt_synth.session = session;
> -
> +	perf_tool__init(&intel_pt_synth.dummy_tool, /*ordered_events=*/false);
>  	err = perf_event__synthesize_attr(&intel_pt_synth.dummy_tool, attr, 1,
>  					  &id, intel_pt_event_synth);
>  	if (err)
> diff --git a/tools/perf/util/s390-cpumsf.c b/tools/perf/util/s390-cpumsf.c
> index 5834bad6ac0f..eb835e531cd6 100644
> --- a/tools/perf/util/s390-cpumsf.c
> +++ b/tools/perf/util/s390-cpumsf.c
> @@ -953,7 +953,6 @@ s390_cpumsf_process_event(struct perf_session *session,
>  }
>  
>  struct s390_cpumsf_synth {
> -	struct perf_tool cpumsf_tool;
>  	struct perf_session *session;
>  };
>
Ian Rogers June 26, 2024, 5:54 p.m. UTC | #2
On Tue, Jun 25, 2024 at 11:59 PM Adrian Hunter <adrian.hunter@intel.com> wrote:
>
> On 25/06/24 20:25, Ian Rogers wrote:
> > Ensure tool is initialized to avoid lazy initialization pattern so
> > that more uses of struct perf_tool can be made const.
>
> This does not look necessary.
>
> The dummy tool is not used, and is not subject to lazy initialization,
> so the existing initialization to zero is fine.

Thanks, I wonder if we should try to save space in this case with
something like:

```
struct intel_pt_synth {
  struct perf_session *session;
  struct perf_tool dummy_tool[0];
};
```

I'll play around while dropping the initialization calls.

Thanks,
Ian

> >
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > ---
> >  tools/perf/util/arm-spe.c     | 1 +
> >  tools/perf/util/cs-etm.c      | 1 +
> >  tools/perf/util/intel-bts.c   | 1 +
> >  tools/perf/util/intel-pt.c    | 2 +-
> >  tools/perf/util/s390-cpumsf.c | 1 -
> >  5 files changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
> > index 70bad18c4a0d..06a198b2f483 100644
> > --- a/tools/perf/util/arm-spe.c
> > +++ b/tools/perf/util/arm-spe.c
> > @@ -1097,6 +1097,7 @@ static int arm_spe_synth_event(struct perf_session *session,
> >
> >       memset(&arm_spe_synth, 0, sizeof(struct arm_spe_synth));
> >       arm_spe_synth.session = session;
> > +     perf_tool__init(&arm_spe_synth.dummy_tool, /*ordered_events=*/false);
> >
> >       return perf_event__synthesize_attr(&arm_spe_synth.dummy_tool, attr, 1,
> >                                          &id, arm_spe_event_synth);
> > diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> > index 231cd833c012..02eb5b3eed14 100644
> > --- a/tools/perf/util/cs-etm.c
> > +++ b/tools/perf/util/cs-etm.c
> > @@ -1619,6 +1619,7 @@ static int cs_etm__synth_event(struct perf_session *session,
> >
> >       memset(&cs_etm_synth, 0, sizeof(struct cs_etm_synth));
> >       cs_etm_synth.session = session;
> > +     perf_tool__init(&cs_etm_synth.dummy_tool, /*ordered_events=*/false);
> >
> >       return perf_event__synthesize_attr(&cs_etm_synth.dummy_tool, attr, 1,
> >                                          &id, cs_etm__event_synth);
> > diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
> > index 779982c478e0..ae97109542be 100644
> > --- a/tools/perf/util/intel-bts.c
> > +++ b/tools/perf/util/intel-bts.c
> > @@ -761,6 +761,7 @@ static int intel_bts_synth_event(struct perf_session *session,
> >
> >       memset(&intel_bts_synth, 0, sizeof(struct intel_bts_synth));
> >       intel_bts_synth.session = session;
> > +     perf_tool__init(&intel_bts_synth.dummy_tool, /*ordered_events=*/false);
> >
> >       return perf_event__synthesize_attr(&intel_bts_synth.dummy_tool, attr, 1,
> >                                          &id, intel_bts_event_synth);
> > diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
> > index bed35029e1f6..48ed60e521ed 100644
> > --- a/tools/perf/util/intel-pt.c
> > +++ b/tools/perf/util/intel-pt.c
> > @@ -3687,7 +3687,7 @@ static int intel_pt_synth_event(struct perf_session *session, const char *name,
> >
> >       memset(&intel_pt_synth, 0, sizeof(struct intel_pt_synth));
> >       intel_pt_synth.session = session;
> > -
> > +     perf_tool__init(&intel_pt_synth.dummy_tool, /*ordered_events=*/false);
> >       err = perf_event__synthesize_attr(&intel_pt_synth.dummy_tool, attr, 1,
> >                                         &id, intel_pt_event_synth);
> >       if (err)
> > diff --git a/tools/perf/util/s390-cpumsf.c b/tools/perf/util/s390-cpumsf.c
> > index 5834bad6ac0f..eb835e531cd6 100644
> > --- a/tools/perf/util/s390-cpumsf.c
> > +++ b/tools/perf/util/s390-cpumsf.c
> > @@ -953,7 +953,6 @@ s390_cpumsf_process_event(struct perf_session *session,
> >  }
> >
> >  struct s390_cpumsf_synth {
> > -     struct perf_tool cpumsf_tool;
> >       struct perf_session *session;
> >  };
> >
>
diff mbox series

Patch

diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 70bad18c4a0d..06a198b2f483 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -1097,6 +1097,7 @@  static int arm_spe_synth_event(struct perf_session *session,
 
 	memset(&arm_spe_synth, 0, sizeof(struct arm_spe_synth));
 	arm_spe_synth.session = session;
+	perf_tool__init(&arm_spe_synth.dummy_tool, /*ordered_events=*/false);
 
 	return perf_event__synthesize_attr(&arm_spe_synth.dummy_tool, attr, 1,
 					   &id, arm_spe_event_synth);
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 231cd833c012..02eb5b3eed14 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -1619,6 +1619,7 @@  static int cs_etm__synth_event(struct perf_session *session,
 
 	memset(&cs_etm_synth, 0, sizeof(struct cs_etm_synth));
 	cs_etm_synth.session = session;
+	perf_tool__init(&cs_etm_synth.dummy_tool, /*ordered_events=*/false);
 
 	return perf_event__synthesize_attr(&cs_etm_synth.dummy_tool, attr, 1,
 					   &id, cs_etm__event_synth);
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index 779982c478e0..ae97109542be 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -761,6 +761,7 @@  static int intel_bts_synth_event(struct perf_session *session,
 
 	memset(&intel_bts_synth, 0, sizeof(struct intel_bts_synth));
 	intel_bts_synth.session = session;
+	perf_tool__init(&intel_bts_synth.dummy_tool, /*ordered_events=*/false);
 
 	return perf_event__synthesize_attr(&intel_bts_synth.dummy_tool, attr, 1,
 					   &id, intel_bts_event_synth);
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index bed35029e1f6..48ed60e521ed 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -3687,7 +3687,7 @@  static int intel_pt_synth_event(struct perf_session *session, const char *name,
 
 	memset(&intel_pt_synth, 0, sizeof(struct intel_pt_synth));
 	intel_pt_synth.session = session;
-
+	perf_tool__init(&intel_pt_synth.dummy_tool, /*ordered_events=*/false);
 	err = perf_event__synthesize_attr(&intel_pt_synth.dummy_tool, attr, 1,
 					  &id, intel_pt_event_synth);
 	if (err)
diff --git a/tools/perf/util/s390-cpumsf.c b/tools/perf/util/s390-cpumsf.c
index 5834bad6ac0f..eb835e531cd6 100644
--- a/tools/perf/util/s390-cpumsf.c
+++ b/tools/perf/util/s390-cpumsf.c
@@ -953,7 +953,6 @@  s390_cpumsf_process_event(struct perf_session *session,
 }
 
 struct s390_cpumsf_synth {
-	struct perf_tool cpumsf_tool;
 	struct perf_session *session;
 };