Changes in kernel/generic/src/console/cmd.c [851f33a:4ce914d4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/cmd.c
r851f33a r4ce914d4 108 108 109 109 #ifdef CONFIG_TEST 110 static int cmd_tests(cmd_arg_t *argv); 111 static cmd_info_t tests_info = { 112 .name = "tests", 113 .description = "Print available kernel tests.", 114 .func = cmd_tests, 115 .argc = 0 116 }; 117 110 118 static char test_buf[MAX_CMDLINE + 1]; 111 119 static int cmd_test(cmd_arg_t *argv); 112 120 static cmd_arg_t test_argv[] = { 113 121 { 114 .type = ARG_TYPE_STRING _OPTIONAL,122 .type = ARG_TYPE_STRING, 115 123 .buffer = test_buf, 116 124 .len = sizeof(test_buf) … … 119 127 static cmd_info_t test_info = { 120 128 .name = "test", 121 .description = " Print list of kernel tests or run atest.",129 .description = "Run kernel test.", 122 130 .func = cmd_test, 123 131 .argc = 1, … … 199 207 }; 200 208 201 /* Data and methods for 'call0' and 'mcall0'command. */209 /* Data and methods for 'call0' command. */ 202 210 static char call0_buf[MAX_CMDLINE + 1]; 203 211 static char carg1_buf[MAX_CMDLINE + 1]; … … 347 355 }; 348 356 349 static char flag_buf[MAX_CMDLINE + 1];350 351 357 static int cmd_threads(cmd_arg_t *argv); 352 static cmd_arg_t threads_argv = {353 .type = ARG_TYPE_STRING_OPTIONAL,354 .buffer = flag_buf,355 .len = sizeof(flag_buf)356 };357 358 static cmd_info_t threads_info = { 358 359 .name = "threads", 359 .description = "List all threads (use -a for additional information).",360 .description = "List all threads.", 360 361 .func = cmd_threads, 361 .argc = 1, 362 .argv = &threads_argv 362 .argc = 0 363 363 }; 364 364 365 365 static int cmd_tasks(cmd_arg_t *argv); 366 static cmd_arg_t tasks_argv = {367 .type = ARG_TYPE_STRING_OPTIONAL,368 .buffer = flag_buf,369 .len = sizeof(flag_buf)370 };371 366 static cmd_info_t tasks_info = { 372 367 .name = "tasks", 373 .description = "List all tasks (use -a for additional information).",368 .description = "List all tasks.", 374 369 .func = cmd_tasks, 375 .argc = 1, 376 .argv = &tasks_argv 370 .argc = 0 377 371 }; 378 372 … … 501 495 &zone_info, 502 496 #ifdef CONFIG_TEST 497 &tests_info, 503 498 &test_info, 504 499 &bench_info, … … 515 510 void cmd_initialize(cmd_info_t *cmd) 516 511 { 517 spinlock_initialize(&cmd->lock, "cmd .lock");512 spinlock_initialize(&cmd->lock, "cmd"); 518 513 link_initialize(&cmd->link); 519 514 } … … 663 658 printf("Duplicate symbol, be more specific.\n"); 664 659 } else if (rc == EOK) { 665 ipl_t ipl;666 667 ipl = interrupts_disable();668 660 fnc = (unative_t (*)(void)) arch_construct_function(&fptr, 669 661 (void *) symaddr, (void *) cmd_call0); 670 662 printf("Calling %s() (%p)\n", symbol, symaddr); 671 663 printf("Result: %#" PRIxn "\n", fnc()); 672 interrupts_restore(ipl);673 664 } else { 674 665 printf("No symbol information available.\n"); … … 690 681 continue; 691 682 692 thread_t *thread; 693 if ((thread = thread_create((void (*)(void *)) cmd_call0, 694 (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) { 695 irq_spinlock_lock(&thread->lock, true); 696 thread->cpu = &cpus[i]; 697 irq_spinlock_unlock(&thread->lock, true); 698 699 printf("cpu%" PRIs ": ", i); 700 701 thread_ready(thread); 702 thread_join(thread); 703 thread_detach(thread); 683 thread_t *t; 684 if ((t = thread_create((void (*)(void *)) cmd_call0, (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) { 685 spinlock_lock(&t->lock); 686 t->cpu = &cpus[i]; 687 spinlock_unlock(&t->lock); 688 printf("cpu%u: ", i); 689 thread_ready(t); 690 thread_join(t); 691 thread_detach(t); 704 692 } else 705 printf("Unable to create thread for cpu% " PRIs "\n", i);693 printf("Unable to create thread for cpu%u\n", i); 706 694 } 707 695 … … 728 716 printf("Duplicate symbol, be more specific.\n"); 729 717 } else if (rc == EOK) { 730 ipl_t ipl;731 732 ipl = interrupts_disable();733 718 fnc = (unative_t (*)(unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call1); 734 719 printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol); 735 720 printf("Result: %#" PRIxn "\n", fnc(arg1)); 736 interrupts_restore(ipl);737 721 } else { 738 722 printf("No symbol information available.\n"); … … 762 746 printf("Duplicate symbol, be more specific.\n"); 763 747 } else if (rc == EOK) { 764 ipl_t ipl;765 766 ipl = interrupts_disable();767 748 fnc = (unative_t (*)(unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call2); 768 749 printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n", 769 750 arg1, arg2, symaddr, symbol); 770 751 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2)); 771 interrupts_restore(ipl);772 752 } else { 773 753 printf("No symbol information available.\n"); … … 797 777 printf("Duplicate symbol, be more specific.\n"); 798 778 } else if (rc == EOK) { 799 ipl_t ipl;800 801 ipl = interrupts_disable();802 779 fnc = (unative_t (*)(unative_t, unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call3); 803 780 printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n", 804 781 arg1, arg2, arg3, symaddr, symbol); 805 782 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3)); 806 interrupts_restore(ipl);807 783 } else { 808 784 printf("No symbol information available.\n"); … … 919 895 /** Command for listings Thread information 920 896 * 921 * @param argv Ignore d897 * @param argv Ignores 922 898 * 923 899 * @return Always 1 924 900 */ 925 int cmd_threads(cmd_arg_t *argv) 926 { 927 if (str_cmp(flag_buf, "-a") == 0) 928 thread_print_list(true); 929 else if (str_cmp(flag_buf, "") == 0) 930 thread_print_list(false); 931 else 932 printf("Unknown argument \"%s\".\n", flag_buf); 933 901 int cmd_threads(cmd_arg_t * argv) 902 { 903 thread_print_list(); 934 904 return 1; 935 905 } … … 937 907 /** Command for listings Task information 938 908 * 939 * @param argv Ignore d909 * @param argv Ignores 940 910 * 941 911 * @return Always 1 942 912 */ 943 int cmd_tasks(cmd_arg_t *argv) 944 { 945 if (str_cmp(flag_buf, "-a") == 0) 946 task_print_list(true); 947 else if (str_cmp(flag_buf, "") == 0) 948 task_print_list(false); 949 else 950 printf("Unknown argument \"%s\".\n", flag_buf); 951 913 int cmd_tasks(cmd_arg_t * argv) 914 { 915 task_print_list(); 952 916 return 1; 953 917 } … … 1057 1021 1058 1022 #ifdef CONFIG_TEST 1023 /** Command for printing kernel tests list. 1024 * 1025 * @param argv Ignored. 1026 * 1027 * return Always 1. 1028 */ 1029 int cmd_tests(cmd_arg_t *argv) 1030 { 1031 size_t len = 0; 1032 test_t *test; 1033 for (test = tests; test->name != NULL; test++) { 1034 if (str_length(test->name) > len) 1035 len = str_length(test->name); 1036 } 1037 1038 for (test = tests; test->name != NULL; test++) 1039 printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)")); 1040 1041 printf("%-*s Run all safe tests\n", len, "*"); 1042 return 1; 1043 } 1044 1059 1045 static bool run_test(const test_t *test) 1060 1046 { … … 1063 1049 /* Update and read thread accounting 1064 1050 for benchmarking */ 1065 irq_spinlock_lock(&TASK->lock, true); 1051 ipl_t ipl = interrupts_disable(); 1052 spinlock_lock(&TASK->lock); 1066 1053 uint64_t ucycles0, kcycles0; 1067 1054 task_get_accounting(TASK, &ucycles0, &kcycles0); 1068 irq_spinlock_unlock(&TASK->lock, true); 1055 spinlock_unlock(&TASK->lock); 1056 interrupts_restore(ipl); 1069 1057 1070 1058 /* Execute the test */ … … 1073 1061 1074 1062 /* Update and read thread accounting */ 1075 uint64_t ucycles1, kcycles1; 1076 irq_spinlock_lock(&TASK->lock, true); 1063 uint64_t ucycles1, kcycles1; 1064 ipl = interrupts_disable(); 1065 spinlock_lock(&TASK->lock); 1077 1066 task_get_accounting(TASK, &ucycles1, &kcycles1); 1078 irq_spinlock_unlock(&TASK->lock, true); 1067 spinlock_unlock(&TASK->lock); 1068 interrupts_restore(ipl); 1079 1069 1080 1070 uint64_t ucycles, kcycles; … … 1082 1072 order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix); 1083 1073 order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix); 1084 1074 1085 1075 printf("Time: %" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles\n", 1086 1076 ucycles, usuffix, kcycles, ksuffix); 1087 1077 1088 1078 if (ret == NULL) { … … 1090 1080 return true; 1091 1081 } 1092 1082 1093 1083 printf("%s\n", ret); 1094 1084 return false; … … 1116 1106 /* Update and read thread accounting 1117 1107 for benchmarking */ 1118 irq_spinlock_lock(&TASK->lock, true); 1108 ipl_t ipl = interrupts_disable(); 1109 spinlock_lock(&TASK->lock); 1119 1110 uint64_t ucycles0, kcycles0; 1120 1111 task_get_accounting(TASK, &ucycles0, &kcycles0); 1121 irq_spinlock_unlock(&TASK->lock, true); 1112 spinlock_unlock(&TASK->lock); 1113 interrupts_restore(ipl); 1122 1114 1123 1115 /* Execute the test */ … … 1126 1118 1127 1119 /* Update and read thread accounting */ 1128 irq_spinlock_lock(&TASK->lock, true); 1120 ipl = interrupts_disable(); 1121 spinlock_lock(&TASK->lock); 1129 1122 uint64_t ucycles1, kcycles1; 1130 1123 task_get_accounting(TASK, &ucycles1, &kcycles1); 1131 irq_spinlock_unlock(&TASK->lock, true); 1132 1124 spinlock_unlock(&TASK->lock); 1125 interrupts_restore(ipl); 1126 1133 1127 if (ret != NULL) { 1134 1128 printf("%s\n", ret); … … 1141 1135 order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix); 1142 1136 printf("OK (%" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles)\n", 1143 1137 ucycles, usuffix, kcycles, ksuffix); 1144 1138 } 1145 1139 … … 1162 1156 } 1163 1157 1164 static void list_tests(void) 1165 { 1166 size_t len = 0; 1167 test_t *test; 1168 1169 for (test = tests; test->name != NULL; test++) { 1170 if (str_length(test->name) > len) 1171 len = str_length(test->name); 1172 } 1173 1174 for (test = tests; test->name != NULL; test++) 1175 printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)")); 1176 1177 printf("%-*s Run all safe tests\n", len, "*"); 1178 } 1179 1180 /** Command for listing and running kernel tests 1158 /** Command for returning kernel tests 1181 1159 * 1182 1160 * @param argv Argument vector. 1183 1161 * 1184 1162 * return Always 1. 1185 *1186 1163 */ 1187 1164 int cmd_test(cmd_arg_t *argv) … … 1197 1174 } 1198 1175 } 1199 } else if (str_cmp((char *) argv->buffer, "") != 0){1176 } else { 1200 1177 bool fnd = false; 1201 1178 … … 1210 1187 if (!fnd) 1211 1188 printf("Unknown test\n"); 1212 } else 1213 list_tests(); 1189 } 1214 1190 1215 1191 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.