Changeset cce6acf in mainline


Ignore:
Timestamp:
2006-12-13T12:10:23Z (18 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e9db6f9e
Parents:
7e13972
Message:

thread CPU cycles accounting

Location:
kernel
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kernel/Makefile

    r7e13972 rcce6acf  
    118118                DEFS += -DCONFIG_VESA_BPP=$(CONFIG_VESA_BPP)
    119119        endif
    120 endif
    121 
    122 ifeq ($(CONFIG_BENCH),y)
    123         DEFS += -DCONFIG_BENCH
    124120endif
    125121
  • kernel/generic/include/proc/thread.h

    r7e13972 rcce6acf  
    146146
    147147        uint64_t ticks;                         /**< Ticks before preemption. */
     148       
     149        uint64_t cycles;                        /**< Task accounting. */
     150        uint64_t last_cycle;            /**< Last sampled cycle. */
    148151
    149152        int priority;                           /**< Thread's priority. Implemented as index to CPU->rq */
     
    190193extern void thread_print_list(void);
    191194extern void thread_destroy(thread_t *t);
     195extern void thread_update_accounting(void);
    192196extern bool thread_exists(thread_t *t);
    193197
  • kernel/generic/src/console/cmd.c

    r7e13972 rcce6acf  
    6868#ifdef CONFIG_TEST
    6969#include <test.h>
    70 #endif
    71 
    72 #ifdef CONFIG_BENCH
    73 #include <arch/cycle.h>
    7470#endif
    7571
     
    866862{
    867863        printf("%s\t\t%s\n", test->name, test->desc);
    868 #ifdef CONFIG_BENCH
    869         uint64_t t0 = get_cycle();
    870 #endif
     864       
     865        /* Update and read thread accounting
     866           for benchmarking */
     867        ipl_t ipl = interrupts_disable();
     868        spinlock_lock(&THREAD->lock);
     869        thread_update_accounting();
     870        uint64_t t0 = THREAD->cycles;
     871        spinlock_unlock(&THREAD->lock);
     872        interrupts_restore(ipl);
     873       
     874        /* Execute the test */
    871875        char * ret = test->entry();
    872 #ifdef CONFIG_BENCH
    873         uint64_t dt = get_cycle() - t0;
     876       
     877        /* Update and read thread accounting */
     878        ipl = interrupts_disable();
     879        spinlock_lock(&THREAD->lock);
     880        thread_update_accounting();
     881        uint64_t dt = THREAD->cycles - t0;
     882        spinlock_unlock(&THREAD->lock);
     883        interrupts_restore(ipl);
     884       
    874885        printf("Time: %llu cycles\n", dt);
    875 #endif
    876886       
    877887        if (ret == NULL) {
  • kernel/generic/src/proc/scheduler.c

    r7e13972 rcce6acf  
    4848#include <arch/asm.h>
    4949#include <arch/faddr.h>
     50#include <arch/cycle.h>
    5051#include <atomic.h>
    5152#include <synch/spinlock.h>
     
    309310        if (THREAD) {
    310311                spinlock_lock(&THREAD->lock);
     312               
     313                /* Update thread accounting */
     314                THREAD->cycles += get_cycle() - THREAD->last_cycle;
     315               
    311316#ifndef CONFIG_FPU_LAZY
    312317                fpu_context_save(THREAD->saved_fpu_context);
     
    316321                         * This is the place where threads leave scheduler();
    317322                         */
     323                       
     324                        /* Save current CPU cycle */
     325                        THREAD->last_cycle = get_cycle();
     326                       
    318327                        spinlock_unlock(&THREAD->lock);
    319328                        interrupts_restore(THREAD->saved_context.ipl);
  • kernel/generic/src/proc/thread.c

    r7e13972 rcce6acf  
    4343#include <mm/page.h>
    4444#include <arch/asm.h>
     45#include <arch/cycle.h>
    4546#include <arch.h>
    4647#include <synch/synch.h>
     
    326327        t->thread_arg = arg;
    327328        t->ticks = -1;
     329        t->cycles = 0;
    328330        t->priority = -1;               /* start in rq[0] */
    329331        t->cpu = NULL;
     
    530532        ipl = interrupts_disable();
    531533        spinlock_lock(&threads_lock);
     534       
     535        printf("tid    name       address    state    task       ctx code       stack      cycles     cpu  kst        wq\n");
     536        printf("------ ---------- ---------- -------- ---------- --- ---------- ---------- ---------- ---- ---------- ----------\n");
    532537
    533538        for (cur = threads_btree.leaf_head.next; cur != &threads_btree.leaf_head; cur = cur->next) {
     
    540545               
    541546                        t = (thread_t *) node->value[i];
    542                         printf("%s: address=%#zx, tid=%zd, state=%s, task=%#zx, context=%ld, code=%#zx, stack=%#zx, cpu=",
    543                                 t->name, t, t->tid, thread_states[t->state], t->task, t->task->context, t->thread_code, t->kstack);
     547                       
     548                        uint64_t cycles;
     549                        char suffix;
     550                       
     551                        if (t->cycles > 1000000000000000000LL) {
     552                                cycles = t->cycles / 1000000000000000000LL;
     553                                suffix = 'E';
     554                        } else if (t->cycles > 1000000000000LL) {
     555                                cycles = t->cycles / 1000000000000LL;
     556                                suffix = 'T';
     557                        } else if (t->cycles > 1000000LL) {
     558                                cycles = t->cycles / 1000000LL;
     559                                suffix = 'M';
     560                        } else {
     561                                cycles = t->cycles;
     562                                suffix = ' ';
     563                        }
     564                       
     565                        printf("%-6zd %-10s %#10zx %-8s %#10zx %-3ld %#10zx %#10zx %9llu%c ", t->tid, t->name, t, thread_states[t->state], t->task, t->task->context, t->thread_code, t->kstack, cycles, suffix);
     566                       
    544567                        if (t->cpu)
    545                                 printf("cpu%zd", t->cpu->id);
     568                                printf("%-4zd", t->cpu->id);
    546569                        else
    547570                                printf("none");
    548                         if (t->state == Sleeping) {
    549                                 printf(", kst=%#zx", t->kstack);
    550                                 printf(", wq=%#zx", t->sleep_queue);
    551                         }
     571                       
     572                        if (t->state == Sleeping)
     573                                printf(" %#10zx %#10zx", t->kstack, t->sleep_queue);
     574                       
    552575                        printf("\n");
    553576                }
     
    572595       
    573596        return btree_search(&threads_btree, (btree_key_t) ((uintptr_t) t), &leaf) != NULL;
     597}
     598
     599
     600/** Update accounting of current thread.
     601 *
     602 * Note that thread_lock on THREAD must be already held and
     603 * interrupts must be already disabled.
     604 *
     605 * @param t Pointer to thread.
     606 *
     607 */
     608void thread_update_accounting(void)
     609{
     610        uint64_t time = get_cycle();
     611        THREAD->cycles += time - THREAD->last_cycle;
     612        THREAD->last_cycle = time;
    574613}
    575614
  • kernel/kernel.config

    r7e13972 rcce6acf  
    121121# Compile kernel tests
    122122! CONFIG_TEST (y/n)
    123 
    124 # Benchmark tests
    125 ! [CONFIG_TEST=y] CONFIG_BENCH (y/n)
Note: See TracChangeset for help on using the changeset viewer.