From: Pavel Machek <pavel@ucw.cz>
To: Eric Dumazet <dada1@cosmosbay.com>
Cc: Andrew Morton <akpm@osdl.org>, David Miller <davem@davemloft.net>,
linux-kernel@vger.kernel.org,
Christoph Lameter <clameter@sgi.com>
Subject: Re: [PATCH] SLAB : use a multiply instead of a divide in obj_to_index()
Date: Tue, 5 Dec 2006 14:42:00 +0000 [thread overview]
Message-ID: <20061205144159.GB4388@ucw.cz> (raw)
In-Reply-To: <200612041741.51846.dada1@cosmosbay.com>
Hi!
> When some objects are allocated by one CPU but freed by another CPU we can
> consume lot of cycles doing divides in obj_to_index().
>
> (Typical load on a dual processor machine where network interrupts are handled
> by one particular CPU (allocating skbufs), and the other CPU is running the
> application (consuming and freeing skbufs))
>
> Here on one production server (dual-core AMD Opteron 285), I noticed this
> divide took 1.20 % of CPU_CLK_UNHALTED events in kernel. But Opteron are
> quite modern cpus and the divide is much more expensive on oldest
> architectures :
>
> On a 200 MHz sparcv9 machine, the division takes 64 cycles instead of 1 cycle
> for a multiply.
>
> Doing some math, we can use a reciprocal multiplication instead of a divide.
>
> If we want to compute V = (A / B) (A and B being u32 quantities)
> we can instead use :
>
> V = ((u64)A * RECIPROCAL(B)) >> 32 ;
>
> where RECIPROCAL(B) is precalculated to ((1LL << 32) + (B - 1)) / B
Well, I guess it should be gcc doing this optimalization, not we by
hand. And I believe gcc *is* smart enough to do it in some cases...
pavel
--
Thanks for all the (sleeping) penguins.
next prev parent reply other threads:[~2006-12-05 15:12 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-22 21:35 [PATCH] prune_icache_sb Wendy Cheng
2006-11-22 23:36 ` Andrew Morton
2006-11-27 23:52 ` Wendy Cheng
2006-11-28 0:52 ` Andrew Morton
2006-11-28 21:41 ` Wendy Cheng
2006-11-29 0:21 ` Andrew Morton
2006-11-29 6:02 ` Wendy Cheng
2006-11-30 16:05 ` Wendy Cheng
2006-11-30 19:31 ` Nate Diller
2006-12-01 21:23 ` Andrew Morton
2006-12-03 17:49 ` Wendy Cheng
2006-12-03 20:47 ` Andrew Morton
2006-12-04 5:57 ` Wendy Cheng
2006-12-04 6:28 ` Andrew Morton
2006-12-04 16:41 ` [PATCH] SLAB : use a multiply instead of a divide in obj_to_index() Eric Dumazet
2006-12-04 16:55 ` Christoph Lameter
2006-12-04 18:18 ` Eric Dumazet
2006-12-04 19:49 ` Andrew Morton
2006-12-04 19:55 ` Christoph Lameter
2006-12-04 21:34 ` Eric Dumazet
2006-12-04 21:56 ` David Miller
2006-12-04 22:45 ` Eric Dumazet
2006-12-05 14:42 ` Pavel Machek [this message]
2006-12-04 16:51 ` [PATCH] prune_icache_sb Russell Cattelan
2006-12-04 20:46 ` Wendy Cheng
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=20061205144159.GB4388@ucw.cz \
--to=pavel@ucw.cz \
--cc=akpm@osdl.org \
--cc=clameter@sgi.com \
--cc=dada1@cosmosbay.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.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
all inboxes | Powered by JetHome®