Subversion Repositories HelenOS

Rev

Rev 2042 | Rev 2051 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2042 Rev 2050
Line 115... Line 115...
115
    .description = "Run kernel test.",
115
    .description = "Run kernel test.",
116
    .func = cmd_test,
116
    .func = cmd_test,
117
    .argc = 1,
117
    .argc = 1,
118
    .argv = test_argv
118
    .argv = test_argv
119
};
119
};
-
 
120
 
-
 
121
static int cmd_bench(cmd_arg_t *argv);
-
 
122
static 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
};
-
 
132
static 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
-
 
138
};
120
#endif
139
#endif
121
 
140
 
122
/* Data and methods for 'description' command. */
141
/* Data and methods for 'description' command. */
123
static int cmd_desc(cmd_arg_t *argv);
142
static int cmd_desc(cmd_arg_t *argv);
124
static void desc_help(void);
143
static void desc_help(void);
Line 409... Line 428...
409
    &zones_info,
428
    &zones_info,
410
    &zone_info,
429
    &zone_info,
411
#ifdef CONFIG_TEST
430
#ifdef CONFIG_TEST
412
    &tests_info,
431
    &tests_info,
413
    &test_info,
432
    &test_info,
-
 
433
    &bench_info,
414
#endif
434
#endif
415
    NULL
435
    NULL
416
};
436
};
417
 
437
 
418
 
438
 
Line 869... Line 889...
869
    uint64_t t0 = task_get_accounting(TASK);
889
    uint64_t t0 = task_get_accounting(TASK);
870
    spinlock_unlock(&TASK->lock);
890
    spinlock_unlock(&TASK->lock);
871
    interrupts_restore(ipl);
891
    interrupts_restore(ipl);
872
   
892
   
873
    /* Execute the test */
893
    /* Execute the test */
874
    char * ret = test->entry();
894
    char * ret = test->entry(false);
875
   
895
   
876
    /* Update and read thread accounting */
896
    /* Update and read thread accounting */
877
    ipl = interrupts_disable();
897
    ipl = interrupts_disable();
878
    spinlock_lock(&TASK->lock);
898
    spinlock_lock(&TASK->lock);
879
    uint64_t dt = task_get_accounting(TASK) - t0;
899
    uint64_t dt = task_get_accounting(TASK) - t0;
880
    spinlock_unlock(&TASK->lock);
900
    spinlock_unlock(&TASK->lock);
881
    interrupts_restore(ipl);
901
    interrupts_restore(ipl);
882
   
902
   
-
 
903
    uint64_t cycles;
-
 
904
    char suffix;
-
 
905
    order(dt, &cycles, &suffix);
-
 
906
       
883
    printf("Time: %llu cycles\n", dt);
907
    printf("Time: %llu%c cycles\n", cycles, suffix);
884
   
908
   
885
    if (ret == NULL) {
909
    if (ret == NULL) {
886
        printf("Test passed\n");
910
        printf("Test passed\n");
887
        return true;
911
        return true;
888
    }
912
    }
889
 
913
 
890
    printf("%s\n", ret);
914
    printf("%s\n", ret);
891
    return false;
915
    return false;
892
}
916
}
893
 
917
 
-
 
918
static 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;
-
 
982
}
-
 
983
 
894
/** Command for returning kernel tests
984
/** Command for returning kernel tests
895
 *
985
 *
896
 * @param argv Argument vector.
986
 * @param argv Argument vector.
897
 *
987
 *
898
 * return Always 1.
988
 * return Always 1.
Line 924... Line 1014...
924
            printf("Unknown test\n");
1014
            printf("Unknown test\n");
925
    }
1015
    }
926
   
1016
   
927
    return 1;
1017
    return 1;
928
}
1018
}
-
 
1019
 
-
 
1020
/** Command for returning kernel tests as benchmarks
-
 
1021
 *
-
 
1022
 * @param argv Argument vector.
-
 
1023
 *
-
 
1024
 * return Always 1.
-
 
1025
 */
-
 
1026
int 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
 
929
#endif
1047
#endif
930
 
1048
 
931
/** @}
1049
/** @}
932
 */
1050
 */