On Monday 15 September 2008 17:13:08 luca ellero wrote: > Hi everybody, Hello > > I was reading this article: > http://www.cs.fsu.edu/~baker/devices/notes/spinlock.html > > and I noticed this excerpt: > > If you strip off the debugging extras, and get down to the raw > > spinlock object for the SMP case for the i386, it looks like this: > > > > typedef struct { > > unsigned int slock; > > } raw_spinlock_t; no it doesn't. If you stip away debugging extras, it looks like this: typedef struct { } raw_spinlock_t; > > > > Earlier versions of Linux had the raw lock value field slock > > declared as "volatile". Do you know what that means? Why is > > that not done in the 2.6.25 kernel? First off, the code lies in include/linux/spinlock_types_up.h, if anyone disagrees with me - are we looking at the same file? > But, sadly, the writer doesn't give the answer. I think he means the questions as a hint for self-study > So, obviously, my question is: > > Why slock is not declared as "volatile" in the 2.6.25 kernel? the section you refer to (volatile), was introduced in commit fb1c8f93d869b34cacb8b8932e2b83d96a19d720 in sep. 2005. volatile ensures that the variable stays in the memory, i.e. it is not stored in any register for optimization. >From the allmighty K&R [p211]: "The purpose of volatile is to force an implementation to suppress optimization that could otherwise occur. For example, for a machine with memory-mapped input/output, a pointer to a device register might be declared as a pointer to volatile, in order to prevent the compiler from removing apparently redundant references through the pointer" As this is an SMP spinlock, having it in a local register is a bad idea :-) as to why it's not used any more, I'm not too sure, as it is used (when you compile with the debug-spinlock on. Now, I'm not testing this against 2.6.25.3, but in the normal linux-tree, there hasn't been a change in spinlock_types_up.h since July 2007. -- Med vennlig hilsen - Yours Sincerely Henrik Austad -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ