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