Skip to content

Commit 005bf0e

Browse files
Yinghai LuIngo Molnar
authored andcommitted
irq: optimize init_kstat_irqs/init_copy_kstat_irqs
Simplify and make init_kstat_irqs etc more type proof, suggested by Andrew. Signed-off-by: Yinghai Lu <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 0f3c2a8 commit 005bf0e

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

kernel/irq/handle.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,21 @@ static struct irq_desc irq_desc_init = {
7171

7272
void init_kstat_irqs(struct irq_desc *desc, int cpu, int nr)
7373
{
74-
unsigned long bytes;
75-
char *ptr;
7674
int node;
77-
78-
/* Compute how many bytes we need per irq and allocate them */
79-
bytes = nr * sizeof(unsigned int);
75+
void *ptr;
8076

8177
node = cpu_to_node(cpu);
82-
ptr = kzalloc_node(bytes, GFP_ATOMIC, node);
83-
printk(KERN_DEBUG " alloc kstat_irqs on cpu %d node %d\n", cpu, node);
78+
ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), GFP_ATOMIC, node);
8479

85-
if (ptr)
86-
desc->kstat_irqs = (unsigned int *)ptr;
80+
/*
81+
* don't overwite if can not get new one
82+
* init_copy_kstat_irqs() could still use old one
83+
*/
84+
if (ptr) {
85+
printk(KERN_DEBUG " alloc kstat_irqs on cpu %d node %d\n",
86+
cpu, node);
87+
desc->kstat_irqs = ptr;
88+
}
8789
}
8890

8991
static void init_one_irq_desc(int irq, struct irq_desc *desc, int cpu)

kernel/irq/numa_migrate.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@ static void init_copy_kstat_irqs(struct irq_desc *old_desc,
1717
struct irq_desc *desc,
1818
int cpu, int nr)
1919
{
20-
unsigned long bytes;
21-
2220
init_kstat_irqs(desc, cpu, nr);
2321

24-
if (desc->kstat_irqs != old_desc->kstat_irqs) {
25-
/* Compute how many bytes we need per irq and allocate them */
26-
bytes = nr * sizeof(unsigned int);
27-
28-
memcpy(desc->kstat_irqs, old_desc->kstat_irqs, bytes);
29-
}
22+
if (desc->kstat_irqs != old_desc->kstat_irqs)
23+
memcpy(desc->kstat_irqs, old_desc->kstat_irqs,
24+
nr * sizeof(*desc->kstat_irqs));
3025
}
3126

3227
static void free_kstat_irqs(struct irq_desc *old_desc, struct irq_desc *desc)

0 commit comments

Comments
 (0)