在Linux内核中,CPU mask机制被用于表示系统中多个处理器的各种组合,正在被重新修改。修改的原因是CPU masks通常放在堆栈上,但是随着处理器数量的增长将消耗堆栈上大量的空间。新设计的API可以将CPU masks从堆栈上移出来.

问题:
两个明显的问题是:
   1. 将CPU masks放在堆栈上限制了NR_CPUS只能接近128(但是人们期望NR_CPUS能够为4096甚至更高), 而且
   2. 拍打式地解决问题(whack-a-mole attempts to fix the worst offenders),只能使问题越变越糟,最终解决不了问题。

目标:
   1) 当CONFIG_CPUMASK_OFFSTACK=y时cpumasks不再放在堆栈上。
      当CONFIG_CPUMASK_OFFSTACK=n时cpumask_var_t为struct cpumask[1](而且alloc_cpumask_var等为空操作)。
   2) Convert to new cpumask functions which .ly go to nr_cpu_ids for large NR_CPUS, so booting huge configured kernels . small machines doesn't suck.
   3) 当CONFIG_CPUMASK_OFFSTACK=y时,nr_cpu_ids < NR_CPUS时分配空间更小的cpumasks, 这需要完成(2).
   4) 只有在真正必要时才将cpumask_var_t用于static cpumasks或原始的bitmaps,前者在nr_cpu_ids << NR_CPUS时可以节省空间。
   5) 当CONFIG_CPUMASK_OFFSTACK=y时struct cpumask将为undefined,以禁止在堆栈上对cpumasks (确保(1))和cpumask赋值(用于(3))。这需要完成(4).

预计在2.6.30版本时完成上述目标.

注意:我们并不能禁止人们在堆栈上创建bitmaps of NR_CPUS以及使用to_cpumask()。但至少应当明确指出问题所在。

解决方法:
    为了避免变化太大,引入另外一套cpumask API,当所有的都处理完成后再废弃旧的API。
    * 第一步是替换cpus_*函数. 新的接口以cpumask_为起始字符; 这些新函数以(const) struct cpumask指针为参数, 只能操作一些bit位(若操作的bit位数量少则为CONFIG_NR_CPUS,否则为nr_cpu_ids). 替换方法如下:
          for_each_cpu_mask(i, my_cpumask)
              ...
          if (i == NR_CPUS)
      最后一步替换为"(i >= nr_cpu_ids)"后才安全:
          for_each_cpu(i, &my_cpumask)
              ...
          if (i >= nr_cpu_ids)

* 接下来是废弃cpumask_t和NR_CPUS (现在CONFIG_NR_CPUS即使对!SMP也有定义).
    * 引入cpumask_var_t来替换cpumask_t定义(除了作为函数参数和返回值以外,总是 (const) struct cpumask *). 对大多数人来说这就是struct cpumask[1],而且alloc_cpumask_var/free_cpumask_var为空操作。否则当CONFIG_CPUMASK_OFFSTACK=y时是一个cpumask指针。
    * alloc_cpumask_var现在分配所有的CONFIG_NR_CPUS比特位,并将nr_cpu_ids和NR_CPUS之间的所有比特位清零。以后将被修改为仅仅做分配操作。
    * 增加了一些新函数以便不再需要临时的cpumasks. 两个最有用的函数是for_each_cpu_and() (对两个cpumasks的intersection的遍历)和cpu_any_but() (排除一个cpu进行操作).
    * 基于类似目的新增work_on_cpu()函数,目的是临时设置当前thread的cpus_allowed以便在一个特定的CPU上执行。增加该函数的原因是此时需要一个临时的cpumask,另外很容易出bug因为要与用户空间对thread设置cpumask存在竞争。
    * 新增to_cpumask()将raw bitmaps转换为struct cpumask *.
    * cpu_online_mask/cpu_possible_mask等为const (替换的是存在指针的cpu_online_map/cpu_possible_map)。这意味着只有很少数的情况操作cpu, 否则可以使用新增的set_cpu_online()/set_cpu_possible()或init_cpu_online()/init_cpu_possible() 函数。
    * 一旦所有的cpumask_t (即struct cpumask)都被删除后,当CONFIG_CPUMASK_OFFSTACK=y时'struct cpumask'将不再有定义。

希望最终可以满足SGI人员的期望,可设置CONFIG_NR_CPUS为16384。

以下是cpu mask近期的一些修改历史,see also cpumask tree in [url]http://lwn.net/Articles/313345/.[/url]
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Sat Dec 13 21:19:41 2008 +1030

cpumask: centralize cpu_online_map and cpu_possible_map
   
    Impact: cleanup
   
    Each SMP arch defines these themselves.  Move them to a central
    location.
   
    Twists:
    1) Some archs (m32, parisc, s390) set possible_map to all 1, so we add a
       CONFIG_INIT_ALL_POSSIBLE for this rather than break them.
   
    2) mips and sparc32 '#define cpu_possible_map phys_cpu_present_map'.
       Those archs simply have phys_cpu_present_map replaced everywhere.
   
    3) Alpha defined cpu_possible_map to cpu_present_map; this is tricky
       so I just manipulate them both in sync.
   
    4) IA64, cris and m32r have gratuitous 'extern cpumask_t cpu_possible_map'
       declarations.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Sat Dec 13 21:20:25 2008 +1030

cpumask: 改变cpumask_scnprintf, cpumask_parse_user, cpulist_parse, and cpulist_scnprintf函数参数为指针.
   
    Impact: change calling convention of existing cpumask APIs
   
    大多数cpumask函数以cpus_为起始串,这些被以struct cpumask指针为参数的cpumask_XXX替换
   
    这4个函数没有好的替换名称,但幸运的是这几个函数很少使用, 因而直接修改。
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Sat Dec 13 21:20:26 2008 +1030

cpumask: make irq_set_affinity() take a const struct cpumask
   
    Impact: change existing irq_chip API
   
    Not much point with gentle transition here: the struct irq_chip's
    setaffinity method signature needs to change.
   
    Fortunately, not widely used code, but hits a few architectures.
   
    Note: In irq_select_affinity() I save a temporary in by mangling
    irq_desc[irq].affinity directly.  Ingo, does this break anything?
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Sat Dec 13 21:20:26 2008 +1030

cpumask: convert struct clock_event_device to cpumask pointers.
   
    Impact: change calling convention of existing clock_event APIs
   
    struct clock_event_timer's cpumask field gets changed to take pointer,
    as does the ->broadcast function.
   
    Another single-patch change.  For safety, we BUG_ON() in
    clockevents_register_device() if it's not set.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Sat Dec 13 21:20:27 2008 +1030

cpumask: Add CONFIG_CPUMASK_OFFSTACK
   
    Impact: Add config option to enable code in cpumask.h
   
    Currently it can be set if DEBUG_PER_CPU_MAPS, or set specifically by
    an arch.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Sat Dec 13 21:20:27 2008 +1030

cpumask: Introduce cpumask_of_{node,pcibus} to replace {node,pcibus}_to_cpumask
   
    Impact: New APIs
   
    The old node_to_cpumask/node_to_pcibus returned a cpumask_t: these
    return a pointer to a struct cpumask.  Part of removing cpumasks from
    the stack.
   
    This defines them in the generic non-NUMA case.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Sat Dec 13 21:20:28 2008 +1030

cpumask: Use all NR_CPUS bits unless CONFIG_CPUMASK_OFFSTACK
   
    Impact: futureproof as we convert more code to new APIs
   
    The old cpumask operators treat all NR_CPUS bits as relevent, the new
    .es use nr_cpumask_bits.  For large NR_CPUS and small nr_cpu_ids, this
    makes a difference.
   
    However, mixing the two can cause problems with undefined bits.  An
    arch which sets CONFIG_CPUMASK_OFFSTACK should have converted across
    to the new operators, so it's safe in that case.
   
    (Thanks to Stephen Rothwell for bisecting the initial unused-bits bug,
    and Mike Travis for this solution).
   
Author: Mike Travis <[email]travis@sgi.com[/email]>
Date:   Fri Dec 19 16:56:37 2008 +1030

cpumask: Add alloc_cpumask_var_node()
   
    Impact: New API
   
    This will be needed in x86 code to allocate the domain and old_domain
    cpumasks . the same node as where the containing irq_cfg struct is
    allocated.
   
    (Also fixes double-dump_stack . rare CONFIG_DEBUG_PER_CPU_MAPS case)
   
Author: Mike Travis <[email]travis@sgi.com[/email]>
Date:   Fri Dec 19 16:56:52 2008 +1030

cpumask: documentation for cpumask_var_t
   
    Impact: New kerneldoc comments
   
    Additional documentation added to all the alloc_cpumask and free_cpumask
    functions.
   
Author: Mike Travis <[email]travis@sgi.com[/email]>
Date:   Mon Dec 15 20:26:48 2008 -0800

cpumask: add sysfs displays for configured and disabled cpu maps
   
    Impact: add new sysfs files.
   
    Add sysfs files "kernel_max" and "offline" to display the max CPU index
    allowed (NR_CPUS-1), and the map of cpus that are offline.
   
    Cpus can be offlined via HOTPLUG, disabled by the BIOS ACPI tables, or
    if they exceed the number of cpus allowed by the NR_CPUS config option,
    or the "maxcpus=NUM" kernel start parameter.
   
    The "possible_cpus=NUM" parameter can also extend the number of possible
    cpus allowed, in which case the cpus not present at startup will be
    in the offline state.  (These cpus can be HOTPLUGGED . after system
    startup [pending a follow-on patch to provide the capability via the
    /sys/devices/sys/cpu/cpuN/online mechanism to bring them .line.])
   
    By design, the "offlined cpus > possible cpus" display will always
    use the following formats:
   
      * all possible cpus .line:   "x$"    or "x-y$"
      * some possible cpus offline: ".*,x$" or ".*,x-y$"
   
    where:
      x == number of possible cpus (nr_cpu_ids); and
      y == number of cpus >= NR_CPUS or maxcpus (if y > x).
   
    .e use of this feature is for distros to select (or configure) the
    appropriate kernel to install for the resident system.
   
    Notes:
      * cpus offlined <= possible cpus will be printed for all architectures.
      * cpus offlined >  possible cpus will .ly be printed for arches that
          set 'total_cpus' [X86 .ly in this patch].
   
    Based . tip/cpus4096 + .../rusty/linux-2.6-for-ingo.git/master +
         x86-only-patches sent 12/15.
   
Author: Mike Travis <[email]travis@sgi.com[/email]>
Date:   Wed Dec 17 14:14:30 2008 -0800

sysfs: add documentation to cputopology.txt for system cpumasks
   
    Add information to cputopology.txt explaining the output of various
    system cpumask's.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Fri Dec 26 22:23:38 2008 +1030

cpumask: x86: Introduce cpumask_of_{node,pcibus} to replace {node,pcibus}_to_cpumask
   
    Impact: New APIs
   
    The old node_to_cpumask/node_to_pcibus returned a cpumask_t: these
    return a pointer to a struct cpumask.  Part of removing cpumasks from
    the stack.
   
    Also makes __pcibus_to_node take a const pointer.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Fri Dec 26 22:23:38 2008 +1030

cpumask: sparc: Introduce cpumask_of_{node,pcibus} to replace {node,pcibus}_to_cpumask
   
    Impact: New APIs
   
    The old node_to_cpumask/node_to_pcibus returned a cpumask_t: these
    return a pointer to a struct cpumask.  Part of removing cpumasks from
    the stack.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Fri Dec 26 22:23:39 2008 +1030

cpumask: sh: Introduce cpumask_of_{node,pcibus} to replace {node,pcibus}_to_cpumask
   
    Impact: New APIs
   
    The old node_to_cpumask/node_to_pcibus returned a cpumask_t: these
    return a pointer to a struct cpumask.  Part of removing cpumasks from
    the stack.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Fri Dec 26 22:23:39 2008 +1030

cpumask: powerpc: Introduce cpumask_of_{node,pcibus} to replace {node,pcibus}_to_cpumask
   
    Impact: New APIs
   
    The old node_to_cpumask/node_to_pcibus returned a cpumask_t: these
    return a pointer to a struct cpumask.  Part of removing cpumasks from
    the stack.
   
    (Also replaces powerpc internal uses of node_to_cpumask).
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Fri Dec 26 22:23:40 2008 +1030

cpumask: IA64: Introduce cpumask_of_{node,pcibus} to replace {node,pcibus}_to_cpumask
   
    Impact: New APIs
   
    The old node_to_cpumask/node_to_pcibus returned a cpumask_t: these
    return a pointer to a struct cpumask.  Part of removing cpumasks from
    the stack.
   
    We can also use the new for_each_cpu_and() to avoid a temporary cpumask,
    and a gratuitous test in sn_topology_show.
   
    (Includes fix from KOSAKI Motohiro <[email]kosaki.motohiro@jp.fujitsu.com[/email]>)
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Fri Dec 26 22:23:40 2008 +1030

cpumask: Mips: Introduce cpumask_of_{node,pcibus} to replace {node,pcibus}_to_cpumask
   
    Impact: New APIs
   
    The old node_to_cpumask/node_to_pcibus returned a cpumask_t: these
    return a pointer to a struct cpumask.  Part of removing cpumasks from
    the stack.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Fri Dec 26 22:23:41 2008 +1030

cpumask: alpha: Introduce cpumask_of_{node,pcibus} to replace {node,pcibus}_to_cpumask
   
    Impact: New APIs
   
    The old node_to_cpumask/node_to_pcibus returned a cpumask_t: these
    return a pointer to a struct cpumask.  Part of removing cpumasks from
    the stack.
   
    I'm not sure the existing code even compiles, but new version is
    straightforward.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Fri Dec 26 22:23:41 2008 +1030

cpumask: cpu_coregroup_mask(): x86
   
    Impact: New API
   
    Like cpu_coregroup_map, but returns a (const) pointer.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Fri Dec 26 22:23:42 2008 +1030

cpumask: cpu_coregroup_mask(): sparc
   
    Like cpu_coregroup_map, but returns a (const) pointer.
   
    Compile-tested . sparc64 (defconfig).
   
commit 9be3eec2c83848a1ca57ebad13c63c95d0df01e2
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Fri Dec 26 22:23:42 2008 +1030

cpumask: cpu_coregroup_mask(): s390
   
    Like cpu_coregroup_map, but returns a (const) pointer.
   
    Compile-tested . s390 (defconfig).
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Fri Dec 26 22:23:43 2008 +1030

cpumask: 用cpu_coregroup_mask替换cpu_coregroup_map。
   
    cpu_coregroup_map返回类型为cpumask_t, 将被废弃.
   
Merge: be4d638... 3c92ec8...
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 08:02:35 2008 +1030

Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6

Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 09:05:12 2008 +1030

cpumask: make CONFIG_NR_CPUS always valid.
   
    Impact: cleanup
   
    目前有NR_CPUS宏, 在UP上为1, 在SMP上为CONFIG_NR_CPUS. 
    若总是设置CONFIG_NR_CPUS为有效(在!SMP上总是为1),则可以跳过中间代码。
   
    This also allows us to find and check all the unaudited NR_CPUS usage
    as we prepare for v. large NR_CPUS.
   
    To avoid breaking every arch, we cheat and do this for the moment
    in the header if the arch doesn't.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 09:05:13 2008 +1030

bitmap: test for constant as well as small size for inline versions
   
    Impact: 减少text段size
   
    对nbits <= BITS_PER_LONG,bitmap_zero等有一个fastpath, 但只有在编译时知道nbits才能真正应用。
   
    This .ly saves about 1200 bytes . an allyesconfig kernel, but with
    cpumasks going variable that number will increase.
   
       text        data    bss    dec        hex    filename
    35327852        5035607 6782976 47146435        2cf65c3 vmlinux-before
    35326640        5035607 6782976 47145223        2cf6107 vmlinux-after
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 09:05:14 2008 +1030

bitmap: fix seq_bitmap and seq_cpumask to take const pointer
   
    Impact: cleanup
   
    seq_bitmap just calls bitmap_scnprintf . the bits: that arg can be const.
    Similarly, seq_cpumask just calls seq_bitmap.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 09:05:14 2008 +1030

cpumask: switch over to cpu_online/possible/active/present_mask: core
   
    Impact: cleanup
   
    This implements the obsolescent cpu_online_map in terms of
    cpu_online_mask, rather than the other way around.  Same for the other
    maps.
   
    The documentation comments are also updated to refer to _mask rather
    than _map.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 09:05:15 2008 +1030

cpumask: make cpumask.h eat its own dogfood.
   
    Changes:
    1) cpumask_t to struct cpumask,
    2) cpus_weight_nr to cpumask_weight,
    3) cpu_isset to cpumask_test_cpu,
    4) ->bits to cpumask_bits()
    5) cpu_*_map to cpu_*_mask.
    6) for_each_cpu_mask_nr to for_each_cpu
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 09:05:16 2008 +1030

cpumask: make set_cpu_*/init_cpu_* out-of-line
   
    They're .ly for use in boot/cpu hotplug code anyway, and this avoids
    the use of deprecated cpu_*_map.
   
    Stephen Rothwell points out that gcc 4.2.4 (on powerpc at least)
    didn't like the cast away of const anyway:
   
      include/linux/cpumask.h: In function 'set_cpu_possible':
      include/linux/cpumask.h:1052: warning: passing argument 2 of 'cpumask_set_cpu' discards qualifiers from pointer target

type
   
    So this kills two birds with .e stone.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 09:05:16 2008 +1030

cpumask: smp_call_function_many()
   
    Impact: Implementation change to remove cpumask_t from stack.
   
    Actually change smp_call_function_mask() to smp_call_function_many().
    We avoid cpumasks . the stack in this version.
   
    (S390 has its own version, but that's going away apparently).
   
    We have to do some dancing to figure out if 0 or 1 other cpus are in
    the mask supplied and the .line mask without allocating a tmp
    cpumask.  It's still fairly cheap.
   
    We allocate the cpumask at the end of the call_function_data
    structure: if allocation fails we fallback to smp_call_function_single
    rather than using the baroque quiescing code (which needs a cpumask .
    stack).
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 09:05:17 2008 +1030

cpumask: arch_send_call_function_ipi_mask: core
   
    Impact: new API to reduce stack usage
   
    We're weaning the core code off handing cpumask's around .-stack.
    This introduces arch_send_call_function_ipi_mask().
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 09:05:17 2008 +1030

cpumask: use for_each_online_cpu() in drivers/infiniband/hw/ehca/ehca_irq.c
   
    Impact: cleanup
   
    In future, accessing cpu numbers beyond nr_cpu_ids (the runtime limit)
    will be undefined.  We can avoid future problems by using
    for_each_online_cpu() here.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 09:05:18 2008 +1030

cpumask: use new cpumask API in drivers/infiniband/hw/ehca
   
    Impact: cleanup
   
    We're moving from handing around cpumask_t's to handing around struct
    cpumask *'s.  cpus_*, cpumask_t and cpu_*_map are deprecated: convert
    to cpumask_*, cpu_*_mask.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 09:05:18 2008 +1030

cpumask: use new cpumask API in drivers/infiniband/hw/ipath
   
    Impact: cleanup
   
    We're moving from handing around cpumask_t's to handing around struct
    cpumask *'s.  cpus_*, cpumask_t and cpu_*_map are deprecated: convert
    to cpumask_*, cpu_*_mask.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Tue Dec 30 09:05:19 2008 +1030

cpumask: Use nr_cpu_ids in seq_cpumask
   
    Impact: cleanup, futureproof
   
    nr_cpu_ids is the (badly named) runtime limit . possible CPU numbers;
    ie. the variable version of NR_CPUS.
   
    With the new cpumask operators, .ly bits less than this are defined.
    So we should use it everywhere, rather than NR_CPUS.  Eventually this
    will make it possible to allocate cpumasks of the minimal length at runtime.

Merge: e12f010... 6a94cb7...
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Wed Dec 31 23:05:57 2008 +1030

Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
   
    Conflicts:
   
        arch/x86/kernel/io_apic.c

Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:13 2009 +1030

cpumask: Remove IA64 definition of total_cpus now it's in core code
   
    Impact: fix IA64 compile
   
    Fortunately, they have exactly the same semantics.
   
Author: Li Zefan <[email]lizf@cn.fujitsu.com[/email]>
Date:   Wed Dec 31 16:45:50 2008 +0800

cpumask: fix bogus kernel-doc
   
    Impact: fix kernel-doc
   
    alloc_bootmem_cpumask_var() returns avoid.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:14 2009 +1030

percpu: fix percpu accessors to potentially !cpu_possible() cpus: pnpbios
   
    Impact: CPU iterator bugfixes
   
    Percpu areas are .ly allocated for possible cpus.  In general, you
    shouldn't access random cpu's percpu areas.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:14 2009 +1030

percpu: fix percpu accessors to potentially !cpu_possible() cpus: m32r
   
    Impact: CPU iterator bugfixes
   
    Percpu areas are .ly allocated for possible cpus.  In general, you
    shouldn't access random cpu's percpu areas.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:15 2009 +1030

cpumask: prepare for iterators to .ly go to nr_cpu_ids/nr_cpumask_bits.: core
   
    Impact: cleanup
   
    In future, all cpumask ops will .ly be valid (in general) for bit
    numbers < nr_cpu_ids.  So use that instead of NR_CPUS in iterators
    and other comparisons.
   
    This is always safe: no cpu number can be >= nr_cpu_ids, and
    nr_cpu_ids is initialized to NR_CPUS at boot.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:15 2009 +1030

cpumask: Use accessors code in core
   
    Impact: use new API
   
    cpu_*_map are going away in favour of cpu_*_mask, but const pointers.
    So we have accessors where we really do want to frob them.  Archs
    will also need the (trivial) conversion before we can finally remove
    cpu_*_map.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:16 2009 +1030

parisc: remove gratuitous cpu_online_map declaration.
   
    This is defined in linux/cpumask.h (included in this file already),
    and this is now defined differently.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:16 2009 +1030

avr32: define __fls
   
    Like fls, but can't be handed 0 and returns the bit number.
   
    (I broke this arch in linux-next by using __fls in generic code).
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:17 2009 +1030

blackfin: define __fls
   
    Like fls, but can't be handed 0 and returns the bit number.
   
    (I broke this arch in linux-next by using __fls in generic code).
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:18 2009 +1030

m68k: define __fls
   
    Like fls, but can't be handed 0 and returns the bit number.
   
    (I broke this arch in linux-next by using __fls in generic code).
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:18 2009 +1030

m68knommu: define __fls
   
    Like fls, but can't be handed 0 and returns the bit number.
   
    (I broke this arch in linux-next by using __fls in generic code).
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:19 2009 +1030

bitmap: find_last_bit()
   
    Impact: New API
   
    As the name suggests.  For the moment everyone uses the generic .e.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:19 2009 +1030

cpumask: Use find_last_bit()
   
    Impact: cleanup
   
    There's .e obvious place to use it: to find the highest possible cpu.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:21 2009 +1030

cpumask: Introduce topology_core_cpumask()/topology_thread_cpumask(): ia64/powerpc/s390
/sparc
   
    Impact: New API
   
    老的topology_core_siblings() and topology_thread_siblings()返回cpumask_t;
    新函数返回类型为(const) struct cpumask *.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:22 2009 +1030

cpumask: convert kernel trace functions
   
    Impact: Reduce future memory usage, use new cpumask API.
   
    (最终将根据nr_cpu_ids而不是NR_CPUS来为cpumask_var_t分配空间.
   
    Convert kernel trace functions to use struct cpumask API:
    1) Use cpumask_copy/cpumask_test_cpu/for_each_cpu.
    2) Use cpumask_var_t and alloc_cpumask_var/free_cpumask_var everywhere.
    3) Use ._each_cpu instead of playing with current->cpus_allowed.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:23 2009 +1030

cpumask: convert kernel trace functions further
   
    Impact: Reduce future memory usage, use new cpumask API.
   
    Since the last patch was created and acked, more old cpumask users
    slipped into kernel/trace.
   
    Mostly trivial conversions, except struct trace_iterator's "started"
    member becomes a cpumask_var_t.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:24 2009 +1030

cpumask: remove any_online_cpu() users: mm/
   
    Impact: 删除废弃的API usage
   
    any_online_cpu()函数名不错, 但参数为cpumask_t, 而不是指针.
   
    有几处地方any_online_cpu()的参数并不需要mask.
    用cpumask_any()和cpumask_any_and()替换所有的callers.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:24 2009 +1030

cpumask: convert kernel/compat.c
   
    Impact: 减少内存的使用, 使用新的cpumask API.
   
    直接转换; 通过cpumask_size()给出cpumasks的size(现在是一个变量而不是固定值),
    使用cpumask_var_t作为堆栈上的cpu masks.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:25 2009 +1030

cpumask: convert kernel/workqueue.c
   
    Impact: 减少内存的使用, 使用新的cpumask API.
   
    cpu_populated_map成为一个cpumask_var_t, and cpu_singlethread_map简化为一个cpumask指针:
    it's simply the cpumask containing the first possible CPU anyway.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:25 2009 +1030

cpumask: convert kernel time functions
   
    Impact: 使用新的APIs
   
    将kernel/time中的函数改用struct cpumask *.
   
    注意在tick-broadcast.c中使用的很糟糕的bitmap声明,应当为cpumask_var_t,
    but there was no obvious initialization function to
    put the alloc_cpumask_var() calls in.  This was safe.
   
    (对于CONFIG_CPUMASK_OFFSTACK'struct cpumask'最终将变为undefined,所以这里使用bitmap表示我们真正的含义).
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:26 2009 +1030

cpumask: convert kernel/irq
   
    Impact: 减少内核堆栈的使用, 使用新的cpumask API.  ALPHA mod!
   
    主要改变是irq_default_affinity成为一个cpumask_var_t, 所以将它视为一个指针.(this effects alpha).
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:26 2009 +1030

cpumask: convert RCU implementations
   
    Impact: 使用新的cpumask API.
   
    rcu_ctrlblk中包含了一个cpumask而且代码已经很优化,因而当配置了CONFIG_CPUMASK_OFFSTACK时不想使用cpumask_var_t (即指针方式).
    可以用一个dangling bitmap, 并在__rcu_init中分配空间以接生内存,但是目前仍然使用bitmap.
   
    (对于CONFIG_CPUMASK_OFFSTACK'struct cpumask'最终将变为undefined,所以这里使用bitmap表示我们真正的含义).
   
    对rcu_torture_shuffle_tasks()和force_quiescent_state()中的for_each_cpu_and, 使用cpumask_var_t以便删除堆栈上的cpumasks.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:27 2009 +1030

cpumask: convert kernel/profile.c
   
    Impact: 减少内核堆栈和内存的使用,使用新的cpumask API.
   
    prof_cpu_mask中不再使用静态的cpumask_t, prof_cpu_mask_write_procand中不再使用堆栈上的cpumask_t。
    两者都使用cpumask_var_t.
   
    只有当profiling为on时才分配prof_cpu_mask, 但对于!CPUMASK_OFFSTACK GCC可以将NULL检查优化掉。
   
    而且删除了一些奇怪的和不必要的类型映射。
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:28 2009 +1030

cpumask: convert kernel/cpu.c
   
    Impact: 减少内核堆栈和内存的使用,使用新的cpumask API.
   
    Use cpumask_var_t for take_cpu_down() stack var, and frozen_cpus.
   
    注意:在core_initcall分配frozen_cpus之前可以调用notify_cpu_starting(),
    但是当CONFIG_CPUMASK_OFFSTACK=n时GCC可以将NULL检查优化掉。
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:28 2009 +1030
    cpumask: convert rest of files in kernel/
   
    Impact: Reduce stack usage, use new cpumask API.
   
    主要将cpumask_t改变为'struct cpumask',并将一些简单的API进行了修改。
    主要是两个函数:
   
    1) 在kernel/softlockup.c中使用cpumask_any_but来避免临时变量,
    2) 在taskstats_user_cmd()中使用cpumask_var_t.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:29 2009 +1030

cpumask: convert mm/
   
    Impact: Use new API
   
    将内核mm functions转换为使用struct cpumask.
   
    We skip include/linux/percpu.h and mm/allocpercpu.c, which are in flux.
   
Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:29 2009 +1030

cpumask: replace for_each_cpu_mask_nr with for_each_cpu in kernel/time/
   
    Impact: cleanup
   
    简单替换,现在使用_nr是多余的了。

Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:30 2009 +1030

cpumask: zero extra bits in alloc_cpumask_var_node
   
    Impact: extra safety checks during transition
   
    当设置了CONFIG_CPUMASKS_OFFSTACK, 新的cpumask_XXX操作仅用到最多nr_cpu_ids个比特,而不是NR_CPUS。
    使用原来的cpus_XXX操作这些masks将会访问到没有定义的bits.
   
    所以,现在在alloc_cpumask_var_node()中将没有定义的bits清零,直到所有的老的cpumask函数都被删除。

Author: Rusty Russell <[email]rusty@rustcorp.com.au[/email]>
Date:   Thu Jan 1 10:12:30 2009 +1030

cpumask: CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS
   
    Impact: new debug CONFIG options
   
    这有助于查找没有转换的代码。
   
参考资料:
[1] Rusty Russell, cpumask tree, 05 January 2009, [url]http://lwn.net/Articles/313345/[/url]
[2] Rusty Russell, Fun with cpumasks, 07 Jan 2009, [url]http://ozlabs.org/~rusty/index.cgi/2009/01/07#2009-01-07[/url]

转载于:https://blog.51cto.com/kapok/127219

CPU mask机制变化相关推荐

  1. 添加了Packed padded sequence和mask机制的Seq2Seq(Attention)模型

    文章目录 Introduction 数据预处理 搭建模型 Encoder Attention Decoder Seq2Seq 训练Seq2Seq模型 推断 BLEU 完整代码 Introduction ...

  2. 英特尔CPU控制机制存在隐秘开关 可被黑客利用成为后门

    本文讲的是 英特尔CPU控制机制存在隐秘开关 可被黑客利用成为后门,研究人员发现为政府客户设置的未公开通融措施 俄罗斯科技公司 Positive Technologies 的安全研究员,发现了未公开配 ...

  3. 【Android 逆向】函数拦截 ( CPU 高速缓存机制 | CPU 高速缓存机制 导致 函数拦截失败 )

    文章目录 一.CPU 高速缓存机制 二.CPU 高速缓存机制 导致 函数拦截失败 一.CPU 高速缓存机制 CPU 架构模型中 , 指令 在开始时 , 存放在内存中 , 如 : /proc/pid/m ...

  4. Hyper-V 3中虚拟机CPU竞争机制

    Hyper-V 3中虚拟机CPU竞争机制 Windows Server 2012姗姗来迟,最新的Hyper-V 3给我们带来更多的惊喜,后续三篇博文和大家共同学习虚拟机CPU竞争机制. 第一部分:分配 ...

  5. 剖析Intel IA32架构下C语言及CPU浮点数机制

    (转载请注名原作者及出处) pdf格式下载:http://www.binghua.com/Soft/Class2/Class5/200409/63.html 剖析Intel IA32架构下C语言及CP ...

  6. android cpu温控 机制,魔趣 Android 4.X ROM 中 CPU 调节器各种模式介绍和选择

    摘要 使用Android手机有尝试过CPU超频的应该都知道"无修饰CPU控制工具"吧?这款工具除了要设置最高频率和最低频率之外,还要设置CPU和IO调节模式.不同调节模式对应的性能 ...

  7. 你所不知的X86 CPU微码机制

    你一定知道,x86 CPU芯片有后门. 你可能知道,x86 CPU芯片有未公开指令. 你未必知道,x86 CPU芯片存在的微码机制. X86 CPU架构中的微码,在安全研究报道中很少被提及.我们限于对 ...

  8. 详解keras中的Mask机制

    文章目录 一. Mask背景 1.2 例子1 1.2 例子2 二. 原理 三. 方式 3.1 配置keras.layers.Embedding 层 3.2 添加keras.layers.Masking ...

  9. CPU 时间片轮转机制 (RR 调度)

    时间片轮转机制(RR 调度) 时间片轮转法(Round-Robin,RR)主要用于分时系统中的进程调度.为了实现轮转调度,系统把所有就绪进程按先入先出的原则排成一个队列.新来的进程加到就绪队列末尾.每 ...

最新文章

  1. Android开发技术周报 Issue#81
  2. 本周有哪些值得读的 AI 论文?进来告诉你答案
  3. curl有php内存缓存,PHP CURL内存泄露的解决方法
  4. Java基础总结--1
  5. 谷歌这个大杀器要让英伟达慌了,实战评测:TPU相比GPU简直又快又省
  6. SQL server置疑数据库修复
  7. 非华为电脑多屏协同_升级版多屏协同,实现多窗口,华为电脑管家11.0版
  8. 一淘网发声明否认胁迫导航网站合作
  9. 这个阿里网盘要下线了。。
  10. 一文搞定细菌基因组De Novo测序分析
  11. WSL安装及其后续配置
  12. 怎么恢复删除的文件?实用小妙招
  13. 以TSPITR方式恢复表空间数据一例
  14. 【DFS专题训练】王子救公主 C++程序题
  15. Burp Suite win10下安装图文教程
  16. 什么是负载均衡?什么是高可用?说说常见的负载均衡案例
  17. php微信模版消息中发送emoji表情
  18. Python 3.0中ACCESS学习(三) 打开记录集并输出数据
  19. mac下npm安装全局组件报错
  20. Xshell复制粘贴快捷键(右键粘贴)

热门文章

  1. C#学生成绩管理系统
  2. 国内类github代码托管平台
  3. Mini Crossbow AAT自动跟踪云台设置(配合TeleFlyTiny模块)
  4. co-lab 上传文件
  5. Gtest Advance
  6. golang圣经学习
  7. 2021吊打面试官系列!mysql客户端命令
  8. VMware虚拟机安装2022年最新版Ubantu详细图文安装教程
  9. json文件转为Excel文件
  10. 八、分组查询(group by)