Changeset 95155b0c in mainline for kernel/generic/src/console
- Timestamp:
- 2006-12-19T10:12:24Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c8410ec9
- Parents:
- 7e7c8747
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/cmd.c
r7e7c8747 r95155b0c 117 117 .argc = 1, 118 118 .argv = test_argv 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 119 138 }; 120 139 #endif … … 412 431 &tests_info, 413 432 &test_info, 433 &bench_info, 414 434 #endif 415 435 NULL … … 872 892 873 893 /* Execute the test */ 874 char * ret = test->entry( );894 char * ret = test->entry(false); 875 895 876 896 /* Update and read thread accounting */ … … 881 901 interrupts_restore(ipl); 882 902 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); 884 908 885 909 if (ret == NULL) { … … 890 914 printf("%s\n", ret); 891 915 return false; 916 } 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; 892 982 } 893 983 … … 927 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 1047 #endif 930 1048
Note:
See TracChangeset
for help on using the changeset viewer.