Changeset a2a00e8 in mainline


Ignore:
Timestamp:
2010-03-28T23:05:18Z (14 years ago)
Author:
Stanislav Kozina <stanislav.kozina@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
07640dfd
Parents:
34bba0e
Message:

Accounting separated to kernel and user time.

Location:
kernel/generic
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/proc/task.h

    r34bba0e ra2a00e8  
    123123        /** Accumulated accounting. */
    124124        uint64_t cycles;
     125        uint64_t ucycles;
     126        uint64_t kcycles;
    125127} task_t;
    126128
     
    134136extern task_t *task_find_by_id(task_id_t id);
    135137extern int task_kill(task_id_t id);
    136 extern uint64_t task_get_accounting(task_t *t);
     138extern uint64_t task_get_accounting(task_t *t, uint64_t *ucycles, uint64_t *kcycles);
    137139extern void task_print_list(void);
    138140
  • kernel/generic/include/proc/thread.h

    r34bba0e ra2a00e8  
    175175        /** Thread accounting. */
    176176        uint64_t cycles;
     177        uint64_t ucycles;
     178        uint64_t kcycles;
    177179        /** Last sampled cycle. */
    178180        uint64_t last_cycle;
     
    237239extern void thread_print_list(void);
    238240extern void thread_destroy(thread_t *);
    239 extern void thread_update_accounting(void);
     241extern void thread_update_accounting(bool);
    240242extern bool thread_exists(thread_t *);
    241243
  • kernel/generic/src/console/cmd.c

    r34bba0e ra2a00e8  
    10271027        ipl_t ipl = interrupts_disable();
    10281028        spinlock_lock(&TASK->lock);
    1029         uint64_t t0 = task_get_accounting(TASK);
     1029        uint64_t ucycles, kcycles;
     1030        uint64_t t0 = task_get_accounting(TASK, &ucycles, &kcycles);
    10301031        spinlock_unlock(&TASK->lock);
    10311032        interrupts_restore(ipl);
     
    10381039        ipl = interrupts_disable();
    10391040        spinlock_lock(&TASK->lock);
    1040         uint64_t dt = task_get_accounting(TASK) - t0;
     1041        uint64_t dt = task_get_accounting(TASK, &ucycles, &kcycles) - t0;
    10411042        spinlock_unlock(&TASK->lock);
    10421043        interrupts_restore(ipl);
     
    10801081                ipl_t ipl = interrupts_disable();
    10811082                spinlock_lock(&TASK->lock);
    1082                 uint64_t t0 = task_get_accounting(TASK);
     1083                uint64_t ucycles, kcycles;
     1084                uint64_t t0 = task_get_accounting(TASK, &ucycles, &kcycles);
    10831085                spinlock_unlock(&TASK->lock);
    10841086                interrupts_restore(ipl);
     
    10911093                ipl = interrupts_disable();
    10921094                spinlock_lock(&TASK->lock);
    1093                 uint64_t dt = task_get_accounting(TASK) - t0;
     1095                uint64_t dt = task_get_accounting(TASK, &ucycles, &kcycles) - t0;
    10941096                spinlock_unlock(&TASK->lock);
    10951097                interrupts_restore(ipl);
  • kernel/generic/src/interrupt/interrupt.c

    r34bba0e ra2a00e8  
    5151#include <print.h>
    5252#include <symtab.h>
     53#include <proc/thread.h>
    5354
    5455static struct {
     
    9091{
    9192        ASSERT(n < IVT_ITEMS);
     93
     94        /* Account user cycles */
     95        if (THREAD)
     96                thread_update_accounting(true);
    9297
    9398#ifdef CONFIG_UDEBUG
  • kernel/generic/src/proc/scheduler.c

    r34bba0e ra2a00e8  
    315315                /* Update thread accounting */
    316316                THREAD->cycles += get_cycle() - THREAD->last_cycle;
     317                THREAD->kcycles += get_cycle() - THREAD->last_cycle;
    317318               
    318319#ifndef CONFIG_FPU_LAZY
  • kernel/generic/src/proc/task.c

    r34bba0e ra2a00e8  
    185185        ta->capabilities = 0;
    186186        ta->cycles = 0;
     187        ta->ucycles = 0;
     188        ta->kcycles = 0;
    187189
    188190#ifdef CONFIG_UDEBUG
     
    317319 *
    318320 * @param t             Pointer to thread.
    319  *
    320  * @return              Number of cycles used by the task and all its threads
    321  *                      so far.
    322  */
    323 uint64_t task_get_accounting(task_t *t)
    324 {
    325         /* Accumulated value of task */
     321 * @param ucycles       Out pointer to sum of all user cycles.
     322 * @param kcycles       Out pointer to sum of all kernel cycles.
     323 */
     324uint64_t task_get_accounting(task_t *t, uint64_t *ucycles, uint64_t *kcycles)
     325{
     326        /* Accumulated values of task */
    326327        uint64_t ret = t->cycles;
     328        uint64_t uret = t->ucycles;
     329        uint64_t kret = t->kcycles;
    327330       
    328331        /* Current values of threads */
     
    336339                        if (thr == THREAD) {
    337340                                /* Update accounting of current thread */
    338                                 thread_update_accounting();
     341                                thread_update_accounting(false);
    339342                        }
     343                        uret += thr->ucycles;
     344                        kret += thr->kcycles;
    340345                        ret += thr->cycles;
    341346                }
     
    343348        }
    344349       
     350        *ucycles = uret;
     351        *kcycles = kret;
     352
    345353        return ret;
    346354}
     
    410418                       
    411419        uint64_t cycles;
    412         char suffix;
    413         order(task_get_accounting(t), &cycles, &suffix);
     420        uint64_t ucycles;
     421        uint64_t kcycles;
     422        char suffix, usuffix, ksuffix;
     423        cycles = task_get_accounting(t, &ucycles, &kcycles);
     424        order(cycles, &cycles, &suffix);
     425        order(ucycles, &ucycles, &usuffix);
     426        order(kcycles, &kcycles, &ksuffix);
    414427
    415428#ifdef __32_BITS__     
    416         printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64
    417             "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles,
    418             suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls));
     429        printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64 "%c %9" PRIu64 "%c %9"
     430                PRIu64 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles, suffix,
     431                ucycles, usuffix, kcycles, ksuffix, atomic_get(&t->refcount),
     432                atomic_get(&t->active_calls));
    419433#endif
    420434
    421435#ifdef __64_BITS__
    422         printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64
    423             "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles,
    424             suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls));
     436        printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64 "%c %9" PRIu64 "%c %9"
     437                PRIu64 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles, suffix,
     438                ucycles, usuffix, kcycles, ksuffix, atomic_get(&t->refcount),
     439                atomic_get(&t->active_calls));
    425440#endif
    426441
     
    445460
    446461#ifdef __32_BITS__     
    447         printf("taskid name         ctx address    as         "
    448             "cycles     threads calls  callee\n");
    449         printf("------ ------------ --- ---------- ---------- "
    450             "---------- ------- ------ ------>\n");
     462        printf("taskid name         ctx address    as        "
     463            " cycles     ucycles    kcycles    threads calls  callee\n");
     464        printf("------ ------------ --- ---------- ----------"
     465            " ---------- ---------- ---------- ------- ------ ------>\n");
    451466#endif
    452467
    453468#ifdef __64_BITS__
    454         printf("taskid name         ctx address            as                 "
    455             "cycles     threads calls  callee\n");
    456         printf("------ ------------ --- ------------------ ------------------ "
    457             "---------- ------- ------ ------>\n");
     469        printf("taskid name         ctx address            as                "
     470            " cycles     ucycles    kcycles    threads calls  callee\n");
     471        printf("------ ------------ --- ------------------ ------------------"
     472            " ---------- ---------- ---------- ---------- ------- ------ ------>\n");
    458473#endif
    459474
  • kernel/generic/src/proc/thread.c

    r34bba0e ra2a00e8  
    132132        spinlock_lock(&THREAD->lock);
    133133        if (!THREAD->uncounted) {
    134                 thread_update_accounting();
     134                thread_update_accounting(true);
    135135                uint64_t cycles = THREAD->cycles;
    136136                THREAD->cycles = 0;
     137                uint64_t ucycles = THREAD->ucycles;
     138                THREAD->ucycles = 0;
     139                uint64_t kcycles = THREAD->kcycles;
     140                THREAD->kcycles = 0;
     141
    137142                spinlock_unlock(&THREAD->lock);
    138143               
    139144                spinlock_lock(&TASK->lock);
    140145                TASK->cycles += cycles;
     146                TASK->ucycles += ucycles;
     147                TASK->kcycles += kcycles;
    141148                spinlock_unlock(&TASK->lock);
    142149        } else
     
    324331        t->ticks = -1;
    325332        t->cycles = 0;
     333        t->ucycles = 0;
     334        t->kcycles = 0;
    326335        t->uncounted = uncounted;
    327336        t->priority = -1;               /* start in rq[0] */
     
    614623        thread_t *t = avltree_get_instance(node, thread_t, threads_tree_node);
    615624       
    616         uint64_t cycles;
    617         char suffix;
     625        uint64_t cycles, ucycles, kcycles;
     626        char suffix, usuffix, ksuffix;
    618627        order(t->cycles, &cycles, &suffix);
     628        order(t->ucycles, &ucycles, &usuffix);
     629        order(t->kcycles, &kcycles, &ksuffix);
    619630
    620631#ifdef __32_BITS__
    621         printf("%-6" PRIu64" %-10s %10p %-8s %10p %-3" PRIu32 " %10p %10p %9" PRIu64 "%c ",
     632        printf("%-6" PRIu64" %-10s %10p %-8s %10p %-3" PRIu32 " %10p %10p %9" PRIu64 "%c %9" PRIu64 "%c %9" PRIu64 "%c ",
    622633            t->tid, t->name, t, thread_states[t->state], t->task,
    623         t->task->context, t->thread_code, t->kstack, cycles, suffix);
     634        t->task->context, t->thread_code, t->kstack, cycles, suffix, ucycles, usuffix, kcycles, ksuffix);
    624635#endif
    625636
    626637#ifdef __64_BITS__
    627         printf("%-6" PRIu64" %-10s %18p %-8s %18p %-3" PRIu32 " %18p %18p %9" PRIu64 "%c ",
     638        printf("%-6" PRIu64" %-10s %18p %-8s %18p %-3" PRIu32 " %18p %18p %9" PRIu64 "%c %9" PRIu64 "%c %9" PRIu64 "%c ",
    628639            t->tid, t->name, t, thread_states[t->state], t->task,
    629         t->task->context, t->thread_code, t->kstack, cycles, suffix);
     640        t->task->context, t->thread_code, t->kstack, cycles, suffix, ucycles, usuffix, kcycles, ksuffix);
    630641#endif
    631642                       
     
    661672#ifdef __32_BITS__     
    662673        printf("tid    name       address    state    task       "
    663                 "ctx code       stack      cycles     cpu  "
     674                "ctx code       stack      cycles     ucycles    kcycles    cpu  "
    664675                "waitqueue\n");
    665676        printf("------ ---------- ---------- -------- ---------- "
    666                 "--- ---------- ---------- ---------- ---- "
     677                "--- ---------- ---------- ---------- ---------- ---------- ---- "
    667678                "----------\n");
    668679#endif
     
    670681#ifdef __64_BITS__
    671682        printf("tid    name       address            state    task               "
    672                 "ctx code               stack              cycles     cpu  "
     683                "ctx code               stack              cycles     ucycles    kcycles    cpu  "
    673684                "waitqueue\n");
    674685        printf("------ ---------- ------------------ -------- ------------------ "
    675                 "--- ------------------ ------------------ ---------- ---- "
     686                "--- ------------------ ------------------ ---------- ---------- ---------- ---- "
    676687                "------------------\n");
    677688#endif
     
    706717 * interrupts must be already disabled.
    707718 *
    708  */
    709 void thread_update_accounting(void)
     719 * @param user  True to update user accounting, false for kernel.
     720 */
     721void thread_update_accounting(bool user)
    710722{
    711723        uint64_t time = get_cycle();
    712724        THREAD->cycles += time - THREAD->last_cycle;
     725        if (user) {
     726                THREAD->ucycles += time - THREAD->last_cycle;
     727        } else {
     728                THREAD->kcycles += time - THREAD->last_cycle;
     729        }
    713730        THREAD->last_cycle = time;
    714731}
  • kernel/generic/src/ps/ps.c

    r34bba0e ra2a00e8  
    132132        copy_to_uspace(uspace_info->name, t->name, sizeof(t->name));
    133133
    134         uint64_t cycles = task_get_accounting(t);
     134        uint64_t ucycles;
     135        uint64_t kcycles;
     136        uint64_t cycles = task_get_accounting(t, &ucycles, &kcycles);
    135137        copy_to_uspace(&uspace_info->cycles, &cycles, sizeof(cycles));
    136138
Note: See TracChangeset for help on using the changeset viewer.