• V
    sched/topology: Make sched_init_numa() use a set for the deduplicating sort · 8471a27a
    Valentin Schneider 提交于
    mainline inclusion
    from mainline-v5.12-rc1
    commit 620a6dc4
    category: bugfix
    bugzilla: 182847,https://gitee.com/openeuler/kernel/issues/I48TV8
    CVE: NA
    
    ----------------------------------------------------------
    
    The deduplicating sort in sched_init_numa() assumes that the first line in
    the distance table contains all unique values in the entire table. I've
    been trying to pen what this exactly means for the topology, but it's not
    straightforward. For instance, topology.c uses this example:
    
      node   0   1   2   3
        0:  10  20  20  30
        1:  20  10  20  20
        2:  20  20  10  20
        3:  30  20  20  10
    
      0 ----- 1
      |     / |
      |   /   |
      | /     |
      2 ----- 3
    
    Which works out just fine. However, if we swap nodes 0 and 1:
    
      1 ----- 0
      |     / |
      |   /   |
      | /     |
      2 ----- 3
    
    we get this distance table:
    
      node   0  1  2  3
        0:  10 20 20 20
        1:  20 10 20 30
        2:  20 20 10 20
        3:  20 30 20 10
    
    Which breaks the deduplicating sort (non-representative first line). In
    this case this would just be a renumbering exercise, but it so happens that
    we can have a deduplicating sort that goes through the whole table in O(n²)
    at the extra cost of a temporary memory allocation (i.e. any form of set).
    
    The ACPI spec (SLIT) mentions distances are encoded on 8 bits. Following
    this, implement the set as a 256-bits bitmap. Should this not be
    satisfactory (i.e. we want to support 32-bit values), then we'll have to go
    for some other sparse set implementation.
    
    This has the added benefit of letting us allocate just the right amount of
    memory for sched_domains_numa_distance[], rather than an arbitrary
    (nr_node_ids + 1).
    
    Note: DT binding equivalent (distance-map) decodes distances as 32-bit
    values.
    Signed-off-by: NValentin Schneider <valentin.schneider@arm.com>
    Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lkml.kernel.org/r/20210122123943.1217-2-valentin.schneider@arm.comSigned-off-by: NJialin Zhang <zhangjialin11@huawei.com>
    Reviewed-by: NCheng Jian <cj.chengjian@huawei.com>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    8471a27a
topology.h 4.8 KB