From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754662AbcAEVSq (ORCPT ); Tue, 5 Jan 2016 16:18:46 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:47038 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751970AbcAEVSm (ORCPT ); Tue, 5 Jan 2016 16:18:42 -0500 Date: Tue, 5 Jan 2016 22:18:34 +0100 From: Peter Zijlstra To: ling.ma.program@gmail.com Cc: waiman.long@hpe.com, mingo@redhat.com, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, ling.ml@alibaba-inc.com Subject: Re: [RFC PATCH] alispinlock: acceleration from lock integration on multi-core platform Message-ID: <20160105211834.GR6344@twins.programming.kicks-ass.net> References: <1451549374-30875-1-git-send-email-ling.ma.program@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1451549374-30875-1-git-send-email-ling.ma.program@gmail.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 31, 2015 at 04:09:34PM +0800, ling.ma.program@gmail.com wrote: > +void alispinlock(struct ali_spinlock *lock, struct ali_spinlock_info *ali) > +{ > + struct ali_spinlock_info *next, *old; > + > + ali->next = NULL; > + ali->locked = 1; > + old = xchg(&lock->lock_p, ali); > + > + /* If NULL we are the first one */ > + if (old) { > + WRITE_ONCE(old->next, ali); > + if(ali->flags & ALI_LOCK_FREE) > + return; > + while((READ_ONCE(ali->locked))) > + cpu_relax_lowlatency(); > + return; > + } > + old = READ_ONCE(lock->lock_p); > + > + /* Handle all pending works */ > +repeat: > + if(old == ali) > + goto end; > + > + while (!(next = READ_ONCE(ali->next))) > + cpu_relax(); > + > + ali->fn(ali->para); > + ali->locked = 0; > + > + if(old != next) { > + while (!(ali = READ_ONCE(next->next))) > + cpu_relax(); > + next->fn(next->para); > + next->locked = 0; > + goto repeat; > + > + } else > + ali = next; So I have a whole bunch of problems with this thing.. For one I object to this being called a lock. Its much more like an async work queue like thing. It suffers the typical problems all those constructs do; namely it wrecks accountability. But here that is compounded by the fact that you inject other people's work into 'your' lock region, thereby bloating lock hold times. Worse, afaict (from a quick reading) there really isn't a bound on the amount of work you inject. This will completely wreck scheduling latency. At the very least the callback loop should have a need_resched() test on, but even that will not work if this has IRQs disabled. And while its a cute collapse of an MCS lock and lockless list style work queue (MCS after all is a lockless list), saving a few cycles from the naive spinlock+llist implementation of the same thing, I really do not see enough justification for any of this.