From: Jérôme Glisse <[email protected]>

Register CPUs as initiator under HMS scheme. CPUs are registered per
node (one initiator device per node per CPU). We also add the CPU to
the node default link so it is connected to main memory for the node.
For details see Documentation/vm/hms.rst.

Signed-off-by: Jérôme Glisse <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: Ross Zwisler <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Haggai Eran <[email protected]>
Cc: Balbir Singh <[email protected]>
Cc: Aneesh Kumar K.V <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Felix Kuehling <[email protected]>
Cc: Philip Yang <[email protected]>
Cc: Christian König <[email protected]>
Cc: Paul Blinzer <[email protected]>
Cc: Logan Gunthorpe <[email protected]>
Cc: John Hubbard <[email protected]>
Cc: Ralph Campbell <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: Mark Hairgrove <[email protected]>
Cc: Vivek Kini <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Dave Airlie <[email protected]>
Cc: Ben Skeggs <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
---
 drivers/base/cpu.c  |  5 +++++
 drivers/base/node.c | 18 +++++++++++++++++-
 include/linux/cpu.h |  4 ++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index eb9443d5bae1..160454bc5c38 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -76,6 +76,8 @@ void unregister_cpu(struct cpu *cpu)
 {
        int logical_cpu = cpu->dev.id;
 
+       hms_initiator_unregister(&cpu->initiator);
+
        unregister_cpu_under_node(logical_cpu, cpu_to_node(logical_cpu));
 
        device_unregister(&cpu->dev);
@@ -392,6 +394,9 @@ int register_cpu(struct cpu *cpu, int num)
        dev_pm_qos_expose_latency_limit(&cpu->dev,
                                        PM_QOS_RESUME_LATENCY_NO_CONSTRAINT);
 
+       hms_initiator_register(&cpu->initiator, &cpu->dev,
+                              cpu_to_node(num), 0);
+
        return 0;
 }
 
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 05621ba3cf13..43f1820cdadb 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -375,9 +375,19 @@ int register_cpu_under_node(unsigned int cpu, unsigned int 
nid)
        if (ret)
                return ret;
 
-       return sysfs_create_link(&obj->kobj,
+       ret = sysfs_create_link(&obj->kobj,
                                 &node_devices[nid]->dev.kobj,
                                 kobject_name(&node_devices[nid]->dev.kobj));
+       if (ret)
+               return ret;
+
+       if (IS_ENABLED(CONFIG_HMS)) {
+               struct cpu *cpu = container_of(obj, struct cpu, dev);
+
+               hms_link_initiator(node_devices[nid]->link, cpu->initiator);
+       }
+
+       return 0;
 }
 
 int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
@@ -396,6 +406,12 @@ int unregister_cpu_under_node(unsigned int cpu, unsigned 
int nid)
        sysfs_remove_link(&obj->kobj,
                          kobject_name(&node_devices[nid]->dev.kobj));
 
+       if (IS_ENABLED(CONFIG_HMS)) {
+               struct cpu *cpu = container_of(obj, struct cpu, dev);
+
+               hms_unlink_initiator(node_devices[nid]->link, cpu->initiator);
+       }
+
        return 0;
 }
 
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 218df7f4d3e1..1e3a777bfa3d 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -14,6 +14,7 @@
 #ifndef _LINUX_CPU_H_
 #define _LINUX_CPU_H_
 
+#include <linux/hms.h>
 #include <linux/node.h>
 #include <linux/compiler.h>
 #include <linux/cpumask.h>
@@ -27,6 +28,9 @@ struct cpu {
        int node_id;            /* The node which contains the CPU */
        int hotpluggable;       /* creates sysfs control file if hotpluggable */
        struct device dev;
+#if defined(CONFIG_HMS)
+       struct hms_initiator *initiator;
+#endif
 };
 
 extern void boot_cpu_init(void);
-- 
2.17.2

Reply via email to