Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2038 → Rev 2039

/trunk/kernel/generic/src/proc/task.c
119,6 → 119,7
 
ta->capabilities = 0;
ta->accept_new_threads = true;
ta->cycles = 0;
ipc_answerbox_init(&ta->answerbox);
for (i = 0; i < IPC_MAX_PHONES; i++)
266,6 → 267,36
return (task_t *) btree_search(&tasks_btree, (btree_key_t) id, &leaf);
}
 
/** Get accounting data of given task.
*
* Note that task_lock on @t must be already held and
* interrupts must be already disabled.
*
* @param t Pointer to thread.
*
*/
uint64_t task_get_accounting(task_t *t)
{
/* Accumulated value of task */
uint64_t ret = t->cycles;
/* Current values of threads */
link_t *cur;
for (cur = t->th_head.next; cur != &t->th_head; cur = cur->next) {
thread_t *thr = list_get_instance(cur, thread_t, th_link);
spinlock_lock(&thr->lock);
if (thr == THREAD) /* Update accounting of current thread */
thread_update_accounting();
ret += thr->cycles;
spinlock_unlock(&thr->lock);
}
return ret;
}
 
/** Kill task.
*
* @param id ID of the task to be killed.
344,8 → 375,8
ipl = interrupts_disable();
spinlock_lock(&tasks_lock);
printf("taskid name ctx address as active calls callee\n");
printf("------ ---------- --- ---------- ---------- ------------ ------>\n");
printf("taskid name ctx address as cycles threads calls callee\n");
printf("------ ---------- --- ---------- ---------- ---------- ------- ------ ------>\n");
 
for (cur = tasks_btree.leaf_head.next; cur != &tasks_btree.leaf_head; cur = cur->next) {
btree_node_t *node;
359,12 → 390,29
t = (task_t *) node->value[i];
spinlock_lock(&t->lock);
printf("%-6lld %-10s %-3ld %#10zx %#10zx %12zd", t->taskid, t->name, t->context, t, t->as, atomic_get(&t->active_calls));
uint64_t cycles = task_get_accounting(t);
char suffix;
if (cycles > 1000000000000000000LL) {
cycles = cycles / 1000000000000000000LL;
suffix = 'E';
} else if (cycles > 1000000000000LL) {
cycles = cycles / 1000000000000LL;
suffix = 'T';
} else if (cycles > 1000000LL) {
cycles = cycles / 1000000LL;
suffix = 'M';
} else
suffix = ' ';
printf("%-6lld %-10s %-3ld %#10zx %#10zx %9llu%c %7zd %6zd", t->taskid, t->name, t->context, t, t->as, cycles, suffix, t->refcount, atomic_get(&t->active_calls));
for (j = 0; j < IPC_MAX_PHONES; j++) {
if (t->phones[j].callee)
printf(" %zd:%#zx", j, t->phones[j].callee);
}
printf("\n");
spinlock_unlock(&t->lock);
}
}
/trunk/kernel/generic/src/proc/thread.c
113,11 → 113,27
void *arg = THREAD->thread_arg;
THREAD->last_cycle = get_cycle();
 
/* this is where each thread wakes up after its creation */
/* This is where each thread wakes up after its creation */
spinlock_unlock(&THREAD->lock);
interrupts_enable();
 
f(arg);
/* Accumulate accounting to the task */
ipl_t ipl = interrupts_disable();
spinlock_lock(&THREAD->lock);
thread_update_accounting();
uint64_t cycles = THREAD->cycles;
THREAD->cycles = 0;
spinlock_unlock(&THREAD->lock);
spinlock_lock(&TASK->lock);
TASK->cycles += cycles;
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
thread_exit();
/* not reached */
}
533,7 → 549,7
ipl = interrupts_disable();
spinlock_lock(&threads_lock);
printf("tid name address state task ctx code stack cycles cpu kst wq\n");
printf("tid name address state task ctx code stack cycles cpu kstack waitqueue\n");
printf("------ ---------- ---------- -------- ---------- --- ---------- ---------- ---------- ---- ---------- ----------\n");
 
for (cur = threads_btree.leaf_head.next; cur != &threads_btree.leaf_head; cur = cur->next) {
603,8 → 619,6
* Note that thread_lock on THREAD must be already held and
* interrupts must be already disabled.
*
* @param t Pointer to thread.
*
*/
void thread_update_accounting(void)
{