From: "Alex Bennée" <alex.bennee@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm <qemu-arm@nongnu.org>,
QEMU Developers <qemu-devel@nongnu.org>,
takeharu.kato@linaro.org, Renato Golin <renato.golin@linaro.org>
Subject: Re: [Qemu-devel] [RFC PATCH] target/arm: support reading of CNTVCT_EL0 from user-space
Date: Mon, 16 Apr 2018 16:29:07 +0100 [thread overview]
Message-ID: <874lkbb264.fsf@linaro.org> (raw)
In-Reply-To: <CAFEAcA-1GVMOSJVQ5p8+qpo8P-+fBq0-6TaA2mdvLDbk3fiihg@mail.gmail.com>
Peter Maydell <peter.maydell@linaro.org> writes:
> On 16 April 2018 at 15:03, Alex Bennée <alex.bennee@linaro.org> wrote:
>> Since kernel commit a86bd139f2 (arm64: arch_timer: Enable CNTVCT_EL0
>> trap..) user-space has been able to read this system register. This
>> patch enables access to that register although currently it always
>> returns 0 as we don't yet have a mechanism for managing timers in
>> linux-user mode.
>>
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>> target/arm/helper.c | 20 +++++++++++++++++---
>> 1 file changed, 17 insertions(+), 3 deletions(-)
>>
>> diff --git a/target/arm/helper.c b/target/arm/helper.c
>> index b14fdab140..8244badd63 100644
>> --- a/target/arm/helper.c
>> +++ b/target/arm/helper.c
>> @@ -2121,11 +2121,25 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
>> };
>>
>> #else
>> -/* In user-mode none of the generic timer registers are accessible,
>> - * and their implementation depends on QEMU_CLOCK_VIRTUAL and qdev gpio outputs,
>> - * so instead just don't register any of them.
>> +
>> +/* In user-mode most of the generic timer registers are inaccessible
>> + * however modern kernels (4.12+) allow access to cntvct_el0
>> */
>> +
>> +static uint64_t gt_virt_cnt_read(CPUARMState *env, const ARMCPRegInfo *ri)
>> +{
>> + /* Currently we have no support for QEMUTimer in linux-user so we
>> + * can't call gt_get_countervalue(env).
>> + */
>> + return 0;
>> +}
>> +
>> static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
>> + { .name = "CNTVCT_EL0", .state = ARM_CP_STATE_AA64,
>> + .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 0, .opc2 = 2,
>> + .access = PL0_R, .type = ARM_CP_NO_RAW | ARM_CP_IO,
>> + .readfn = gt_virt_cnt_read,
>> + },
>> REGINFO_SENTINEL
>> };
>
> CNTVCT_EL0 isn't much use without CNTFRQ_EL0 which tells
> you how fast it ticks...
I've added it but of course:
/* Note that CNTFRQ is purely reads-as-written for the benefit
* of software; writing it doesn't actually change the timer frequency.
* Our reset value matches the fixed frequency we implement the timer at.
*/
So it's not like we do anything with it internally. I assume in real
life you could mess with this but still have a monotonically increasing
counter.
>
> It looks like other targets use cpu_get_host_ticks() for an
> arbitrary time-counter thingy. Not sure you can get the frequency
> for it, though :-(
Hmm I've just used:
return cpu_get_clock()/GTIMER_SCALE;
For now....
>
> thanks
> -- PMM
--
Alex Bennée
next prev parent reply other threads:[~2018-04-16 15:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-16 14:03 [Qemu-devel] [RFC PATCH] target/arm: support reading of CNTVCT_EL0 from user-space Alex Bennée
2018-04-16 14:29 ` Peter Maydell
2018-04-16 15:29 ` Alex Bennée [this message]
2018-04-16 15:36 ` Peter Maydell
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=874lkbb264.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=renato.golin@linaro.org \
--cc=takeharu.kato@linaro.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 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).