public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Jackson <pj@sgi.com>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: linux-kernel@vger.kernel.org, mbligh@aracnet.com, akpm@osdl.org,
	wli@holomorphy.com, colpatch@us.ibm.com
Subject: Re: [PATCH] mask ADT: new mask.h file [2/22]
Date: Tue, 6 Apr 2004 20:55:27 -0700	[thread overview]
Message-ID: <20040406205527.56317c03.pj@sgi.com> (raw)
In-Reply-To: <1081255616.28514.72.camel@bach>

Rusty suggested:
> 1) I think you only want the fastpath when it's eliminated by the
> compiler, so perhaps:
> 	if (__builtin_constant_p(nbits) && nbits <= BITS_PER_LONG)

It's not quite a cut and dried decision.

Define a 'small' system to be one where NR_CPUS <= BITS_PER_LONG, and a
'large' system to be those that aren't small.

If one had a bitmap operator called in a performance critical path on a
'small' system with a non-constant (unknown to the optimizer) bitmap
size, then one would _not_ want the above check for builtin_constant.

Leaving out the buildin_constant check results in code that checks the
variable size at runtime, performs the fast inline instructions on a
single word if it fits, else jumps to an out-of-line block of code that
calls the real __bitmap_op() function.

Since on a 'small' system, the bitmap size probably fits in a word, and
since on a performance critical path, it's worth checking for the fast
inline instruction opportunity, avoiding a jump out of line and avoiding
a real function call, the code obtained by leaving out the check for
builtin_constant is ideal.

However ... it costs you a half dozen machine instructions of text
space, for the out-of-line code block to handle the slow case that calls
the real __bitmap_op() function.

Since almost all systems are small, and since almost all bitmap operations
are not on critical paths, and since almost all bitmap operations are
called with a constant bitmap size, these half dozen machine instructions
are almost never worth a slug of warm spit.

Better to do just as Rusty suggests - if called with a non-constant
size, just say screw it and call the __bitmap_op() routine.  While that
call might not have been necessary (might even be an 'issue' in a
performance critical path), it's not worth the half-dozen machine
instructions to find out.

So I guess the real question is:

	Is it worth the slug of warm source code spit, the
	extra __builtin_constant_p(nbits) condition, to get rid
	of these six instructions for each bitmap_op() call
	made with a non-constant bitmap size?

Or the real real question - is this discussion worth a slug of warm
lkml posts ... ;)?

				===

Aha - I just built an 8 CPU SMP i386 config with my latest stuff.
Exactly one call appears to any __bitmap_* function, in the routine
bitmap_parse() of lib/bitmap.c:

	bitmap_shift_right(maskp, maskp, CHUNKSZ, nmaskbits);

Ok - change this to the following, and save six text instructions
testing for the possibility that nmaskbits < BITS_PER_LONG:

	__bitmap_shift_right(maskp, maskp, CHUNKSZ, nmaskbits);

There .. now the inline bitmap_* operators are _always_ seeing
constant bitmap sizes (for this exhaustive sampling of size one ;).

Conclusions:

     1) To heck with the extra __builtin_constant_p(nbits) condition.

	It's not worth polluting the source code with stuff to futz
	with a six instruction space/time tradeoff in some situation
	that doesn't yet exist, and if it did exist, might or might
	not want such a tradeoff.

     2) No - this post wasn't worth a slug of warm spit ;).

-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

  parent reply	other threads:[~2004-04-07  3:58 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-29 12:12 [PATCH] mask ADT: new mask.h file [2/22] Paul Jackson
2004-03-30  0:30 ` Matthew Dobson
2004-03-30  0:27   ` Paul Jackson
2004-03-30  1:56     ` Matthew Dobson
2004-03-30  0:47   ` Paul Jackson
2004-03-30  1:53     ` Matthew Dobson
2004-03-30  2:06     ` William Lee Irwin III
2004-03-30  1:31       ` Paul Jackson
2004-03-30  1:27   ` William Lee Irwin III
2004-03-30  1:27     ` Paul Jackson
2004-03-30  6:38       ` William Lee Irwin III
2004-03-30  8:45         ` Paul Jackson
2004-03-30 10:19           ` William Lee Irwin III
2004-03-31  0:16             ` Ray Bryant
2004-03-31  0:14               ` Jesse Barnes
2004-03-30  2:07     ` William Lee Irwin III
2004-04-01  0:38 ` Matthew Dobson
2004-04-01  0:58   ` Paul Jackson
2004-04-01  1:11     ` Matthew Dobson
2004-04-01  1:18       ` Paul Jackson
2004-04-01  1:27     ` Andrew Morton
2004-04-01  1:35       ` Paul Jackson
2004-04-05  1:26 ` Rusty Russell
2004-04-05  7:05   ` Paul Jackson
2004-04-05  7:42     ` Rusty Russell
2004-04-05  8:08       ` Paul Jackson
2004-04-06  4:59         ` Rusty Russell
2004-04-06  6:06           ` Paul Jackson
2004-04-06  6:23             ` Nick Piggin
2004-04-06  6:34               ` Paul Jackson
2004-04-06  6:49                 ` Nick Piggin
2004-04-06  6:59                   ` Paul Jackson
2004-04-06  7:08                   ` Paul Jackson
2004-04-06  7:03                 ` William Lee Irwin III
2004-04-06  7:33                   ` Paul Jackson
2004-04-06  6:39             ` Rusty Russell
2004-04-06  6:45               ` Paul Jackson
2004-04-06  7:24                 ` Rusty Russell
2004-04-06  7:34                   ` Paul Jackson
2004-04-06 10:40                   ` Paul Jackson
2004-04-07  0:02                     ` Rusty Russell
2004-04-07  1:49                       ` Paul Jackson
2004-04-07  3:55                       ` Paul Jackson [this message]
2004-04-06  6:55               ` Nick Piggin
2004-04-06  7:34                 ` Paul Jackson
2004-04-06  7:02               ` Paul Jackson
2004-04-05  7:46     ` Paul Jackson

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=20040406205527.56317c03.pj@sgi.com \
    --to=pj@sgi.com \
    --cc=akpm@osdl.org \
    --cc=colpatch@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbligh@aracnet.com \
    --cc=rusty@rustcorp.com.au \
    --cc=wli@holomorphy.com \
    /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