Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754936AbbGCMbg (ORCPT ); Fri, 3 Jul 2015 08:31:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38573 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753434AbbGCMba (ORCPT ); Fri, 3 Jul 2015 08:31:30 -0400 Subject: Re: [PATCH] sched,kvm: Fix KVM preempt_notifier usage To: Peter Zijlstra References: <558BED42.1030000@gmail.com> <20150625120949.GZ3644@twins.programming.kicks-ass.net> <558BF0E4.50602@gmail.com> <20150625125514.GA3644@twins.programming.kicks-ass.net> <55966E0B.7060100@redhat.com> <20150703121907.GH19282@twins.programming.kicks-ass.net> Cc: Pontus Fuchs , Linus Torvalds , mingo@redhat.com, "linux-kernel@vger.kernel.org" , gleb@kernel.org From: Paolo Bonzini X-Enigmail-Draft-Status: N1110 Message-ID: <5596809D.4000905@redhat.com> Date: Fri, 3 Jul 2015 14:31:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 In-Reply-To: <20150703121907.GH19282@twins.programming.kicks-ass.net> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1628 Lines: 50 On 03/07/2015 14:19, Peter Zijlstra wrote: > On Fri, Jul 03, 2015 at 01:12:11PM +0200, Paolo Bonzini wrote: >> In fact you shouldn't have just tested the patch on a case _without_ >> preemption notifiers, you should have also benchmarked the impact that >> static keys have _with_ preemption notifiers. In a >> not-really-artificial case (one single-processor guest running on the >> host), the static key patch adds a static_key_slow_inc on a relatively >> hot path for KVM, which is not acceptable. > > Spawning the first vcpu is a hot path? This is not *spawning* the first VCPU. Basically any critical section for vcpu->mutex includes a preempt_notifier_register/unregister pair: /* * Switches to specified vcpu, until a matching vcpu_put() */ int vcpu_load(struct kvm_vcpu *vcpu) { int cpu; if (mutex_lock_killable(&vcpu->mutex)) return -EINTR; cpu = get_cpu(); preempt_notifier_register(&vcpu->preempt_notifier); kvm_arch_vcpu_load(vcpu, cpu); put_cpu(); return 0; } void vcpu_put(struct kvm_vcpu *vcpu) { preempt_disable(); kvm_arch_vcpu_put(vcpu); preempt_notifier_unregister(&vcpu->preempt_notifier); preempt_enable(); mutex_unlock(&vcpu->mutex); } So basically you're adding at least one static_key_slow_inc/dec pair to every userspace exit. Paolo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/