lkml.org 
[lkml]   [2015]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] x86/spinlocks: Fix regression in spinlock contention detection
From
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 <stdio.h>

#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 <peterz@infradead.org> wrote:
> On Tue, May 05, 2015 at 04:08:22PM +0530, Raghavendra K T wrote:
>> ================
>> #include <stdio.h>
>>
>> #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)
>
>


\
 
 \ /
  Last update: 2015-05-05 16:41    [W:0.093 / U:0.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site