From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755187AbdKJHNA (ORCPT ); Fri, 10 Nov 2017 02:13:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54694 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750800AbdKJHM7 (ORCPT ); Fri, 10 Nov 2017 02:12:59 -0500 Date: Fri, 10 Nov 2017 15:12:55 +0800 From: Peter Xu To: Paolo Bonzini Cc: kvm@vger.kernel.org, Radim =?utf-8?B?S3LEjW3DocWZ?= , Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] sched/swait: allow swake_up() to return Message-ID: <20171110071255.GI20627@xz-mi> References: <20171109091854.24367-1-peterx@redhat.com> <20171109091854.24367-2-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 10 Nov 2017 07:12:59 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 09, 2017 at 11:06:53AM +0100, Paolo Bonzini wrote: > On 09/11/2017 10:18, 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++; > > } > > > > 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. > > Better subject: > > sched/swait: make swake_up() return whether there were any waiters > > I like this patch. I'll see how PeterZ would like me to do next, or I can drop this patch and send another clean up which is part of patch 2. Thanks for the positive feedback and commenting. :-) -- Peter Xu