From: Jaeyong Yoo Subject: Re: [PATCH RFC v2 2/9] xen/arm: Implement save and restore for gic, vtimer, and ptimer Date: Thu, 04 Jul 2013 08:53:37 +0900 Message-ID: <003501ce7848$890752a0$9b15f7e0$%yoo@samsung.com> References: <1372842943-27482-1-git-send-email-jaeyong.yoo@samsung.com> <1372842943-27482-3-git-send-email-jaeyong.yoo@samsung.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-reply-to: Content-language: ko List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: 'Stefano Stabellini' Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org > -----Original Message----- > From: Stefano Stabellini [mailto:stefano.stabellini@eu.citrix.com] > Sent: Wednesday, July 03, 2013 8:30 PM > To: Jaeyong Yoo > Cc: xen-devel@lists.xen.org > Subject: 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. Got it.