[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v8 10/11] viridian: add implementation of synthetic timers


  • To: 'Jan Beulich' <JBeulich@xxxxxxxx>
  • From: Paul Durrant <Paul.Durrant@xxxxxxxxxx>
  • Date: Mon, 18 Mar 2019 14:37:16 +0000
  • Accept-language: en-GB, en-US
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wei.liu2@xxxxxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>, "Tim \(Xen.org\)" <tim@xxxxxxx>, George Dunlap <George.Dunlap@xxxxxxxxxx>, Julien Grall <julien.grall@xxxxxxx>, xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Ian Jackson <Ian.Jackson@xxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 18 Mar 2019 14:40:11 +0000
  • Ironport-data: A9a23:faBYjKv8jlbaCJzSbX86Rd6RDufnOphVZvmCV/efNkXfuVnxXxfKv+ XnISukaPC7kbIZn3lbVNaBeN5awmLHBBYJDnCkaGLho2FJtskGzZbc75TXyHWoHeHi8/xtGX m4vBi1OqDptakrgOyubH8qbzWGDMwhcZcRRBLwgX9byTxR5RwIJSEVOr77snKoX0QKOXdxpm bzIE5lPoo3Jzza/GbNE0Z1j+P1t/c+J74+SMN/lLZFA0T/lnMLgQxXdmZF2jQEZCm4sw/LWy HpnJyThuRrUYbo1oCoHwl6cxf55sDOo9VNqc1RplBA+2q5RmoSnucaIMnubPL3mfKBsN+i1e PQN9SNbUsksfCbCNqjBkPiQ7ir/t4qxCJ53rYC0w1KFm2g9R6BIDAGWHR0dt7czRiYtyAMfk VIJ/z3SD+4kV6koHJurBNLO2agNdhUP0sVti32ZAv1wi0lnwAhSlHy4hC7u2KjmlrkZ7SN1B /FPKCvwQAinaTeN8anyaQ4c8G7G65CpbxUG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56clIV9qqn2QMfpxDqFuXVxOH9SDupkscRUVzYe+p8uma+Ae tcQWLlU59XETmcwbPlbH8dCnK6u4eS5ZQt0c2vODf6wcl5lYu1BYpjple4QU1C3vLtRuI0pb +oRtEL4I/ZVKLwk0HY6ec2B3iGJK6leMqifJNmOd8caZZL2fnv58q4euWLfyAeVvnYqzLXq2 bhLpTExSV4VAJ2wXwqZmmiBhh30kr6d3BUz1/W8rL3qziJXvR89C0vQrFel1xcAhfAwwfS7X 2HEHnr5FBWerqWOuNMhs0bV2q/awZx4OrOiczUSKvTvjm+ILkENmBMZZN3xlGDo1gaFSjQvD OTmrLU1Rr5h2UTwjtRTw/j/4Be6jL/XXidbNk4oNpVfYjPxp28a6eRuAczGzDtANY7n2wpsX MvO1P1WtaaW3/nTfx++KpzbWB/RamO9LtFrAP5kQ69h2esEFX6KOFbZZkt42GdkC2nLY2+np KM+/PUikQDoew=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHU3X2WVMvWAzv7yUWT06FGctY0sqYRYLYAgAATJKA=
  • Thread-topic: [Xen-devel] [PATCH v8 10/11] viridian: add implementation of synthetic timers

> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@xxxxxxxx]
> Sent: 18 March 2019 14:24
> To: Paul Durrant <Paul.Durrant@xxxxxxxxxx>
> Cc: Julien Grall <julien.grall@xxxxxxx>; Andrew Cooper 
> <Andrew.Cooper3@xxxxxxxxxx>; Roger Pau Monne
> <roger.pau@xxxxxxxxxx>; Wei Liu <wei.liu2@xxxxxxxxxx>; George Dunlap 
> <George.Dunlap@xxxxxxxxxx>; Ian
> Jackson <Ian.Jackson@xxxxxxxxxx>; Stefano Stabellini 
> <sstabellini@xxxxxxxxxx>; xen-devel <xen-
> devel@xxxxxxxxxxxxxxxxxxxx>; Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>; 
> Tim (Xen.org)
> <tim@xxxxxxx>
> Subject: Re: [Xen-devel] [PATCH v8 10/11] viridian: add implementation of 
> synthetic timers
> 
> >>> On 18.03.19 at 12:20, <paul.durrant@xxxxxxxxxx> wrote:
> > @@ -72,11 +77,14 @@ static void update_reference_tsc(struct domain *d, bool 
> > initialize)
> >       * ticks per 100ns shifted left by 64.
> >       */
> >      p->TscScale = ((10000ul << 32) / d->arch.tsc_khz) << 32;
> > +    smp_wmb();
> > +
> > +    seq = p->TscSequence + 1;
> > +    if ( seq == 0xFFFFFFFF || seq == 0 ) /* Avoid both 'invalid' values */
> > +        seq = 1;
> >
> > -    p->TscSequence++;
> > -    if ( p->TscSequence == 0xFFFFFFFF ||
> > -         p->TscSequence == 0 ) /* Avoid both 'invalid' values */
> > -        p->TscSequence = 1;
> > +    p->TscSequence = seq;
> > +    vd->reference_tsc_valid = true;
> 
> Strictly speaking, don't you need another smp_wmb() between
> these two lines?
> 

Since the data in the page is not used by time_now() I don't think so.

> > +static void start_stimer(struct viridian_stimer *vs)
> > +{
> > +    const struct vcpu *v = vs->v;
> > +    struct viridian_vcpu *vv = v->arch.hvm.viridian;
> > +    unsigned int stimerx = vs - &vv->stimer[0];
> > +    int64_t now = time_now(v->domain);
> > +    int64_t expiration;
> > +    s_time_t timeout;
> > +
> > +    if ( !test_and_set_bit(stimerx, &vv->stimer_enabled) )
> > +        printk(XENLOG_G_INFO "%pv: VIRIDIAN STIMER%u: enabled\n", v,
> > +               stimerx);
> > +
> > +    if ( vs->config.periodic )
> > +    {
> > +        /*
> > +         * The specification says that if the timer is lazy then we
> > +         * skip over any missed expirations so we can treat this case
> > +         * as the same as if the timer is currently stopped, i.e. we
> > +         * just schedule expiration to be 'count' ticks from now.
> > +         */
> > +        if ( !vs->started || vs->config.lazy )
> > +            expiration = now + vs->count;
> > +        else
> > +        {
> > +            unsigned int missed = 0;
> > +
> > +            /*
> > +             * The timer is already started, so we're re-scheduling.
> > +             * Hence advance the timer expiration by one tick.
> > +             */
> > +            expiration = vs->expiration + vs->count;
> > +
> > +            /* Now check to see if any expirations have been missed */
> > +            if ( expiration - now <= 0 )
> > +                missed = ((now - expiration) / vs->count) + 1;
> > +
> > +            /*
> > +             * The specification says that if the timer is not lazy then
> > +             * a non-zero missed count should be used to reduce the period
> > +             * of the timer until it catches up, unless the count has
> > +             * reached a 'significant number', in which case the timer
> > +             * should be treated as lazy. Unfortunately the specification
> > +             * does not state what that number is so the choice of number
> > +             * here is a pure guess.
> > +             */
> > +            if ( missed > 3 )
> > +                expiration = now + vs->count;
> > +            else if ( missed )
> > +                expiration = now + (vs->count / missed);
> > +        }
> > +    }
> > +    else
> > +    {
> > +        expiration = vs->count;
> > +        if ( expiration - now <= 0 )
> > +        {
> > +            vs->expiration = expiration;
> > +            stimer_expire(vs);
> 
> Aren't you introducing a risk for races by calling the timer function
> directly from here? start_timer(), after all, gets called from quite a
> few places.
> 

In practice I don't think there should be any problematic race, but I'll check 
again.

> > +            return;
> > +        }
> > +    }
> > +    ASSERT(expiration - now > 0);
> > +
> > +    vs->expiration = expiration;
> > +    timeout = (expiration - now) * 100ull;
> > +
> > +    vs->started = true;
> > +    migrate_timer(&vs->timer, smp_processor_id());
> 
> Why is this smp_processor_id() when viridian_time_vcpu_init() uses
> v->processor? How relevant is it in the first place to trace the pCPU
> the vCPU runs on for the timer?
> 

I was just following suit with other timer code. It seems to be the norm to 
migrate to the current pCPU just prior to starting a timer.

  Paul

> Jan
> 


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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.