tty: don't use custom kputc; this fixes tty printf()s.
[minix.git] / servers / pm / schedule.c
blob6378eb5651225c6cfbfd801fc1c78bc7e279f660
1 #include "pm.h"
2 #include <minix/callnr.h>
3 #include <minix/com.h>
4 #include <minix/config.h>
5 #include <minix/sysinfo.h>
6 #include <minix/type.h>
7 #include <machine/archtypes.h>
8 #include <lib.h>
9 #include "mproc.h"
10 #include "kernel/proc.h" /* for MIN_USER_Q */
12 PRIVATE timer_t sched_timer;
15 * makes a kernel call that schedules the process using the actuall scheduling
16 * parameters set for this process
18 PUBLIC int schedule_process(struct mproc * rmp)
20 int err;
22 if ((err = sys_schedule(rmp->mp_endpoint, rmp->mp_priority,
23 rmp->mp_time_slice)) != OK) {
24 printf("PM: An error occurred when trying to schedule %s: %d\n",
25 rmp->mp_name, err);
28 return err;
31 /*===========================================================================*
32 * do_noquantum *
33 *===========================================================================*/
35 PUBLIC void do_noquantum(void)
37 int rv, proc_nr_n;
38 register struct mproc *rmp;
40 if (pm_isokendpt(m_in.m_source, &proc_nr_n) != OK) {
41 printf("PM: WARNING: got an invalid endpoint in OOQ msg %u.\n",
42 m_in.m_source);
43 return;
46 rmp = &mproc[proc_nr_n];
47 if (rmp->mp_priority < MIN_USER_Q) {
48 rmp->mp_priority += 1; /* lower priority */
51 schedule_process(rmp);
54 /*===========================================================================*
55 * takeover_scheduling *
56 *===========================================================================*/
57 PUBLIC void takeover_scheduling(void)
59 struct mproc *trmp;
60 int proc_nr;
62 tmr_inittimer(&sched_timer);
64 for (proc_nr=0, trmp=mproc; proc_nr < NR_PROCS; proc_nr++, trmp++) {
65 /* Don't takeover system processes. When the system starts,
66 * this will typically only takeover init, from which other
67 * user space processes will inherit. */
68 if (trmp->mp_flags & IN_USE && !(trmp->mp_flags & PRIV_PROC)) {
69 if (sys_schedctl(trmp->mp_endpoint))
70 printf("PM: Error while taking over scheduling for %s\n",
71 trmp->mp_name);
72 trmp->mp_flags |= PM_SCHEDULED;
76 pm_set_timer(&sched_timer, 100, balance_queues, 0);
79 /*===========================================================================*
80 * balance_queues *
81 *===========================================================================*/
83 PUBLIC void balance_queues(tp)
84 struct timer *tp;
86 struct mproc *rmp;
87 int proc_nr;
88 int rv;
90 for (proc_nr=0, rmp=mproc; proc_nr < NR_PROCS; proc_nr++, rmp++) {
91 if (rmp->mp_flags & IN_USE) {
92 if (rmp->mp_priority > rmp->mp_max_priority) {
93 rmp->mp_priority -= 1; /* increase priority */
94 schedule_process(rmp);
99 pm_set_timer(&sched_timer, 100, balance_queues, 0);