dmonakhov / lmbench

LMBench micro benchmark site
GNU General Public License v2.0
36 stars 10 forks source link

wrong sched_pin() on 64bits linux platform when ncpus > 32 #1

Open zhouchengming1 opened 7 years ago

zhouchengming1 commented 7 years ago

Hi, we found a bug in sched_pin() on 64bits linux platform when ncpus > 32.

The code is like this: int word = i / (8 sizeof(unsigned long)); int bit = i % (8 sizeof(unsigned long)); mask[word] |= (1 << bit);

On 64bits platform, bit can be [0, 63], but (1 << bit) has only 32 bits. So if we want to bind this task to cpu33, (1 << 33) == (1 << 1), then this task will be bind to cpu1.

If I modify the code like this, I can get correct results. mask[word] |= ((unsigned long)1 << bit); Because ((unsigned long)1 << bit) has 64 bits.

Thanks.

mateoconlechuga commented 7 years ago

You should really be using the stdint.h definitions uint64_t as well.