Re: read-write spinlocks ??

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

 



K.R. Foley wrote:
Gaurav Dhiman wrote:

Thanks for your reply, it clears my doubt of keeping two locks, one
for read and one for write. As this info can be stored in one element
only, we dont need two.


You're right, but in fact, the implementation has been so that both information are encoded inside a single integer. You don't really need two counters, but :
- a counter of readers



why we need to keep a count of readers, does that matter ?


Because you can't get a write lock while there are any readers.

From this and the rest of your message, I am not sure you are getting how this works:

readers and writers are mutually exclusive. While there are readers you can't get the write lock. While there is a writer, there are no readers.



- a bit indicating whether a writer owns the lock or not



So, in fact, one bit of the integer is reserved to "mark" the rwlock as owned by a writer or not. Have a look at include/asm-i386/rwlock.h, and particularly the definition of RW_LOCK_BIAS.



Can you let me know whats the significance of this flag, is this flag used to mark the writer and other bits used for keeping a count of reades.


This is the value that is subtracted to get the write lock. It also happens to be the init/idle value of the lock. So, if subtracting RW_LOCK_BIAS from the lock value yields 0x00000000 then you have acquired the write lock.

Since we are on the subject, read locks are also gotten by subtracting from the value of the lock and are represented by any number less than 0x01000000.

Sorry. Short circuit. That should have read any number less than 0x01000000 but greater than zero.





Have a look at the implementation of __build_read_lock_const() and __build_write_lock_const() is the same file.



cud not understand this assembly code, where is the helper function defined, it is calling ?


helper is the name of the function (in this case the spin function) that is passed in like:

__build_write_lock(rw, "__write_lock_failed");

Which is in spinlock.h



Sincerly,

Thomas
--
Thomas Petazzoni
thomas.petazzoni@xxxxxxxx



--

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






--
   kr

--
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