Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1856329imm; Fri, 7 Sep 2018 07:13:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY1O4uLtGVkuMKbsifTE12cE4niITxpf7vdNHRBRGEDRGuhIsjdSaCAGMs3rwulzRFEGTKP X-Received: by 2002:a62:e218:: with SMTP id a24-v6mr8544490pfi.75.1536329626212; Fri, 07 Sep 2018 07:13:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536329626; cv=none; d=google.com; s=arc-20160816; b=Xk/WPXDgJ9SDyCH/MKvuL705V3c1aSX2XX/IW5Sih7Mo4txffRT5jjdYt5OLh0H5hG E7dCCX2BJe8abJ3LaP45OZPGvpYc0hFIICKvF1IRM+w9NEfKQRCsfiJeNKG4y+Hqx1w7 9vsejULxJVMLaomrFwbKLt2iHpobajaT3RLvO8D3sVpMqsVER5ZcrkoP5TyQubUY7VLA 7AIeDTdYgDBBh24RJ5h+ES2YaTYzSOazB6TcNsncDg5R0LIhMwsIfBDNumJ/1iBZZfVc td5juy5mb8+sBdND7aIjw0FLnte3w0Z5pMqZysOi+bdBuEnOMNjAuDD/1y3+XRdjkGBn M/0A== 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=3pmzCNIJYHlas3PvLTKDHQ/B7mXZHynNkyFh50XKbKQ=; b=vt6B1BSx3D2GghQlUqXJC0i1krihOBzHdqF9HZQXgF4/nKXbzBlJLaLFQ2lKxz2Yp0 JfgqpXJDCI51TSUPNg4ezkPWrYyDI2qMeI8nR1976bw5kXbje8e6AEQyH2OCFfw8p7l1 qd7hHtJHrJCFiueaJpcaccnMWleFC91jPwF9T51Hxh15NnkAqjSgh0lLeCzJc4lcPhC4 WwVM2KeilKoJpA2e22+/bBe06jgwv21DBFSVoGgrPqI/YPIT2nLfn9MIylRMvCGIPvc1 Z3ImInRdoFO6od2eaYY+zeVo3hTHemdLSYKZj1Gxmnk1W3/GrUG4C4mYOuejye308AEG wOBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=WHl4gD55; 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 t31-v6si8637216pga.167.2018.09.07.07.13.30; Fri, 07 Sep 2018 07:13: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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=WHl4gD55; 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 S1729114AbeIGRGp (ORCPT + 99 others); Fri, 7 Sep 2018 13:06:45 -0400 Received: from merlin.infradead.org ([205.233.59.134]:55692 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727568AbeIGRGp (ORCPT ); Fri, 7 Sep 2018 13:06:45 -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=3pmzCNIJYHlas3PvLTKDHQ/B7mXZHynNkyFh50XKbKQ=; b=WHl4gD55xzcf6nsbA24/6AkS2 GNR1Udfp2NrtoO4ww2+xLKprPheQBjH11M4FKcmy/ws5Bjk0nFppSrY7tmP3Gtm/mnK3bwc16nNgc SzP2SUbceumTD3yjfUffCY60AX55gplqSs1eZj/lf8+NQC3ZmxqrUNgq5vg4jmtHaz/yE1Q2RUcaq GN4H/kqWnfwEBaiPboryX7utLxDgs5q2uGxybqehgvaFqvUSnZnuP9bZgS7/Tjh67zvYQUVVzJsIA rgfMhTLnZ4YL5SK6zj/w2+NaKrWfDbhIzMpAFYaYdlYwoY6r+QUu0AaGTOs05U7wAJxIrTx7IlnpW JBpFTxK0A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyFpo-0001my-Bx; Fri, 07 Sep 2018 12:26:00 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A649E20210312; Fri, 7 Sep 2018 14:25:57 +0200 (CEST) Date: Fri, 7 Sep 2018 14:25:57 +0200 From: Peter Zijlstra To: subhra mazumdar Cc: linux-kernel@vger.kernel.org, dhaval.giani@oracle.com, steven.sistare@oracle.com Subject: Re: [RFC PATCH 2/2] pipe: use pipe busy wait Message-ID: <20180907122557.GY24106@hirez.programming.kicks-ass.net> References: <20180830202458.32579-1-subhra.mazumdar@oracle.com> <20180830202458.32579-3-subhra.mazumdar@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180830202458.32579-3-subhra.mazumdar@oracle.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); }