All of lore.kernel.org
 help / color / mirror / Atom feed
* [V2] perf/core: Avoid calling perf_mux_hrtimer_restart multiple times when scheduling event groups
@ 2021-10-15  7:04 Athira Rajeev
  2021-10-16  1:08 ` Song Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Athira Rajeev @ 2021-10-15  7:04 UTC (permalink / raw)
  To: peterz, acme, jolsa
  Cc: linux-kernel, songliubraving, maddy, kjain, mingo, eranian

Perf uses multiplexing if there are more events to be scheduled than the
available counters. With multiplexing, event groups will be rotated at
specified interval of time which is set using "hrtimer". During event
scheduling, if any of the event group fails to schedule, multiplexing
gets enabled by setting "rotate_necessary" for that event context and
starting the hrtimer by calling "perf_mux_hrtimer_restart".

Patch adds an optimisation to avoid calling "perf_mux_hrtimer_restart"
multiple times if already rotate_necessary is set for that context.
Even though "perf_mux_hrtimer_restart" will just return if hrtimer is
already active, this could avoid the overhead of calling this function
multiple times if there are many event groups. Patch adds the check to
avoid calling perf_mux_hrtimer_restart() for each event group on
every schedule.

Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
---
Changelog:
From v1 -> v2:
 - Rebased on top of latest kernel source.

 kernel/events/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index f23ca260307f..9e1a06646ad0 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3753,8 +3753,10 @@ static int merge_sched_in(struct perf_event *event, void *data)
 			perf_cgroup_event_disable(event, ctx);
 			perf_event_set_state(event, PERF_EVENT_STATE_ERROR);
 		} else {
-			ctx->rotate_necessary = 1;
-			perf_mux_hrtimer_restart(cpuctx);
+			if (!ctx->rotate_necessary) {
+				ctx->rotate_necessary = 1;
+				perf_mux_hrtimer_restart(cpuctx);
+			}
 			group_update_userpage(event);
 		}
 	}
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [V2] perf/core: Avoid calling perf_mux_hrtimer_restart multiple times when scheduling event groups
  2021-10-15  7:04 [V2] perf/core: Avoid calling perf_mux_hrtimer_restart multiple times when scheduling event groups Athira Rajeev
@ 2021-10-16  1:08 ` Song Liu
  2021-10-18 11:07   ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Song Liu @ 2021-10-16  1:08 UTC (permalink / raw)
  To: Athira Rajeev
  Cc: Peter Zijlstra, Arnaldo Carvalho de Melo, Jiri Olsa,
	linux-kernel, maddy, kjain, mingo, eranian



> On Oct 15, 2021, at 12:04 AM, Athira Rajeev <atrajeev@linux.vnet.ibm.com> wrote:
> 
> Perf uses multiplexing if there are more events to be scheduled than the
> available counters. With multiplexing, event groups will be rotated at
> specified interval of time which is set using "hrtimer". During event
> scheduling, if any of the event group fails to schedule, multiplexing
> gets enabled by setting "rotate_necessary" for that event context and
> starting the hrtimer by calling "perf_mux_hrtimer_restart".
> 
> Patch adds an optimisation to avoid calling "perf_mux_hrtimer_restart"
> multiple times if already rotate_necessary is set for that context.
> Even though "perf_mux_hrtimer_restart" will just return if hrtimer is
> already active, this could avoid the overhead of calling this function
> multiple times if there are many event groups. Patch adds the check to
> avoid calling perf_mux_hrtimer_restart() for each event group on
> every schedule.
> 
> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>

Acked-by: Song Liu <song@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [V2] perf/core: Avoid calling perf_mux_hrtimer_restart multiple times when scheduling event groups
  2021-10-16  1:08 ` Song Liu
@ 2021-10-18 11:07   ` Peter Zijlstra
  2021-10-21 12:22     ` Athira Rajeev
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2021-10-18 11:07 UTC (permalink / raw)
  To: Song Liu
  Cc: Athira Rajeev, Arnaldo Carvalho de Melo, Jiri Olsa, linux-kernel,
	maddy, kjain, mingo, eranian

On Sat, Oct 16, 2021 at 01:08:04AM +0000, Song Liu wrote:
> 
> 
> > On Oct 15, 2021, at 12:04 AM, Athira Rajeev <atrajeev@linux.vnet.ibm.com> wrote:
> > 
> > Perf uses multiplexing if there are more events to be scheduled than the
> > available counters. With multiplexing, event groups will be rotated at
> > specified interval of time which is set using "hrtimer". During event
> > scheduling, if any of the event group fails to schedule, multiplexing
> > gets enabled by setting "rotate_necessary" for that event context and
> > starting the hrtimer by calling "perf_mux_hrtimer_restart".
> > 
> > Patch adds an optimisation to avoid calling "perf_mux_hrtimer_restart"
> > multiple times if already rotate_necessary is set for that context.
> > Even though "perf_mux_hrtimer_restart" will just return if hrtimer is
> > already active, this could avoid the overhead of calling this function
> > multiple times if there are many event groups. Patch adds the check to
> > avoid calling perf_mux_hrtimer_restart() for each event group on
> > every schedule.
> > 
> > Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
> 
> Acked-by: Song Liu <song@kernel.org>

Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [V2] perf/core: Avoid calling perf_mux_hrtimer_restart multiple times when scheduling event groups
  2021-10-18 11:07   ` Peter Zijlstra
@ 2021-10-21 12:22     ` Athira Rajeev
  0 siblings, 0 replies; 4+ messages in thread
From: Athira Rajeev @ 2021-10-21 12:22 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Song Liu, Arnaldo Carvalho de Melo, Jiri Olsa, linux-kernel,
	maddy, kjain, mingo, eranian



> On 18-Oct-2021, at 4:37 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> 
> On Sat, Oct 16, 2021 at 01:08:04AM +0000, Song Liu wrote:
>> 
>> 
>>> On Oct 15, 2021, at 12:04 AM, Athira Rajeev <atrajeev@linux.vnet.ibm.com> wrote:
>>> 
>>> Perf uses multiplexing if there are more events to be scheduled than the
>>> available counters. With multiplexing, event groups will be rotated at
>>> specified interval of time which is set using "hrtimer". During event
>>> scheduling, if any of the event group fails to schedule, multiplexing
>>> gets enabled by setting "rotate_necessary" for that event context and
>>> starting the hrtimer by calling "perf_mux_hrtimer_restart".
>>> 
>>> Patch adds an optimisation to avoid calling "perf_mux_hrtimer_restart"
>>> multiple times if already rotate_necessary is set for that context.
>>> Even though "perf_mux_hrtimer_restart" will just return if hrtimer is
>>> already active, this could avoid the overhead of calling this function
>>> multiple times if there are many event groups. Patch adds the check to
>>> avoid calling perf_mux_hrtimer_restart() for each event group on
>>> every schedule.
>>> 
>>> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
>> 
>> Acked-by: Song Liu <song@kernel.org>
> 
> Thanks!

Thanks for checking the patch.

Hi Peterz,
Should I resend this patch with Acked-by or can you consider pulling it, if the patch looks fine to you.

Thanks
Athira.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-21 12:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15  7:04 [V2] perf/core: Avoid calling perf_mux_hrtimer_restart multiple times when scheduling event groups Athira Rajeev
2021-10-16  1:08 ` Song Liu
2021-10-18 11:07   ` Peter Zijlstra
2021-10-21 12:22     ` Athira Rajeev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.