Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1448959ybn; Wed, 25 Sep 2019 18:46:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOaY5EXqZIo6jHLxaCCtiHbjx3jvf1xSY2JimAxtlvT8OfCM/QOhrtnVGY4fnVmR0yGE8Z X-Received: by 2002:a17:906:5957:: with SMTP id g23mr1015562ejr.312.1569462367438; Wed, 25 Sep 2019 18:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569462367; cv=none; d=google.com; s=arc-20160816; b=z2iMeJ6oIdL4W0V5woEogkbTgz2HMhs3Gc8v8IJLpKqxZiYPJRQQ/lcPB1zcFShkEx QGFpIdFxQRsa79P879Wh85sqZKFFsuidqax4tsdz+pET5ujcCcrX/yMQeXd24Od0iARp cuINyYtBxpwqba+a1wpCmD//P/xSbLnTCKs33UadrIlJS+z3t5/m6Qbk5/Ak9TW9sa7B Q1BShXEH0Wiuqri4yW3WdVIluZL31q55Qi+JzkWNRnzdnYXtGzhJ/Oj2bJGg8g46j+4F 7aXGdIhr7UCouXlS4w/InyK9fHyQ0Q4NYAVn5Na1fK3NA+aDFDWnAAd2ShRiEjUyPfwU ssFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=/g8501+xXPx9KBW91ZExYmZcRElzY2bnL/DarT6l+8M=; b=W7OqGs8Scw7ktG7UDJ9rQ9gB38R2AcRx+4Q+GEPB8C6wiFPgNeZSUvKb6BZvbgvl9X Q20Y42uWTTvlepd0zrJstsONTKt7enjS3K3+04fm/nbkB/d4aR+2BYKdoJQfmIDRG7SA laveBv99s9FU1dJ2CfpD4dgSCikZMz39OqccaG8IMv3yeDmn6YfamB34kT22P/OFATtu 6JWxzk0fpkf/Yw4As/DrMD/8J3IYzgeouPde3iryaXuffOuuVuZa7XG4qqlifa0MifgB kwIraR7DR3vjTECwiE/DnfJwRR9BSoEFFr6pMlMi2CQkImwoR4w+BtkBgSj4WADpnpM0 RQPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=Bgwn3WTm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k7si286493ejk.266.2019.09.25.18.45.43; Wed, 25 Sep 2019 18:46:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=Bgwn3WTm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2504753AbfIXLnK (ORCPT + 99 others); Tue, 24 Sep 2019 07:43:10 -0400 Received: from merlin.infradead.org ([205.233.59.134]:48382 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbfIXLnJ (ORCPT ); Tue, 24 Sep 2019 07:43:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/g8501+xXPx9KBW91ZExYmZcRElzY2bnL/DarT6l+8M=; b=Bgwn3WTm0Lnrg1//d4BerjSWo pVdHxf41TMDMWPLe0SRTGe45Qh+3KOt+d/rjiQ68qbhxGc+V0OinUYo9Ftq8x9LM1mcezWmyDWCdT 0YlyN89b6LqQs/uTUzoAhrkDekSAfbOG+y9lUuwHkKJOTyUFgXD3xoyQYPcO3Jj3QjwaItur8s8RC tr2Dn/XVev/7ANYQoVCUVpwrM3+fE0O+xKUSGnC9yJWKxhg+tB9NRfFFBl8jDg8hfVavSrCIcDCwe Px4xdxsdBRC8OUaYdTOUv8kmfcjeFhoA03EyvdBgE1v1wbkg/NUzTTQJ30P5YgKpRUnsNGEqbxEEO g5ubY8j8w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.2 #3 (Red Hat Linux)) id 1iCjDh-00086A-Kl; Tue, 24 Sep 2019 11:43:01 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id CD830305E42; Tue, 24 Sep 2019 13:42:14 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 648D829E510E7; Tue, 24 Sep 2019 13:43:00 +0200 (CEST) Date: Tue, 24 Sep 2019 13:43:00 +0200 From: Peter Zijlstra To: Pavel Begunkov Cc: Jens Axboe , Ingo Molnar , Ingo Molnar , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 0/2] Optimise io_uring completion waiting Message-ID: <20190924114300.GM2332@hirez.programming.kicks-ass.net> References: <731b2087-7786-5374-68ff-8cba42f0cd68@kernel.dk> <759b9b48-1de3-1d43-3e39-9c530bfffaa0@kernel.dk> <43244626-9cfd-0c0b-e7a1-878363712ef3@gmail.com> <20190924094942.GN2349@hirez.programming.kicks-ass.net> <6f935fb9-6ebd-1df1-0cd0-69e34a16fa7e@kernel.dk> <29e6e06e-351f-c19d-ed7c-51f30c9ca887@kernel.dk> <08193e07-6f05-a496-492d-06ed8ce3aea1@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <08193e07-6f05-a496-492d-06ed8ce3aea1@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 24, 2019 at 02:11:29PM +0300, Pavel Begunkov wrote: > @@ -2717,15 +2757,18 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, > return ret; > } > > + iowq.nr_timeouts = atomic_read(&ctx->cq_timeouts); > + prepare_to_wait_exclusive(&ctx->wait, &iowq.wq, TASK_INTERRUPTIBLE); > + do { > + if (io_should_wake(&iowq)) > + break; > + schedule(); > + if (signal_pending(current)) > + break; > + set_current_state(TASK_INTERRUPTIBLE); > + } while (1); > + finish_wait(&ctx->wait, &iowq.wq); It it likely OK, but for paranoia, I'd prefer this form: for (;;) { prepare_to_wait_exclusive(&ctx->wait, &iowq.wq, TASK_INTERRUPTIBLE); if (io_should_wake(&iowq)) break; schedule(); if (signal_pending(current)) break; } finish_wait(&ctx->wait, &iowq.wq); The thing is, if we ever succeed with io_wake_function() (that CPU observes io_should_wake()), but when waking here, we do not observe is_wake_function() and go sleep again, we might never wake up if we don't put ourselves back on the wait-list again.