Getting SharC to check some locking
[akaros.git] / kern / src / schedule.c
1 /*
2  * Copyright (c) 2009 The Regents of the University of California
3  * Barret Rhoden <brho@cs.berkeley.edu>
4  * See LICENSE for details.
5  *
6  * Scheduling and dispatching.
7  */
8
9 #ifdef __SHARC__
10 #pragma nosharc
11 #endif
12
13 #include <schedule.h>
14 #include <process.h>
15 #include <monitor.h>
16 #include <stdio.h>
17 #include <assert.h>
18 #include <atomic.h>
19 #include <sys/queue.h>
20
21 void schedule_init(void)
22 {
23         TAILQ_INIT(&proc_runnablelist);
24         return;
25 }
26
27 void schedule_proc(struct proc *p)
28 {
29         spin_lock_irqsave(&runnablelist_lock);
30         printd("Scheduling PID: %d\n", p->env_id);
31         TAILQ_INSERT_TAIL(&proc_runnablelist, p, proc_link);
32         spin_unlock_irqsave(&runnablelist_lock);
33         return;
34 }
35
36 void deschedule_proc(struct proc *p)
37 {
38         spin_lock_irqsave(&runnablelist_lock);
39         printd("Descheduling PID: %d\n", p->env_id);
40         TAILQ_REMOVE(&proc_runnablelist, p, proc_link);
41         spin_unlock_irqsave(&runnablelist_lock);
42         return;
43 }
44
45 /*
46  * FIFO - just pop the head from the list and run it.
47  * Using irqsave spinlocks for now, since this could be called from a timer
48  * interrupt handler (though ought to be in a bottom half or something).
49  */
50 void schedule(void)
51 {
52         struct proc *p;
53         
54         spin_lock_irqsave(&runnablelist_lock);
55         p = TAILQ_FIRST(&proc_runnablelist);
56         if (p) {
57                 TAILQ_REMOVE(&proc_runnablelist, p, proc_link);
58                 spin_unlock_irqsave(&runnablelist_lock);
59                 printd("PID of proc i'm running: %d\n", p->env_id);
60                 proc_run(p);
61         } else {
62                 spin_unlock_irqsave(&runnablelist_lock);
63                 printk("No processes to schedule, enjoy the Monitor!\n");
64                 while (1)
65                         monitor(NULL);
66         }
67         return;
68 }
69
70 void dump_proclist(struct proc_list *list)
71 {
72         struct proc *p;
73         TAILQ_FOREACH(p, list, proc_link)
74                 printk("PID: %d\n", p->env_id);
75         return;
76 }