From: Christian Borntraeger Subject: Re: [PATCH 2/6] kvm-s390: use hrtimer for clock wakeup from idle Date: Wed, 6 May 2009 14:36:12 +0200 Message-ID: <200905061436.13071.borntraeger@de.ibm.com> References: <1241534358-32172-1-git-send-email-ehrhardt@linux.vnet.ibm.com> <1241534358-32172-3-git-send-email-ehrhardt@linux.vnet.ibm.com> <4A017E1F.6030908@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: ehrhardt@linux.vnet.ibm.com, kvm@vger.kernel.org, Carsten Otte To: Avi Kivity Return-path: Received: from mtagate4.de.ibm.com ([195.212.29.153]:62457 "EHLO mtagate4.de.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760253AbZEFMgP (ORCPT ); Wed, 6 May 2009 08:36:15 -0400 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate4.de.ibm.com (8.14.3/8.13.8) with ESMTP id n46CaE3l043146 for ; Wed, 6 May 2009 12:36:14 GMT Received: from d12av01.megacenter.de.ibm.com (d12av01.megacenter.de.ibm.com [9.149.165.212]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n46CaEIx4382918 for ; Wed, 6 May 2009 14:36:14 +0200 Received: from d12av01.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av01.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n46CaD6A016141 for ; Wed, 6 May 2009 14:36:14 +0200 In-Reply-To: <4A017E1F.6030908@redhat.com> Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: Am Wednesday 06 May 2009 14:10:07 schrieb Avi Kivity: > ehrhardt@linux.vnet.ibm.com wrote: > > From: Christian Borntraeger > > > > This patch reworks the s390 clock comparator wakeup to hrtimer. The clock > > comparator is a per-cpu value that is compared against the TOD clock. If > > ckc <= TOD an external interrupt 1004 is triggered. Since the clock comparator > > and the TOD clock have a much higher resolution than jiffies we should use > > hrtimers to trigger the wakeup. This speeds up guest nanosleep for small > > values. > > > > Since hrtimers callbacks run in hard-irq context, I added a tasklet to do > > the actual work with enabled interrupts. > > > > > > -void kvm_s390_idle_wakeup(unsigned long data) > > +void kvm_s390_tasklet(unsigned long parm) > > { > > - struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; > > + struct kvm_vcpu *vcpu = (struct kvm_vcpu *) parm; > > > > - spin_lock_bh(&vcpu->arch.local_int.lock); > > + spin_lock(&vcpu->arch.local_int.lock); > > vcpu->arch.local_int.timer_due = 1; > > if (waitqueue_active(&vcpu->arch.local_int.wq)) > > wake_up_interruptible(&vcpu->arch.local_int.wq); > > - spin_unlock_bh(&vcpu->arch.local_int.lock); > > + spin_unlock(&vcpu->arch.local_int.lock); > > } > > > > Why can't this be done from the timer context (after adjusting the locks)? It can be done, in fact I did that in my first version. The thing is, we would need to change all local_int.locks to spinlock_irqs, since standard timers are softirqs and hrtimers and hardirqs. Enabling and disabling irqs is a relatively expensive operating on s390 (but locks via compare and swap are quite cheap). Since we take this specific lock in lots of places this lock is on some hot pathes. The idle wakeup on the other hand is not that critical. Christian