Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4442730imm; Mon, 17 Sep 2018 14:06:47 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYsgTTHPY9Kb8sKBMHL0A78jbApx8Pj+53mCy4Ex0CC/STkslrPQGgsDwONgWIOAYMktFt7 X-Received: by 2002:a63:b258:: with SMTP id t24-v6mr25594061pgo.317.1537218407006; Mon, 17 Sep 2018 14:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537218406; cv=none; d=google.com; s=arc-20160816; b=PFqcoCArtf/Stdts54gwmQdsRIlOiz6bDVrmunKIxBIkmWuEl37ahe+c+FnWsvW7fh ItJTzaawEahFJFkfOgeWjHLV1aFmQWrpsb+9iegzleRTySmqcxbsD4g0XZh6AnPBNf0p x87HQQpxfGCswQbe4FcIkWMdkKXU/6aRkHR5tj8cZyUjHYwDSEq6NJXsF4YRiUDmF8yP cUWpIADFa+S6LjoJllhxAdiJE/G1OQ5XyOsX6N07zsry6Y449mfEKApy85qdJ4zkOxUc dhbevGgwVnKiOgLplrLo8z2u9OexuvUtM8pQqVeqxsWPVMbJGLwfo3xp5lxU8dSaJLF6 Wnfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=IWKHzgQHjytR3xTEyVS8uF3QhBxCmkQl9MzyPuQArg4=; b=TGXMN2NvSoJC8a/YywP1WOljPsDU07/NeqnyYvU4wu/e4Un+bjzAKtUNng69zdba/D DROWhjgQ/9QzqdXFSM65s0UL2CRRcP5FzoHubvL4pJ7ZvUXeXVmqFmG6JrN0pK3VzVMw HRHvata5rcE5ppl56um4AkCrQJu8iSxEXN25I2YU+TtT25PtySp8/PKuZu+IAT3YS7ec ykBY4zuEqwUmUJLX3kPG5aBk5yJMpBx+FUskEh8a3GjnacH/U2f0Oo2ENT0bnK5vZ6wv u5oc/DkohP27ECvB+Txjd4EY3dS2EswgvBQk8p3LSqaPe9ewLfsc5WpDYZbpdwM6kmXz 2kDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=xbpeTQBb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s2-v6si16172017plp.144.2018.09.17.14.06.29; Mon, 17 Sep 2018 14:06:46 -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=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=xbpeTQBb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728458AbeIRCfG (ORCPT + 99 others); Mon, 17 Sep 2018 22:35:06 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:43140 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728009AbeIRCfG (ORCPT ); Mon, 17 Sep 2018 22:35:06 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w8HL4J4k072181; Mon, 17 Sep 2018 21:05:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=IWKHzgQHjytR3xTEyVS8uF3QhBxCmkQl9MzyPuQArg4=; b=xbpeTQBbdMdrkyZCv3neQVTrcwvgKYhP3Mj7FBK3y4urd/vDbem7p3Qlm4cFIF2imhuL 7Mc+jrmLHxXeigEr1VXJGAcDZ2eW5WknM089hgcYTrPRRLpGc60yX35z8pIm/9ikC/bp XMb6AnfYaMZnAhX237Cu0ylD3IFrpI3/m4Xqq2wUyFkE+pj7uuCmdYKhCZAtqgivjKJe tAljefS8YzBtfwQuyOa2LDEi+5lfFPofNuzG07FEHkl6M3HGKZVIFHwm1EJ1bGXCgA3a HGz/Tvm4boxn0TBPfk9oV7xIpstcX41Vp+v90CBHnYVOkFQqVIWwqOBsLBdaofAdbh7Y Vg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2mgsgtgu6w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Sep 2018 21:05:43 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w8HL5aIa013013 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Sep 2018 21:05:37 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w8HL5aHM005158; Mon, 17 Sep 2018 21:05:36 GMT Received: from [10.132.91.175] (/10.132.91.175) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 17 Sep 2018 14:05:36 -0700 Subject: Re: [RFC PATCH 2/2] pipe: use pipe busy wait To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, dhaval.giani@oracle.com, steven.sistare@oracle.com References: <20180830202458.32579-1-subhra.mazumdar@oracle.com> <20180830202458.32579-3-subhra.mazumdar@oracle.com> <20180907122557.GY24106@hirez.programming.kicks-ass.net> From: Subhra Mazumdar Message-ID: <304ffc06-1ab9-19d5-d5ca-e63e2abe2900@oracle.com> Date: Mon, 17 Sep 2018 14:05:40 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180907122557.GY24106@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9019 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809170209 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/07/2018 05:25 AM, Peter Zijlstra wrote: > On Thu, Aug 30, 2018 at 01:24:58PM -0700, subhra mazumdar wrote: >> +void pipe_busy_wait(struct pipe_inode_info *pipe) >> +{ >> + unsigned long wait_flag = pipe->pipe_wait_flag; >> + unsigned long start_time = pipe_busy_loop_current_time(); >> + >> + pipe_unlock(pipe); >> + preempt_disable(); >> + for (;;) { >> + if (pipe->pipe_wait_flag > wait_flag) { >> + preempt_enable(); >> + pipe_lock(pipe); >> + return; >> + } >> + if (pipe_busy_loop_timeout(pipe, start_time)) >> + break; >> + cpu_relax(); >> + } >> + preempt_enable(); >> + pipe_lock(pipe); >> + if (pipe->pipe_wait_flag > wait_flag) >> + return; >> + pipe_wait(pipe); >> +} >> + >> +void wake_up_busy_poll(struct pipe_inode_info *pipe) >> +{ >> + pipe->pipe_wait_flag++; >> +} > Why not just busy wait on current->state ? A little something like: > > diff --git a/fs/pipe.c b/fs/pipe.c > index bdc5d3c0977d..8d9f1c95ff99 100644 > --- a/fs/pipe.c > +++ b/fs/pipe.c > @@ -106,6 +106,7 @@ void pipe_double_lock(struct pipe_inode_info *pipe1, > void pipe_wait(struct pipe_inode_info *pipe) > { > DEFINE_WAIT(wait); > + u64 start; > > /* > * Pipes are system-local resources, so sleeping on them > @@ -113,7 +114,15 @@ void pipe_wait(struct pipe_inode_info *pipe) > */ > prepare_to_wait(&pipe->wait, &wait, TASK_INTERRUPTIBLE); > pipe_unlock(pipe); > - schedule(); > + > + preempt_disable(); > + start = local_clock(); > + while (!need_resched() && current->state != TASK_RUNNING && > + (local_clock() - start) < pipe->poll_usec) > + cpu_relax(); > + schedule_preempt_disabled(); > + preempt_enable(); > + > finish_wait(&pipe->wait, &wait); > pipe_lock(pipe); > } This will make the current thread always spin and block as it itself does the state change to TASK_RUNNING in finish_wait.