All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Travis <travis@sgi.com>
To: Bert Wesarg <bert.wesarg@googlemail.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
	Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Christoph Lameter <cl@linux-foundation.org>,
	Jack Steiner <steiner@sgi.com>,
	linux-kernel@vger.kernel.org, Paul Jackson <pj@sgi.com>
Subject: Re: [PATCH 7/8] cpumask: Provide a generic set of CPUMASK_ALLOC macros
Date: Wed, 16 Jul 2008 06:01:30 -0700	[thread overview]
Message-ID: <487DF12A.1090604@sgi.com> (raw)
In-Reply-To: <487DE8BB.5070407@sgi.com>

Mike Travis wrote:
> Bert Wesarg wrote:
...
>>> + *   CPUMASK_VAR(v, m)                 Declares cpumask_t *v =
>>> + *                                             m + offset(struct m, v)
>>                                                       offsetof
>> and why can't you use a &(m->v)?
> 
> I thought about this but what if kmalloc fails?  It's ok to add the
> offset to a NULL pointer, but dereferencing a null pointer (even though
> it's just to get the address) may introduce a fault, yes?
> 
> I'll look into this further.  

Answering my own question, apparently it is ok.  The pointer is simply used
to provide the base to which the offset is added.  

        struct allmasks *allmasks = ((void *)0);
  400557:       48 c7 45 d8 00 00 00    movq   $0x0,0xffffffffffffffd8(%rbp)
  40055e:       00

        cpumask_t *online_policy_cpus = &(allmasks->online_policy_cpus);
  40055f:       48 8b 45 d8             mov    0xffffffffffffffd8(%rbp),%rax
  400563:       48 89 45 e0             mov    %rax,0xffffffffffffffe0(%rbp)
        cpumask_t *saved_mask = &(allmasks->saved_mask);
  400567:       48 8b 45 d8             mov    0xffffffffffffffd8(%rbp),%rax
  40056b:       48 05 00 02 00 00       add    $0x200,%rax
  400571:       48 89 45 e8             mov    %rax,0xffffffffffffffe8(%rbp)
        cpumask_t *set_mask = &(allmasks->set_mask);
  400575:       48 8b 45 d8             mov    0xffffffffffffffd8(%rbp),%rax
  400579:       48 05 00 04 00 00       add    $0x400,%rax
  40057f:       48 89 45 f0             mov    %rax,0xfffffffffffffff0(%rbp)
        cpumask_t *covered_cpus = &(allmasks->covered_cpus);
  400583:       48 8b 45 d8             mov    0xffffffffffffffd8(%rbp),%rax
  400587:       48 05 00 06 00 00       add    $0x600,%rax
  40058d:       48 89 45 f8             mov    %rax,0xfffffffffffffff8(%rbp)

Sometimes the most obvious is also the most elusive... ;-)

I've updated the code and the patch description to clarify the checking
of a NULL structure base before using the cpumask_t pointers.  I've also
changed CPUMASK_VAR to CPUMASK_PTR to be a bit more clear on it's function.

  * Provide a generic set of CPUMASK_ALLOC macros patterned after the
    SCHED_CPUMASK_ALLOC macros.  This is used where multiple cpumask_t
    variables are declared on the stack to reduce the amount of stack
    space required when the NR_CPUS count is large enough to warrant it.

    Basically, if NR_CPUS <= BITS_PER_LONG then the multiple cpumask_t
    structure (which needs to be pre-defined) is declared as a local
    variable and pointers to each mask is provided.  The compiler
    will optimize out the extra dereference, resulting in code that
    is the same without the pointer reference.

    If NR_CPUS > BITS_PER_LONG, then instead of declaring the combined
    cpumask_t structure on the stack, kmalloc is used to obtain the
    memory space.  In this case, the CPUMASK_FREE is now kfree instead
    of a nop.

    For both cases, CPUMASK_PTR declares and initializes each cpumask_t
    pointer but these should *not* be used before the structure pointer
    is verified not to be NULL.  (This check for NULL will be optimized
    out for the case where the structure is declared as local memory.)

One question that remains, should the threshold to use kmalloc be
BITS_PER_LONG or something larger?  Sched uses NR_CPUS > 128, though
it has about 7 cpumask_t vars it uses.  My (obvious) concern is when
NR_CPUS is 4096 (and soon 16384), but where is the line between a
fairly large system and a really huge system?

Thanks,
Mike

  reply	other threads:[~2008-07-16 13:01 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-15 21:14 [PATCH 0/8] cpumask: Replace/optimize cpumask_of_cpu & cpumask_t operations Mike Travis
2008-07-15 21:14 ` [PATCH 1/8] cpumask: Replace cpumask_of_cpu with cpumask_of_cpu_ptr Mike Travis
2008-07-18  5:30   ` Rusty Russell
2008-07-18 13:43     ` Mike Travis
2008-07-20 10:03       ` Rusty Russell
2008-07-23 11:20         ` Ingo Molnar
2008-07-23 11:23           ` Ingo Molnar
2008-07-23 14:26             ` Mike Travis
2008-07-24  0:46               ` Rusty Russell
2008-07-23 14:16           ` Mike Travis
2008-07-23 17:45         ` Mike Travis
2008-07-15 21:14 ` [PATCH 2/8] cpumask: Optimize cpumask_of_cpu in arch/x86/kernel/io_apic_64.c Mike Travis
2008-07-15 21:14 ` [PATCH 3/8] cpumask: Optimize cpumask_of_cpu in arch/x86/kernel/ldt.c Mike Travis
2008-07-15 21:14 ` [PATCH 4/8] cpumask: Optimize cpumask_of_cpu in drivers/misc/sgi-xp/xpc_main.c Mike Travis
2008-07-16 11:17   ` Dean Nelson
2008-07-15 21:14 ` [PATCH 5/8] cpumask: Optimize cpumask_of_cpu in kernel/time/tick-common.c Mike Travis
2008-07-15 21:14 ` [PATCH 6/8] cpumask: Optimize cpumask_of_cpu in lib/smp_processor_id.c Mike Travis
2008-07-18 20:33   ` Ingo Molnar
2008-07-18 20:35     ` Ingo Molnar
2008-07-18 22:36       ` Mike Travis
2008-07-15 21:14 ` [PATCH 7/8] cpumask: Provide a generic set of CPUMASK_ALLOC macros Mike Travis
2008-07-16  6:41   ` Bert Wesarg
2008-07-16 12:25     ` Mike Travis
2008-07-16 13:01       ` Mike Travis [this message]
2008-07-15 21:14 ` [PATCH 8/8] cpumask: Use optimized CPUMASK_ALLOC macros in the centrino_target Mike Travis
2008-07-18 20:04 ` [PATCH 0/8] cpumask: Replace/optimize cpumask_of_cpu & cpumask_t operations Ingo Molnar

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=487DF12A.1090604@sgi.com \
    --to=travis@sgi.com \
    --cc=akpm@linux-foundation.org \
    --cc=bert.wesarg@googlemail.com \
    --cc=cl@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=pj@sgi.com \
    --cc=rusty@rustcorp.com.au \
    --cc=steiner@sgi.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 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.