From: Eric Dumazet <dada1@cosmosbay.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
Davide Libenzi <davidel@xmailserver.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [patch v2] epoll use a single inode ...
Date: Tue, 6 Mar 2007 19:10:13 +0100 [thread overview]
Message-ID: <200703061910.13431.dada1@cosmosbay.com> (raw)
In-Reply-To: <200703061828.00253.dada1@cosmosbay.com>
[-- Attachment #1: Type: text/plain, Size: 2099 bytes --]
On Tuesday 06 March 2007 18:28, Eric Dumazet wrote:
> On Tuesday 06 March 2007 18:19, Linus Torvalds wrote:
>
> > > Using reciprocal divides permits to change each divide by two
> > > multiplies, less expensive on current CPUS.
> >
> > Are you sure?
>
> I am going to test this, but at least on Opterons, the reciprocal divide I
> added into mm/slab.c gave me a nice speedup.
>
With attached test program (one million calls to pipe()), I got about 0.1 s of
speedup on my 1.6 GHz Pentium(M) dell D610 machine
(3.350 s instead of 3.450 s, on many runs)
Thats about 100 ns saved per number() call
But then I realized that on ia32, gcc compilers is not very smart :
static inline u32 reciprocal_divide(u32 A, u32 R)
{
return (u32)(((u64)A * R) >> 32);
}
It generates two multiplies... arg...
//begin of reciprocal_divide()
4b0: 8b 4c 24 28 mov 0x28(%esp),%ecx
4b4: 89 f0 mov %esi,%eax
4b6: f7 64 24 24 mull 0x24(%esp)
4ba: 0f af ce imul %esi,%ecx
4bd: 8d 14 11 lea (%ecx,%edx,1),%edx
// end of reciprocal_divide()
4c0: 8b 8c 24 8c 00 00 00 mov 0x8c(%esp),%ecx
4c7: 89 d0 mov %edx,%eax
4c9: 0f af c8 imul %eax,%ecx
4cc: 29 ce sub %ecx,%esi
4ce: 8b 4c 24 1c mov 0x1c(%esp),%ecx
4d2: 0f b6 34 31 movzbl (%ecx,%esi,1),%esi
4d6: 89 f1 mov %esi,%ecx
4d8: 89 c6 mov %eax,%esi
4da: 88 0f mov %cl,(%edi)
4dc: 47 inc %edi
4dd: ff 44 24 20 incl 0x20(%esp)
4e1: 85 c0 test %eax,%eax
4e3: 75 cb jne 4b0 <number+0x160>
So even with a total of 3 multiplies per digit, we win...
Maybe some bit of x86 asm is needed to make gcc be smarter (using only one
multiply for reciprocal_divide())
[-- Attachment #2: pipes.c --]
[-- Type: text/plain, Size: 241 bytes --]
/*
* micro benchmark to time calls to pipe()/close()
*/
main()
{
int fd[100*2];
unsigned int l, i;
for (l = 0 ; l < 10000 ; l++) {
for (i = 0 ; i < 100*2 ; i+=2)
pipe(fd + i);
for (i = 0 ; i < 100*2 ; i++)
close(fd[i]);
}
}
next prev parent reply other threads:[~2007-03-06 18:10 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-05 23:41 Davide Libenzi
2007-03-06 0:00 ` Linus Torvalds
2007-03-06 0:12 ` Davide Libenzi
2007-03-06 0:20 ` Davide Libenzi
2007-03-06 0:25 ` Linus Torvalds
2007-03-06 2:25 ` H. Peter Anvin
2007-03-06 2:34 ` Davide Libenzi
2007-03-06 2:37 ` H. Peter Anvin
2007-03-06 2:43 ` Davide Libenzi
2007-03-06 6:22 ` Eric Dumazet
2007-03-06 6:31 ` Davide Libenzi
2007-03-06 6:37 ` Davide Libenzi
2007-03-06 16:28 ` H. Peter Anvin
2007-03-06 17:09 ` Linus Torvalds
2007-03-06 17:14 ` H. Peter Anvin
2007-03-06 17:12 ` Eric Dumazet
2007-03-06 17:19 ` Linus Torvalds
2007-03-06 17:27 ` H. Peter Anvin
2007-03-06 17:28 ` Eric Dumazet
2007-03-06 18:10 ` Eric Dumazet [this message]
2007-03-06 20:20 ` Eric Dumazet
2007-03-07 3:47 ` Linus Torvalds
2007-03-07 5:40 ` H. Peter Anvin
2007-03-07 6:57 ` Eric Dumazet
2007-03-07 7:13 ` H. Peter Anvin
2007-03-07 23:46 ` Sami Farin
2007-03-06 18:10 ` Davide Libenzi
2007-03-10 8:06 ` Pavel Machek
2007-03-10 8:24 ` Davide Libenzi
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=200703061910.13431.dada1@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=akpm@linux-foundation.org \
--cc=davidel@xmailserver.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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
Powered by JetHome