Re: set_bit and clear_bit from asm386/bitops.h

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

 




Do you mean to say that when i want to use set_bit() for locking purpose, i have to do it in the following way?

smp_mb__before_set_bit()
set_bit()
smp_mb__after_set_bit()

Thank you
-nsmurthy

At 12:56 PM 7/20/2005, Erik Mouw wrote:
On Wed, Jul 20, 2005 at 10:12:33AM +0530, ns srinivasa murthy wrote:
> I could not find any difference between the functions set_bit and clear_bit.

There is: set_bit() sets a bit, while clear_bit() clears a bit.

> But it is mentioned in bitops.h file that  smp_mb__before_clear_bit()
> and/or smp_mb__after_clear_bit() shall be called in order to ensure changes
> are visible on other processors.This is mentioned for bit_clear() function
> only.

clear_bit() uses a LOCK prefix, so the result will be atomic and
visible to the other processors. However, the compiler can reorder the
instruction of the function (it's an inline function), and that could
lead to unwanted results if you use it to create locks. In order to
force the compiler to issue the instruction on the place you want, you
need to put a memory barrier before or after clear_bit().

> My doubt:
> Is it not required to call smp_mb__before_set_bit() and
> smp_mb__after_set_bit() in case of set_bit() function.
> If not why is it not required?

It is only required when you need set/clear_bit() for locking purposes,
not when you just want to set or clear a bit.

(don't see this as an invitation to invent your own locking primitives,
use what the kernel already has available).


Erik

--
Erik Mouw
J.A.K.Mouw@xxxxxxxxxxxxxx  mouw@xxxxxxxxxxxx



[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