From: Atish Patra <atishp@atishpatra.org>
To: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org,
LIU Zhiwei <lzw194868@alibaba-inc.com>
Subject: Re: [RESEND] qemu/timer: Add host ticks function for RISC-V
Date: Fri, 8 Sep 2023 15:32:50 -0700 [thread overview]
Message-ID: <CAOnJCUJPA9nzJRUuxd13WJzhGjWPBbmnNFn4Fcw4Wcf7WOO2fw@mail.gmail.com> (raw)
In-Reply-To: <20230908033129.694-1-zhiwei_liu@linux.alibaba.com>
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
next prev parent reply other threads:[~2023-09-08 22:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-08 3:31 [RESEND] qemu/timer: Add host ticks function for RISC-V LIU Zhiwei
2023-09-08 22:32 ` Atish Patra [this message]
[not found] <20230908033129.694-1-zhiwei._5Fliu@linux.alibaba.com>
2023-09-08 10:29 ` 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
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=CAOnJCUJPA9nzJRUuxd13WJzhGjWPBbmnNFn4Fcw4Wcf7WOO2fw@mail.gmail.com \
--to=atishp@atishpatra.org \
--cc=lzw194868@alibaba-inc.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=zhiwei_liu@linux.alibaba.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;
as well as URLs for NNTP newsgroup(s).