irq/matrix: simplify CPU selection logic
PATCH 1/1 irq/matrix: simplify CPU selection logic
The functions matrix_find_best_cpu() and matrix_find_best_cpu_managed() were refactored to simplify the CPU selection logic and improve readability.
- In matrix_find_best_cpu(), the selection logic was clarified by ensuring that the best_cpu is only updated when a CPU has more available IRQ vectors than the previously selected CPU.
- In matrix_find_best_cpu_managed(), the logic was modified to select the CPU with the fewest managed_allocated IRQ vectors, ensuring that the best_cpu is only updated when a CPU has a strictly fewer number of allocated vectors. Previously, the best_cpu was updated even when the managed_allocated values were equal, which was unnecessary and inconsistent.
This change improves code clarity and ensures that CPU selection is more predictable, especially in high-load or resource-constrained scenarios.
Impact:
- The change improves the readability of both functions and makes the CPU selection behavior more explicit and predictable.
- There is no functional change under normal operating conditions. The behavior change only affects scenarios where the managed_allocated value is equal between CPUs, which is rare and would have previously led to unnecessary updates to best_cpu.
--- kernel/irq/matrix.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
kernel/irq/matrix.c +12 -6
@@ -140,14 +140,17 @@ static unsigned int matrix_find_best_cpu(struct irq_matrix *m, best_cpu =UINT_MAX ; +/* Select the online CPU with the most available vectors */ for_each_cpu (cpu, msk) { cm =per_cpu_ptr (m->maps, cpu); -if (!cm->online || cm->available <= maxavl) +if (!cm->online)continue ; - best_cpu = cpu; - maxavl = cm->available; +if (cm->available > maxavl) { + best_cpu = cpu; + maxavl = cm->available; + } }return best_cpu; }
@@ -161,14 +164,17 @@ static unsigned int matrix_find_best_cpu_managed(struct irq_matrix *m, best_cpu =UINT_MAX ; +/* Select the online CPU with the fewest managed allocated vectors */ for_each_cpu (cpu, msk) { cm =per_cpu_ptr (m->maps, cpu); -if (!cm->online || cm->managed_allocated > allocated) +if (!cm->online)continue ; - best_cpu = cpu; - allocated = cm->managed_allocated; +if (cm->managed_allocated < allocated) { + best_cpu = cpu; + allocated = cm->managed_allocated; + } }return best_cpu; }
Signature · 1 line
2.43.0
Thomas Gleixner
maintainerQuoted 3 lines · Zhan Xusheng
The functions
matrix_find_best_cpu()andmatrix_find_best_cpu_managed()were refactored to simplify the CPU selection logic and improve readability.
You are describing what your patch is doing, but fail to provide any explanation why this patch is required and which problem it actucally solves. See:
https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#changelog
When you read that document, please read the paragraph about selecting the subsystem prefix too.
Thanks,
tglx