* Re: [RESEND] qemu/timer: Add host ticks function for RISC-V
[not found] <20230908033129.694-1-zhiwei._5Fliu@linux.alibaba.com>
@ 2023-09-08 10:29 ` Paolo Bonzini
2023-09-09 1:35 ` Atish Patra
0 siblings, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2023-09-08 10:29 UTC (permalink / raw)
To: LIU Zhiwei; +Cc: qemu-devel, qemu-riscv, LIU Zhiwei
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND] qemu/timer: Add host ticks function for RISC-V
2023-09-08 10:29 ` [RESEND] qemu/timer: Add host ticks function for RISC-V Paolo Bonzini
@ 2023-09-09 1:35 ` Atish Patra
2023-09-09 7:18 ` Paolo Bonzini
0 siblings, 1 reply; 7+ messages in thread
From: Atish Patra @ 2023-09-09 1:35 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: LIU Zhiwei, qemu-devel, qemu-riscv, LIU Zhiwei
On Fri, Sep 8, 2023 at 3:29 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> Queued, thanks.
>
I didn't realize it was already queued. Gmail threads failed me this time.
@Paolo Bonzini : Can you please drop this one as this will break as
soon as the host riscv system
has the latest kernel ? I have provided more details in the original thread.
https://lists.gnu.org/archive/html/qemu-devel/2023-09/msg01941.html
> Paolo
>
>
--
Regards,
Atish
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND] qemu/timer: Add host ticks function for RISC-V
2023-09-09 1:35 ` Atish Patra
@ 2023-09-09 7:18 ` Paolo Bonzini
2023-09-09 14:45 ` Palmer Dabbelt
0 siblings, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2023-09-09 7:18 UTC (permalink / raw)
To: Atish Patra; +Cc: LIU Zhiwei, qemu-devel, open list:RISC-V, LIU Zhiwei
[-- Attachment #1: Type: text/plain, Size: 880 bytes --]
Il sab 9 set 2023, 03:35 Atish Patra <atishp@atishpatra.org> ha scritto:
> On Fri, Sep 8, 2023 at 3:29 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
> >
> > Queued, thanks.
> >
>
> I didn't realize it was already queued. Gmail threads failed me this time.
> @Paolo Bonzini : Can you please drop this one as this will break as
> soon as the host riscv system
> has the latest kernel ? I have provided more details in the original
> thread.
>
> https://lists.gnu.org/archive/html/qemu-devel/2023-09/msg01941.html
If you have dynamic clock adjustment, does rdcycle increase with a fixed
frequency or does it provide the raw number of clock cycles? If the latter,
I agree that it should be provided by perf; but if the frequency is fixed
then it would be the same as rdtsc on Intel.
Paolo
>
> > Paolo
> >
> >
>
>
> --
> Regards,
> Atish
>
>
[-- Attachment #2: Type: text/html, Size: 1702 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND] qemu/timer: Add host ticks function for RISC-V
2023-09-09 7:18 ` Paolo Bonzini
@ 2023-09-09 14:45 ` Palmer Dabbelt
2023-09-11 5:56 ` LIU Zhiwei
0 siblings, 1 reply; 7+ messages in thread
From: Palmer Dabbelt @ 2023-09-09 14:45 UTC (permalink / raw)
To: pbonzini; +Cc: atishp, zhiwei_liu, qemu-devel, qemu-riscv, lzw194868
On Sat, 09 Sep 2023 00:18:02 PDT (-0700), pbonzini@redhat.com wrote:
> Il sab 9 set 2023, 03:35 Atish Patra <atishp@atishpatra.org> ha scritto:
>
>> On Fri, Sep 8, 2023 at 3:29 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>> >
>> > Queued, thanks.
>> >
>>
>> I didn't realize it was already queued. Gmail threads failed me this time.
>> @Paolo Bonzini : Can you please drop this one as this will break as
>> soon as the host riscv system
>> has the latest kernel ? I have provided more details in the original
>> thread.
>>
>> https://lists.gnu.org/archive/html/qemu-devel/2023-09/msg01941.html
>
>
> If you have dynamic clock adjustment, does rdcycle increase with a fixed
> frequency or does it provide the raw number of clock cycles? If the latter,
> I agree that it should be provided by perf; but if the frequency is fixed
> then it would be the same as rdtsc on Intel.
That really depends on exactly how the system is set up, but there are
systems for which the rdcycle frequency changes when clock speeds change
and thus will produce surprising answers for users trying to use rdcycle
as a RTC. We have rdtime for that, but it has other problems (it's
trapped and emulated in M-mode on some systems, so it's slow and noisy).
So we're steering folks towards perf where we can, as at least that way
we've got a higher-level interface we can use to describe these quirks.
>
> Paolo
>
>
>>
>> > Paolo
>> >
>> >
>>
>>
>> --
>> Regards,
>> Atish
>>
>>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND] qemu/timer: Add host ticks function for RISC-V
2023-09-09 14:45 ` Palmer Dabbelt
@ 2023-09-11 5:56 ` LIU Zhiwei
0 siblings, 0 replies; 7+ messages in thread
From: LIU Zhiwei @ 2023-09-11 5:56 UTC (permalink / raw)
To: Palmer Dabbelt, pbonzini; +Cc: atishp, qemu-devel, qemu-riscv, lzw194868
On 2023/9/9 22:45, Palmer Dabbelt wrote:
> On Sat, 09 Sep 2023 00:18:02 PDT (-0700), pbonzini@redhat.com wrote:
>> Il sab 9 set 2023, 03:35 Atish Patra <atishp@atishpatra.org> ha scritto:
>>
>>> On Fri, Sep 8, 2023 at 3:29 AM Paolo Bonzini <pbonzini@redhat.com>
>>> wrote:
>>> >
>>> > Queued, thanks.
>>> >
>>>
>>> I didn't realize it was already queued. Gmail threads failed me this
>>> time.
>>> @Paolo Bonzini : Can you please drop this one as this will break as
>>> soon as the host riscv system
>>> has the latest kernel ? I have provided more details in the original
>>> thread.
>>>
>>> https://lists.gnu.org/archive/html/qemu-devel/2023-09/msg01941.html
>>
>>
>> If you have dynamic clock adjustment, does rdcycle increase with a fixed
>> frequency or does it provide the raw number of clock cycles? If the
>> latter,
>> I agree that it should be provided by perf; but if the frequency is
>> fixed
>> then it would be the same as rdtsc on Intel.
>
> That really depends on exactly how the system is set up, but there are
> systems for which the rdcycle frequency changes when clock speeds
> change and thus will produce surprising answers for users trying to
> use rdcycle as a RTC. We have rdtime for that, but it has other
> problems (it's trapped and emulated in M-mode on some systems, so it's
> slow and noisy).
>
> So we're steering folks towards perf where we can, as at least that
> way we've got a higher-level interface we can use to describe these
> quirks.
OK. I will send a v2 patch using rdtime.
Thanks,
Zhiwei
>
>>
>> Paolo
>>
>>
>>>
>>> > Paolo
>>> >
>>> >
>>>
>>>
>>> --
>>> Regards,
>>> Atish
>>>
>>>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RESEND] qemu/timer: Add host ticks function for RISC-V
@ 2023-09-08 3:31 LIU Zhiwei
2023-09-08 22:32 ` Atish Patra
0 siblings, 1 reply; 7+ messages in thread
From: LIU Zhiwei @ 2023-09-08 3:31 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-riscv, LIU Zhiwei, LIU Zhiwei
From: LIU Zhiwei <lzw194868@alibaba-inc.com>
Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
---
include/qemu/timer.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 9a91cb1248..105767c195 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -979,6 +979,25 @@ static inline int64_t cpu_get_host_ticks(void)
return cur - ofs;
}
+#elif defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 32
+static inline int64_t cpu_get_host_ticks(void)
+{
+ uint32_t lo, hi;
+ asm volatile("RDCYCLE %0\n\t"
+ "RDCYCLEH %1"
+ : "=r"(lo), "=r"(hi));
+ return lo | (uint64_t)hi << 32;
+}
+
+#elif defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen > 32
+static inline int64_t cpu_get_host_ticks(void)
+{
+ int64_t val;
+
+ asm volatile("RDCYCLE %0" : "=r"(val));
+ return val;
+}
+
#else
/* The host CPU doesn't have an easily accessible cycle counter.
Just return a monotonically increasing value. This will be
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RESEND] qemu/timer: Add host ticks function for RISC-V
2023-09-08 3:31 LIU Zhiwei
@ 2023-09-08 22:32 ` Atish Patra
0 siblings, 0 replies; 7+ messages in thread
From: Atish Patra @ 2023-09-08 22:32 UTC (permalink / raw)
To: LIU Zhiwei; +Cc: qemu-devel, qemu-riscv, LIU Zhiwei
On Thu, Sep 7, 2023 at 8:33 PM LIU Zhiwei <zhiwei_liu@linux.alibaba.com> wrote:
>
> From: LIU Zhiwei <lzw194868@alibaba-inc.com>
>
> Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
> ---
> include/qemu/timer.h | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/include/qemu/timer.h b/include/qemu/timer.h
> index 9a91cb1248..105767c195 100644
> --- a/include/qemu/timer.h
> +++ b/include/qemu/timer.h
> @@ -979,6 +979,25 @@ static inline int64_t cpu_get_host_ticks(void)
> return cur - ofs;
> }
>
> +#elif defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 32
> +static inline int64_t cpu_get_host_ticks(void)
> +{
> + uint32_t lo, hi;
> + asm volatile("RDCYCLE %0\n\t"
> + "RDCYCLEH %1"
> + : "=r"(lo), "=r"(hi));
> + return lo | (uint64_t)hi << 32;
> +}
> +
> +#elif defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen > 32
> +static inline int64_t cpu_get_host_ticks(void)
> +{
> + int64_t val;
> +
> + asm volatile("RDCYCLE %0" : "=r"(val));
> + return val;
> +}
> +
rdcycle won't be accessible from the user space directly in the
future. rdcycle will be accessible via perf similar to other
architectures from the next kernel release [1].
rdtime must be used to compute the host ticks if the host is a riscv.
This is the equivalent of rdtsc in x86.
[1] https://lore.kernel.org/lkml/CAP-5=fVcMg7TL6W_jH61PW6dYMobuTs13d4JDuTAx=mxJ+PNtQ@mail.gmail.com/T/#md852c28f4070212973b796c232ecd37dc1c6cb2b
> #else
> /* The host CPU doesn't have an easily accessible cycle counter.
> Just return a monotonically increasing value. This will be
> --
> 2.17.1
>
>
--
Regards,
Atish
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-09-11 5:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20230908033129.694-1-zhiwei._5Fliu@linux.alibaba.com>
2023-09-08 10:29 ` [RESEND] qemu/timer: Add host ticks function for RISC-V Paolo Bonzini
2023-09-09 1:35 ` Atish Patra
2023-09-09 7:18 ` Paolo Bonzini
2023-09-09 14:45 ` Palmer Dabbelt
2023-09-11 5:56 ` LIU Zhiwei
2023-09-08 3:31 LIU Zhiwei
2023-09-08 22:32 ` Atish Patra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).