File also-fetch-node-info-for-non-PCI-devices.patch of Package irqbalance.16087

From 9f50c04498de697d92916438f4694449c5ae22d5 Mon Sep 17 00:00:00 2001
From: Kairui Song <kasong@redhat.com>
Date: Thu, 28 Jan 2021 15:24:32 +0800
Subject: [PATCH 1/1] Also fetch node info for non-PCI devices

This is a backport of 31dea01f3a47aa6374 adapted for v1.4.0. It adds
process_one_line() and get_int() as found at the time of commit.

non-PCI devices could also be bind to a certain node. So if failed to
fetch the info from sysfs, try to get it from /proc/irq/<irq>/node.
---
 classify.c   | 11 ++++++-----
 cputree.c    | 25 +++++++++++++++++++++++++
 irqbalance.h |  3 +++
 3 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/classify.c b/classify.c
index df8a89b..4f1993e 100644
--- a/classify.c
+++ b/classify.c
@@ -395,11 +395,12 @@ static struct irq_info *add_one_irq_to_db(const char *devpath, int irq, struct u
 get_numa_node:
 	numa_node = -1;
 	if (numa_avail) {
-		sprintf(path, "%s/numa_node", devpath);
-		fd = fopen(path, "r");
-		if (fd) {
-			fscanf(fd, "%d", &numa_node);
-			fclose(fd);
+		if (devpath != NULL) {
+			sprintf(path, "%s/numa_node", devpath);
+			process_one_line(path, get_int, &numa_node);
+		} else {
+			sprintf(path, "/proc/irq/%i/node", irq);
+			process_one_line(path, get_int, &numa_node);
 		}
 	}
 
diff --git a/cputree.c b/cputree.c
index d09af43..36924ca 100644
--- a/cputree.c
+++ b/cputree.c
@@ -59,6 +59,31 @@ cpumask_t cpu_possible_map;
 */
 cpumask_t unbanned_cpus;
 
+int process_one_line(char *path, void (*cb)(char *line, void *data), void *data)
+{
+	FILE *file;
+	char *line = NULL;
+	size_t size = 0;
+	int ret = -1;
+
+	file = fopen(path, "r");
+	if (!file)
+		return ret;
+
+	if (getline(&line, &size, file) > 0) {
+		cb(line, data);
+		ret = 0;
+	}
+	free(line);
+	fclose(file);
+	return ret;
+}
+
+void get_int(char *line, void *data)
+{
+	*(int *)data = strtoul(line, NULL, 10);
+}
+
 /*
  * By default do not place IRQs on CPUs the kernel keeps isolated or
  * nohz_full, as specified through the boot commandline. Users can
diff --git a/irqbalance.h b/irqbalance.h
index 8d5b329..6c4b0c2 100644
--- a/irqbalance.h
+++ b/irqbalance.h
@@ -160,5 +160,8 @@ extern unsigned int log_mask;
 
 #define SOCKET_PATH "irqbalance"
 
+extern int process_one_line(char *path, void (*cb)(char *line, void *data), void *data);
+extern void get_int(char *line, void *data);
+
 #endif /* __INCLUDE_GUARD_IRQBALANCE_H_ */
 
-- 
2.30.1

openSUSE Build Service is sponsored by