From: Punit Agrawal <punitagrawal@gmail.com>
To: Nicolas Saenz Julienne <nsaenzju@redhat.com>
Cc: linux-rt-users@vger.kernel.org, peterx@redhat.com,
williams@redhat.com, jkacur@redhat.com
Subject: Re: [PATCH v2 2/3] oslat: Add aarch64 support
Date: Tue, 14 Sep 2021 10:52:13 +0900 [thread overview]
Message-ID: <87ee9r9b5e.fsf@stealth> (raw)
In-Reply-To: <20210913083908.48408-2-nsaenzju@redhat.com> (Nicolas Saenz Julienne's message of "Mon, 13 Sep 2021 10:39:07 +0200")
Hi Nicolas,
Apologies for the late comment. I just caught up with the thread.
Nicolas Saenz Julienne <nsaenzju@redhat.com> writes:
> The callbacks are based on Linux's implementation:
> - CNTVCT_EL0 provides direct access to the system virtual timer[1].
> - 'yield' serves as a CPU hint with similar semantics as x86's
> 'pause'[2].
>
> In contrast with the kernel's implementation, there isn't a need for
> isb() after reading CNTVCT_EL0, this is only needed in-kernel as the
> register read has to be ordered with a subsequent locking operation.
>
> [1] See Linux's '__arch_get_hw_counter()' in arch/arm64/include/asm/vdso/gettimeofday.h
> [2] See Linux's 1baa82f4803 ("arm64: Implement cpu_relax as yield").
> Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>
> --
>
> Changes since v1:
> - Code cleanup
> - Add compiler barriers
>
> src/oslat/oslat.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c
> index 33cccd3..c90ec1a 100644
> --- a/src/oslat/oslat.c
> +++ b/src/oslat/oslat.c
> @@ -71,6 +71,19 @@ static inline void frc(uint64_t *pval)
> {
> __asm__ __volatile__("mfspr %0, 268\n" : "=r" (*pval));
> }
> +# elif defined(__aarch64__)
> +# define relax() __asm__ __volatile("yield" : : : "memory")
> +
> +static inline void frc(uint64_t *pval)
> +{
> + /*
> + * This isb() is required to prevent that the counter value
> + * is speculated.
> + */
> + __asm__ __volatile__("isb" : : : "memory");
> + __asm__ __volatile__("mrs %0, cntvct_el0" : "=r" (*pval) :: "memory");
> +
Although the isb() ensures completion of instructions before the counter
is read, I think there is still the problem of speculative execution of
instructions after the counter read being moved forward. See the
examples in Arm ARM DDI 0487F.b Section D11.2.2 "The Virtual counter"
So from my understanding the problem would be something like below -
isb()
... <- speculatively executed instructions from after the counter read
mrs %0, cntvct_el0
This would skew the counter value to a later point than what is intended
- a following isb() would address the issue.
> +}
> # else
> # define relax() do { } while (0)
> # define frc(x)
next prev parent reply other threads:[~2021-09-14 1:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-13 8:39 [PATCH v2 1/3] oslat: Rename cpu_mhz/cpu_hz to counter_mhz/counter_hz Nicolas Saenz Julienne
2021-09-13 8:39 ` [PATCH v2 2/3] oslat: Add aarch64 support Nicolas Saenz Julienne
2021-09-13 18:38 ` John Kacur
2021-09-14 1:52 ` Punit Agrawal [this message]
2021-09-14 10:16 ` nsaenzju
2021-09-14 12:48 ` John Kacur
2021-09-15 1:52 ` Punit Agrawal
2021-09-13 8:39 ` [PATCH v2 3/3] oslat: Allow for arch specific counter frequency measurements Nicolas Saenz Julienne
2021-09-13 18:39 ` John Kacur
2021-09-13 13:35 ` [PATCH v2 1/3] oslat: Rename cpu_mhz/cpu_hz to counter_mhz/counter_hz John Kacur
2021-09-13 14:57 ` Peter Xu
2021-09-13 18:39 ` John Kacur
2021-09-13 18:38 ` John Kacur
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=87ee9r9b5e.fsf@stealth \
--to=punitagrawal@gmail.com \
--cc=jkacur@redhat.com \
--cc=linux-rt-users@vger.kernel.org \
--cc=nsaenzju@redhat.com \
--cc=peterx@redhat.com \
--cc=williams@redhat.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