Ejemplo n.º 1
0
asmlinkage long compat_sys_times(struct compat_tms __user *tbuf)
{
    /*
     *	In the SMP world we might just be unlucky and have one of
     *	the times increment as we use it. Since the value is an
     *	atomically safe type this is just fine. Conceptually its
     *	as if the syscall took an instant longer to occur.
     */
    if (tbuf) {
        struct compat_tms tmp;
        struct task_struct *tsk = current;
        struct task_struct *t;
        cputime_t utime, stime, cutime, cstime;

        read_lock(&tasklist_lock);
        utime = tsk->signal->utime;
        stime = tsk->signal->stime;
        t = tsk;
        do {
            utime = cputime_add(utime, t->utime);
            stime = cputime_add(stime, t->stime);
            t = next_thread(t);
        } while (t != tsk);

        /*
         * While we have tasklist_lock read-locked, no dying thread
         * can be updating current->signal->[us]time.  Instead,
         * we got their counts included in the live thread loop.
         * However, another thread can come in right now and
         * do a wait call that updates current->signal->c[us]time.
         * To make sure we always see that pair updated atomically,
         * we take the siglock around fetching them.
         */
        spin_lock_irq(&tsk->sighand->siglock);
        cutime = tsk->signal->cutime;
        cstime = tsk->signal->cstime;
        spin_unlock_irq(&tsk->sighand->siglock);
        read_unlock(&tasklist_lock);

        tmp.tms_utime = compat_jiffies_to_clock_t(cputime_to_jiffies(utime));
        tmp.tms_stime = compat_jiffies_to_clock_t(cputime_to_jiffies(stime));
        tmp.tms_cutime = compat_jiffies_to_clock_t(cputime_to_jiffies(cutime));
        tmp.tms_cstime = compat_jiffies_to_clock_t(cputime_to_jiffies(cstime));
        if (copy_to_user(tbuf, &tmp, sizeof(tmp)))
            return -EFAULT;
    }
    return compat_jiffies_to_clock_t(jiffies);
}
static void dump_softlock_debug(unsigned long data)
{
	int i, reboot;
	u64 system[NR_CPUS], num_jifs;

	memset(system, 0, NR_CPUS*sizeof(u64));

	num_jifs = jiffies - beattime;
	for_each_possible_cpu(i) {
		system[i] = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM] -
				heartbeats[i];
	}

	reboot = 0;

	for_each_possible_cpu(i) {
		if ((num_jifs - cputime_to_jiffies(system[i])) <
						msecs_to_jiffies(10)) {
			WARN(1, "cpu %d wedged\n", i);
			smp_call_function_single(i, smp_dumpstack, NULL, 1);
			reboot = 1;
		}
	}

	if (reboot) {
		panic_timeout = 10;
		trigger_all_cpu_backtrace();
		panic("Soft lock on CPUs\n");
	}
}
static __inline__ void
cputime_to_compat_timeval(const cputime_t cputime, struct compat_timeval *value)
{
	unsigned long jiffies = cputime_to_jiffies(cputime);
	value->tv_usec = (jiffies % HZ) * (1000000L / HZ);
	value->tv_sec = jiffies / HZ;
}
Ejemplo n.º 4
0
//Work handler to update CPU time in Linked List
void work_handler( struct work_struct *work )
{
	int *pids = NULL;
    int count = 0;
   	int index,pid;
    unsigned long cpu_time;
//	Works *wk = (Works*)work;
	/*Insert code here for updation of CPU Time*/
    // get the pids
	//printk(KERN_INFO "work handler called\n");
	ll_get_pids(&pids,&count);
	//printk(KERN_INFO "PID count = %d", count);
    for (index = 0; index <count; ++index)
	{

		pid = pids[index];

		if( get_cpu_use(pid,&cpu_time) == SUCCESS )
		{
			//printk(KERN_INFO "PID: %d CPU TIME: %lu\n", pid,cpu_time);
			ll_update_time(pid,jiffies_to_msecs(cputime_to_jiffies(cpu_time))); 
		}
		else
		{ 
			//printk(KERN_INFO "get_cpu_use() failed");
			ll_delete_pid(pid);
		}
	}
	
	kfree(pids);
}
Ejemplo n.º 5
0
void acct_update_integrals(struct task_struct *tsk)
{
	if (likely(tsk->mm)) {
		cputime_t time, dtime;
		struct timeval value;
		unsigned long flags;
		u64 delta;

		local_irq_save(flags);
		time = tsk->stime + tsk->utime;
		dtime = time - tsk->acct_timexpd;
		jiffies_to_timeval(cputime_to_jiffies(dtime), &value);
		delta = value.tv_sec;
		delta = delta * USEC_PER_SEC + value.tv_usec;

		if (delta == 0)
			goto out;
		tsk->acct_timexpd = time;
		tsk->acct_rss_mem1 += delta * get_mm_rss(tsk->mm);
		tsk->acct_vm_mem1 += delta * tsk->mm->total_vm;
	out:
		local_irq_restore(flags);
	}
}