提交 b4b33f85 创建 作者: Austin Clements's avatar Austin Clements

Add sys_setaffinity syscall

上级 37d6db3b
......@@ -51,6 +51,7 @@ long sys_pread(int fd, void *ubuf, size_t count, off_t offset);
long sys_async(int, size_t, off_t, u32, u32);
long sys_script(void *addr, u64 len, u64 chunk);
long sys_setfs(u64 base);
long sys_setaffinity(int cpu);
extern long (*syscalls[])(u64, u64, u64, u64, u64);
// other exported/imported functions
......
......@@ -84,6 +84,8 @@ struct proc : public rcu_freed {
void set_state(enum procstate s);
enum procstate get_state(void) const { return state_; }
int set_cpu_pin(int cpu);
private:
enum procstate state_; // Process state
};
......@@ -31,4 +31,5 @@
#define SYS_async 30
#define SYS_script 31
#define SYS_setfs 32
#define SYS_ncount 33 /* total number of system calls */
#define SYS_setaffinity 33
#define SYS_ncount 34 /* total number of system calls */
......@@ -31,6 +31,7 @@ ssize_t pread(int, void*, size_t, off_t);
int async(int, size_t, off_t, u32, u32);
int script(void *addr, u64 len, u64 chunk);
int setfs(u64 base);
int setaffinity(int cpu);
// ulib.c
int stat(char*, struct stat*);
......
......@@ -46,12 +46,6 @@ wqlock_init(wqlock_t *lock)
initlock(lock);
}
static void
setaffinity(int c)
{
// XXX(sbw)
}
static void*
workerth(void *x)
{
......
......@@ -61,5 +61,6 @@ long (*syscalls[])(u64, u64, u64, u64, u64) = {
SYSCALL(async),
SYSCALL(script),
SYSCALL(setfs),
SYSCALL(setaffinity),
};
......@@ -85,6 +85,30 @@ proc::set_state(enum procstate s)
state_ = s;
}
int
proc::set_cpu_pin(int cpu)
{
if (cpu < -1 || cpu >= ncpu)
return -1;
acquire(&lock);
if (myproc() != this)
panic("set_cpu_pin not implemented for non-current proc");
if (cpu == -1) {
cpu_pin = 0;
release(&lock);
return 0;
}
// Since we're the current proc, there's no runq to get off.
// post_swtch will put us on the new runq.
cpuid = cpu;
cpu_pin = 1;
myproc()->set_state(RUNNABLE);
sched();
assert(mycpu()->id == cpu);
return 0;
}
// Give up the CPU for one scheduling round.
void
yield(void)
......
......@@ -60,7 +60,9 @@ sched(void)
struct proc *next = schednext();
if (next == nullptr) {
if (myproc()->get_state() != RUNNABLE) {
if (myproc()->get_state() != RUNNABLE ||
// proc changed its CPU pin?
myproc()->cpuid != mycpu()->id) {
next = idleproc();
} else {
myproc()->set_state(RUNNING);
......
......@@ -131,3 +131,9 @@ sys_setfs(u64 base)
switchvm(p);
return 0;
}
long
sys_setaffinity(int cpu)
{
return myproc()->set_cpu_pin(cpu);
}
......@@ -48,3 +48,4 @@ SYSCALL(pread)
SYSCALL(async)
SYSCALL(script)
SYSCALL(setfs)
SYSCALL(setaffinity)
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论