Skip to content

Commit fb39d33

Browse files
committed
smp,percpu: add for_each_percpu() function ...
and use it for SMP booting of AP CPUs. Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
1 parent 62f8600 commit fb39d33

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

common/percpu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,10 @@ percpu_t *get_percpu_page(unsigned int cpu) {
5858
list_add(&percpu->list, &percpu_frames);
5959
return percpu;
6060
}
61+
62+
void for_each_percpu(void (*func)(percpu_t *percpu)) {
63+
percpu_t *percpu;
64+
65+
list_for_each_entry (percpu, &percpu_frames, list)
66+
func(percpu);
67+
}

include/percpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,6 @@ typedef struct percpu percpu_t;
125125

126126
extern void init_percpu(void);
127127
extern percpu_t *get_percpu_page(unsigned int cpu);
128+
extern void for_each_percpu(void (*func)(percpu_t *percpu));
128129

129130
#endif /* KTF_PERCPU_H */

smp/smp.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,17 @@ void __noreturn ap_startup(void) {
6363
UNREACHABLE();
6464
}
6565

66-
static __text_init void boot_cpu(unsigned int cpu) {
67-
percpu_t *percpu = get_percpu_page(cpu);
66+
static __text_init void boot_cpu(percpu_t *percpu) {
6867
apic_icr_t icr;
6968

7069
if (percpu->bsp)
7170
return;
7271

73-
ap_cpuid = cpu;
72+
ap_cpuid = percpu->cpu_id;
7473
ap_callin = false;
7574
smp_wmb();
7675

77-
dprintk("Starting AP: %u\n", cpu);
76+
dprintk("Starting AP: %u\n", percpu->cpu_id);
7877

7978
memset(&icr, 0, sizeof(icr));
8079
apic_icr_set_dest(&icr, percpu->apic_id);
@@ -97,7 +96,7 @@ static __text_init void boot_cpu(unsigned int cpu) {
9796
while (!ap_callin)
9897
cpu_relax();
9998

100-
dprintk("AP: %u Done \n", cpu);
99+
dprintk("AP: %u Done \n", percpu->cpu_id);
101100
}
102101

103102
void __text_init init_smp(void) {
@@ -113,8 +112,7 @@ void __text_init init_smp(void) {
113112
printk("Initializing SMP support (CPUs: %u)\n", nr_cpus);
114113
ap_cr3 = cr3;
115114

116-
for (unsigned int i = 0; i < nr_cpus; i++)
117-
boot_cpu(i);
115+
for_each_percpu(boot_cpu);
118116
}
119117

120118
unsigned get_nr_cpus(void) { return nr_cpus; }

0 commit comments

Comments
 (0)