drm/amdkfd: Try to schedule bottom half on same core
Subsystems (3)
Felix Kuehling
maintainerPATCH 1/1 drm/amdkfd: Try to schedule bottom half on same core
On systems that support SMT (hyperthreading) schedule the bottom half of the KFD interrupt handler on the same core. This makes it possible to reserve a core for interrupt handling and have the bottom half run on that same core.
On systems without SMT, pick another core in the same NUMA node, as before.
Use for_each_cpu_wrap instead of open-coding it.
--- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +16 -4
@@ -24,6 +24,7 @@#include <linux/bsearch.h> #include <linux/pci.h> #include <linux/slab.h> +#include <linux/topology.h> #include "kfd_priv.h" #include "kfd_device_queue_manager.h" #include "kfd_pm4_headers_vi.h"
@@ -801,13 +802,24 @@ static inline void kfd_queue_work(struct workqueue_struct *wq, struct work_struct *work) {int cpu, new_cpu; +const struct cpumask *mask =NULL ; cpu = new_cpu =smp_processor_id (); -do { - new_cpu =cpumask_next (new_cpu, cpu_online_mask) % nr_cpu_ids; -if (cpu_to_node (new_cpu) ==numa_node_id ()) + +#if defined(CONFIG_SCHED_SMT ) +/* CPU threads in the same core */ + mask =cpu_smt_mask (cpu); +#endif +if (!mask ||cpumask_weight (mask) <=1 ) { +/* CPU threads in the same NUMA node */ + mask =cpu_cpu_mask (cpu); +/* Pick the next online CPU thread in the same core or NUMA node */ +for_each_cpu_wrap (cpu, mask, cpu+1 ) { +if (cpu != new_cpu &&cpu_online (cpu)) { + new_cpu = cpu;break ; - }while (cpu != new_cpu); + } + }queue_work_on (new_cpu, wq, work); }
Signature · 1 line
2.32.0
Felix Kuehling
maintainerAm 2022-08-10 um 19:41 schrieb Felix Kuehling:
Quoted 33 lines
On systems that support SMT (hyperthreading) schedule the bottom half of the KFD interrupt handler on the same core. This makes it possible to reserve a core for interrupt handling and have the bottom half run on that same core.
On systems without SMT, pick another core in the same NUMA node, as before.
Use
for_each_cpu_wrapinstead of open-coding it.Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_device.c +2
-0@@ -24,6 +24,7 @@#include <linux/bsearch.h> #include <linux/pci.h> #include <linux/slab.h> +#include <linux/topology.h> #include "kfd_priv.h" #include "kfd_device_queue_manager.h" #include "kfd_pm4_headers_vi.h" @@ -801,13 +802,24 @@ static inline void kfd_queue_work(struct workqueue_struct *wq, struct work_struct *work) {int cpu, new_cpu; +const struct cpumask *mask =NULL ;
drivers/gpu/drm/amd/amdkfd/kfd_device.c static inline void kfd_queue_work(struct workqueue_struct *wq, · line 813
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device.c +6
-3cpu = new_cpu =smp_processor_id (); - do { - new_cpu = cpumask_next(new_cpu, cpu_online_mask) % nr_cpu_ids; - if (cpu_to_node(new_cpu) == numa_node_id()) + +#if defined(CONFIG_SCHED_SMT ) +/* CPU threads in the same core */ + mask =cpu_smt_mask (cpu); +#endif +if (!mask ||cpumask_weight (mask) <=1 ) {
There is a stray { here, left over from when I removed some instrumentation and switched branches. I'll fix that before submitting.
Regards,
Felix
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_device.c +8
-1+/* CPU threads in the same NUMA node */ + mask =cpu_cpu_mask (cpu); +/* Pick the next online CPU thread in the same core or NUMA node */ +for_each_cpu_wrap (cpu, mask, cpu+1 ) { +if (cpu != new_cpu &&cpu_online (cpu)) { + new_cpu = cpu;break ; - }while (cpu != new_cpu); + } + }queue_work_on (new_cpu, wq, work); }
Felix Kuehling
maintainerPATCH v2 1/1 drm/amdkfd: Try to schedule bottom half on same core
In reply to Felix KuehlingOn systems that support SMT (hyperthreading) schedule the bottom half of the KFD interrupt handler on the same core. This makes it possible to reserve a core for interrupt handling and have the bottom half run on that same core.
On systems without SMT, pick another core in the same NUMA node, as before.
Use for_each_cpu_wrap instead of open-coding it.
--- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +16 -4
@@ -24,6 +24,7 @@#include <linux/bsearch.h> #include <linux/pci.h> #include <linux/slab.h> +#include <linux/topology.h> #include "kfd_priv.h" #include "kfd_device_queue_manager.h" #include "kfd_pm4_headers_vi.h"
@@ -801,13 +802,24 @@ static inline void kfd_queue_work(struct workqueue_struct *wq, struct work_struct *work) {int cpu, new_cpu; +const struct cpumask *mask =NULL ; cpu = new_cpu =smp_processor_id (); -do { - new_cpu =cpumask_next (new_cpu, cpu_online_mask) % nr_cpu_ids; -if (cpu_to_node (new_cpu) ==numa_node_id ()) + +#if defined(CONFIG_SCHED_SMT ) +/* CPU threads in the same core */ + mask =cpu_smt_mask (cpu); +#endif +if (!mask ||cpumask_weight (mask) <=1 ) +/* CPU threads in the same NUMA node */ + mask =cpu_cpu_mask (cpu); +/* Pick the next online CPU thread in the same core or NUMA node */ +for_each_cpu_wrap (cpu, mask, cpu+1 ) { +if (cpu != new_cpu &&cpu_online (cpu)) { + new_cpu = cpu;break ; - }while (cpu != new_cpu); + } + }queue_work_on (new_cpu, wq, work); }
Signature · 1 line
2.32.0
Quoted 11 lines · Felix Kuehling
On systems that support SMT (hyperthreading) schedule the bottom half of the KFD interrupt handler on the same core. This makes it possible to reserve a core for interrupt handling and have the bottom half run on that same core.
On systems without SMT, pick another core in the same NUMA node, as before.
Use
for_each_cpu_wrapinstead of open-coding it.Signed-off-by Felix Kuehling <[email protected]>
nit-pick below, looks better to use new_cpu as iterator, either way this is
Quoted 35 lines
--- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_device.c +11
-3@@ -24,6 +24,7 @@#include <linux/bsearch.h> #include <linux/pci.h> #include <linux/slab.h> +#include <linux/topology.h> #include "kfd_priv.h" #include "kfd_device_queue_manager.h" #include "kfd_pm4_headers_vi.h" @@ -801,13 +802,24 @@ static inline void kfd_queue_work(struct workqueue_struct *wq, struct work_struct *work) {int cpu, new_cpu; +const struct cpumask *mask =NULL ; cpu = new_cpu =smp_processor_id (); - do { - new_cpu = cpumask_next(new_cpu, cpu_online_mask) % nr_cpu_ids; - if (cpu_to_node(new_cpu) == numa_node_id()) + +#if defined(CONFIG_SCHED_SMT ) +/* CPU threads in the same core */ + mask =cpu_smt_mask (cpu); +#endif +if (!mask ||cpumask_weight (mask) <=1 ) +/* CPU threads in the same NUMA node */ + mask =cpu_cpu_mask (cpu); +/* Pick the next online CPU thread in the same core or NUMA node */
drivers/gpu/drm/amd/amdkfd/kfd_device.c static inline void kfd_queue_work(struct workqueue_struct *wq, · line 825
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device.c +5
-1+for_each_cpu_wrap (cpu, mask, cpu+1 ) { +if (cpu != new_cpu &&cpu_online (cpu)) { + new_cpu = cpu;break ; - }while (cpu != new_cpu); + } + }queue_work_on (new_cpu, wq, work); }
for_each_cpu_wrap(new_cpu, mask, cpu + 1) {
if (cpu != new_cpu && cpu_online(new_cpu)) {
cpu = new_cpu;
break;
}
}
queue_work_on(cpu, wq, work);Felix Kuehling
maintainerQuoted 10 lines · Philip Yang
Quoted 8 lines · Felix Kuehling
On systems that support SMT (hyperthreading) schedule the bottom half of the KFD interrupt handler on the same core. This makes it possible to reserve a core for interrupt handling and have the bottom half run on that same core.
On systems without SMT, pick another core in the same NUMA node, as before.
Quoted 7 lines
Quoted 3 lines
Use
for_each_cpu_wrapinstead of open-coding it.Signed-off-by Felix Kuehling <[email protected]>nit-pick below, looks better to use
new_cpuas iterator, either way this isReviewed-by Philip Yang <[email protected]>
Thank you. I think I prefer cpu as the iterator and new_cpu as the variable that holds the CPU we choose to schedule to.
Regards,
Felix
Quoted 54 lines
Quoted 35 lines
---
drivers/gpu/drm/amd/amdkfd/kfd_device.c| 20 ++++++++++++++++----1 file changed, 16 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_device.c +10
-3@@ -24,6 +24,7 @@ #include <linux/bsearch.h> #include <linux/pci.h> #include <linux/slab.h> +#include <linux/topology.h> #include "kfd_priv.h" #include "kfd_device_queue_manager.h" #include "kfd_pm4_headers_vi.h"@@ -801,13 +802,24 @@ static inline void kfd_queue_work(struct workqueue_struct *wq, struct work_struct *work) { int cpu, new_cpu; + const struct cpumask *mask = NULL; cpu = new_cpu = smp_processor_id(); - do { - new_cpu = cpumask_next(new_cpu, cpu_online_mask) % nr_cpu_ids; - if (cpu_to_node(new_cpu) == numa_node_id()) + +#if defined(CONFIG_SCHED_SMT ) + /* CPU threads in the same core */ + mask = cpu_smt_mask(cpu); +#endif + if (!mask || cpumask_weight(mask) <= 1) + /* CPU threads in the same NUMA node */ + mask = cpu_cpu_mask(cpu);drivers/gpu/drm/amd/amdkfd/kfd_device.c static inline void kfd_queue_work(struct · line 824
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device.c +6
-1+ /* Pick the next online CPU thread in the same core or NUMA node */ + for_each_cpu_wrap(cpu, mask, cpu+1) { + if (cpu != new_cpu && cpu_online(cpu)) { + new_cpu = cpu; break; - } while (cpu != new_cpu); + } + } queue_work_on(new_cpu, wq, work); }for_each_cpu_wrap(new_cpu, mask, cpu + 1) { if (cpu !=
new_cpu&&cpu_online(new_cpu)) { cpu =new_cpu;
break;
}
}
queue_work_on(cpu, wq, work);
Dave Airlie
maintainerQuoted 17 lines · Felix Kuehling
Quoted 14 lines · Philip Yang
Quoted 11 lines · Felix Kuehling
On systems that support SMT (hyperthreading) schedule the bottom half of the KFD interrupt handler on the same core. This makes it possible to reserve a core for interrupt handling and have the bottom half run on that same core.
On systems without SMT, pick another core in the same NUMA node, as before.
Use
for_each_cpu_wrapinstead of open-coding it.Signed-off-by Felix Kuehling <[email protected]>
Quoted 7 lines
Quoted 4 lines
nit-pick below, looks better to use
new_cpuas iterator, either way this isReviewed-by Philip Yang <[email protected]>Thank you. I think I prefer cpu as the iterator and
new_cpuas the variable that holds the CPU we choose to schedule to.
I don't think this sort of thing should be in a driver.
queue_work_node seems like it should be used or enhanced. Doing this sort of thing in driver code should be the last place to do it.
At least please task someone to work on an upstream answer to this sort of hacky downstream thing.
Dave.