[Patch 24a/23] mask v2 - UP fix, faster mask_of_bit, MASK_ALL* names

From: Paul Jackson (pj_at_sgi.com)
Date: 04/04/04

  • Next message: James Morris: "[SELINUX] Add IPv6 support"
    Date:	Sat, 3 Apr 2004 22:16:41 -0800
    To: Paul Jackson <pj@sgi.com>
    
    

    This patch replaces 24/23. Patch 24/23 was fouled up beyond all recall.

    This patch 24a/23 applies after the 23 mask v2 patches 1/23 - 23/23,
    based on the 2.6.4 Linux kernel.

    It closely follows some excellent suggestions from Matthew.

    1) It corrects a build error for UP (1 CPU, no SMP).
       Real cpu_online_map and cpu_possible_map data words are
       needed, so that cpumask_of_cpu() will evalutate correctly
       when in used in contexts requiring a real lvalue, as in
       sys_sched_getaffinity().

    2) Since the MASK_ALL* implementation alternatives (for the
       single long and multiple long cases) are split across the
       base mask.h file and the derived cpumask.h/nodemask.h files,
       rename them to MASK_ALL_SINGLE_LONG/MASK_ALL_MULTIPLE_LONG,
       as suggested by Matthew, for code clarity.

    3) Optimize the single word flavor of mask_of_bit (resulting
       in better code on small systems for cpumask_of_cpu).

    The mask.h header is once again (still, if you don't count 24/23) usable
    in its own right.

    Diffstat:
     include/linux/cpumask.h | 11 ++++-------
     include/linux/mask.h | 12 ++++++++----
     include/linux/nodemask.h | 4 ++--
     kernel/sched.c | 5 +++++
     4 files changed, 19 insertions(+), 13 deletions(-)

    diff -Naur Apr01/include/linux/cpumask.h Apr03/include/linux/cpumask.h
    --- Apr01/include/linux/cpumask.h 2004-04-03 19:51:42.000000000 -0800
    +++ Apr03/include/linux/cpumask.h 2004-04-03 19:41:04.000000000 -0800
    @@ -92,9 +92,9 @@
     #define next_cpu(cpu, mask) mask_next((cpu), (mask), NR_CPUS)
     #define cpumask_of_cpu(cpu) mask_of_bit((cpu), _unused_cpumask_arg_)
     #if NR_CPUS <= BITS_PER_LONG
    -#define CPU_MASK_ALL MASK_ALL1(NR_CPUS)
    +#define CPU_MASK_ALL MASK_ALL_SINGLE_LONG(NR_CPUS)
     #else
    -#define CPU_MASK_ALL MASK_ALL2(NR_CPUS)
    +#define CPU_MASK_ALL MASK_ALL_MULTIPLE_LONG(NR_CPUS)
     #endif
     #define CPU_MASK_NONE MASK_NONE(NR_CPUS)
     #define cpus_addr(mask) mask_addr(mask)
    @@ -108,11 +108,11 @@
      * on them manage all (possible) and online cpus.
      */
     
    -#ifdef CONFIG_SMP
    -
     extern cpumask_t cpu_online_map;
     extern cpumask_t cpu_possible_map;
     
    +#ifdef CONFIG_SMP
    +
     #define num_online_cpus() cpus_weight(cpu_online_map)
     #define num_possible_cpus() cpus_weight(cpu_possible_map)
     #define cpu_online(cpu) cpu_isset((cpu), cpu_online_map)
    @@ -134,9 +134,6 @@
     
     #else /* !CONFIG_SMP */
     
    -#define cpu_online_map cpumask_of_cpu(0)
    -#define cpu_possible_map cpumask_of_cpu(0)
    -
     #define num_online_cpus() 1
     #define num_possible_cpus() 1
     #define cpu_online(cpu) ({ BUG_ON((cpu) != 0); 1; })
    diff -Naur Apr01/include/linux/mask.h Apr03/include/linux/mask.h
    --- Apr01/include/linux/mask.h 2004-04-03 19:51:41.000000000 -0800
    +++ Apr03/include/linux/mask.h 2004-04-03 20:21:19.000000000 -0800
    @@ -334,19 +334,23 @@
     #define mask_of_bit(bit, T) \
     ({ \
             typeof(T) m; \
    - mask_clearall(m, 8*sizeof(m)); \
    - mask_setbit((bit), m); \
    + if (sizeof(m) == sizeof(unsigned long)) \
    + m._m[0] = 1UL<<(bit); \
    + else { \
    + mask_clearall(m, 8*sizeof(m)); \
    + mask_setbit((bit), m); \
    + } \
             m; \
     })
     
     /* Use if nbits <= BITS_PER_LONG */
    -#define MASK_ALL1(nbits) \
    +#define MASK_ALL_SINGLE_LONG(nbits) \
     { { \
             [BITS_TO_LONGS(nbits)-1] = MASK_LAST_WORD(nbits) \
     } }
     
     /* Use if nbits > BITS_PER_LONG */
    -#define MASK_ALL2(nbits) \
    +#define MASK_ALL_MULTIPLE_LONG(nbits) \
     { { \
             [0 ... BITS_TO_LONGS(nbits)-2] = ~0UL, \
             [BITS_TO_LONGS(nbits)-1] = MASK_LAST_WORD(nbits) \
    diff -Naur Apr01/include/linux/nodemask.h Apr03/include/linux/nodemask.h
    --- Apr01/include/linux/nodemask.h 2004-04-03 19:51:42.000000000 -0800
    +++ Apr03/include/linux/nodemask.h 2004-04-03 19:41:04.000000000 -0800
    @@ -93,9 +93,9 @@
     #define nodemask_of_node(node) \
                             mask_of_bit((node), _unused_nodemask_arg_)
     #if MAX_NUMNODES <= BITS_PER_LONG
    -#define NODE_MASK_ALL MASK_ALL1(MAX_NUMNODES)
    +#define NODE_MASK_ALL MASK_ALL_SINGLE_LONG(MAX_NUMNODES)
     #else
    -#define NODE_MASK_ALL MASK_ALL2(MAX_NUMNODES)
    +#define NODE_MASK_ALL MASK_ALL_MULTIPLE_LONG(MAX_NUMNODES)
     #endif
     #define NODE_MASK_NONE MASK_NONE(MAX_NUMNODES)
     #define nodes_addr(mask) mask_addr(mask)
    diff -Naur Apr01/kernel/sched.c Apr03/kernel/sched.c
    --- Apr01/kernel/sched.c 2004-04-03 19:51:42.000000000 -0800
    +++ Apr03/kernel/sched.c 2004-04-03 19:41:05.000000000 -0800
    @@ -2340,6 +2340,11 @@
             return retval;
     }
     
    +#ifndef CONFIG_SMP
    +cpumask_t cpu_online_map = CPU_MASK_ALL;
    +cpumask_t cpu_possible_map = CPU_MASK_ALL;
    +#endif
    +
     /**
      * sys_sched_getaffinity - get the cpu affinity of a process
      * @pid: pid of the process

    -- 
                              I won't rest till it's the best ...
                              Programmer, Linux Scalability
                              Paul Jackson <pj@sgi.com> 1.650.933.1373
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: James Morris: "[SELINUX] Add IPv6 support"

    Relevant Pages

    • [2.6 patch] net/ipv6/: misc cleanups
      ... OK, updated patch below. ... static void sf_markstate(struct ifmcaddr6 *pmc); ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • [BK PATCHES] 2.6.x net driver updates
      ... through these ChangeSets: ... This patch does an indentation fix to amd8111e_rx_pollwhich was ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: 2.6.3-mm3 hangs on boot x440 (scsi?)
      ... any ideas why the patch fails if the system has an ACPI ... expanded-pci-config-space.patch and tell me whether it continues to fail ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: memory leaks in 2.6.6...
      ... > Thanks to smatch I have found few memory leaks and other related issues ... See the patch in attachment. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Using get_cycles for add_timer_randomness
      ... /dev/random on ppc64 before and after this patch, ... Since many architectures have a working get_cycles ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)