
This functionality is required for BSD top(1), as exposed through the CTL_KERN KERN_CP_TIME sysctl(2) call. The idea is that the overall time spent in the system is divided into five categories. While NetBSD uses a separate category for the kernel ("system") and interrupts, we redefine "system" to mean userspace system services and "interrupts" to mean time spent in the kernel, thereby providing the same categories as MINIX3's own top(1), while adding the "nice" category which, like on NetBSD, is used for time spent by processes with a priority lowered by the system administrator. Change-Id: I2114148d1e07d9635055ceca7b163f337c53c43a
47 lines
1.2 KiB
C
47 lines
1.2 KiB
C
#include "kernel/system.h"
|
|
#include <minix/endpoint.h>
|
|
|
|
/*===========================================================================*
|
|
* do_schedctl *
|
|
*===========================================================================*/
|
|
int do_schedctl(struct proc * caller, message * m_ptr)
|
|
{
|
|
struct proc *p;
|
|
uint32_t flags;
|
|
int priority, quantum, cpu;
|
|
int proc_nr;
|
|
int r;
|
|
|
|
/* check parameter validity */
|
|
flags = m_ptr->m_lsys_krn_schedctl.flags;
|
|
if (flags & ~SCHEDCTL_FLAG_KERNEL) {
|
|
printf("do_schedctl: flags 0x%x invalid, caller=%d\n",
|
|
flags, caller - proc);
|
|
return EINVAL;
|
|
}
|
|
|
|
if (!isokendpt(m_ptr->m_lsys_krn_schedctl.endpoint, &proc_nr))
|
|
return EINVAL;
|
|
|
|
p = proc_addr(proc_nr);
|
|
|
|
if ((flags & SCHEDCTL_FLAG_KERNEL) == SCHEDCTL_FLAG_KERNEL) {
|
|
/* the kernel becomes the scheduler and starts
|
|
* scheduling the process.
|
|
*/
|
|
priority = m_ptr->m_lsys_krn_schedctl.priority;
|
|
quantum = m_ptr->m_lsys_krn_schedctl.quantum;
|
|
cpu = m_ptr->m_lsys_krn_schedctl.cpu;
|
|
|
|
/* Try to schedule the process. */
|
|
if((r = sched_proc(p, priority, quantum, cpu, FALSE) != OK))
|
|
return r;
|
|
p->p_scheduler = NULL;
|
|
} else {
|
|
/* the caller becomes the scheduler */
|
|
p->p_scheduler = caller;
|
|
}
|
|
|
|
return(OK);
|
|
}
|