mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
scheduler: cpu target
This commit is contained in:
@@ -28,6 +28,7 @@ typedef struct thread_t {
|
|||||||
struct thread_t *sleepprev;
|
struct thread_t *sleepprev;
|
||||||
struct proc_t *proc;
|
struct proc_t *proc;
|
||||||
struct cpu_t *cpu;
|
struct cpu_t *cpu;
|
||||||
|
struct cpu_t *cputarget;
|
||||||
context_t context;
|
context_t context;
|
||||||
extracontext_t extracontext;
|
extracontext_t extracontext;
|
||||||
void *kernelstack;
|
void *kernelstack;
|
||||||
@@ -88,5 +89,6 @@ void sched_setroot(vnode_t *);
|
|||||||
thread_t *sched_newthread(void *ip, size_t kstacksize, int priority, proc_t *proc, void *ustack);
|
thread_t *sched_newthread(void *ip, size_t kstacksize, int priority, proc_t *proc, void *ustack);
|
||||||
void sched_destroyproc(proc_t *);
|
void sched_destroyproc(proc_t *);
|
||||||
void sched_destroythread(thread_t *);
|
void sched_destroythread(thread_t *);
|
||||||
|
void sched_targetcpu(struct cpu_t *cpu);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+36
-10
@@ -106,6 +106,31 @@ void sched_destroyproc(proc_t *proc) {
|
|||||||
slab_free(processcache, proc);
|
slab_free(processcache, proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static thread_t *getinrunqueue(rqueue_t *rq) {
|
||||||
|
thread_t *thread = rq->list;
|
||||||
|
|
||||||
|
while (thread) {
|
||||||
|
if (thread->cputarget == NULL || thread->cputarget == _cpu())
|
||||||
|
break;
|
||||||
|
|
||||||
|
thread = thread->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thread) {
|
||||||
|
if (thread->prev)
|
||||||
|
thread->prev->next = thread->next;
|
||||||
|
else
|
||||||
|
rq->list = thread->next;
|
||||||
|
|
||||||
|
if (thread->next)
|
||||||
|
thread->next->prev = thread->prev;
|
||||||
|
else
|
||||||
|
rq->last = thread->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
|
||||||
static thread_t *runqueuenext(int minprio) {
|
static thread_t *runqueuenext(int minprio) {
|
||||||
bool intstate = interrupt_set(false);
|
bool intstate = interrupt_set(false);
|
||||||
|
|
||||||
@@ -115,18 +140,13 @@ static thread_t *runqueuenext(int minprio) {
|
|||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
// TODO use the bitmap for this
|
// TODO use the bitmap for this
|
||||||
for (int i = 0; i < RUNQUEUE_COUNT && i <= minprio; ++i) {
|
for (int i = 0; i < RUNQUEUE_COUNT && i <= minprio && thread == NULL; ++i) {
|
||||||
if (runqueue[i].list) {
|
thread = getinrunqueue(&runqueue[i]);
|
||||||
thread = runqueue[i].list;
|
if (thread && runqueue[i].list == NULL)
|
||||||
runqueue[i].list = thread->next;
|
runqueuebitmap &= ~((uint64_t)1 << i);
|
||||||
if (runqueue[i].list == NULL) {
|
|
||||||
runqueue[i].last = NULL;
|
|
||||||
runqueuebitmap &= ~((uint64_t)1 << i);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (thread)
|
if (thread)
|
||||||
thread->flags &= ~SCHED_THREAD_FLAGS_QUEUED;
|
thread->flags &= ~SCHED_THREAD_FLAGS_QUEUED;
|
||||||
|
|
||||||
@@ -355,6 +375,12 @@ static void cpuidlethread() {
|
|||||||
CPU_HALT();
|
CPU_HALT();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sched_targetcpu(cpu_t *cpu) {
|
||||||
|
bool intstatus = interrupt_set(false);
|
||||||
|
_cpu()->thread->cputarget = cpu;
|
||||||
|
interrupt_set(intstatus);
|
||||||
|
}
|
||||||
|
|
||||||
void sched_init() {
|
void sched_init() {
|
||||||
threadcache = slab_newcache(sizeof(thread_t), 0, NULL, NULL);
|
threadcache = slab_newcache(sizeof(thread_t), 0, NULL, NULL);
|
||||||
__assert(threadcache);
|
__assert(threadcache);
|
||||||
|
|||||||
Reference in New Issue
Block a user