MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / sys_sched_setaffinity

Function sys_sched_setaffinity

src/syscall.cpp:297–330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

295}
296
297[[nodiscard]] auto sys_sched_setaffinity(int pid, size_t cpusetsize,
298 const uint64_t* mask) -> int {
299 auto& task_manager = TaskManagerSingleton::instance();
300
301 TaskControlBlock* target;
302 if (pid == 0) {
303 target = task_manager.GetCurrentTask();
304 } else {
305 // 查找指定 PID 的任务
306 target = task_manager.FindTask(static_cast<Pid>(pid));
307 if (!target) {
308 klog::Err("[Syscall] sys_sched_setaffinity: Task {} not found", pid);
309 return -1;
310 }
311 }
312
313 if (!target) {
314 return -1;
315 }
316
317 // 简单实现:更新 cpu_affinity
318 if (cpusetsize < sizeof(uint64_t)) {
319 return -1;
320 }
321
322 target->aux->cpu_affinity = *mask;
323
324 klog::Debug("[Syscall] Set CPU affinity for task {} to {:#x}", target->pid,
325 *mask);
326
327 /// @todo 如果当前任务不在允许的 CPU 上运行,应该触发迁移
328
329 return 0;
330}
331
332[[nodiscard]] auto sys_kill(int pid, int sig) -> int {
333 auto result =

Callers 2

syscall_dispatcherFunction · 0.85
test_affinity_set_getFunction · 0.85

Calls 4

ErrFunction · 0.85
DebugFunction · 0.85
GetCurrentTaskMethod · 0.80
FindTaskMethod · 0.80

Tested by 1

test_affinity_set_getFunction · 0.68