From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1170270AbdDXMwP (ORCPT ); Mon, 24 Apr 2017 08:52:15 -0400 Received: from merlin.infradead.org ([205.233.59.134]:52204 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933029AbdDXMwJ (ORCPT ); Mon, 24 Apr 2017 08:52:09 -0400 Date: Mon, 24 Apr 2017 14:52:00 +0200 From: Peter Zijlstra To: Steven Rostedt Cc: LKML , Thomas Gleixner , Ingo Molnar , Clark Williams , Daniel Bristot de Oliveira , John Kacur Subject: Re: [RFC][PATCH tip/sched/core] sched/rt: Simplify the IPI rt balancing logic Message-ID: <20170424125200.vxfmehm4tpdpeisc@hirez.programming.kicks-ass.net> References: <20170421224929.1a4bbeec@gandalf.local.home> <20170424085154.d6ny6vmbmuaoxiln@hirez.programming.kicks-ass.net> <20170424084318.2d03700f@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170424084318.2d03700f@gandalf.local.home> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 24, 2017 at 08:43:18AM -0400, Steven Rostedt wrote: > On Mon, 24 Apr 2017 10:51:54 +0200 > Peter Zijlstra wrote: > > > On Fri, Apr 21, 2017 at 10:49:29PM -0400, Steven Rostedt wrote: > > > When a CPU schedules in a lower priority task and wants to make sure > > > overloaded CPUs know about it. It increments the rto_loop_next. Then it does > > > an atomic_inc_return() on rto_loop_start. If the returned value is not "1", > > > then it does atomic_dec() on rt_loop_start and returns. If the value is "1", > > > then it will take the rto_lock to synchronize with a possible IPI being sent > > > around to the overloaded CPUs. > > > > > + start = atomic_inc_return(&rq->rd->rto_loop_start); > > > + if (start != 1) > > > + goto out; > > > > > +out: > > > + atomic_dec(&rq->rd->rto_loop_start); > > > > > > Did you just write a very expensive test-and-set trylock? > > Probably. I didn't know we had a generic one. Where is it? > There isn't. What I was getting at though is that something like: static inline bool rto_start_trylock(atomic_t *v) { int zero = 0; return atomic_try_cmpxchg(v, &zero, 1); } static void rto_start_unlock(atomic_t *v) { atomic_set_release(v, 0); } Is more: clearer, faster and correct. Clearer as that it better describes what it does, faster as that you only have a single atomic, and more correct because it does a RELEASE in the case we care about.