Changeset f4f866c in mainline for kernel/generic/src/proc/thread.c


Ignore:
Timestamp:
2010-04-23T21:42:26Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6c39a907
Parents:
38aaacc2 (diff), 80badbe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/thread.c

    r38aaacc2 rf4f866c  
    5050#include <synch/rwlock.h>
    5151#include <cpu.h>
    52 #include <func.h>
     52#include <str.h>
    5353#include <context.h>
    5454#include <adt/avl.h>
     
    8484        "Exiting",
    8585        "Lingering"
    86 };
     86};
     87
     88typedef struct {
     89        thread_id_t thread_id;
     90        thread_t *thread;
     91} thread_iterator_t;
    8792
    8893/** Lock protecting the threads_tree AVL tree.
     
    132137        spinlock_lock(&THREAD->lock);
    133138        if (!THREAD->uncounted) {
    134                 thread_update_accounting();
    135                 uint64_t cycles = THREAD->cycles;
    136                 THREAD->cycles = 0;
     139                thread_update_accounting(true);
     140                uint64_t ucycles = THREAD->ucycles;
     141                THREAD->ucycles = 0;
     142                uint64_t kcycles = THREAD->kcycles;
     143                THREAD->kcycles = 0;
     144
    137145                spinlock_unlock(&THREAD->lock);
    138146               
    139147                spinlock_lock(&TASK->lock);
    140                 TASK->cycles += cycles;
     148                TASK->ucycles += ucycles;
     149                TASK->kcycles += kcycles;
    141150                spinlock_unlock(&TASK->lock);
    142151        } else
     
    323332        t->thread_arg = arg;
    324333        t->ticks = -1;
    325         t->cycles = 0;
     334        t->ucycles = 0;
     335        t->kcycles = 0;
    326336        t->uncounted = uncounted;
    327337        t->priority = -1;               /* start in rq[0] */
     
    614624        thread_t *t = avltree_get_instance(node, thread_t, threads_tree_node);
    615625       
    616         uint64_t cycles;
    617         char suffix;
    618         order(t->cycles, &cycles, &suffix);
     626        uint64_t ucycles, kcycles;
     627        char usuffix, ksuffix;
     628        order_suffix(t->ucycles, &ucycles, &usuffix);
     629        order_suffix(t->kcycles, &kcycles, &ksuffix);
    619630
    620631#ifdef __32_BITS__
    621         printf("%-6" PRIu64" %-10s %10p %-8s %10p %-3" PRIu32 " %10p %10p %9" PRIu64 "%c ",
    622             t->tid, t->name, t, thread_states[t->state], t->task,
    623         t->task->context, t->thread_code, t->kstack, cycles, suffix);
     632        printf("%-6" PRIu64" %-10s %10p %-8s %10p %-3" PRIu32 " %10p %10p %9"
     633                PRIu64 "%c %9" PRIu64 "%c ", t->tid, t->name, t,
     634                thread_states[t->state], t->task, t->task->context, t->thread_code,
     635                t->kstack, ucycles, usuffix, kcycles, ksuffix);
    624636#endif
    625637
    626638#ifdef __64_BITS__
    627         printf("%-6" PRIu64" %-10s %18p %-8s %18p %-3" PRIu32 " %18p %18p %9" PRIu64 "%c ",
    628             t->tid, t->name, t, thread_states[t->state], t->task,
    629         t->task->context, t->thread_code, t->kstack, cycles, suffix);
     639        printf("%-6" PRIu64" %-10s %18p %-8s %18p %-3" PRIu32 " %18p %18p %9"
     640                PRIu64 "%c %9" PRIu64 "%c ", t->tid, t->name, t,
     641                thread_states[t->state], t->task, t->task->context, t->thread_code,
     642                t->kstack, ucycles, usuffix, kcycles, ksuffix);
    630643#endif
    631644                       
     
    661674#ifdef __32_BITS__     
    662675        printf("tid    name       address    state    task       "
    663                 "ctx code       stack      cycles     cpu  "
     676                "ctx code       stack      ucycles    kcycles    cpu  "
    664677                "waitqueue\n");
    665678        printf("------ ---------- ---------- -------- ---------- "
    666                 "--- ---------- ---------- ---------- ---- "
     679                "--- ---------- ---------- ---------- ---------- ---- "
    667680                "----------\n");
    668681#endif
     
    670683#ifdef __64_BITS__
    671684        printf("tid    name       address            state    task               "
    672                 "ctx code               stack              cycles     cpu  "
     685                "ctx code               stack              ucycles    kcycles    cpu  "
    673686                "waitqueue\n");
    674687        printf("------ ---------- ------------------ -------- ------------------ "
    675                 "--- ------------------ ------------------ ---------- ---- "
     688                "--- ------------------ ------------------ ---------- ---------- ---- "
    676689                "------------------\n");
    677690#endif
     
    706719 * interrupts must be already disabled.
    707720 *
    708  */
    709 void thread_update_accounting(void)
     721 * @param user  True to update user accounting, false for kernel.
     722 */
     723void thread_update_accounting(bool user)
    710724{
    711725        uint64_t time = get_cycle();
    712         THREAD->cycles += time - THREAD->last_cycle;
     726        if (user) {
     727                THREAD->ucycles += time - THREAD->last_cycle;
     728        } else {
     729                THREAD->kcycles += time - THREAD->last_cycle;
     730        }
    713731        THREAD->last_cycle = time;
    714732}
     733
     734static bool thread_search_walker(avltree_node_t *node, void *arg)
     735{
     736        thread_t *thread =
     737            (thread_t *) avltree_get_instance(node, thread_t, threads_tree_node);
     738        thread_iterator_t *iterator = (thread_iterator_t *) arg;
     739       
     740        if (thread->tid == iterator->thread_id) {
     741                iterator->thread = thread;
     742                return false;
     743        }
     744       
     745        return true;
     746}
     747
     748/** Find thread structure corresponding to thread ID.
     749 *
     750 * The threads_lock must be already held by the caller of this function and
     751 * interrupts must be disabled.
     752 *
     753 * @param id Thread ID.
     754 *
     755 * @return Thread structure address or NULL if there is no such thread ID.
     756 *
     757 */
     758thread_t *thread_find_by_id(thread_id_t thread_id)
     759{
     760        thread_iterator_t iterator;
     761       
     762        iterator.thread_id = thread_id;
     763        iterator.thread = NULL;
     764       
     765        avltree_walk(&threads_tree, thread_search_walker, (void *) &iterator);
     766       
     767        return iterator.thread;
     768}
     769
    715770
    716771/** Process syscall to create new thread.
Note: See TracChangeset for help on using the changeset viewer.