From mboxrd@z Thu Jan 1 00:00:00 1970 From: Srivatsa Vaddagiri Subject: Re: [PATCH RFC V4 4/5] kvm : pv-ticketlocks support for linux guests running on KVM hypervisor Date: Tue, 17 Jan 2012 17:03:20 +0530 Message-ID: <20120117113312.GB30398@linux.vnet.ibm.com> References: <20120114182501.8604.68416.sendpatchset@oc5400248562.ibm.com> <20120114182645.8604.68884.sendpatchset@oc5400248562.ibm.com> <20120117110210.GA17420@amt.cnet> Reply-To: Srivatsa Vaddagiri Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: Jeremy Fitzhardinge , Raghavendra K T , linux-doc@vger.kernel.org, Peter Zijlstra , Jan Kiszka , Virtualization , Paul Mackerras , "H. Peter Anvin" , Stefano Stabellini , Xen , Dave Jiang , KVM , Glauber Costa , X86 , Ingo Molnar , Avi Kivity , Rik van Riel , Konrad Rzeszutek Wilk , Sasha Levin , Sedat Dilek , Thomas Gleixner , Greg Kroah-Hartman , LKML , Dave Hansen Return-path: Content-Disposition: inline In-Reply-To: <20120117110210.GA17420@amt.cnet> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org List-Id: kvm.vger.kernel.org * Marcelo Tosatti [2012-01-17 09:02:11]: > > +/* Kick vcpu waiting on @lock->head to reach value @ticket */ > > +static void kvm_unlock_kick(struct arch_spinlock *lock, __ticket_t ticket) > > +{ > > + int cpu; > > + int apicid; > > + > > + add_stats(RELEASED_SLOW, 1); > > + > > + for_each_cpu(cpu, &waiting_cpus) { > > + const struct kvm_lock_waiting *w = &per_cpu(lock_waiting, cpu); > > + if (ACCESS_ONCE(w->lock) == lock && > > + ACCESS_ONCE(w->want) == ticket) { > > + add_stats(RELEASED_SLOW_KICKED, 1); > > + apicid = per_cpu(x86_cpu_to_apicid, cpu); > > + kvm_kick_cpu(apicid); > > + break; > > + } > > + } > > What prevents a kick from being lost here, if say, the waiter is at > local_irq_save in kvm_lock_spinning, before the lock/want assignments? The waiter does check for lock becoming available before actually sleeping: + /* + * check again make sure it didn't become free while + * we weren't looking. + */ + if (ACCESS_ONCE(lock->tickets.head) == want) { + add_stats(TAKEN_SLOW_PICKUP, 1); + goto out; + } - vatsa From mboxrd@z Thu Jan 1 00:00:00 1970 From: Srivatsa Vaddagiri Subject: Re: [PATCH RFC V4 4/5] kvm : pv-ticketlocks support for linux guests running on KVM hypervisor Date: Tue, 17 Jan 2012 17:03:20 +0530 Message-ID: <20120117113312.GB30398@linux.vnet.ibm.com> References: <20120114182501.8604.68416.sendpatchset@oc5400248562.ibm.com> <20120114182645.8604.68884.sendpatchset@oc5400248562.ibm.com> <20120117110210.GA17420@amt.cnet> Reply-To: Srivatsa Vaddagiri Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <20120117110210.GA17420@amt.cnet> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org To: Marcelo Tosatti Cc: Jeremy Fitzhardinge , Raghavendra K T , linux-doc@vger.kernel.org, Peter Zijlstra , Jan Kiszka , Virtualization , Paul Mackerras , "H. Peter Anvin" , Stefano Stabellini , Xen , Dave Jiang , KVM , Glauber Costa , X86 , Ingo Molnar , Avi Kivity , Rik van Riel , Konrad Rzeszutek Wilk , Sasha Levin , Sedat Dilek , Thomas Gleixner , Greg Kroah-Hartman , LKML Dave Hansen List-Id: virtualization@lists.linuxfoundation.org * Marcelo Tosatti [2012-01-17 09:02:11]: > > +/* Kick vcpu waiting on @lock->head to reach value @ticket */ > > +static void kvm_unlock_kick(struct arch_spinlock *lock, __ticket_t ticket) > > +{ > > + int cpu; > > + int apicid; > > + > > + add_stats(RELEASED_SLOW, 1); > > + > > + for_each_cpu(cpu, &waiting_cpus) { > > + const struct kvm_lock_waiting *w = &per_cpu(lock_waiting, cpu); > > + if (ACCESS_ONCE(w->lock) == lock && > > + ACCESS_ONCE(w->want) == ticket) { > > + add_stats(RELEASED_SLOW_KICKED, 1); > > + apicid = per_cpu(x86_cpu_to_apicid, cpu); > > + kvm_kick_cpu(apicid); > > + break; > > + } > > + } > > What prevents a kick from being lost here, if say, the waiter is at > local_irq_save in kvm_lock_spinning, before the lock/want assignments? The waiter does check for lock becoming available before actually sleeping: + /* + * check again make sure it didn't become free while + * we weren't looking. + */ + if (ACCESS_ONCE(lock->tickets.head) == want) { + add_stats(TAKEN_SLOW_PICKUP, 1); + goto out; + } - vatsa