From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751317AbdFSRxa (ORCPT ); Mon, 19 Jun 2017 13:53:30 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33426 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750780AbdFSRx3 (ORCPT ); Mon, 19 Jun 2017 13:53:29 -0400 Date: Mon, 19 Jun 2017 10:53:26 -0700 From: "Paul E. McKenney" To: "Eric W. Biederman" Cc: "Luis R. Rodriguez" , peterz@infradead.org, oleg@redhat.com, josh@joshtriplett.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, paul.gortmaker@windriver.com, dmitry.torokhov@gmail.com, linux-kernel@vger.kernel.org Subject: Re: [RFC v2 1/2] swait: add idle variants which don't contribute to load average Reply-To: paulmck@linux.vnet.ibm.com References: <87zid92ns2.fsf@xmission.com> <20170615184820.22994-1-mcgrof@kernel.org> <20170615184820.22994-2-mcgrof@kernel.org> <87k24bsmh4.fsf@xmission.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87k24bsmh4.fsf@xmission.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 17061917-0056-0000-0000-0000038DC19A X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007256; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00877074; UDB=6.00436879; IPR=6.00657216; BA=6.00005431; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015888; XFM=3.00000015; UTC=2017-06-19 17:53:27 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17061917-0057-0000-0000-000007C3D714 Message-Id: <20170619175326.GV3721@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-06-19_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706190294 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 16, 2017 at 03:31:51PM -0500, Eric W. Biederman wrote: > "Luis R. Rodriguez" writes: > > > There are cases where folks are using an interruptible swait when > > using kthreads. This is rather confusing given you'd expect > > interruptible waits to be -- interruptible, but kthreads are not > > interruptible ! The reason for such practice though is to avoid > > having these kthreads contribute to the system load average. > > > > When systems are idle some kthreads may spend a lot of time blocking if > > using swait_event_timeout(). This would contribute to the system load > > average. On systems without preemption this would mean the load average > > of an idle system is bumped to 2 instead of 0. On systems with PREEMPT=y > > this would mean the load average of an idle system is bumped to 3 > > instead of 0. > > > > This adds proper API using TASK_IDLE to make such goals explicit and > > avoid confusion. > > > > Suggested-by: "Eric W. Biederman" > > Signed-off-by: Luis R. Rodriguez > > --- > > include/linux/swait.h | 25 +++++++++++++++++++++++++ > > 1 file changed, 25 insertions(+) > > > > diff --git a/include/linux/swait.h b/include/linux/swait.h > > index 2c700694d50a..105c70e23286 100644 > > --- a/include/linux/swait.h > > +++ b/include/linux/swait.h > > @@ -194,4 +194,29 @@ do { \ > > __ret; \ > > }) > > > > +#define __swait_event_idle(wq, condition) \ > > + ___swait_event(wq, condition, TASK_IDLE, 0, schedule()) > > + > > +#define swait_event_idle(wq, condition) \ > > +({ \ > > + int __ret = 0; \ > > + if (!(condition)) \ > > + __ret = __swait_event_idle(wq, condition); \ > > + __ret; \ > > +}) > > The wait isn't interruptible so a return code doesn't make sense here. How about as shown below? Thanx, Paul ------------------------------------------------------------------------ commit 48a96574e9c62ca5e13744e86e2219eb38f080b4 Author: Luis R. Rodriguez Date: Thu Jun 15 11:48:19 2017 -0700 swait: add idle variants which don't contribute to load average There are cases where folks are using an interruptible swait when using kthreads. This is rather confusing given you'd expect interruptible waits to be -- interruptible, but kthreads are not interruptible ! The reason for such practice though is to avoid having these kthreads contribute to the system load average. When systems are idle some kthreads may spend a lot of time blocking if using swait_event_timeout(). This would contribute to the system load average. On systems without preemption this would mean the load average of an idle system is bumped to 2 instead of 0. On systems with PREEMPT=y this would mean the load average of an idle system is bumped to 3 instead of 0. This adds proper API using TASK_IDLE to make such goals explicit and avoid confusion. Suggested-by: "Eric W. Biederman" Signed-off-by: Luis R. Rodriguez [ paulmck: No return value from swait_event_idle per Eric's feedback. ] Signed-off-by: Paul E. McKenney Acked-by: "Eric W. Biederman" diff --git a/include/linux/swait.h b/include/linux/swait.h index c1f9c62a8a50..80d8aee5e7e1 100644 --- a/include/linux/swait.h +++ b/include/linux/swait.h @@ -169,4 +169,27 @@ do { \ __ret; \ }) +#define __swait_event_idle(wq, condition) \ + ___swait_event(wq, condition, TASK_IDLE, 0, schedule()) + +#define swait_event_idle(wq, condition) \ +do { \ + if (!(condition)) \ + __swait_event_idle(wq, condition); \ +} while (0) + +#define __swait_event_idle_timeout(wq, condition, timeout) \ + ___swait_event(wq, ___wait_cond_timeout(condition), \ + TASK_IDLE, timeout, \ + __ret = schedule_timeout(__ret)) + +#define swait_event_idle_timeout(wq, condition, timeout) \ +({ \ + long __ret = timeout; \ + if (!___wait_cond_timeout(condition)) \ + __ret = __swait_event_idle_timeout(wq, \ + condition, timeout); \ + __ret; \ +}) + #endif /* _LINUX_SWAIT_H */