Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2993096AbbEEOLJ (ORCPT ); Tue, 5 May 2015 10:11:09 -0400 Received: from mail-ie0-f171.google.com ([209.85.223.171]:35369 "EHLO mail-ie0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2993076AbbEEOKU (ORCPT ); Tue, 5 May 2015 10:10:20 -0400 MIME-Version: 1.0 In-Reply-To: <20150505105812.GK21418@twins.programming.kicks-ass.net> References: <1430799331-20445-1-git-send-email-tahsin@google.com> <20150505091714.GF21418@twins.programming.kicks-ass.net> <55489D9E.4010003@linux.vnet.ibm.com> <20150505105812.GK21418@twins.programming.kicks-ass.net> Date: Tue, 5 May 2015 07:10:19 -0700 Message-ID: Subject: Re: [PATCH] x86/spinlocks: Fix regression in spinlock contention detection From: Tahsin Erdogan To: Peter Zijlstra Cc: Raghavendra K T , tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, Waiman.Long@hp.com, borntraeger@de.ibm.com, oleg@redhat.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1360 Lines: 57 The conversion to signed happens with types shorter than int (__ticket_t is either u8 or u16). By changing Raghavendra's program to use unsigned short int, you can see the problem: ================ #include #define LOCK_INC 2 int main() { unsigned short int head = 32700, tail=2; if ((tail - head) > LOCK_INC) printf(" tail - head > LOCK_INC \n"); else printf(" tail - head < LOCK_INC \n"); return 0; } ================ gcc -g -o t main.c ./t tail - head < LOCK_INC However, having just unsigned int returns the opposite result (unsigned int head = 32700, tail=2;) gcc -g -o t main.c ./t tail - head > LOCK_INC On Tue, May 5, 2015 at 3:58 AM, Peter Zijlstra wrote: > On Tue, May 05, 2015 at 04:08:22PM +0530, Raghavendra K T wrote: >> ================ >> #include >> >> #define LOCK_INC 2 > > Note that to be completely identical to the kernel code you should've > written: > > #define LOCK_INC ((unsigned int)2) > > as per: > > #define TICKET_LOCK_INC ((__ticket_t)__TICKET_LOCK_INC) > > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/