Ejemplo n.º 1
0
void select_timer_block(ticks interval)
{
    struct timeval timeout;
    struct timeval *timeout_pointer = 0;
    int result;
    descriptor d;

    if (interval){
        ticks_to_timeval(&timeout, interval);
        timeout_pointer = &timeout;
    }

    table_foreach (read_handlers, d, z)
        FD_SET((unsigned long)d, &reads);

    table_foreach (write_handlers, d, z)
        FD_SET((unsigned long)d, &writes);

    result = select(FD_SETSIZE, &reads, &writes, 0, timeout_pointer);

    if (result > 0) {
        scan_table(&reads, read_handlers);
        scan_table(&writes, write_handlers);
    }
}
/*
 * Fill the part of a LWP structure that is common between kernel tasks and
 * user processes.  Also return a CPU estimate in 'estcpu', because we generate
 * the value as a side effect here, and the LWP structure has no estcpu field.
 */
static void
fill_lwp_common(struct kinfo_lwp * l, int kslot, uint32_t * estcpu)
{
	struct proc *kp;
	struct timeval tv;
	clock_t uptime;
	uint32_t hz;

	kp = &proc_tab[kslot];

	uptime = getticks();
	hz = sys_hz();

	/*
	 * We use the process endpoint as the LWP ID.  Not only does this allow
	 * users to obtain process endpoints with "ps -s" (thus replacing the
	 * MINIX3 ps(1)'s "ps -E"), but if we ever do implement kernel threads,
	 * this is probably still going to be accurate.
	 */
	l->l_lid = kp->p_endpoint;

	/*
	 * The time during which the process has not been swapped in or out is
	 * not applicable for us, and thus, we set it to the time the process
	 * has been running (in seconds).  This value is relevant mostly for
	 * ps(1)'s CPU usage correction for processes that have just started.
	 */
	if (kslot >= NR_TASKS)
		l->l_swtime = uptime - mproc_tab[kslot - NR_TASKS].mp_started;
	else
		l->l_swtime = uptime;
	l->l_swtime /= hz;

	/*
	 * Sleep (dequeue) times are not maintained for kernel tasks, so
	 * pretend they are never asleep (which is pretty accurate).
	 */
	if (kslot < NR_TASKS)
		l->l_slptime = 0;
	else
		l->l_slptime = (uptime - kp->p_dequeued) / hz;

	l->l_priority = kp->p_priority;
	l->l_usrpri = kp->p_priority;
	l->l_cpuid = kp->p_cpu;
	ticks_to_timeval(&tv, kp->p_user_time + kp->p_sys_time);
	l->l_rtime_sec = tv.tv_sec;
	l->l_rtime_usec = tv.tv_usec;

	/*
	 * Obtain CPU usage percentages and estimates through library code
	 * shared between the kernel and this service; see its source for
	 * details.  We note that the produced estcpu value is rather different
	 * from the one produced by NetBSD, but this should not be a problem.
	 */
	l->l_pctcpu = cpuavg_getstats(&kp->p_cpuavg, &l->l_cpticks, estcpu,
	    uptime, hz);
}