LibC: Implement sched_getcpu
This commit is contained in:
parent
e01e35713b
commit
dd2bbe4588
|
|
@ -28,6 +28,8 @@ int sched_setparam(pid_t pid, const struct sched_param* param);
|
|||
int sched_setscheduler(pid_t pid, int, const struct sched_param* param);
|
||||
int sched_yield(void);
|
||||
|
||||
int sched_getcpu(void);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@
|
|||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <kernel/API/SharedPage.h>
|
||||
|
||||
extern volatile Kernel::API::SharedPage* g_shared_page;
|
||||
|
||||
int sched_get_priority_max(int policy)
|
||||
{
|
||||
(void)policy;
|
||||
|
|
@ -18,3 +22,17 @@ int sched_yield(void)
|
|||
{
|
||||
return syscall(SYS_YIELD);
|
||||
}
|
||||
|
||||
int sched_getcpu(void)
|
||||
{
|
||||
if (g_shared_page == nullptr)
|
||||
return -1;
|
||||
|
||||
uint8_t cpu;
|
||||
#if defined(__x86_64__)
|
||||
asm volatile("movb %%gs:0, %0" : "=r"(cpu));
|
||||
#elif defined(__i686__)
|
||||
asm volatile("movb %%fs:0, %0" : "=q"(cpu));
|
||||
#endif
|
||||
return cpu;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue