From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751963AbdCAFoR (ORCPT ); Wed, 1 Mar 2017 00:44:17 -0500 Received: from LGEAMRELO12.lge.com ([156.147.23.52]:54284 "EHLO lgeamrelo12.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751864AbdCAFoL (ORCPT ); Wed, 1 Mar 2017 00:44:11 -0500 X-Original-SENDERIP: 156.147.1.126 X-Original-MAILFROM: byungchul.park@lge.com X-Original-SENDERIP: 10.177.222.33 X-Original-MAILFROM: byungchul.park@lge.com Date: Wed, 1 Mar 2017 14:43:23 +0900 From: Byungchul Park To: Peter Zijlstra Cc: mingo@kernel.org, tglx@linutronix.de, walken@google.com, boqun.feng@gmail.com, kirill@shutemov.name, linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, npiggin@gmail.com, kernel-team@lge.com Subject: Re: [PATCH v5 06/13] lockdep: Implement crossrelease feature Message-ID: <20170301054323.GE11663@X58A-UD3R> References: <1484745459-2055-1-git-send-email-byungchul.park@lge.com> <1484745459-2055-7-git-send-email-byungchul.park@lge.com> <20170228134018.GK5680@worktop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170228134018.GK5680@worktop> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 28, 2017 at 02:40:18PM +0100, Peter Zijlstra wrote: > > +static int commit_xhlocks(struct cross_lock *xlock) > > +{ > > + struct task_struct *curr = current; > > + struct hist_lock *xhlock_c = xhlock_curr(curr); > > + struct hist_lock *xhlock = xhlock_c; > > + > > + do { > > + xhlock = xhlock_prev(curr, xhlock); > > + > > + if (!xhlock_used(xhlock)) > > + break; > > + > > + if (before(xhlock->hlock.gen_id, xlock->hlock.gen_id)) > > + break; > > + > > + if (same_context_xhlock(xhlock) && > > + before(xhlock->prev_gen_id, xlock->hlock.gen_id) && > > + !commit_xhlock(xlock, xhlock)) > > + return 0; > > + } while (xhlock_c != xhlock); > > + > > + return 1; > > +} > > So I'm still struggling with prev_gen_id; is it an optimization or is it > required for correctness? It's an optimization, but very essential and important optimization. in hlocks[] ------------ A gen_id (4) --+ | previous gen_id B gen_id (3) <-+ C gen_id (3) D gen_id (2) oldest -> E gen_id (1) in xhlocks[] ------------ ^ A gen_id (4) prev_gen_id (3: B's gen id) | B gen_id (3) prev_gen_id (3: C's gen id) | C gen_id (3) prev_gen_id (2: D's gen id) | D gen_id (2) prev_gen_id (1: E's gen id) | E gen_id (1) prev_gen_id (NA) Let's consider the case that the gen id of xlock to commit is 3. In this case, it's engough to generate 'the xlock -> C'. 'the xlock -> B' and 'the xlock -> A' are unnecessary since it's covered by 'C -> B' and 'B -> A' which are already generated by original lockdep. I use the prev_gen_id to avoid adding this kind of redundant dependencies. In other words, xhlock->prev_gen_id >= xlock->hlock.gen_id means that the previous lock in hlocks[] is able to handle the dependency on its commit stage.