From: Marc Zyngier <maz@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: will@kernel.org, catalin.marinas@arm.com,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
kvmarm@lists.cs.columbia.edu
Subject: Re: [PATCH] perf: arm_spe: Use Inner Shareable DSB when draining the buffer
Date: Mon, 19 Oct 2020 13:55:42 +0100 [thread overview]
Message-ID: <6878fd559ca5c63a251c47c271df7c5e@kernel.org> (raw)
In-Reply-To: <20201019122455.GD34028@C02TD0UTHF1T.local>
On 2020-10-19 13:24, Mark Rutland wrote:
> On Tue, Oct 06, 2020 at 05:13:31PM +0100, Alexandru Elisei wrote:
>> Hi Marc,
>>
>> Thank you for having a look at the patch!
>>
>> On 10/6/20 4:32 PM, Marc Zyngier wrote:
>> > Hi Alex,
>> >
>> > On Tue, 06 Oct 2020 16:05:20 +0100,
>> > Alexandru Elisei <alexandru.elisei@arm.com> wrote:
>> >> From ARM DDI 0487F.b, page D9-2807:
>> >>
>> >> "Although the Statistical Profiling Extension acts as another observer in
>> >> the system, for determining the Shareability domain of the DSB
>> >> instructions, the writes of sample records are treated as coming from the
>> >> PE that is being profiled."
>> >>
>> >> Similarly, on page D9-2801:
>> >>
>> >> "The memory type and attributes that are used for a write by the
>> >> Statistical Profiling Extension to the Profiling Buffer is taken from the
>> >> translation table entries for the virtual address being written to. That
>> >> is:
>> >> - The writes are treated as coming from an observer that is coherent with
>> >> all observers in the Shareability domain that is defined by the
>> >> translation tables."
>> >>
>> >> All the PEs are in the Inner Shareable domain, use a DSB ISH to make sure
>> >> writes to the profiling buffer have completed.
>> > I'm a bit sceptical of this change. The SPE writes are per-CPU, and
>> > all we are trying to ensure is that the CPU we are running on has
>> > drained its own queue of accesses.
>> >
>> > The accesses being made within the IS domain doesn't invalidate the
>> > fact that they are still per-CPU, because "the writes of sample
>> > records are treated as coming from the PE that is being profiled.".
>> >
>> > So why should we have an IS-wide synchronisation for accesses that are
>> > purely local?
>>
>> I think I might have misunderstood how perf spe works. Below is my
>> original train
>> of thought.
>>
>> In the buffer management event interrupt we drain the buffer, and if
>> the buffer is
>> full, we call arm_spe_perf_aux_output_end() -> perf_aux_output_end().
>> The comment
>> for perf_aux_output_end() says "Commit the data written by hardware
>> into the ring
>> buffer by adjusting aux_head and posting a PERF_RECORD_AUX into the
>> perf buffer.
>> It is the pmu driver's responsibility to observe ordering rules of the
>> hardware,
>> so that all the data is externally visible before this is called." My
>> conclusion
>> was that after we drain the buffer, the data must be visible to all
>> CPUs.
>
> FWIW, this reasoning sounds correct to me. The DSB NSH will be
> sufficient to drain the buffer, but we need the DSB ISH to ensure that
> it's visbile to other CPUs at the instant we call
> perf_aux_output_end().
Right. I think I missed that last bit (and Alex's email at the same
time).
> Otherwise, if CPU x is reading the ring-buffer written by CPU y, it
> might see the aux buffer pointers updated before the samples are
> viisble, and hence read junk from the buffer.
>
> We can add a comment to that effect (or rework perf_aux_output_end()
> somehow to handle that ordering).
I'd rather this is done in perf_aux_output_end(), as a full blown DSB
ISH
on guest entry is pretty harsh... It would also nicely split the
responsibilities:
- KVM stops SPE and make sure the output is drained
- Perf makes the data visible to all CPUs
Thoughts?
M.
--
Jazz is not dead. It just smells funny...
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: will@kernel.org, suzuki.poulose@arm.com, catalin.marinas@arm.com,
linux-kernel@vger.kernel.org, james.morse@arm.com,
linux-arm-kernel@lists.infradead.org,
Alexandru Elisei <alexandru.elisei@arm.com>,
kvmarm@lists.cs.columbia.edu, julien.thierry.kdev@gmail.com
Subject: Re: [PATCH] perf: arm_spe: Use Inner Shareable DSB when draining the buffer
Date: Mon, 19 Oct 2020 13:55:42 +0100 [thread overview]
Message-ID: <6878fd559ca5c63a251c47c271df7c5e@kernel.org> (raw)
In-Reply-To: <20201019122455.GD34028@C02TD0UTHF1T.local>
On 2020-10-19 13:24, Mark Rutland wrote:
> On Tue, Oct 06, 2020 at 05:13:31PM +0100, Alexandru Elisei wrote:
>> Hi Marc,
>>
>> Thank you for having a look at the patch!
>>
>> On 10/6/20 4:32 PM, Marc Zyngier wrote:
>> > Hi Alex,
>> >
>> > On Tue, 06 Oct 2020 16:05:20 +0100,
>> > Alexandru Elisei <alexandru.elisei@arm.com> wrote:
>> >> From ARM DDI 0487F.b, page D9-2807:
>> >>
>> >> "Although the Statistical Profiling Extension acts as another observer in
>> >> the system, for determining the Shareability domain of the DSB
>> >> instructions, the writes of sample records are treated as coming from the
>> >> PE that is being profiled."
>> >>
>> >> Similarly, on page D9-2801:
>> >>
>> >> "The memory type and attributes that are used for a write by the
>> >> Statistical Profiling Extension to the Profiling Buffer is taken from the
>> >> translation table entries for the virtual address being written to. That
>> >> is:
>> >> - The writes are treated as coming from an observer that is coherent with
>> >> all observers in the Shareability domain that is defined by the
>> >> translation tables."
>> >>
>> >> All the PEs are in the Inner Shareable domain, use a DSB ISH to make sure
>> >> writes to the profiling buffer have completed.
>> > I'm a bit sceptical of this change. The SPE writes are per-CPU, and
>> > all we are trying to ensure is that the CPU we are running on has
>> > drained its own queue of accesses.
>> >
>> > The accesses being made within the IS domain doesn't invalidate the
>> > fact that they are still per-CPU, because "the writes of sample
>> > records are treated as coming from the PE that is being profiled.".
>> >
>> > So why should we have an IS-wide synchronisation for accesses that are
>> > purely local?
>>
>> I think I might have misunderstood how perf spe works. Below is my
>> original train
>> of thought.
>>
>> In the buffer management event interrupt we drain the buffer, and if
>> the buffer is
>> full, we call arm_spe_perf_aux_output_end() -> perf_aux_output_end().
>> The comment
>> for perf_aux_output_end() says "Commit the data written by hardware
>> into the ring
>> buffer by adjusting aux_head and posting a PERF_RECORD_AUX into the
>> perf buffer.
>> It is the pmu driver's responsibility to observe ordering rules of the
>> hardware,
>> so that all the data is externally visible before this is called." My
>> conclusion
>> was that after we drain the buffer, the data must be visible to all
>> CPUs.
>
> FWIW, this reasoning sounds correct to me. The DSB NSH will be
> sufficient to drain the buffer, but we need the DSB ISH to ensure that
> it's visbile to other CPUs at the instant we call
> perf_aux_output_end().
Right. I think I missed that last bit (and Alex's email at the same
time).
> Otherwise, if CPU x is reading the ring-buffer written by CPU y, it
> might see the aux buffer pointers updated before the samples are
> viisble, and hence read junk from the buffer.
>
> We can add a comment to that effect (or rework perf_aux_output_end()
> somehow to handle that ordering).
I'd rather this is done in perf_aux_output_end(), as a full blown DSB
ISH
on guest entry is pretty harsh... It would also nicely split the
responsibilities:
- KVM stops SPE and make sure the output is drained
- Perf makes the data visible to all CPUs
Thoughts?
M.
--
Jazz is not dead. It just smells funny...
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: Alexandru Elisei <alexandru.elisei@arm.com>,
linux-arm-kernel@lists.infradead.org,
kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org,
james.morse@arm.com, julien.thierry.kdev@gmail.com,
suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org
Subject: Re: [PATCH] perf: arm_spe: Use Inner Shareable DSB when draining the buffer
Date: Mon, 19 Oct 2020 13:55:42 +0100 [thread overview]
Message-ID: <6878fd559ca5c63a251c47c271df7c5e@kernel.org> (raw)
In-Reply-To: <20201019122455.GD34028@C02TD0UTHF1T.local>
On 2020-10-19 13:24, Mark Rutland wrote:
> On Tue, Oct 06, 2020 at 05:13:31PM +0100, Alexandru Elisei wrote:
>> Hi Marc,
>>
>> Thank you for having a look at the patch!
>>
>> On 10/6/20 4:32 PM, Marc Zyngier wrote:
>> > Hi Alex,
>> >
>> > On Tue, 06 Oct 2020 16:05:20 +0100,
>> > Alexandru Elisei <alexandru.elisei@arm.com> wrote:
>> >> From ARM DDI 0487F.b, page D9-2807:
>> >>
>> >> "Although the Statistical Profiling Extension acts as another observer in
>> >> the system, for determining the Shareability domain of the DSB
>> >> instructions, the writes of sample records are treated as coming from the
>> >> PE that is being profiled."
>> >>
>> >> Similarly, on page D9-2801:
>> >>
>> >> "The memory type and attributes that are used for a write by the
>> >> Statistical Profiling Extension to the Profiling Buffer is taken from the
>> >> translation table entries for the virtual address being written to. That
>> >> is:
>> >> - The writes are treated as coming from an observer that is coherent with
>> >> all observers in the Shareability domain that is defined by the
>> >> translation tables."
>> >>
>> >> All the PEs are in the Inner Shareable domain, use a DSB ISH to make sure
>> >> writes to the profiling buffer have completed.
>> > I'm a bit sceptical of this change. The SPE writes are per-CPU, and
>> > all we are trying to ensure is that the CPU we are running on has
>> > drained its own queue of accesses.
>> >
>> > The accesses being made within the IS domain doesn't invalidate the
>> > fact that they are still per-CPU, because "the writes of sample
>> > records are treated as coming from the PE that is being profiled.".
>> >
>> > So why should we have an IS-wide synchronisation for accesses that are
>> > purely local?
>>
>> I think I might have misunderstood how perf spe works. Below is my
>> original train
>> of thought.
>>
>> In the buffer management event interrupt we drain the buffer, and if
>> the buffer is
>> full, we call arm_spe_perf_aux_output_end() -> perf_aux_output_end().
>> The comment
>> for perf_aux_output_end() says "Commit the data written by hardware
>> into the ring
>> buffer by adjusting aux_head and posting a PERF_RECORD_AUX into the
>> perf buffer.
>> It is the pmu driver's responsibility to observe ordering rules of the
>> hardware,
>> so that all the data is externally visible before this is called." My
>> conclusion
>> was that after we drain the buffer, the data must be visible to all
>> CPUs.
>
> FWIW, this reasoning sounds correct to me. The DSB NSH will be
> sufficient to drain the buffer, but we need the DSB ISH to ensure that
> it's visbile to other CPUs at the instant we call
> perf_aux_output_end().
Right. I think I missed that last bit (and Alex's email at the same
time).
> Otherwise, if CPU x is reading the ring-buffer written by CPU y, it
> might see the aux buffer pointers updated before the samples are
> viisble, and hence read junk from the buffer.
>
> We can add a comment to that effect (or rework perf_aux_output_end()
> somehow to handle that ordering).
I'd rather this is done in perf_aux_output_end(), as a full blown DSB
ISH
on guest entry is pretty harsh... It would also nicely split the
responsibilities:
- KVM stops SPE and make sure the output is drained
- Perf makes the data visible to all CPUs
Thoughts?
M.
--
Jazz is not dead. It just smells funny...
next prev parent reply other threads:[~2020-10-19 12:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-06 15:05 [PATCH] perf: arm_spe: Use Inner Shareable DSB when draining the buffer Alexandru Elisei
2020-10-06 15:05 ` Alexandru Elisei
2020-10-06 15:05 ` Alexandru Elisei
2020-10-06 15:32 ` Marc Zyngier
2020-10-06 15:32 ` Marc Zyngier
2020-10-06 15:32 ` Marc Zyngier
2020-10-06 16:13 ` Alexandru Elisei
2020-10-06 16:13 ` Alexandru Elisei
2020-10-06 16:13 ` Alexandru Elisei
2020-10-19 12:24 ` Mark Rutland
2020-10-19 12:24 ` Mark Rutland
2020-10-19 12:24 ` Mark Rutland
2020-10-19 12:55 ` Marc Zyngier [this message]
2020-10-19 12:55 ` Marc Zyngier
2020-10-19 12:55 ` Marc Zyngier
2020-10-19 13:01 ` Will Deacon
2020-10-19 13:01 ` Will Deacon
2020-10-19 13:01 ` Will Deacon
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=6878fd559ca5c63a251c47c271df7c5e@kernel.org \
--to=maz@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=will@kernel.org \
/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 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.