linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: linux-os <linux-os@chaos.analogic.com>
To: Linus Torvalds <torvalds@osdl.org>
Cc: dean gaudet <dean-list-linux-kernel@arctic.org>,
	Andreas Steinmetz <ast@domdv.de>,
	Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Richard Henderson <rth@redhat.com>, Andi Kleen <ak@muc.de>,
	Andrew Morton <akpm@osdl.org>, Jan Hubicka <jh@suse.cz>
Subject: Re: Semaphore assembly-code bug
Date: Mon, 1 Nov 2004 17:16:37 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.61.0411011651580.26464@chaos.analogic.com> (raw)
In-Reply-To: <Pine.LNX.4.58.0411011327400.28839@ppc970.osdl.org>

On Mon, 1 Nov 2004, Linus Torvalds wrote:

>
>
> On Mon, 1 Nov 2004, linux-os wrote:
>>
>> Wrong.
>>
>> (1)  The '486 didn't have the rdtsc instruction.
>> (2)  There are no 'serializing' or other black-magic aspects of
>> using the internal cycle-counter. That's exactly how you you
>> can benchmark the execution time of accessible code sequences.
>
> Sorry, but you shouldn't argue with people who know more than you do. I
> know Dean, and he analyzes things for work, and does know what he is
> doing.
>
> "rdtsc" _does_ partly serialize things, and it's not even architecturally
> defined, so you'll find that it serializes things in different ways on
> different CPU's. You can't just do
>
> 	rdtsc
> 	...
> 	rdtsc
>
> and expect the stuff in between the rdtsc's to be timed exactly: some of
> it will overlap with the rdtsc's, some of it won't.
>
> On Intel, if I recall correctly, rdtsc is totally serializing, so you're
> testing not just the instructions between the rdtsc's, but the length of
> the pipeline, and the time it takes for stuff around it to calm down.
> Which is why two rdtsc's in sequence will show quite a lot of overhead on
> a P4 (something like 80 cycles).
>
> So you really want to do more operations in between the rdtsc's.
>
> Try the appended program. On a P4, the two sequnces are the same for me
> (92 cycles, 80 cycles overhead), while on a Pentium M, the sequence of two
> popl's (57 cycles) is faster than the sequence of "lea+popl" (59 cycles)
> and the overhead is 47 cycles.
>
> So can you _please_ just admit that you were wrong? On a P4, the pop/pop
> is the same cost as lea/pop, and on a Pentium M the pop/pop is faster,
> according to this test. Your contention that "pop" has to be slower than
> "lea" is WRONG.
>
> 		Linus
>
> ----
> #define PUSHEBX "pushl %%ebx\n\t"
> #define PUSHECX "pushl %%ecx\n\t"
> #define POPECX "popl %%ecx\n\t"
> #define POPEBX "popl %%ebx\n\t"
>
> #ifdef TEST_LEA
>
> #undef POPECX
> #define POPECX "leal 4(%%esp),%%esp\n\t"
>
> #endif
>
> #ifdef TEST_OVERHEAD
>
> #undef PUSHEBX
> #undef PUSHECX
> #undef POPEBX
> #undef POPECX
>
> #define PUSHEBX
> #define PUSHECX
> #define POPEBX
> #define POPECX
>
> #endif
>
> int main(void)
> {
> 	unsigned long start;
> 	unsigned long long end;
>
> 	asm volatile(
> 		PUSHEBX
> 		PUSHECX
> 		PUSHEBX
> 		PUSHECX
> 		PUSHEBX
> 		PUSHECX
> 		PUSHEBX
> 		PUSHECX
> 		PUSHEBX
> 		PUSHECX
> 		PUSHEBX
> 		PUSHECX
> 		PUSHEBX
> 		PUSHECX
> 		PUSHEBX
> 		PUSHECX
> 		"rdtsc\n\t"
> 		POPECX
> 		POPEBX
> 		POPECX
> 		POPEBX
> 		POPECX
> 		POPEBX
> 		POPECX
> 		POPEBX
> 		POPECX
> 		POPEBX
> 		POPECX
> 		POPEBX
> 		POPECX
> 		POPEBX
> 		POPECX
> 		POPEBX
> 		"movl %%eax,%%esi\n\t"
> 		"rdtsc"
> 		:"=A" (end), "=S" (start));
> 	printf("%ld cycles\n", (long) end-start);
> }
>

You just don't get it. I, too, can make a so-called bench-mark
that will "prove" something that's so incredibly invalid that
it shouldn't even deserve an answer. However, because you
are supposed to know what you are doing, I will give you
an answer.

It is totally impossible to perform useful work with memory,
i.e., poping the value of something from memory into a register,
without incurring the cost of that memory access. It doesn't
matter if the memory is in cache or if it needs to be read
using the memory controller. Time is time and it never runs
backwards. I spend most of my days with hardware logic analyzers
looking at the memory accesses so I damn-well know what I
am taking about. That memory-access takes a time-slot that
something else can't use. You never get it back. It is gone
forever. This is very important to understand. If you don't
understand this, you can fall into the "black-magic" trap.

Modern CPUs make it easy for so-called software engineers to
perceive so-called facts that are not, in fact, true. Because
it is possible for the CPU to perform memory-access independent
of instruction sequence (so-called parallel operations), it is
possible to make bench-marks that prove nothing, but seem to
show that a read from memory is free. It can never be free. It
will eventually show up. It was just deferred. Of course, if
your computer is just going to run that single bench-mark, then
return to a prompt, you can readily become victum of a very
common error because there is now plenty of time available to
just spin (or wait for an interrupt).

So, if you really want to make things fast, you keep your
memory accesses to the absolute minimum. Poping something
from the stack is the antithesis of what you want to do.

It's really amusing. Software development has devolved
into some black magic where logic, mathematics, and
physical testing no longer thrive.

Instead, we must listen to those who profess to know
about this magic because of some innate enlightenment
imparted to those favored few who are able to perceive
the trueness of their intellectual perception without
regard for contrary physical observations.

It's wonderful to not be bothered by tests, measurements,
documentation, or other facts.

Wake up and don't be dragged into the black-magic trap.


Cheers,
Dick Johnson
Penguin : Linux version 2.6.9 on an i686 machine (5537.79 BogoMips).
  Notice : All mail here is now cached for review by John Ashcroft.
                  98.36% of all statistics are fiction.

  parent reply	other threads:[~2004-11-02  1:51 UTC|newest]

Thread overview: 246+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-18 22:45 Linux v2.6.9 Linus Torvalds
2004-10-18 23:27 ` Thomas Zehetbauer
2004-10-19  2:54 ` Eric W. Biederman
2004-10-19 16:55   ` Jesper Juhl
2004-10-19 14:36 ` Linux v2.6.9... (compile stats) John Cherry
2004-10-19 16:18   ` Matthew Dharm
2004-10-19 16:49     ` viro
2004-10-19 21:37     ` John Cherry
2004-10-20 22:11     ` John Cherry
2004-10-20 22:41       ` viro
2004-10-21  0:12         ` Linus Torvalds
2004-10-21  0:29           ` Jeff Garzik
2004-10-21  0:44             ` viro
2004-10-21  1:55             ` viro
2004-10-21  1:59               ` Jeff Garzik
2004-10-21  2:24                 ` viro
2004-10-21  2:37                   ` Jeff Garzik
2004-10-21  4:35                     ` viro
2004-10-21  8:57                       ` Jeff Garzik
2004-10-20 22:50       ` Dave Jones
2004-10-19 17:38 ` Linux v2.6.9 and GPL Buyout Jeff V. Merkey
2004-10-19 19:13   ` Russell King
2004-10-19 19:04     ` Jeff V. Merkey
2004-10-19 19:24   ` Kurt Wall
2004-10-19 19:12     ` Jeff V. Merkey
2004-10-19 20:01     ` Richard B. Johnson
2004-10-19 20:39       ` Matt Mackall
2004-10-20  0:06         ` Richard B. Johnson
2004-10-20  5:21           ` Matt Mackall
2004-10-19 19:28   ` Andre Hedrick
2004-10-19 19:10     ` Jeff V. Merkey
2004-10-19 19:30   ` Rik van Riel
2004-10-19 19:05     ` Jeff V. Merkey
2004-10-19 20:14       ` Diego Calleja
2004-10-19 19:41         ` Jeff V. Merkey
2004-10-20  8:27           ` Bernd Petrovitsch
2004-10-20  8:45             ` Jens Axboe
2004-10-19 19:47         ` Jeff V. Merkey
2004-10-19 20:05     ` Richard B. Johnson
2004-10-19 19:38       ` Jeff V. Merkey
2004-10-19 20:30         ` Thomas Gleixner
2004-10-19 20:15           ` Jeff V. Merkey
2004-10-22 23:22           ` Tonnerre
2004-10-19 19:45   ` Ross Biro
2004-10-19 19:36     ` Jeff V. Merkey
2004-10-19 19:54   ` David Johnson
2004-10-19 19:55   ` viro
2004-10-19 19:25     ` Jeff V. Merkey
2004-10-19 20:38   ` Dax Kelson
2004-10-19 20:09     ` Jeff V. Merkey
2004-10-19 22:16       ` Jim Nelson
2004-10-19 22:57         ` Bernd Petrovitsch
2004-10-19 22:27       ` Scott Robert Ladd
2004-10-20 19:41         ` Bill Davidsen
2004-10-20  1:15       ` Horst von Brand
2004-10-20  1:16       ` Bastiaan Spandaw
2004-10-20 19:35         ` Bill Davidsen
2004-10-20  3:45       ` Ryan Anderson
2004-10-20  4:18         ` Lee Revell
2004-10-20  4:41           ` Lee Revell
2004-10-20 11:49             ` Richard B. Johnson
2004-10-29 12:12               ` Semaphore assembly-code bug linux-os
2004-10-29 14:46                 ` Linus Torvalds
2004-10-29 15:11                   ` Andi Kleen
2004-10-29 18:18                     ` Linus Torvalds
2004-10-29 18:35                       ` Richard Henderson
2004-10-29 16:06                   ` Andreas Steinmetz
2004-10-29 17:08                     ` linux-os
2004-10-29 18:06                       ` Linus Torvalds
2004-10-29 18:39                         ` linux-os
2004-10-29 19:12                           ` Linus Torvalds
2004-11-01  1:31                             ` linux-os
2004-11-01  5:49                               ` Linus Torvalds
2004-11-01 20:23                               ` dean gaudet
2004-11-01 20:52                                 ` linux-os
2004-11-01 21:23                                   ` dean gaudet
2004-11-01 22:22                                     ` linux-os
2004-11-01 21:40                                   ` Linus Torvalds
2004-11-01 21:46                                     ` Linus Torvalds
2004-11-02 15:02                                       ` linux-os
2004-11-02 16:02                                         ` Linus Torvalds
2004-11-02 16:06                                           ` Linus Torvalds
2004-11-02 16:51                                             ` linux-os
2004-11-01 22:16                                     ` linux-os [this message]
2004-11-01 22:26                                       ` Linus Torvalds
2004-11-01 23:14                                         ` linux-os
2004-11-01 23:42                                           ` Linus Torvalds
2004-11-03  1:52                                       ` Horst von Brand
2004-11-03 21:24                                       ` Bill Davidsen
2004-11-02  6:37                                     ` Chris Friesen
2004-10-29 18:58                         ` Andreas Steinmetz
2004-10-29 19:15                           ` Linus Torvalds
2004-10-29 19:40                             ` Andreas Steinmetz
2004-10-29 19:56                               ` Linus Torvalds
2004-10-29 22:07                                 ` Jeff Garzik
2004-10-29 23:50                               ` dean gaudet
2004-10-30  0:15                                 ` Linus Torvalds
2004-10-29 23:37                         ` dean gaudet
2004-10-29 17:22                   ` linux-os
2004-10-29 17:55                     ` Richard Henderson
2004-10-29 18:17                       ` linux-os
2004-10-29 18:42                         ` Linus Torvalds
2004-10-29 18:54                           ` Linus Torvalds
2004-10-30  3:35                           ` Jeff Garzik
2004-10-29 19:20                     ` Linus Torvalds
2004-10-29 19:26                       ` Linus Torvalds
2004-10-29 21:03                       ` Linus Torvalds
2004-10-29 17:57                   ` Richard Henderson
2004-10-29 18:37                   ` Gabriel Paubert
2004-10-20  5:58           ` Linux v2.6.9 and GPL Buyout John Alvord
2004-10-20 14:42           ` Martin Waitz
2004-10-21 23:59       ` Kelledin
2004-10-22  8:46       ` Bernd Petrovitsch
2004-10-22  9:07       ` David Weinehall
2004-10-22 16:15         ` Jeff V. Merkey
2004-10-22 17:52           ` Al Viro
2004-10-22 17:22             ` Jeff V. Merkey
2004-10-22 19:37               ` Jeff V. Merkey
2004-10-22 20:46                 ` Grahame White
2004-10-22 20:58                 ` Buddy Lucas
2004-10-22 21:00                 ` Richard B. Johnson
2004-10-22 21:03                 ` Thomas Gleixner
2004-10-23 12:33                 ` Bernd Petrovitsch
2004-10-24 14:15                 ` Kai Henningsen
2004-10-27  1:45                 ` Horst von Brand
2004-10-24 11:00           ` Matthias Andree
2004-10-24 14:13           ` Kai Henningsen
2004-10-25 18:44             ` Bill Davidsen
2004-10-20 19:46     ` Bill Davidsen
2004-10-19 21:02   ` Pekka Pietikainen
2004-10-19 20:27     ` Jeff V. Merkey
2004-10-22  6:54       ` Erik Andersen
2004-10-22 16:12         ` Jeff V. Merkey
2004-10-19 21:17     ` Paul Fulghum
2004-10-20 20:41     ` Geert Uytterhoeven
2004-10-23 13:43       ` James Bruce
2004-10-19 21:26   ` Ramón Rey Vicente
2004-10-19 22:52   ` Buddy Lucas
2004-10-20 23:43   ` Eric Bambach
2004-10-20 23:48     ` Eric Bambach
2004-10-20 23:59     ` Hua Zhong
2004-10-21  0:13     ` Russell Miller
2004-10-21  0:18       ` Adam Heath
2004-10-21 10:16       ` Horst von Brand
2004-10-22  8:48   ` Ingo Molnar
2004-10-22 16:15     ` Jeff V. Merkey
2004-10-23  0:14   ` Jon Masters
2004-10-22 23:46     ` Jeff V. Merkey
2004-10-23  0:57       ` Jon Masters
2004-10-23  4:42         ` Jeff V. Merkey
2004-10-23  6:32           ` Nick Piggin
     [not found]             ` <20041023064538.GA7866@galt.devicelogics.com>
2004-10-23  7:20               ` Jeff V. Merkey
2004-10-23 10:11           ` Gene Heskett
2004-10-23 16:28           ` Linus Torvalds
2004-10-24  2:48             ` Jesper Juhl
2004-10-24  5:11             ` Jeff V. Merkey
2004-10-24 11:14               ` Jon Masters
2004-10-24 11:50               ` Jim Nelson
2004-10-24 15:35               ` Ingo Molnar
2004-10-24 15:53               ` Bernd Petrovitsch
2004-10-31 23:14               ` Jan 'JaSan' Sarenik
2004-10-24  2:11           ` Buddy Lucas
2004-10-23  0:38     ` Lee Revell
2004-10-23  0:07       ` Jeff V. Merkey
2004-10-23  1:06         ` Lee Revell
2004-10-21  2:41 ` Linux v2.6.9 (Strange tty problem?) Paul
2004-10-21  9:07   ` Alan Cox
2004-10-21 12:39     ` Russell King
2004-10-21 13:20     ` Paul Fulghum
2004-10-21 15:37       ` Alan Cox
2004-10-21 17:00         ` Paul Fulghum
2004-10-21 15:47       ` Paul Fulghum
2004-10-21 18:12     ` Paul Fulghum
2004-10-31 21:11 ` Linux v2.6.9 dies when starting X on radeon 9200 SE PCI Helge Hafting
     [not found] <Pine.LNX.4.58.0410181540080.2287@ppc970.osdl.org.suse.lists.linux.kernel>
     [not found] ` <417550FB.8020404@drdos.com.suse.lists.linux.kernel>
     [not found]   ` <1098218286.8675.82.camel@mentorng.gurulabs.com.suse.lists.linux.kernel>
     [not found]     ` <41757478.4090402@drdos.com.suse.lists.linux.kernel>
     [not found]       ` <20041020034524.GD10638@michonline.com.suse.lists.linux.kernel>
     [not found]         ` <1098245904.23628.84.camel@krustophenia.net.suse.lists.linux.kernel>
     [not found]           ` <1098247307.23628.91.camel@krustophenia.net.suse.lists.linux.kernel>
     [not found]             ` <Pine.LNX.4.61.0410200744310.10521@chaos.analogic.com.suse.lists.linux.kernel>
     [not found]               ` <Pine.LNX.4.61.0410290805570.11823@chaos.analogic.com.suse.lists.linux.kernel>
     [not found]                 ` <Pine.LNX.4.58.0410290740120.28839@ppc970.osdl.org.suse.lists.linux.kernel>
     [not found]                   ` <41826A7E.6020801@domdv.de.suse.lists.linux.kernel>
     [not found]                     ` <Pine.LNX.4.61.0410291255400.17270@chaos.analogic.com.suse.lists.linux.kernel>
     [not found]                       ` <Pine.LNX.4.58.0410291103000.28839@ppc970.osdl.org.suse.lists.linux.kernel>
     [not found]                         ` <Pine.LNX.4.61.0410291631250.8616@twinlark.arctic.org.suse.lists.linux.kernel>
2004-10-30  2:04                           ` Semaphore assembly-code bug Andi Kleen
     [not found]                   ` <Pine.LNX.4.61.0410291316470.3945@chaos.analogic.com.suse.lists.linux.kernel>
     [not found]                     ` <20041029175527.GB25764@redhat.com.suse.lists.linux.kernel>
     [not found]                       ` <Pine.LNX.4.61.0410291416040.4844@chaos.analogic.com.suse.lists.linux.kernel>
     [not found]                         ` <Pine.LNX.4.58.0410291133220.28839@ppc970.osdl.org.suse.lists.linux.kernel>
2004-10-30  2:13                           ` Andi Kleen
2004-10-30  9:28                             ` Denis Vlasenko
2004-10-30 17:53                               ` Linus Torvalds
2004-10-30 21:00                                 ` Denis Vlasenko
2004-10-31  0:39                                 ` Andi Kleen
2004-10-31  1:43                                   ` Linus Torvalds
2004-10-31  2:04                                     ` Andi Kleen
2004-11-04 16:01 Linux-2.6.9 won't allow a write to a NTFS file-system linux-os
2004-11-04 16:48 ` Giuseppe Bilotta
2004-11-04 17:09   ` linux-os
2004-11-04 17:40     ` Giuseppe Bilotta
2004-11-04 17:46     ` Mathieu Segaud
2004-11-04 22:17     ` Anton Altaparmakov
2004-11-04 22:18       ` Anton Altaparmakov
2004-11-04 22:38       ` linux-os
2004-11-05 14:43         ` Rahul Karnik
2004-11-05  1:46     ` Horst von Brand
2004-11-05 12:41       ` linux-os
2004-12-02  0:04 What if? Imanpreet Singh Arora
2004-12-02  4:40 ` Theodore Ts'o
2004-12-02  6:39   ` Norbert van Nobelen
2004-12-02  8:24   ` James Bruce
2004-12-02 20:25     ` Theodore Ts'o
2004-12-03  2:23       ` David Schwartz
2004-12-02  8:33   ` J.A. Magallon
2004-12-02 10:46     ` Bernd Petrovitsch
2004-12-02 10:56       ` Pawel Sikora
2004-12-13 15:23       ` H. Peter Anvin
2004-12-13 21:08         ` J.A. Magallon
2004-12-16  0:57           ` Alan Cox
2004-12-16  2:44             ` H. Peter Anvin
2004-12-16 13:23               ` Alan Cox
2004-12-16 15:23                 ` Geert Uytterhoeven
2004-12-16 20:37                 ` H. Peter Anvin
2004-12-16 20:52                   ` Jan Engelhardt
2004-12-16 20:56                     ` H. Peter Anvin
2004-12-16 21:08                       ` Jan Engelhardt
2004-12-02 10:25 ` Jan Engelhardt
2004-12-05  0:23   ` Horst von Brand
2004-12-05  6:21     ` Kyle Moffett
2004-12-05 22:43       ` Horst von Brand
2004-12-06 17:27         ` linux-os
2004-12-06 18:52           ` Horst von Brand
2004-12-02 10:53 ` Bernd Petrovitsch
2004-12-11  8:52 ` Gábor Lénárt
2004-12-17  1:33 [Coverity] Untrusted user data in kernel Bryan Fulton
2004-12-17  5:15 ` James Morris
2004-12-17  5:25   ` Patrick McHardy
2004-12-17  6:45     ` James Morris
2004-12-17 13:18       ` Tomas Carnecky
2004-12-17 19:16         ` David S. Miller
2004-12-17 19:34           ` Tomas Carnecky
2004-12-17 19:30             ` David S. Miller
2004-12-17 15:47       ` Bill Davidsen
2004-12-17 16:11         ` linux-os
2004-12-17 16:31           ` Oliver Neukum
2004-12-17 18:37           ` Bill Davidsen
2004-12-17 19:18           ` Tomas Carnecky
2004-12-17 19:30             ` Oliver Neukum
2004-12-17 19:39               ` Tomas Carnecky
2004-12-18  1:42           ` Horst von Brand
2004-12-17 15:10   ` Pavel Machek
2004-12-17 15:38     ` James Morris
2005-01-05 12:04 ` Marcelo Tosatti
2005-01-05 15:09   ` Jan Harkes
2005-01-05 23:17   ` Nathan Scott
     [not found]   ` <20050105161653.GF13455@fi.muni.cz>
     [not found]     ` <20050105140549.GA14622@logos.cnet>
2005-01-06  9:18       ` Jan Kasprzak
2005-01-06 14:48         ` Paulo Marques
2005-01-06 16:29         ` Alan Cox
2005-01-07 21:49   ` [PATCH 2.4.29-pre3-bk4] fs/coda " Jan Harkes
2005-01-07 21:54   ` [PATCH 2.6.10-mm2] " Jan Harkes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.61.0411011651580.26464@chaos.analogic.com \
    --to=linux-os@chaos.analogic.com \
    --cc=ak@muc.de \
    --cc=akpm@osdl.org \
    --cc=ast@domdv.de \
    --cc=dean-list-linux-kernel@arctic.org \
    --cc=jh@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-os@analogic.com \
    --cc=rth@redhat.com \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).