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

Re: [Xen-devel] [PATCH RFC v2 2/9] xen/arm: Implement save and restore for gic, vtimer, and ptimer



On Wed, 3 Jul 2013, Jaeyong Yoo wrote:
> +static int vtimer_save(struct domain *d, hvm_domain_context_t *h)
> +{
> +    struct hvm_hw_vtimer ctxt;
> +    struct vcpu *v;
> +
> +    ctxt.vtb_offset = d->arch.virt_timer_base.offset;
> +
> +    /* Save the state of vtimer */
> +    for_each_vcpu( d, v )
> +    {
> +        ctxt.cval = v->arch.virt_timer.cval;
> +        ctxt.ctl = v->arch.virt_timer.ctl;
> +        if ( hvm_save_entry(VTIMER, v->vcpu_id, h, &ctxt) != 0 )
> +            return 1;
> +    }
> +
> +    return 0;
> +}
> +
> +static int vtimer_load(struct domain *d, hvm_domain_context_t *h)
> +{
> +    int vcpuid;
> +    struct hvm_hw_vtimer ctxt;
> +    struct vcpu *v;
> +    /* Which vcpu is this? */
> +    vcpuid = hvm_load_instance(h);
> +    if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
> +    {
> +        dprintk(XENLOG_G_ERR, "HVM restore: dom%u has no vcpu%u\n",
> +                d->domain_id, vcpuid);
> +        return -EINVAL;
> +    }
> +
> +    if ( hvm_load_entry(VTIMER, h, &ctxt) != 0 )
> +        return -EINVAL;
> +
> +    v->arch.virt_timer.cval = ctxt.cval;
> +    v->arch.virt_timer.ctl = ctxt.ctl;
> +    v->arch.virt_timer.v = v;
> +
> +    d->arch.virt_timer_base.offset = ctxt.vtb_offset;
> +
> +    return 0;
> +}
> +
> +HVM_REGISTER_SAVE_RESTORE(VTIMER, vtimer_save, vtimer_load, 1, 
> HVMSR_PER_VCPU);
> +
> +static int ptimer_save(struct domain *d, hvm_domain_context_t *h)
> +{
> +    struct hvm_hw_ptimer ctxt;
> +    struct vcpu *v;
> +
> +    ctxt.ptb_offset = d->arch.phys_timer_base.offset;
> +
> +    /* Save the state of ptimer */
> +    for_each_vcpu( d, v )
> +    {
> +        ctxt.p_cval = v->arch.phys_timer.cval;
> +        ctxt.p_ctl = v->arch.phys_timer.ctl;
> +
> +        if ( hvm_save_entry(PTIMER, v->vcpu_id, h, &ctxt) != 0 )
> +            return 1;
> +    }
> +
> +    return 0;
> +}
> +
> +static int ptimer_load(struct domain *d, hvm_domain_context_t *h)
> +{
> +    int vcpuid;
> +    struct hvm_hw_ptimer ctxt;
> +    struct vcpu *v;
> +    /* Which vcpu is this? */
> +    vcpuid = hvm_load_instance(h);
> +    if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
> +    {
> +        dprintk(XENLOG_G_ERR, "HVM restore: dom%u has no vcpu%u\n",
> +                d->domain_id, vcpuid);
> +        return -EINVAL;
> +    }
> +
> +    if ( hvm_load_entry(PTIMER, h, &ctxt) != 0 )
> +        return -EINVAL;
> +
> +    v->arch.phys_timer.cval = ctxt.p_cval;
> +    v->arch.phys_timer.ctl = ctxt.p_ctl;
> +    v->arch.phys_timer.v = v;
> +
> +    d->arch.phys_timer_base.offset = ctxt.ptb_offset;
> +
> +    return 0;
> +}

Given that the ptimer and vtimer save and load functions as well as the
save records are identical, I think it might be better to declare a
single timer record with a timer type and reuse the same load and save
functions for both ptimer and vtimer.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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