Changeset 95155b0c in mainline for kernel/generic/src


Ignore:
Timestamp:
2006-12-19T10:12:24Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c8410ec9
Parents:
7e7c8747
Message:

benchmarking with statistics (initial)

Location:
kernel/generic/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/cmd.c

    r7e7c8747 r95155b0c  
    117117        .argc = 1,
    118118        .argv = test_argv
     119};
     120
     121static int cmd_bench(cmd_arg_t *argv);
     122static cmd_arg_t bench_argv[] = {
     123        {
     124                .type = ARG_TYPE_STRING,
     125                .buffer = test_buf,
     126                .len = sizeof(test_buf)
     127        },
     128        {
     129                .type = ARG_TYPE_INT,
     130        }
     131};
     132static cmd_info_t bench_info = {
     133        .name = "bench",
     134        .description = "Run kernel test as benchmark.",
     135        .func = cmd_bench,
     136        .argc = 2,
     137        .argv = bench_argv
    119138};
    120139#endif
     
    412431        &tests_info,
    413432        &test_info,
     433        &bench_info,
    414434#endif
    415435        NULL
     
    872892       
    873893        /* Execute the test */
    874         char * ret = test->entry();
     894        char * ret = test->entry(false);
    875895       
    876896        /* Update and read thread accounting */
     
    881901        interrupts_restore(ipl);
    882902       
    883         printf("Time: %llu cycles\n", dt);
     903        uint64_t cycles;
     904        char suffix;
     905        order(dt, &cycles, &suffix);
     906               
     907        printf("Time: %llu%c cycles\n", cycles, suffix);
    884908       
    885909        if (ret == NULL) {
     
    890914        printf("%s\n", ret);
    891915        return false;
     916}
     917
     918static bool run_bench(const test_t *test, const uint32_t cnt)
     919{
     920        uint32_t i;
     921        bool ret = true;
     922        uint64_t cycles;
     923        char suffix;
     924       
     925        if (cnt < 1)
     926                return true;
     927       
     928        uint64_t *data = malloc(sizeof(uint64_t) * cnt, 0);
     929        if (data == NULL) {
     930                printf("Error allocating memory for statistics\n");
     931                return false;
     932        }
     933       
     934        for (i = 0; i < cnt; i++) {
     935                printf("%s (%d/%d) ... ", test->name, i + 1, cnt);
     936               
     937                /* Update and read thread accounting
     938                   for benchmarking */
     939                ipl_t ipl = interrupts_disable();
     940                spinlock_lock(&TASK->lock);
     941                uint64_t t0 = task_get_accounting(TASK);
     942                spinlock_unlock(&TASK->lock);
     943                interrupts_restore(ipl);
     944               
     945                /* Execute the test */
     946                char * ret = test->entry(true);
     947               
     948                /* Update and read thread accounting */
     949                ipl = interrupts_disable();
     950                spinlock_lock(&TASK->lock);
     951                uint64_t dt = task_get_accounting(TASK) - t0;
     952                spinlock_unlock(&TASK->lock);
     953                interrupts_restore(ipl);
     954               
     955                if (ret != NULL) {
     956                        printf("%s\n", ret);
     957                        ret = false;
     958                        break;
     959                }
     960               
     961                data[i] = dt;
     962                order(dt, &cycles, &suffix);
     963                printf("OK (%llu%c cycles)\n", cycles, suffix);
     964        }
     965       
     966        if (ret) {
     967                printf("\n");
     968               
     969                uint64_t sum = 0;
     970               
     971                for (i = 0; i < cnt; i++) {
     972                        sum += data[i];
     973                }
     974               
     975                order(sum / (uint64_t) cnt, &cycles, &suffix);
     976                printf("Average\t\t%llu%c\n", cycles, suffix);
     977        }
     978       
     979        free(data);
     980       
     981        return ret;
    892982}
    893983
     
    9271017        return 1;
    9281018}
     1019
     1020/** Command for returning kernel tests as benchmarks
     1021 *
     1022 * @param argv Argument vector.
     1023 *
     1024 * return Always 1.
     1025 */
     1026int cmd_bench(cmd_arg_t *argv)
     1027{
     1028        test_t *test;
     1029        uint32_t cnt = argv[1].intval;
     1030       
     1031        bool fnd = false;
     1032       
     1033        for (test = tests; test->name != NULL; test++) {
     1034                if (strcmp(test->name, argv->buffer) == 0) {
     1035                        fnd = true;
     1036                        run_bench(test, cnt);
     1037                        break;
     1038                }
     1039        }
     1040               
     1041        if (!fnd)
     1042                printf("Unknown test\n");
     1043
     1044        return 1;
     1045}
     1046
    9291047#endif
    9301048
  • kernel/generic/src/lib/func.c

    r7e7c8747 r95155b0c  
    222222}
    223223
     224
     225void order(const uint64_t val, uint64_t *rv, char *suffix)
     226{
     227        if (val > 1000000000000000000LL) {
     228                *rv = val / 1000000000000000000LL;
     229                *suffix = 'E';
     230        } else if (val > 1000000000000LL) {
     231                *rv = val / 1000000000000LL;
     232                *suffix = 'T';
     233        } else if (val > 1000000LL) {
     234                *rv = val / 1000000LL;
     235                *suffix = 'M';
     236        } else {
     237                *rv = val;
     238                *suffix = ' ';
     239        }
     240}
     241
    224242/** @}
    225243 */
  • kernel/generic/src/proc/task.c

    r7e7c8747 r95155b0c  
    5353#include <lib/elf.h>
    5454#include <errno.h>
     55#include <func.h>
    5556#include <syscall/copy.h>
    5657#include <console/klog.h>
     
    392393                        spinlock_lock(&t->lock);
    393394                       
    394                         uint64_t cycles = task_get_accounting(t);
     395                        uint64_t cycles;
    395396                        char suffix;
    396                        
    397                         if (cycles > 1000000000000000000LL) {
    398                                 cycles = cycles / 1000000000000000000LL;
    399                                 suffix = 'E';
    400                         } else if (cycles > 1000000000000LL) {
    401                                 cycles = cycles / 1000000000000LL;
    402                                 suffix = 'T';
    403                         } else if (cycles > 1000000LL) {
    404                                 cycles = cycles / 1000000LL;
    405                                 suffix = 'M';
    406                         } else
    407                                 suffix = ' ';
     397                        order(task_get_accounting(t), &cycles, &suffix);
    408398                       
    409399                        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));
  • kernel/generic/src/proc/thread.c

    r7e7c8747 r95155b0c  
    570570                        uint64_t cycles;
    571571                        char suffix;
    572                        
    573                         if (t->cycles > 1000000000000000000LL) {
    574                                 cycles = t->cycles / 1000000000000000000LL;
    575                                 suffix = 'E';
    576                         } else if (t->cycles > 1000000000000LL) {
    577                                 cycles = t->cycles / 1000000000000LL;
    578                                 suffix = 'T';
    579                         } else if (t->cycles > 1000000LL) {
    580                                 cycles = t->cycles / 1000000LL;
    581                                 suffix = 'M';
    582                         } else {
    583                                 cycles = t->cycles;
    584                                 suffix = ' ';
    585                         }
     572                        order(t->cycles, &cycles, &suffix);
    586573                       
    587574                        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);
Note: See TracChangeset for help on using the changeset viewer.