From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [RFC][PATCH 1/3] Introduce a workqueue to deliver PIT timer interrupts. Date: Wed, 09 Jun 2010 13:55:15 +0300 Message-ID: <4C0F7313.1000608@redhat.com> References: <1276019703-18136-1-git-send-email-clalance@redhat.com> <1276019703-18136-2-git-send-email-clalance@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, mtosatti@redhat.com To: Chris Lalancette Return-path: Received: from mx1.redhat.com ([209.132.183.28]:46096 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756931Ab0FIKzS (ORCPT ); Wed, 9 Jun 2010 06:55:18 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o59AtHZb027253 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 9 Jun 2010 06:55:17 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o59AtG9g003785 for ; Wed, 9 Jun 2010 06:55:16 -0400 In-Reply-To: <1276019703-18136-2-git-send-email-clalance@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 06/08/2010 08:55 PM, Chris Lalancette wrote: > We really want to "kvm_set_irq" during the hrtimer callback, > but that is risky because that is during interrupt context. > Instead, offload the work to a workqueue, which is a bit safer > and should provide most of the same functionality. > > > > > +static void pit_do_work(struct work_struct *work) > +{ > + struct kvm_pit *pit = container_of(work, struct kvm_pit, expired); > + struct kvm *kvm = pit->kvm; > + struct kvm_vcpu *vcpu; > + int i; > + struct kvm_kpit_state *ps =&pit->pit_state; > + int inject = 0; > + > + /* Try to inject pending interrupts when > + * last one has been acked. > + */ > + raw_spin_lock(&ps->inject_lock); > + if (ps->irq_ack) { > + ps->irq_ack = 0; > + inject = 1; > + } > + raw_spin_unlock(&ps->inject_lock); > I don't think this needs to be a raw spinlock any longer (a nice side effect).+ > +static enum hrtimer_restart pit_timer_fn(struct hrtimer *data) > +{ > + struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer); > + struct kvm_pit *pt = ktimer->kvm->arch.vpit; > + > + queue_work(pit_wq,&pt->expired); > + > + if (ktimer->t_ops->is_periodic(ktimer)) { > + hrtimer_add_expires_ns(&ktimer->timer, ktimer->period); > spaces/tabs > + return HRTIMER_RESTART; > + } > + else > + return HRTIMER_NORESTART; > +} > + > Somewhere, you have to cancel a pending work struct. At least during destruction, but perhaps also if the pit is configured not to generate interrupts any more. -- error compiling committee.c: too many arguments to function