Re: use bit field or kernel *_bit()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2006-03-01 at 08:55 +0100, Arjan van de Ven wrote:
> > then the question is when we should use which way? thanks!
> 
> 
> set_bit() and friends are "smp safe", that is, if multiple cpus access
> the same memory location (doesn't ahve to be the same bit) at the same
> time, it's safe.
> 
> bitfields do not provide that safety, if cpu 0 is writing bit 0, and cpu
> 1 is writing bit 4 of a memory location, a really big mess will happen.
> 
> 
> The flipside of that is that the "smp safe" comes with a price; it needs
> atomic operations on the cpu level, and those are really expensive. 
> 
> So maybe a rule of thumb:
> If you can guarantee that there will be no parallel accesses (due to
> spinlocks or due to how your code works), use bitfields. If you need
> your code to be SMP safe on itself, use set_bit() and co. If you fall in
> either, think again, because you do you just don't know it yet ;)

thanks! i like this rule.

one more question, for bit field, if we use long xyz:n, will that be an
issue in 32/64bit arch? i feel no, just to make sure.

ming





--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux