All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [patch] spinlocks: remove 'volatile'
@ 2006-07-08  3:54 Albert Cahalan
  2006-07-08  5:25 ` Linus Torvalds
                   ` (2 more replies)
  0 siblings, 3 replies; 119+ messages in thread
From: Albert Cahalan @ 2006-07-08  3:54 UTC (permalink / raw)
  To: linux-kernel, Linus Torvalds, linux-os, khc, mingo, akpm, arjan

Linus Torvalds writes:

> AND I POINTED OUT THAT EVEN IN YOUR TRIVIAL EXAMPLE, VOLATILE WAS
> ACTUALLY THE WRONG THING TO DO.
>
> And that's _exactly_ because the language environment (in this case
> the CPU itself) has evolved past the point it was 30 years ago.

Key thing being "language environment", meaning gcc.

By the language spec, volatile is a low-performance way to
get the job done. Following the language spec is damn hard
these days, considering some of the evil things PCI does in
the name of performance. The compiler probably should offer
an option to call a function for read/write to volatile mem.
Such a function could take a lock, determine if a PCI read
is required to enforce ordering, perform the operation, and
then release the lock.

That's all theoretical though. Today, gcc's volatile does
not follow the C standard on modern hardware. Bummer.
It'd be low-performance anyway though.

^ permalink raw reply	[flat|nested] 119+ messages in thread
* Re: [patch] spinlocks: remove 'volatile'
@ 2006-07-08  6:12 trajce nedev
  2006-07-08  6:19 ` Chase Venters
  2006-07-08 18:23 ` Linus Torvalds
  0 siblings, 2 replies; 119+ messages in thread
From: trajce nedev @ 2006-07-08  6:12 UTC (permalink / raw)
  To: torvalds, acahalan; +Cc: linux-kernel, linux-os, khc, mingo, akpm, arjan

On Fri, 7 Jul 2006, Linus Torvalds wrote:
>
>No.
>
>"volatile" simply CANNOT get the job done. It fundamentally does _nothing_ 
>for all the issues that are fundamental today: CPU memory ordering in SMP, 
>special IO synchronization requirements for memory-mapped IO registers etc 
>etc.
>
>It's not that "volatile" is the "portable way". It's that "volatile" is 
>fundamentally not sufficient for the job.
>

Incorrect.  I haven't been following this thread very closely but your 
assault on volatile is inappropriate.  There are several present day uses in 
assember instructions.

For example, if you're going to clobber hard registers specifically, 
volatile is required because you cannot write a clobber that overlaps input 
or output operands:
	asm volatile ("movc3 %0,%1,%2"
		: /* none */
		: "g" (from), "g" (to), "g" (count)
		: "r0", "r1", "r2", "r3", "r4", "r5");
You cannot have an operand that describes a register class with a single 
member if that register is in the clobber list; there is simply no way to 
specify that an input operand is modified without explicitly specifying it 
as output.  If all the output operands are for that purpose, they are 
considered unused.  volatile is _necessary_ for the asm to prevent the 
compiler from deleting it for this reason.

Furthermore, if the asm modifies memory unpredictably, you must add `memory` 
to the list of clobbers.  The compiler will not keep the memory value cached 
in registers any longer across asm instructions; volatile is added if the 
memory you're touching is not listed in the inputs or outputs since the 
`memory` clobber does not count as a side-effect of issuing the asm.  
volatile indicates the asm has side effects that are _important_ and will 
not delete it (if it's reachable, otherwise it is fair game).

If your asm has output operands, gcc currently assumes that the instruction 
has no side effects except changing these output operands (for 
optimization).  The compiler is free to eliminate or move out of loops any 
instructions with side effects if the output operands aren't used.  Even 
more dangerously, if the asm has a side effect on a variable that doesn't 
otherwise appear to change, the old value _may_ be reused later if it's 
found in a register.  volatile is used to prevent the asm from being deleted 
in this case (or more dangerously, combined):
	#define get_and_set_priority(new)		\
	({ 	int __old;				\
		asm volatile ("get_and_set_priority %0, %1"	\
			: "=g" (__old) : "g" (new));	\
		__old; })
The alternative is to write an asm with no outputs so that the compiler 
knows the instruction has side effects and won't eliminate or move it.

Also, gcc will not reschedule instructions across volatile asm's which is 
often necessary:
	*(volatile int *)addr = foo;
	asm volatile ("eieio" : : );
If addr contains the address of a memory-mapped device register, then the 
PowerPC eieio instruction informs the processor that it is necessary to 
store to that device register before issuing any other I/O.

		Trajce Nedev
		tnedev@mail.ru

_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee® 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


^ permalink raw reply	[flat|nested] 119+ messages in thread
* Re: [patch] spinlocks: remove 'volatile'
@ 2006-07-07 10:21 Chuck Ebbert
  2006-07-07 17:09 ` Linus Torvalds
  0 siblings, 1 reply; 119+ messages in thread
From: Chuck Ebbert @ 2006-07-07 10:21 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel, Ingo Molnar, Arjan van de Ven

In-Reply-To: <Pine.LNX.4.64.0607061333190.3869@g5.osdl.org>

On Thu, 6 Jul 2006 13:34:14 -0700, Linus Torvalds wrote:

> > So I _think_ that we should change the "=m" to the much more correct "+m" 
> > at the same time (or before - it's really a bug-fix regardless) as 
> > removing the "volatile".
> 
> Here's a first cut (UNTESTED!) for x86. I didn't check any other 
> architectures, I bet they have similar problems.

>  #define __raw_spin_unlock_string \
>       "movb $1,%0" \
> -             :"=m" (lock->slock) : : "memory"
> +             :"+m" (lock->slock) : : "memory"
 
This really is just an overwrite of whatever is there.  OTOH I can't see
how this change could hurt anything..

-- 
Chuck
 "You can't read a newspaper if you can't read."  --George W. Bush

^ permalink raw reply	[flat|nested] 119+ messages in thread
* Re: [patch] uninline init_waitqueue_*() functions
@ 2006-07-05 11:46 Ingo Molnar
  2006-07-05 17:10 ` Andrew Morton
  0 siblings, 1 reply; 119+ messages in thread
From: Ingo Molnar @ 2006-07-05 11:46 UTC (permalink / raw)
  To: Andrew Morton; +Cc: torvalds, linux-kernel, arjan


* Ingo Molnar <mingo@elte.hu> wrote:

> > true. I redid my tests with both lockdep and debug-spinlocks turned off:
> > 
> >   text            data    bss     dec             filename
> >   21172153        6077270 3081864 30331287        vmlinux.x32.after
> >   21198222        6077106 3081864 30357192        vmlinux.x32.before
> > 
> > with 851 callsites that's a 30.6 bytes win per call site (total 26K) - 
> > still not bad at all.
> 
> and that was with CONFIG_CC_OPTIMIZE_FOR_SIZE enabled. With 
> optimize-for-size disabled the win goes up to 32.6 bytes (total 28K).

i also tried a config with the best size settings (disabling 
FRAME_POINTER, enabling CC_OPTIMIZE_FOR_SIZE), and this gives:

  text            data    bss     dec         filename
  20777768        6076042 3081864 29935674    vmlinux.x32.size.before
  20748140        6076178 3081864 29906182    vmlinux.x32.size.after

or a 34.8 bytes win per callsite (29K total).

	Ingo

^ permalink raw reply	[flat|nested] 119+ messages in thread

end of thread, other threads:[~2006-07-14  3:31 UTC | newest]

Thread overview: 119+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-08  3:54 [patch] spinlocks: remove 'volatile' Albert Cahalan
2006-07-08  5:25 ` Linus Torvalds
2006-07-08  6:39   ` Nick Piggin
2006-07-08 18:53     ` Linus Torvalds
2006-07-08  9:45 ` Joe Korty
2006-07-08  9:52   ` Arjan van de Ven
2006-07-08  9:59   ` David Schwartz
2006-07-08 10:24   ` Thomas Gleixner
2006-07-08 15:49     ` Albert Cahalan
2006-07-08 18:31       ` Thomas Gleixner
2006-07-08 19:33         ` Albert Cahalan
2006-07-08 20:11           ` Linus Torvalds
2006-07-09 21:10             ` Pavel Machek
2006-07-09 22:18               ` Linus Torvalds
2006-07-10 16:25               ` marty fouts
2006-07-08 23:10           ` David Schwartz
2006-07-08 13:57   ` Andi Kleen
2006-07-08 19:13     ` Linus Torvalds
2006-07-08 10:45 ` Krzysztof Halasa
  -- strict thread matches above, loose matches on Subject: below --
2006-07-08  6:12 trajce nedev
2006-07-08  6:19 ` Chase Venters
2006-07-08  6:45   ` trajce nedev
2006-07-08  6:58     ` Arjan van de Ven
2006-07-08  7:02     ` Vadim Lobanov
2006-07-08 13:46     ` Chase Venters
2006-07-09  4:39       ` Benjamin Herrenschmidt
2006-07-14  3:30       ` Steven Rostedt
2006-07-08 18:23 ` Linus Torvalds
2006-07-07 10:21 Chuck Ebbert
2006-07-07 17:09 ` Linus Torvalds
2006-07-05 11:46 [patch] uninline init_waitqueue_*() functions Ingo Molnar
2006-07-05 17:10 ` Andrew Morton
2006-07-05 19:35   ` Ingo Molnar
2006-07-05 20:18     ` Andrew Morton
2006-07-05 20:36       ` Linus Torvalds
2006-07-05 20:47         ` Ingo Molnar
2006-07-05 21:21           ` Linus Torvalds
2006-07-05 21:45             ` Ingo Molnar
2006-07-05 22:09               ` Linus Torvalds
2006-07-05 23:11                 ` Linus Torvalds
2006-07-06  8:16                   ` [patch] spinlocks: remove 'volatile' Ingo Molnar
2006-07-06  8:23                     ` Ingo Molnar
2006-07-06  9:27                     ` Heiko Carstens
2006-07-06  9:34                       ` Arjan van de Ven
2006-07-06 11:59                     ` linux-os (Dick Johnson)
2006-07-06 12:01                       ` Arjan van de Ven
2006-07-06 12:29                         ` linux-os (Dick Johnson)
2006-07-06 12:39                           ` Arjan van de Ven
2006-07-06 13:39                             ` J.A. Magallón
2006-07-06 13:43                               ` Arjan van de Ven
2006-07-06 14:05                               ` Chase Venters
2006-07-06 14:26                               ` Andreas Schwab
2006-07-06 16:40                           ` Nick Piggin
2006-07-06 23:19                           ` David Schwartz
2006-07-06 18:15                         ` Mark Lord
2006-07-06 19:15                           ` Linus Torvalds
2006-07-06 19:33                             ` Chris Friesen
2006-07-06 19:37                               ` Mark Lord
2006-07-06 20:28                                 ` Chris Friesen
2006-07-06 20:32                                   ` Linus Torvalds
2006-07-06 19:38                               ` Arjan van de Ven
2006-07-06 19:41                               ` Måns Rullgård
2006-07-06 19:42                               ` Jeff Garzik
2006-07-06 19:58                               ` Linus Torvalds
2006-07-06 20:27                                 ` Mark Lord
2006-07-06 20:40                                 ` Chris Friesen
2006-07-06 21:00                                   ` Linus Torvalds
2006-07-08  8:40                             ` Avi Kivity
2006-07-08  8:51                               ` Arjan van de Ven
2006-07-08  9:20                                 ` Avi Kivity
2006-07-08  9:51                                   ` Arjan van de Ven
2006-07-08 10:18                                     ` Avi Kivity
2006-07-08 10:28                                       ` Thomas Gleixner
2006-07-09  4:19                                       ` Benjamin Herrenschmidt
2006-07-09 12:47                                         ` Avi Kivity
2006-07-09 19:16                                           ` David Schwartz
2006-07-09 19:51                                             ` Theodore Tso
2006-07-06 16:07                       ` Linus Torvalds
2006-07-06 16:13                         ` Linus Torvalds
2006-07-06 17:04                           ` Jeff Garzik
2006-07-06 17:52                           ` linux-os (Dick Johnson)
2006-07-06 18:00                             ` Linus Torvalds
2006-07-06 21:02                               ` J.A. Magallón
2006-07-06 21:12                                 ` Linus Torvalds
2006-07-06 18:10                             ` Michael Buesch
2006-07-06 18:16                             ` Chase Venters
2006-07-07 18:16                             ` Krzysztof Halasa
2006-07-07 19:51                               ` linux-os (Dick Johnson)
2006-07-07 20:25                                 ` Linus Torvalds
2006-07-07 21:22                                   ` linux-os (Dick Johnson)
2006-07-07 21:48                                     ` Chase Venters
2006-07-08 10:00                                       ` Krzysztof Halasa
2006-07-08 13:41                                         ` Chase Venters
2006-07-08 20:09                                           ` Krzysztof Halasa
2006-07-08 20:40                                             ` Chase Venters
2006-07-08 20:47                                               ` Chase Venters
2006-07-09 10:57                                               ` Krzysztof Halasa
2006-07-07 21:59                                     ` Linus Torvalds
2006-07-07 22:06                                       ` Linus Torvalds
2006-07-08 20:49                                       ` Pavel Machek
2006-07-08 21:43                                         ` Linus Torvalds
2006-07-07 22:05                                     ` J.A. Magallón
2006-07-07 22:22                                       ` Chase Venters
2006-07-07 22:37                                         ` J.A. Magallón
2006-07-08  9:33                                           ` David Schwartz
2006-07-07 22:49                                         ` J.A. Magallón
2006-07-07 22:59                                           ` Vadim Lobanov
2006-07-07 23:18                                           ` Chase Venters
2006-07-07 23:36                                       ` Davide Libenzi
2006-07-07 22:09                                     ` Ingo Molnar
2006-07-08  7:36                                       ` Ingo Molnar
2006-07-07 20:39                                 ` Krzysztof Halasa
2006-07-07 23:06                                 ` Björn Steinbrink
2006-07-08  8:36                                 ` Avi Kivity
2006-07-06 19:32                           ` Jan Engelhardt
2006-07-06 20:26                             ` Jeremy Fitzhardinge
2006-07-06 20:55                               ` Jan Engelhardt
2006-07-06 21:07                                 ` Linus Torvalds
2006-07-06 19:56                     ` Linus Torvalds
2006-07-06 20:34                       ` Linus Torvalds
2006-07-08 22:50                         ` Ralf Baechle
2006-07-09  3:09                           ` Linus Torvalds
2006-07-09  3:07                         ` Keith Owens
2006-07-09  3:29                           ` Linus Torvalds
2006-07-09  3:43                             ` Keith Owens
2006-07-09  3:58                           ` Linus Torvalds
2006-07-09  6:13                             ` David Miller
2006-07-09 14:28                             ` Roman Zippel
2006-07-09 15:27                               ` Linus Torvalds

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.