Ignore:
Timestamp:
2010-06-10T14:24:50Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c0f13d2
Parents:
1113c9e
Message:

merge basic exception accounting (this is the last piece missing from the original "measure" branch by Stanislav Kozina)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/interrupt/interrupt.c

    r1113c9e r8eec3c8  
    5353#include <symtab.h>
    5454#include <proc/thread.h>
    55 
    56 static struct {
    57         const char *name;
    58         iroutine f;
    59 } exc_table[IVT_ITEMS];
    60 
    61 SPINLOCK_INITIALIZE(exctbl_lock);
     55#include <arch/cycle.h>
     56#include <str.h>
     57
     58exc_table_t exc_table[IVT_ITEMS];
     59IRQ_SPINLOCK_INITIALIZE(exctbl_lock);
    6260
    6361/** Register exception handler
     
    7270        ASSERT(n < IVT_ITEMS);
    7371       
    74         spinlock_lock(&exctbl_lock);
     72        irq_spinlock_lock(&exctbl_lock, true);
    7573       
    7674        iroutine old = exc_table[n].f;
    7775        exc_table[n].f = handler;
    7876        exc_table[n].name = name;
    79        
    80         spinlock_unlock(&exctbl_lock);
     77        exc_table[n].cycles = 0;
     78        exc_table[n].count = 0;
     79       
     80        irq_spinlock_unlock(&exctbl_lock, true);
    8181       
    8282        return old;
     
    9292{
    9393        ASSERT(n < IVT_ITEMS);
     94       
     95        uint64_t begin_cycle = get_cycle();
    9496       
    9597        /* Account user cycles */
    9698        if (THREAD) {
    9799                irq_spinlock_lock(&THREAD->lock, false);
    98                 thread_update_accounting(true);
     100                THREAD->ucycles += begin_cycle - THREAD->last_cycle;
    99101                irq_spinlock_unlock(&THREAD->lock, false);
    100102        }
     
    116118                thread_exit();
    117119       
     120        /* Account exception handling */
     121        uint64_t end_cycle = get_cycle();
     122        exc_table[n].cycles += end_cycle - begin_cycle;
     123        exc_table[n].count++;
     124       
     125        /* Do not charge THREAD for exception cycles */
    118126        if (THREAD) {
    119127                irq_spinlock_lock(&THREAD->lock, false);
    120                 thread_update_accounting(false);
     128                THREAD->last_cycle = end_cycle;
    121129                irq_spinlock_unlock(&THREAD->lock, false);
    122130        }
     
    185193        unsigned int i;
    186194       
    187         spinlock_lock(&exctbl_lock);
     195        irq_spinlock_lock(&exctbl_lock, true);
    188196       
    189197#ifdef __32_BITS__
    190         printf("Exc Description          Handler    Symbol\n");
    191         printf("--- -------------------- ---------- --------\n");
     198        printf("Exc Description          Count      Cycles     Handler    Symbol\n");
     199        printf("--- -------------------- ---------- ---------- ---------- --------\n");
    192200#endif
    193201       
    194202#ifdef __64_BITS__
    195         printf("Exc Description          Handler            Symbol\n");
    196         printf("--- -------------------- ------------------ --------\n");
     203        printf("Exc Description          Count      Cycles     Handler            Symbol\n");
     204        printf("--- -------------------- ---------- ---------- ------------------ --------\n");
    197205#endif
    198206       
    199207        for (i = 0; i < IVT_ITEMS; i++) {
    200                 const char *symbol = symtab_fmt_name_lookup((unative_t) exc_table[i].f);
     208                uint64_t count;
     209                char count_suffix;
     210               
     211                order_suffix(exc_table[i].count, &count, &count_suffix);
     212               
     213                uint64_t cycles;
     214                char cycles_suffix;
     215               
     216                order_suffix(exc_table[i].cycles, &cycles, &cycles_suffix);
     217               
     218                const char *symbol =
     219                    symtab_fmt_name_lookup((unative_t) exc_table[i].f);
    201220               
    202221#ifdef __32_BITS__
    203                 printf("%-3u %-20s %10p %s\n", i + IVT_FIRST, exc_table[i].name,
    204                         exc_table[i].f, symbol);
     222                printf("%-3u %-20s %9" PRIu64 "%c %9" PRIu64 "%c %10p %s\n",
     223                    i + IVT_FIRST, exc_table[i].name, count, count_suffix,
     224                    cycles, cycles_suffix, exc_table[i].f, symbol);
    205225#endif
    206226               
    207227#ifdef __64_BITS__
    208                 printf("%-3u %-20s %18p %s\n", i + IVT_FIRST, exc_table[i].name,
    209                         exc_table[i].f, symbol);
     228                printf("%-3u %-20s %9" PRIu64 "%c %9" PRIu64 "%c %18p %s\n",
     229                    i + IVT_FIRST, exc_table[i].name, count, count_suffix,
     230                    cycles, cycles_suffix, exc_table[i].f, symbol);
    210231#endif
    211232               
    212233                if (((i + 1) % 20) == 0) {
    213234                        printf(" -- Press any key to continue -- ");
    214                         spinlock_unlock(&exctbl_lock);
     235                        irq_spinlock_unlock(&exctbl_lock, true);
    215236                        indev_pop_character(stdin);
    216                         spinlock_lock(&exctbl_lock);
     237                        irq_spinlock_lock(&exctbl_lock, true);
    217238                        printf("\n");
    218239                }
    219240        }
    220241       
    221         spinlock_unlock(&exctbl_lock);
     242        irq_spinlock_unlock(&exctbl_lock, true);
    222243#endif
    223244       
Note: See TracChangeset for help on using the changeset viewer.