public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Namhyung Kim <namhyung@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Ravi Bangoria <ravi.bangoria@amd.com>,
	Stephane Eranian <eranian@google.com>,
	Ian Rogers <irogers@google.com>,
	Mingwei Zhang <mizhang@google.com>
Subject: Re: [PATCH v2] perf/core: Optimize event reschedule for a PMU
Date: Tue, 6 Aug 2024 09:54:44 -0400	[thread overview]
Message-ID: <1d7b6780-6d4c-483f-98d7-539e7c3fcf36@linux.intel.com> (raw)
In-Reply-To: <20240805145827.GE12673@noisy.programming.kicks-ass.net>



On 2024-08-05 10:58 a.m., Peter Zijlstra wrote:
> On Mon, Aug 05, 2024 at 11:20:58AM +0200, Peter Zijlstra wrote:
>> On Fri, Aug 02, 2024 at 02:30:19PM -0400, Liang, Kan wrote:
>>>> @@ -2792,7 +2833,14 @@ static int  __perf_install_in_context(void *info)
>>>>  	if (reprogram) {
>>>>  		ctx_sched_out(ctx, EVENT_TIME);
>>>>  		add_event_to_ctx(event, ctx);
>>>> -		ctx_resched(cpuctx, task_ctx, get_event_type(event));
>>>> +		if (ctx->nr_events == 1) {
>>>> +			/* The first event needs to set ctx->is_active. */
>>>> +			ctx_resched(cpuctx, task_ctx, NULL, get_event_type(event));
>>>> +		} else {
>>>> +			ctx_resched(cpuctx, task_ctx, event->pmu_ctx->pmu,
>>>> +				    get_event_type(event));
>>>> +			ctx_sched_in(ctx, EVENT_TIME);
>>>
>>> The changelog doesn't mention the time difference much. As my
>>> understanding, the time is shared among PMUs in the same ctx.
>>> When perf does ctx_resched(), the time is deducted.
>>> There is no problem to stop and restart the global time when perf
>>> re-schedule all PMUs.
>>> But if only one PMU is re-scheduled while others are still running, it
>>> may be a problem to stop and restart the global time. Other PMUs will be
>>> impacted.
>>
>> So afaict, since we hold ctx->lock, nobody can observe EVENT_TIME was
>> cleared for a little while.
>>
>> So the point was to make all the various ctx_sched_out() calls have the
>> same timestamp. It does this by clearing EVENT_TIME first. Then the
>> first ctx_sched_in() will set it again, and later ctx_sched_in() won't
>> touch time.
>>
>> That leaves a little hole, because the time between
>> ctx_sched_out(EVENT_TIME) and the first ctx_sched_in() gets lost.
>>
>> This isn't typically a problem, but not very nice. Let me go find an
>> alternative solution for this. The simple update I did saturday is
>> broken as per the perf test.
> 
> OK, took a little longer than I would have liked, nor is it entirely
> pretty, but it seems to pass 'perf test'.
> 
> Please look at: queue.git perf/resched

Thanks. If I understand correctly, the freeze doesn't mean that the time
deduction. For the other PMUs, it can still see the time in during the
specific PMU reschedule, right? If so, the general idea looks good to me.

I also think of the vPMU time. For that case, perf has to deduct the
vPMU time. The freeze bit cannot be used in the vPMU case. But I
probably have to rebase the below patch on top of EVENT_FROZEN.
https://lore.kernel.org/kvm/20240801045907.4010984-10-mizhang@google.com/

Thanks,
Kan

      parent reply	other threads:[~2024-08-06 13:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-31  0:06 [PATCH v2] perf/core: Optimize event reschedule for a PMU Namhyung Kim
2024-08-02 17:39 ` Namhyung Kim
2024-08-02 18:30 ` Liang, Kan
2024-08-02 18:38   ` Peter Zijlstra
2024-08-02 18:43     ` Peter Zijlstra
2024-08-02 18:50       ` Peter Zijlstra
2024-08-02 19:11         ` Peter Zijlstra
2024-08-02 19:31           ` Liang, Kan
2024-08-02 19:32           ` Namhyung Kim
2024-08-03 10:32           ` Peter Zijlstra
2024-08-03 17:08             ` Namhyung Kim
2024-08-05  6:39               ` Namhyung Kim
2024-08-05  9:15                 ` Peter Zijlstra
2024-08-05  9:05               ` Peter Zijlstra
2024-08-05  9:20   ` Peter Zijlstra
2024-08-05 14:58     ` Peter Zijlstra
2024-08-06  6:19       ` Namhyung Kim
2024-08-06  7:56         ` Peter Zijlstra
2024-08-06  8:07           ` Peter Zijlstra
2024-08-06 19:29             ` Namhyung Kim
2024-08-06 13:54       ` Liang, Kan [this message]

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=1d7b6780-6d4c-483f-98d7-539e7c3fcf36@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=mizhang@google.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.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