[PATCH 06/10] workqueue: Add first_possible_node and node_nr_cpus[]

From: Tejun Heo
Date: Wed Dec 20 2023 - 02:27:16 EST


To track the first possible NUMA node and the number of online CPUs in each
NUMA node, respectively. These will be used to implement system-wide
nr_active for unbound workqueues.

Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
---
kernel/workqueue.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 143c0b31505e..a9f63cd61454 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -53,6 +53,7 @@
#include <linux/nmi.h>
#include <linux/kvm_para.h>
#include <linux/delay.h>
+#include <linux/topology.h>

#include "workqueue_internal.h"

@@ -338,6 +339,8 @@ struct wq_pod_type {
int *cpu_pod; /* cpu -> pod */
};

+static int first_possible_node __read_mostly;
+static int node_nr_cpus[MAX_NUMNODES] __read_mostly;
static struct wq_pod_type wq_pod_types[WQ_AFFN_NR_TYPES];
static enum wq_affn_scope wq_affn_dfl = WQ_AFFN_CACHE;

@@ -5610,6 +5613,8 @@ int workqueue_online_cpu(unsigned int cpu)
struct workqueue_struct *wq;
int pi;

+ node_nr_cpus[cpu_to_node(cpu)]++;
+
mutex_lock(&wq_pool_mutex);

for_each_pool(pool, pi) {
@@ -5665,6 +5670,8 @@ int workqueue_offline_cpu(unsigned int cpu)
}
mutex_unlock(&wq_pool_mutex);

+ node_nr_cpus[cpu_to_node(cpu)]--;
+
return 0;
}

@@ -6601,6 +6608,9 @@ void __init workqueue_init_early(void)

BUILD_BUG_ON(__alignof__(struct pool_workqueue) < __alignof__(long long));

+ first_possible_node = first_node(node_states[N_POSSIBLE]);
+ node_nr_cpus[cpu_to_node(0)]++;
+
BUG_ON(!alloc_cpumask_var(&wq_unbound_cpumask, GFP_KERNEL));
cpumask_copy(wq_unbound_cpumask, cpu_possible_mask);
restrict_unbound_cpumask("HK_TYPE_WQ", housekeeping_cpumask(HK_TYPE_WQ));
--
2.43.0