Skip to content

Commit a6dcb17

Browse files
committed
test: fix st
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
1 parent 69a10d4 commit a6dcb17

5 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,13 @@ auto main(int argc, const char** argv) -> int {
163163
TaskManagerSingleton::create();
164164
TaskManagerSingleton::instance().InitCurrentCore();
165165

166+
TimerInit();
167+
166168
// 唤醒其余 core
167169
WakeUpOtherCores();
168170

169171
DumpStack();
170172

171-
// 初始化定时器
172-
TimerInit();
173-
174173
klog::Info("Hello SimpleKernel");
175174

176175
klog::Info("Initializing test tasks...");

src/task/include/task_manager.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ struct CpuSchedData {
6262
/// 本核心的总调度次数
6363
uint64_t total_schedules{0};
6464

65+
/// Schedule() 是否已被显式调用
66+
bool scheduler_started{false};
67+
6568
/// @name 构造/析构函数
6669
/// @{
6770
CpuSchedData() = default;

src/task/schedule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
auto TaskManager::Schedule() -> void {
2727
auto& cpu_sched = GetCurrentCpuSched();
28+
cpu_sched.scheduler_started = true;
2829
cpu_sched.lock.Lock().or_else([](auto&& err) {
2930
klog::Err("Schedule: Failed to acquire lock: {}", err.message());
3031
while (true) {

src/task/tick_update.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ auto TaskManager::TickUpdate() -> void {
6767
}
6868
}
6969

70-
// 如果需要抢占,触发调度
71-
if (need_preempt) {
70+
if (need_preempt && cpu_sched.scheduler_started) {
7271
Schedule();
7372
}
7473
}

tests/system_test/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,12 @@ auto main(int argc, const char** argv) -> int {
260260
TaskManagerSingleton::create();
261261
TaskManagerSingleton::instance().InitCurrentCore();
262262

263+
TimerInit();
264+
263265
WakeUpOtherCores();
264266

265267
DumpStack();
266268

267-
TimerInit();
268-
269269
klog::Info("Hello SimpleKernel");
270270

271271
for (size_t i = 0; i < kTestCount; ++i) {

0 commit comments

Comments
 (0)