Skip to content

Commit 5b98d21

Browse files
bjorn-rivosKAGA-KOKO
authored andcommitted
genirq/matrix: Dynamic bitmap allocation
A future user of the matrix allocator, does not know the size of the matrix bitmaps at compile time. To avoid wasting memory on unnecessary large bitmaps, size the bitmap at matrix allocation time. Signed-off-by: Björn Töpel <[email protected]> Signed-off-by: Anup Patel <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3c46fc5 commit 5b98d21

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

arch/x86/include/asm/hw_irq.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
#include <asm/irq_vectors.h>
1818

19-
#define IRQ_MATRIX_BITS NR_VECTORS
20-
2119
#ifndef __ASSEMBLY__
2220

2321
#include <linux/percpu.h>

kernel/irq/matrix.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88
#include <linux/cpu.h>
99
#include <linux/irq.h>
1010

11-
#define IRQ_MATRIX_SIZE (BITS_TO_LONGS(IRQ_MATRIX_BITS))
12-
1311
struct cpumap {
1412
unsigned int available;
1513
unsigned int allocated;
1614
unsigned int managed;
1715
unsigned int managed_allocated;
1816
bool initialized;
1917
bool online;
20-
unsigned long alloc_map[IRQ_MATRIX_SIZE];
21-
unsigned long managed_map[IRQ_MATRIX_SIZE];
18+
unsigned long *managed_map;
19+
unsigned long alloc_map[];
2220
};
2321

2422
struct irq_matrix {
@@ -32,8 +30,8 @@ struct irq_matrix {
3230
unsigned int total_allocated;
3331
unsigned int online_maps;
3432
struct cpumap __percpu *maps;
35-
unsigned long scratch_map[IRQ_MATRIX_SIZE];
36-
unsigned long system_map[IRQ_MATRIX_SIZE];
33+
unsigned long *system_map;
34+
unsigned long scratch_map[];
3735
};
3836

3937
#define CREATE_TRACE_POINTS
@@ -50,24 +48,32 @@ __init struct irq_matrix *irq_alloc_matrix(unsigned int matrix_bits,
5048
unsigned int alloc_start,
5149
unsigned int alloc_end)
5250
{
51+
unsigned int cpu, matrix_size = BITS_TO_LONGS(matrix_bits);
5352
struct irq_matrix *m;
5453

55-
if (matrix_bits > IRQ_MATRIX_BITS)
56-
return NULL;
57-
58-
m = kzalloc(sizeof(*m), GFP_KERNEL);
54+
m = kzalloc(struct_size(m, scratch_map, matrix_size * 2), GFP_KERNEL);
5955
if (!m)
6056
return NULL;
6157

58+
m->system_map = &m->scratch_map[matrix_size];
59+
6260
m->matrix_bits = matrix_bits;
6361
m->alloc_start = alloc_start;
6462
m->alloc_end = alloc_end;
6563
m->alloc_size = alloc_end - alloc_start;
66-
m->maps = alloc_percpu(*m->maps);
64+
m->maps = __alloc_percpu(struct_size(m->maps, alloc_map, matrix_size * 2),
65+
__alignof__(*m->maps));
6766
if (!m->maps) {
6867
kfree(m);
6968
return NULL;
7069
}
70+
71+
for_each_possible_cpu(cpu) {
72+
struct cpumap *cm = per_cpu_ptr(m->maps, cpu);
73+
74+
cm->managed_map = &cm->alloc_map[matrix_size];
75+
}
76+
7177
return m;
7278
}
7379

0 commit comments

Comments
 (0)