[PATCH 6/9] workqueue: Add first_possible_node and node_nr_cpus[]

From: Tejun Heo
Date: Fri Jan 12 2024 - 19:30:55 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 f90f797e73a1..3f45baa96d51 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"

@@ -341,6 +342,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;

@@ -5617,6 +5620,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) {
@@ -5672,6 +5677,8 @@ int workqueue_offline_cpu(unsigned int cpu)
}
mutex_unlock(&wq_pool_mutex);

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

@@ -6687,6 +6694,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));
BUG_ON(!alloc_cpumask_var(&wq_requested_unbound_cpumask, GFP_KERNEL));
BUG_ON(!zalloc_cpumask_var(&wq_isolated_cpumask, GFP_KERNEL));
--
2.43.0