函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:kernel\workqueue.c Create Date:2022-07-27 10:27:43
首页 Copyright©Brick

3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
/**
 * wq_calc_node_cpumask - calculate a wq_attrs' cpumask for the specified node
 * @attrs: the wq_attrs of the default pwq of the target workqueue
 * @node: the target NUMA node
 * @cpu_going_down: if >= 0, the CPU to consider as offline
 * @cpumask: outarg, the resulting cpumask
 *
 * Calculate the cpumask a workqueue with @attrs should use on @node.  If
 * @cpu_going_down is >= 0, that cpu is considered offline during
 * calculation.  The result is stored in @cpumask.
 *
 * If NUMA affinity is not enabled, @attrs->cpumask is always used.  If
 * enabled and @node has online CPUs requested by @attrs, the returned
 * cpumask is the intersection of the possible CPUs of @node and
 * @attrs->cpumask.
 *
 * The caller is responsible for ensuring that the cpumask of @node stays
 * stable.
 *
 * Return: %true if the resulting @cpumask is different from @attrs->cpumask,
 * %false if equal.
 */
static bool wq_calc_node_cpumask(const struct workqueue_attrs *attrs, int node,
                 int cpu_going_down, cpumask_t *cpumask)
{
    if (!wq_numa_enabled || attrs->no_numa)
        goto use_dfl;
 
    /* does @node have any online CPUs @attrs wants? */
    cpumask_and(cpumask, cpumask_of_node(node), attrs->cpumask);
    if (cpu_going_down >= 0)
        cpumask_clear_cpu(cpu_going_down, cpumask);
 
    if (cpumask_empty(cpumask))
        goto use_dfl;
 
    /* yeap, return possible CPUs in @node that @attrs wants */
    cpumask_and(cpumask, attrs->cpumask, wq_numa_possible_cpumask[node]);
 
    if (cpumask_empty(cpumask)) {
        pr_warn_once("WARNING: workqueue cpumask: online intersect > "
                "possible intersect\n");
        return false;
    }
 
    return !cpumask_equal(cpumask, attrs->cpumask);
 
use_dfl:
    cpumask_copy(cpumask, attrs->cpumask);
    return false;
}