xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Kubascik <jeff.kubascik@dornerworks.com>
To: Julien Grall <julien@xen.org>, <xen-devel@lists.xenproject.org>
Cc: Stewart Hildebrand <Stewart.Hildebrand@dornerworks.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: Re: [Xen-devel] [PATCH v4 1/2] xen/arm: remove physical timer offset
Date: Fri, 24 Jan 2020 16:43:56 -0500	[thread overview]
Message-ID: <a6a4d197-c511-d7ed-c137-4d5f05f098de@dornerworks.com> (raw)
In-Reply-To: <78db27b5-ab04-904a-f2b8-869969fbae21@xen.org>

On 1/23/2020 7:32 AM, Julien Grall wrote:
> Hi,
> 
> On 21/01/2020 15:07, Jeff Kubascik wrote:
>> The physical timer traps apply an offset so that time starts at 0 for
>> the guest. However, this offset is not currently applied to the physical
>> counter. Per the ARMv8 Reference Manual (ARM DDI 0487E.a), section
>> D11.2.4 Timers, the "Offset" between the counter and timer should be
>> zero for a physical timer. This removes the offset to make the timer and
>> counter consistent.
>>
>> This also cleans up the physical timer implementation to better match
>> the virtual timer - both cval's now hold the hardware value.
>>
>> Signed-off-by: Jeff Kubascik <jeff.kubascik@dornerworks.com>
>> ---
>>   xen/arch/arm/vtimer.c        | 34 ++++++++++++++++++----------------
>>   xen/include/asm-arm/domain.h |  3 ---
>>   2 files changed, 18 insertions(+), 19 deletions(-)
>>
>> diff --git a/xen/arch/arm/vtimer.c b/xen/arch/arm/vtimer.c
>> index 240a850b6e..0c78a65863 100644
>> --- a/xen/arch/arm/vtimer.c
>> +++ b/xen/arch/arm/vtimer.c
>> @@ -62,7 +62,6 @@ static void virt_timer_expired(void *data)
>>
>>   int domain_vtimer_init(struct domain *d, struct xen_arch_domainconfig *config)
>>   {
>> -    d->arch.phys_timer_base.offset = NOW();
>>       d->arch.virt_timer_base.offset = READ_SYSREG64(CNTPCT_EL0);
>>       d->time_offset.seconds = ticks_to_ns(d->arch.virt_timer_base.offset - boot_count);
>>       do_div(d->time_offset.seconds, 1000000000);
>> @@ -108,7 +107,6 @@ int vcpu_vtimer_init(struct vcpu *v)
>>
>>       init_timer(&t->timer, phys_timer_expired, t, v->processor);
>>       t->ctl = 0;
>> -    t->cval = NOW();
>>       t->irq = d0
>>           ? timer_get_irq(TIMER_PHYS_NONSECURE_PPI)
>>           : GUEST_TIMER_PHYS_NS_PPI;
>> @@ -167,6 +165,7 @@ void virt_timer_restore(struct vcpu *v)
>>   static bool vtimer_cntp_ctl(struct cpu_user_regs *regs, uint32_t *r, bool read)
>>   {
>>       struct vcpu *v = current;
>> +    s_time_t expires;
>>
>>       if ( !ACCESS_ALLOWED(regs, EL0PTEN) )
>>           return false;
>> @@ -184,8 +183,9 @@ static bool vtimer_cntp_ctl(struct cpu_user_regs *regs, uint32_t *r, bool read)
>>
>>           if ( v->arch.phys_timer.ctl & CNTx_CTL_ENABLE )
>>           {
>> -            set_timer(&v->arch.phys_timer.timer,
>> -                      v->arch.phys_timer.cval + v->domain->arch.phys_timer_base.offset);
>> +            expires = v->arch.phys_timer.cval > boot_count
>> +                      ? ticks_to_ns(v->arch.phys_timer.cval - boot_count) : 0;
>> +            set_timer(&v->arch.phys_timer.timer, expires);
> 
> While the factoring was optional, my request of a comment wasn't (even
> if it requires to duplicate 3 times).

Understood.

> If you suggest a comment and an update of the commit message, I can
> merge it in this patch on commit.

For the comment:

/* If cval is before the point Xen started, expire timer immediately */

For the commit message:

In the case the guest sets cval to a time before Xen started, the correct
behavior is to expire the timer immediately. To do this, we set the expires
argument of set_timer to zero.

> Cheers,
> 
> --
> Julien Grall
> 

Sincerely,
Jeff Kubascik

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2020-01-24 21:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-21 15:07 [Xen-devel] [PATCH v4 0/2] xen/arm: physical timer improvements Jeff Kubascik
2020-01-21 15:07 ` [Xen-devel] [PATCH v4 1/2] xen/arm: remove physical timer offset Jeff Kubascik
2020-01-23 12:32   ` Julien Grall
2020-01-24 21:43     ` Jeff Kubascik [this message]
2020-01-24 21:58       ` Julien Grall
2020-01-21 15:07 ` [Xen-devel] [PATCH v4 2/2] xen/arm: Sign extend TimerValue when computing the CompareValue Jeff Kubascik
2020-01-23 12:29   ` Julien Grall

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=a6a4d197-c511-d7ed-c137-4d5f05f098de@dornerworks.com \
    --to=jeff.kubascik@dornerworks.com \
    --cc=Stewart.Hildebrand@dornerworks.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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).