From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755100AbbKCRDr (ORCPT ); Tue, 3 Nov 2015 12:03:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43830 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751285AbbKCRDp (ORCPT ); Tue, 3 Nov 2015 12:03:45 -0500 Date: Tue, 3 Nov 2015 18:59:58 +0100 From: Oleg Nesterov To: Peter Zijlstra Cc: mingo@kernel.org, linux-kernel@vger.kernel.org, paulmck@linux.vnet.ibm.com, boqun.feng@gmail.com, corbet@lwn.net, mhocko@kernel.org, dhowells@redhat.com, torvalds@linux-foundation.org, will.deacon@arm.com Subject: Re: [PATCH 4/4] locking: Introduce smp_cond_acquire() Message-ID: <20151103175958.GA4800@redhat.com> References: <20151102132901.157178466@infradead.org> <20151102134941.005198372@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151102134941.005198372@infradead.org> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/02, Peter Zijlstra wrote: > > +#define smp_cond_acquire(cond) do { \ > + while (!(cond)) \ > + cpu_relax(); \ > + smp_read_barrier_depends(); /* ctrl */ \ > + smp_rmb(); /* ctrl + rmb := acquire */ \ > +} while (0) ... > --- a/kernel/task_work.c > +++ b/kernel/task_work.c > @@ -102,13 +102,13 @@ void task_work_run(void) > > if (!work) > break; > + > /* > * Synchronize with task_work_cancel(). It can't remove > * the first entry == work, cmpxchg(task_works) should > * fail, but it can play with *work and other entries. > */ > - raw_spin_unlock_wait(&task->pi_lock); > - smp_mb(); > + smp_cond_acquire(!raw_spin_is_locked(&task->pi_lock)); Unfortunately this doesn't look exactly right... spin_unlock_wait() is not equal to "while (locked) relax", the latter is live-lockable or at least sub-optimal: we do not really need to spin until we observe !spin_is_locked(), we only need to synchronize with the current owner of this lock. Once it drops the lock we can proceed, we do not care if another thread takes the same lock right after that. Oleg.