From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754145AbdKIKXL (ORCPT ); Thu, 9 Nov 2017 05:23:11 -0500 Received: from merlin.infradead.org ([205.233.59.134]:33778 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750945AbdKIKXH (ORCPT ); Thu, 9 Nov 2017 05:23:07 -0500 Date: Thu, 9 Nov 2017 11:23:03 +0100 From: Peter Zijlstra To: Peter Xu Cc: kvm@vger.kernel.org, Paolo Bonzini , Radim Kr??m???? , Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] sched/swait: allow swake_up() to return Message-ID: <20171109102303.vsetymxc6rllomhh@hirez.programming.kicks-ass.net> References: <20171109091854.24367-1-peterx@redhat.com> <20171109091854.24367-2-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171109091854.24367-2-peterx@redhat.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 09, 2017 at 05:18:53PM +0800, Peter Xu wrote: > Let swake_up() to return whether any of the waiters is waked up. One use > case of it would be: > > if (swait_active(wq)) { > swake_up(wq); > // do something when waiter is waked up > waked_up++; > } The word is 'woken', and no that doesn't work. All it says is that there was a waiter, not that you were to one to wake it. Another concurrent wakeup might have done so. > > Logically it's possible that when reaching swake_up() the wait queue is > not active any more, and here doing something like waked_up++ would be > inaccurate. To correct it, we need an atomic version of it. > > With this patch, we can simply re-write it into: > > if (swake_up(wq)) { > // do something when waiter is waked up > waked_up++; > } > > After all we are checking swait_active() inside swake_up() too. We're not in fact; you've been staring at old code; see commit: 35a2897c2a30 ("sched/wait: Remove the lockless swait_active() check in swake_up*()") Also, you're changing the interface relative to the regular wait interface. The two should be similar wherever possible.