docs/atomics: update atomic_read/set comparison with Linux
Recently Linux did a mass conversion of its atomic_read/set calls
so that they at least are READ/WRITE_ONCE. See Linux's commit
62e8a325 ("atomic, arch: Audit atomic_{read,set}()"). It seems though
that their documentation hasn't been updated to reflect this.
The appended updates our documentation to reflect the change, which
means there is effectively no difference between our atomic_read/set
and the current Linux implementation.
While at it, fix the statement that a barrier is implied by
atomic_read/set, which is incorrect. Volatile/atomic semantics prevent
transformations pertaining the variable they apply to; this, however,
has no effect on surrounding statements like barriers do. For more
details on this, see:
  https://gcc.gnu.org/onlinedocs/gcc/Volatiles.html
Signed-off-by: Emilio G. Cota <cota@braap.org>
Message-Id: <1464120374-8950-2-git-send-email-cota@braap.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
			
			
This commit is contained in:
		
							parent
							
								
									141af038dd
								
							
						
					
					
						commit
						56ebe02203
					
				@ -326,9 +326,19 @@ and memory barriers, and the equivalents in QEMU:
 | 
				
			|||||||
  use a boxed atomic_t type; atomic operations in QEMU are polymorphic
 | 
					  use a boxed atomic_t type; atomic operations in QEMU are polymorphic
 | 
				
			||||||
  and use normal C types.
 | 
					  and use normal C types.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- atomic_read and atomic_set in Linux give no guarantee at all;
 | 
					- Originally, atomic_read and atomic_set in Linux gave no guarantee
 | 
				
			||||||
  atomic_read and atomic_set in QEMU include a compiler barrier
 | 
					  at all. Linux 4.1 updated them to implement volatile
 | 
				
			||||||
  (similar to the READ_ONCE/WRITE_ONCE macros in Linux).
 | 
					  semantics via ACCESS_ONCE (or the more recent READ/WRITE_ONCE).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  QEMU's atomic_read/set implement, if the compiler supports it, C11
 | 
				
			||||||
 | 
					  atomic relaxed semantics, and volatile semantics otherwise.
 | 
				
			||||||
 | 
					  Both semantics prevent the compiler from doing certain transformations;
 | 
				
			||||||
 | 
					  the difference is that atomic accesses are guaranteed to be atomic,
 | 
				
			||||||
 | 
					  while volatile accesses aren't. Thus, in the volatile case we just cross
 | 
				
			||||||
 | 
					  our fingers hoping that the compiler will generate atomic accesses,
 | 
				
			||||||
 | 
					  since we assume the variables passed are machine-word sized and
 | 
				
			||||||
 | 
					  properly aligned.
 | 
				
			||||||
 | 
					  No barriers are implied by atomic_read/set in either Linux or QEMU.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- most atomic read-modify-write operations in Linux return void;
 | 
					- most atomic read-modify-write operations in Linux return void;
 | 
				
			||||||
  in QEMU, all of them return the old value of the variable.
 | 
					  in QEMU, all of them return the old value of the variable.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user