From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946179AbcBRSEs (ORCPT ); Thu, 18 Feb 2016 13:04:48 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33095 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423449AbcBRSEq (ORCPT ); Thu, 18 Feb 2016 13:04:46 -0500 Subject: Re: [PATCH v2 02/14] KVM: x86: simplify atomics in kvm_pit_ack_irq To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , linux-kernel@vger.kernel.org References: <1455736496-374-1-git-send-email-rkrcmar@redhat.com> <1455736496-374-3-git-send-email-rkrcmar@redhat.com> Cc: kvm@vger.kernel.org, Yuki Shibuya From: Paolo Bonzini X-Enigmail-Draft-Status: N1110 Message-ID: <56C607BB.3000103@redhat.com> Date: Thu, 18 Feb 2016 19:04:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <1455736496-374-3-git-send-email-rkrcmar@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/02/2016 20:14, Radim Krčmář wrote: > - value = atomic_dec_return(&ps->pending); > - if (value < 0) > - /* spurious acks can be generated if, for example, the > - * PIC is being reset. Handle it gracefully here > - */ > - atomic_inc(&ps->pending); > - else if (value > 0 && ps->reinject) > - /* in this case, we had multiple outstanding pit interrupts > - * that we needed to inject. Reinject > - */ > + if (atomic_dec_if_positive(&ps->pending) > 0 && ps->reinject) > queue_kthread_work(&ps->pit->worker, &ps->pit->expired); Here it would have made sense to do already if (!ps->reinject) { WARN_ON_ONCE(ps->pending || !ps->irq_ack); return; } spin_lock(...) if (atomic_dec_if_positive(&ps->pending) > 0) queue_kthread_work(...); ps->irq_ack = 1; spin_unlock(...) because ps->pending is only ever nonzero, and irq_ack is only ever zero, if ps->reinject. Not a big deal since the ack notifier is going to disappear altogether for the discard policy, but the nice thing is that it lets you remove the ack notifier earlier and disentangle a bit more discard mode. So if you want for v3 you can reorder the patches like this: - patch 1, same - patch 2, what is outlined above - patch 3, remove ack notifier for discard - patch 4..14 the rest Paolo