Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936428AbcLVInz (ORCPT ); Thu, 22 Dec 2016 03:43:55 -0500 Received: from mail-wj0-f195.google.com ([209.85.210.195]:35132 "EHLO mail-wj0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750748AbcLVIny (ORCPT ); Thu, 22 Dec 2016 03:43:54 -0500 Subject: Re: [PATCH v3 03/12] locking/ww_mutex: Extract stamp comparison to __ww_mutex_stamp_after To: zhoucm1 , linux-kernel@vger.kernel.org References: <1482346000-9927-1-git-send-email-nhaehnle@gmail.com> <1482346000-9927-4-git-send-email-nhaehnle@gmail.com> <585B3346.2020001@amd.com> Cc: Maarten Lankhorst , =?UTF-8?Q?Nicolai_H=c3=a4hnle?= , Peter Zijlstra , dri-devel@lists.freedesktop.org, Ingo Molnar From: =?UTF-8?Q?Nicolai_H=c3=a4hnle?= Message-ID: Date: Thu, 22 Dec 2016 09:43:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <585B3346.2020001@amd.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 899 Lines: 19 On 22.12.2016 02:58, zhoucm1 wrote: > On 2016年12月22日 02:46, Nicolai Hähnle wrote: >> +static inline bool __sched >> +__ww_ctx_stamp_after(struct ww_acquire_ctx *a, struct ww_acquire_ctx *b) >> +{ >> + return a->stamp - b->stamp <= LONG_MAX && >> + (a->stamp != b->stamp || a > b); > I want to ask a stupid question, why a can compare with b? They are > pointers of structure. Isn't stamp enough for compare? As far as I understand, the idea is to provide a tie-breaker to ensure that there is a strict order between contexts even if the stamp happens to be equal. Since we get stamps from atomic increments, this really only matters if (a) someone makes a mistake and confuses ww_classes (which CONFIG_DEBUG_MUTEXES would flag) or (b) the ww_class stamp counter wraps around fully during the lifetime of the acquire context. This is extremely unlikely of course. Nicolai