Changeset 95155b0c in mainline for kernel/generic/src/console


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)

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.