Skip to content

Commit 1dac6e0

Browse files
committed
解决 riscv64 多任务未重写内核进程获取接口的问题.
1 parent 95b4d62 commit 1dac6e0

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "smp_la64.h"
22
#include "task/smp.h"
33

4-
int nr_cpu = 256;
5-
64
cpu_local_t *arch_current_cpu() {
75
return NULL;
86
}
@@ -11,4 +9,4 @@ void arch_bsp_cpu_init() {
119
}
1210

1311
void smp_cpu_init(uint64_t *cpu_count0, uint64_t *bsp_cpu_id, cpu_local_t *cpu_local_infos) {
14-
}
12+
}

src/arch/riscv64/task/smp_rv64.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#define EARLY_MAP_BASE 0x80000000
1414
#define EARLY_MAP_END 0x88000000
1515

16-
int nr_cpu = 256;
1716
uint64_t cpuid_to_hartids[MAX_CPU];
1817
atomic_t started_cpu_count;
1918
extern uint64_t bsp_hart_id;
@@ -22,9 +21,6 @@ extern uintptr_t smp_entry;
2221
extern void arch_cpu_init();
2322
extern cpu_local_t cpu_local_infos[MAX_CPU];
2423

25-
extern pcb_t kernel_process;
26-
extern tcb_t bsp_idle_thread;
27-
2824
uint64_t hartid_to_cpuid(uint64_t hartid) {
2925
for (size_t i = 0; i < MAX_CPU; ++i) {
3026
if (cpuid_to_hartids[i] == hartid) {
@@ -52,9 +48,9 @@ _Noreturn void arch_ap_cpu_entry(uint64_t hartid) {
5248
__asm__ volatile("mv tp, %0\n\t" ::"r"(&cpu_local_infos[cpuid]));
5349

5450
tcb_t idle_thread = malloc(STACK_SIZE);
55-
idle_thread->process = kernel_process;
51+
idle_thread->process = get_kernel_process();
5652
idle_thread->tid = alloc_tid();
57-
idle_thread->ct_index = cow_list_add(kernel_process->child_threads, idle_thread);
53+
idle_thread->ct_index = cow_list_add(get_kernel_process()->child_threads, idle_thread);
5854
idle_thread->status = T_RUNNING;
5955
scheduler_set_cpu_idle(idle_thread, arch_current_cpu());
6056
arch_context_init(idle_thread, &idle_thread->context);
@@ -126,7 +122,6 @@ void smp_cpu_init(uint64_t *cpu_count0, uint64_t *bsp_cpu_id, cpu_local_t *cpu_l
126122
0
127123
);
128124
(void)rv;
129-
continue;
130125
}
131126
}
132127
}

src/include/mem/buddy.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ extern uint64_t max_pfn;
190190
extern uint64_t min_pfn;
191191
extern zone_t *zones[__MAX_NR_ZONES];
192192
extern int nr_zones;
193-
extern int nr_cpu;
194193

195194
// 获取页面所属的 zone
196195
#define page_zone(page) (zones[(page)->zone_id])

src/mem/buddy.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ bool zone_has_memory(zone_t *zone) {
6868

6969
// GFP 标志到首选 zone 的映射
7070
static enum zone_type gfp_zone(uint32_t gfp_flags) {
71-
#if defined(__x86_64__)
71+
#ifdef __x86_64__
7272
if (gfp_flags & GFP_DMA)
7373
return ZONE_DMA;
7474
#endif
75-
if (gfp_flags & GFP_DMA32)
75+
if (gfp_flags & GFP_DMA32) {
7676
return ZONE_DMA32;
77+
}
7778
return ZONE_NORMAL;
7879
}
7980

@@ -585,10 +586,11 @@ void percpu_pagecache_init() {
585586
void drain_all_pages(void) {
586587
for (int i = 0; i < __MAX_NR_ZONES; i++) {
587588
zone_t *zone = zones[i];
588-
if (!zone_has_memory(zone))
589+
if (!zone_has_memory(zone)) {
589590
continue;
591+
}
590592

591-
for (int cpu = 0; cpu < nr_cpu; cpu++) {
593+
for (int cpu = 0; cpu < MAX_CPU; cpu++) {
592594
per_cpu_pages_t *pcp = zone_pcp(zone, cpu);
593595
if (pcp->count > 0) {
594596
free_pcppages_bulk(zone, pcp, pcp->count);

0 commit comments

Comments
 (0)