Changes in kernel/generic/src/console/cmd.c [40fb017:98000fb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/cmd.c
r40fb017 r98000fb 46 46 #include <print.h> 47 47 #include <panic.h> 48 #include < typedefs.h>48 #include <arch/types.h> 49 49 #include <adt/list.h> 50 50 #include <arch.h> 51 51 #include <config.h> 52 52 #include <func.h> 53 #include <str .h>53 #include <string.h> 54 54 #include <macros.h> 55 55 #include <debug.h> … … 66 66 #include <ipc/irq.h> 67 67 #include <ipc/event.h> 68 #include <sysinfo/sysinfo.h>69 68 #include <symtab.h> 70 69 #include <errno.h> … … 78 77 static cmd_info_t help_info = { 79 78 .name = "help", 80 .description = "List supported commands.",79 .description = "List of supported commands.", 81 80 .func = cmd_help, 82 81 .argc = 0 83 82 }; 84 83 85 /* Data and methods for 'reboot' command. */86 84 static int cmd_reboot(cmd_arg_t *argv); 87 85 static cmd_info_t reboot_info = { 88 86 .name = "reboot", 89 .description = "Reboot system.",87 .description = "Reboot.", 90 88 .func = cmd_reboot, 91 89 .argc = 0 92 90 }; 93 91 94 /* Data and methods for 'uptime' command. */95 92 static int cmd_uptime(cmd_arg_t *argv); 96 93 static cmd_info_t uptime_info = { 97 94 .name = "uptime", 98 .description = " Show system uptime.",95 .description = "Print uptime information.", 99 96 .func = cmd_uptime, 100 97 .argc = 0 101 98 }; 102 99 103 /* Data and methods for 'continue' command. */104 100 static int cmd_continue(cmd_arg_t *argv); 105 101 static cmd_info_t continue_info = { … … 111 107 112 108 #ifdef CONFIG_TEST 113 114 /* Data and methods for 'test' command. */ 109 static int cmd_tests(cmd_arg_t *argv); 110 static cmd_info_t tests_info = { 111 .name = "tests", 112 .description = "Print available kernel tests.", 113 .func = cmd_tests, 114 .argc = 0 115 }; 116 115 117 static char test_buf[MAX_CMDLINE + 1]; 116 118 static int cmd_test(cmd_arg_t *argv); 117 119 static cmd_arg_t test_argv[] = { 118 120 { 119 .type = ARG_TYPE_STRING _OPTIONAL,121 .type = ARG_TYPE_STRING, 120 122 .buffer = test_buf, 121 123 .len = sizeof(test_buf) … … 124 126 static cmd_info_t test_info = { 125 127 .name = "test", 126 .description = " <test> List kernel tests or run atest.",128 .description = "Run kernel test.", 127 129 .func = cmd_test, 128 130 .argc = 1, … … 130 132 }; 131 133 132 /* Data and methods for 'bench' command. */133 134 static int cmd_bench(cmd_arg_t *argv); 134 135 static cmd_arg_t bench_argv[] = { … … 144 145 static cmd_info_t bench_info = { 145 146 .name = "bench", 146 .description = " <test> <count>Run kernel test as benchmark.",147 .description = "Run kernel test as benchmark.", 147 148 .func = cmd_bench, 148 149 .argc = 2, 149 150 .argv = bench_argv 150 151 }; 151 152 #endif /* CONFIG_TEST */ 152 #endif 153 153 154 154 /* Data and methods for 'description' command. */ 155 155 static int cmd_desc(cmd_arg_t *argv); 156 156 static void desc_help(void); 157 static char desc_buf[MAX_CMDLINE +1];157 static char desc_buf[MAX_CMDLINE+1]; 158 158 static cmd_arg_t desc_argv = { 159 159 .type = ARG_TYPE_STRING, … … 163 163 static cmd_info_t desc_info = { 164 164 .name = "describe", 165 .description = " <command>Describe specified command.",165 .description = "Describe specified command.", 166 166 .help = desc_help, 167 167 .func = cmd_desc, … … 172 172 /* Data and methods for 'symaddr' command. */ 173 173 static int cmd_symaddr(cmd_arg_t *argv); 174 static char symaddr_buf[MAX_CMDLINE +1];174 static char symaddr_buf[MAX_CMDLINE+1]; 175 175 static cmd_arg_t symaddr_argv = { 176 176 .type = ARG_TYPE_STRING, … … 180 180 static cmd_info_t symaddr_info = { 181 181 .name = "symaddr", 182 .description = " <symbol>Return symbol address.",182 .description = "Return symbol address.", 183 183 .func = cmd_symaddr, 184 184 .argc = 1, … … 186 186 }; 187 187 188 /* Data and methods for 'set4' command. */ 189 static char set_buf[MAX_CMDLINE + 1]; 188 static char set_buf[MAX_CMDLINE+1]; 190 189 static int cmd_set4(cmd_arg_t *argv); 191 190 static cmd_arg_t set4_argv[] = { … … 201 200 static cmd_info_t set4_info = { 202 201 .name = "set4", 203 .description = " <addr> <value> Set 4B memory location to a value.",202 .description = "set <dest_addr> <value> - 4byte version", 204 203 .func = cmd_set4, 205 204 .argc = 2, … … 207 206 }; 208 207 209 /* Data and methods for 'call0' and 'mcall0'command. */208 /* Data and methods for 'call0' command. */ 210 209 static char call0_buf[MAX_CMDLINE + 1]; 211 210 static char carg1_buf[MAX_CMDLINE + 1]; … … 221 220 static cmd_info_t call0_info = { 222 221 .name = "call0", 223 .description = " <function> Call function().",222 .description = "call0 <function> -> call function().", 224 223 .func = cmd_call0, 225 224 .argc = 1, … … 236 235 static cmd_info_t mcall0_info = { 237 236 .name = "mcall0", 238 .description = " <function> Call function() on each CPU.",237 .description = "mcall0 <function> -> call function() on each CPU.", 239 238 .func = cmd_mcall0, 240 239 .argc = 1, … … 258 257 static cmd_info_t call1_info = { 259 258 .name = "call1", 260 .description = " <function> <arg1> Call function(arg1).",259 .description = "call1 <function> <arg1> -> call function(arg1).", 261 260 .func = cmd_call1, 262 261 .argc = 2, … … 285 284 static cmd_info_t call2_info = { 286 285 .name = "call2", 287 .description = " <function> <arg1> <arg2> Call function(arg1,arg2).",286 .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).", 288 287 .func = cmd_call2, 289 288 .argc = 3, … … 318 317 static cmd_info_t call3_info = { 319 318 .name = "call3", 320 .description = " <function> <arg1> <arg2> <arg3> Call function(arg1, arg2,arg3).",319 .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).", 321 320 .func = cmd_call3, 322 321 .argc = 4, … … 348 347 cmd_info_t tlb_info = { 349 348 .name = "tlb", 350 .description = "Print TLB of the current CPU.",349 .description = "Print TLB of current processor.", 351 350 .help = NULL, 352 351 .func = cmd_tlb, … … 355 354 }; 356 355 357 static char flag_buf[MAX_CMDLINE + 1];358 359 356 static int cmd_threads(cmd_arg_t *argv); 360 static cmd_arg_t threads_argv = {361 .type = ARG_TYPE_STRING_OPTIONAL,362 .buffer = flag_buf,363 .len = sizeof(flag_buf)364 };365 357 static cmd_info_t threads_info = { 366 358 .name = "threads", 367 .description = "List all threads (use -a for additional information).",359 .description = "List all threads.", 368 360 .func = cmd_threads, 369 .argc = 1, 370 .argv = &threads_argv 361 .argc = 0 371 362 }; 372 363 373 364 static int cmd_tasks(cmd_arg_t *argv); 374 static cmd_arg_t tasks_argv = {375 .type = ARG_TYPE_STRING_OPTIONAL,376 .buffer = flag_buf,377 .len = sizeof(flag_buf)378 };379 365 static cmd_info_t tasks_info = { 380 366 .name = "tasks", 381 .description = "List all tasks (use -a for additional information).",367 .description = "List all tasks.", 382 368 .func = cmd_tasks, 383 .argc = 1, 384 .argv = &tasks_argv 385 }; 386 387 #ifdef CONFIG_UDEBUG 388 389 /* Data and methods for 'btrace' command */ 390 static int cmd_btrace(cmd_arg_t *argv); 391 static cmd_arg_t btrace_argv = { 392 .type = ARG_TYPE_INT, 393 }; 394 static cmd_info_t btrace_info = { 395 .name = "btrace", 396 .description = "<threadid> Show thread stack trace.", 397 .func = cmd_btrace, 398 .argc = 1, 399 .argv = &btrace_argv 400 }; 401 402 #endif /* CONFIG_UDEBUG */ 369 .argc = 0 370 }; 371 403 372 404 373 static int cmd_sched(cmd_arg_t *argv); 405 374 static cmd_info_t sched_info = { 406 375 .name = "scheduler", 407 .description = " Showscheduler information.",376 .description = "List all scheduler information.", 408 377 .func = cmd_sched, 409 378 .argc = 0 … … 418 387 }; 419 388 420 static int cmd_sysinfo(cmd_arg_t *argv);421 static cmd_info_t sysinfo_info = {422 .name = "sysinfo",423 .description = "Dump sysinfo.",424 .func = cmd_sysinfo,425 .argc = 0426 };427 428 389 /* Data and methods for 'zones' command */ 429 390 static int cmd_zones(cmd_arg_t *argv); 430 391 static cmd_info_t zones_info = { 431 392 .name = "zones", 432 .description = "List memory zones.",393 .description = "List of memory zones.", 433 394 .func = cmd_zones, 434 395 .argc = 0 396 }; 397 398 /* Data and methods for 'ipc' command */ 399 static int cmd_ipc(cmd_arg_t *argv); 400 static cmd_arg_t ipc_argv = { 401 .type = ARG_TYPE_INT, 402 }; 403 static cmd_info_t ipc_info = { 404 .name = "ipc", 405 .description = "ipc <taskid> Show IPC information of given task.", 406 .func = cmd_ipc, 407 .argc = 1, 408 .argv = &ipc_argv 435 409 }; 436 410 … … 443 417 static cmd_info_t zone_info = { 444 418 .name = "zone", 445 .description = " <zone>Show memory zone structure.",419 .description = "Show memory zone structure.", 446 420 .func = cmd_zone, 447 421 .argc = 1, 448 422 .argv = &zone_argv 449 };450 451 /* Data and methods for 'ipc' command */452 static int cmd_ipc(cmd_arg_t *argv);453 static cmd_arg_t ipc_argv = {454 .type = ARG_TYPE_INT,455 };456 static cmd_info_t ipc_info = {457 .name = "ipc",458 .description = "<taskid> Show IPC information of a task.",459 .func = cmd_ipc,460 .argc = 1,461 .argv = &ipc_argv462 };463 464 /* Data and methods for 'kill' command */465 static int cmd_kill(cmd_arg_t *argv);466 static cmd_arg_t kill_argv = {467 .type = ARG_TYPE_INT,468 };469 static cmd_info_t kill_info = {470 .name = "kill",471 .description = "<taskid> Kill a task.",472 .func = cmd_kill,473 .argc = 1,474 .argv = &kill_argv475 423 }; 476 424 … … 506 454 &cpus_info, 507 455 &desc_info, 456 &reboot_info, 457 &uptime_info, 508 458 &halt_info, 509 459 &help_info, 510 460 &ipc_info, 511 &kill_info,512 &physmem_info,513 &reboot_info,514 &sched_info,515 461 &set4_info, 516 462 &slabs_info, 517 463 &symaddr_info, 518 &sysinfo_info, 464 &sched_info, 465 &threads_info, 519 466 &tasks_info, 520 & threads_info,467 &physmem_info, 521 468 &tlb_info, 522 &uptime_info,523 469 &version_info, 524 470 &zones_info, 525 471 &zone_info, 526 472 #ifdef CONFIG_TEST 473 &tests_info, 527 474 &test_info, 528 475 &bench_info, 529 476 #endif 530 #ifdef CONFIG_UDEBUG531 &btrace_info,532 #endif533 477 NULL 534 478 }; … … 542 486 void cmd_initialize(cmd_info_t *cmd) 543 487 { 544 spinlock_initialize(&cmd->lock, "cmd .lock");488 spinlock_initialize(&cmd->lock, "cmd"); 545 489 link_initialize(&cmd->link); 546 490 } … … 553 497 for (i = 0; basic_commands[i]; i++) { 554 498 cmd_initialize(basic_commands[i]); 555 } 556 557 for (i = 0; basic_commands[i]; i++) { 558 if (!cmd_register(basic_commands[i])) { 559 printf("Cannot register command %s\n", 560 basic_commands[i]->name); 561 } 562 } 563 } 499 if (!cmd_register(basic_commands[i])) 500 printf("Cannot register command %s\n", basic_commands[i]->name); 501 } 502 } 503 564 504 565 505 /** List supported commands. … … 585 525 } 586 526 587 unsigned int _len = (unsigned int) len;588 if ((_len != len) || (((int) _len) < 0)) {589 printf("Command length overflow\n");590 return 1;591 }592 593 527 for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { 594 528 cmd_info_t *hlp; … … 596 530 597 531 spinlock_lock(&hlp->lock); 598 printf("%-*s %s\n", _len, hlp->name, hlp->description);532 printf("%-*s %s\n", len, hlp->name, hlp->description); 599 533 spinlock_unlock(&hlp->lock); 600 534 } … … 605 539 } 606 540 541 607 542 /** Reboot the system. 608 543 * … … 619 554 } 620 555 556 621 557 /** Print system uptime information. 622 558 * … … 630 566 631 567 /* This doesn't have to be very accurate */ 632 sysarg_t sec = uptime->seconds1;568 unative_t sec = uptime->seconds1; 633 569 634 570 printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n", … … 685 621 uintptr_t symaddr; 686 622 char *symbol; 687 sysarg_t (*fnc)(void);623 unative_t (*fnc)(void); 688 624 fncptr_t fptr; 689 625 int rc; … … 698 634 printf("Duplicate symbol, be more specific.\n"); 699 635 } else if (rc == EOK) { 700 ipl_t ipl; 701 702 ipl = interrupts_disable(); 703 fnc = (sysarg_t (*)(void)) arch_construct_function(&fptr, 636 fnc = (unative_t (*)(void)) arch_construct_function(&fptr, 704 637 (void *) symaddr, (void *) cmd_call0); 705 printf("Calling %s() (%p)\n", symbol, (void *)symaddr);638 printf("Calling %s() (%p)\n", symbol, symaddr); 706 639 printf("Result: %#" PRIxn "\n", fnc()); 707 interrupts_restore(ipl);708 640 } else { 709 641 printf("No symbol information available.\n"); … … 720 652 */ 721 653 722 unsigned int i;654 size_t i; 723 655 for (i = 0; i < config.cpu_count; i++) { 724 656 if (!cpus[i].active) 725 657 continue; 726 658 727 thread_t *thread; 728 if ((thread = thread_create((void (*)(void *)) cmd_call0, 729 (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) { 730 irq_spinlock_lock(&thread->lock, true); 731 thread->cpu = &cpus[i]; 732 irq_spinlock_unlock(&thread->lock, true); 733 659 thread_t *t; 660 if ((t = thread_create((void (*)(void *)) cmd_call0, (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) { 661 spinlock_lock(&t->lock); 662 t->cpu = &cpus[i]; 663 spinlock_unlock(&t->lock); 734 664 printf("cpu%u: ", i); 735 736 thread_ready(thread); 737 thread_join(thread); 738 thread_detach(thread); 665 thread_ready(t); 666 thread_join(t); 667 thread_detach(t); 739 668 } else 740 669 printf("Unable to create thread for cpu%u\n", i); … … 749 678 uintptr_t symaddr; 750 679 char *symbol; 751 sysarg_t (*fnc)(sysarg_t, ...);752 sysarg_t arg1 = argv[1].intval;680 unative_t (*fnc)(unative_t, ...); 681 unative_t arg1 = argv[1].intval; 753 682 fncptr_t fptr; 754 683 int rc; … … 763 692 printf("Duplicate symbol, be more specific.\n"); 764 693 } else if (rc == EOK) { 765 ipl_t ipl; 766 767 ipl = interrupts_disable(); 768 fnc = (sysarg_t (*)(sysarg_t, ...)) 769 arch_construct_function(&fptr, (void *) symaddr, 770 (void *) cmd_call1); 771 printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, 772 (void *) symaddr, symbol); 694 fnc = (unative_t (*)(unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call1); 695 printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol); 773 696 printf("Result: %#" PRIxn "\n", fnc(arg1)); 774 interrupts_restore(ipl);775 697 } else { 776 698 printf("No symbol information available.\n"); … … 785 707 uintptr_t symaddr; 786 708 char *symbol; 787 sysarg_t (*fnc)(sysarg_t, sysarg_t, ...);788 sysarg_t arg1 = argv[1].intval;789 sysarg_t arg2 = argv[2].intval;709 unative_t (*fnc)(unative_t, unative_t, ...); 710 unative_t arg1 = argv[1].intval; 711 unative_t arg2 = argv[2].intval; 790 712 fncptr_t fptr; 791 713 int rc; … … 800 722 printf("Duplicate symbol, be more specific.\n"); 801 723 } else if (rc == EOK) { 802 ipl_t ipl; 803 804 ipl = interrupts_disable(); 805 fnc = (sysarg_t (*)(sysarg_t, sysarg_t, ...)) 806 arch_construct_function(&fptr, (void *) symaddr, 807 (void *) cmd_call2); 724 fnc = (unative_t (*)(unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call2); 808 725 printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n", 809 arg1, arg2, (void *)symaddr, symbol);726 arg1, arg2, symaddr, symbol); 810 727 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2)); 811 interrupts_restore(ipl);812 728 } else { 813 729 printf("No symbol information available.\n"); … … 821 737 uintptr_t symaddr; 822 738 char *symbol; 823 sysarg_t (*fnc)(sysarg_t, sysarg_t, sysarg_t, ...);824 sysarg_t arg1 = argv[1].intval;825 sysarg_t arg2 = argv[2].intval;826 sysarg_t arg3 = argv[3].intval;739 unative_t (*fnc)(unative_t, unative_t, unative_t, ...); 740 unative_t arg1 = argv[1].intval; 741 unative_t arg2 = argv[2].intval; 742 unative_t arg3 = argv[3].intval; 827 743 fncptr_t fptr; 828 744 int rc; … … 837 753 printf("Duplicate symbol, be more specific.\n"); 838 754 } else if (rc == EOK) { 839 ipl_t ipl; 840 841 ipl = interrupts_disable(); 842 fnc = (sysarg_t (*)(sysarg_t, sysarg_t, sysarg_t, ...)) 843 arch_construct_function(&fptr, (void *) symaddr, 844 (void *) cmd_call3); 845 printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n", 846 arg1, arg2, arg3, (void *) symaddr, symbol); 755 fnc = (unative_t (*)(unative_t, unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call3); 756 printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n", 757 arg1, arg2, arg3, symaddr, symbol); 847 758 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3)); 848 interrupts_restore(ipl);849 759 } else { 850 760 printf("No symbol information available.\n"); … … 852 762 return 1; 853 763 } 764 854 765 855 766 /** Print detailed description of 'describe' command. */ … … 902 813 bool pointer = false; 903 814 int rc; 904 905 if (((char *) 815 816 if (((char *)argv->buffer)[0] == '*') { 906 817 rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr); 907 818 pointer = true; 908 } else if (((char *) argv->buffer)[0] >= '0' && 909 ((char *) argv->buffer)[0] <= '9') { 910 uint64_t value; 911 rc = str_uint64((char *) argv->buffer, NULL, 0, true, &value); 912 if (rc == EOK) 913 addr = (uintptr_t) value; 914 } else 819 } else if (((char *) argv->buffer)[0] >= '0' && 820 ((char *)argv->buffer)[0] <= '9') { 821 rc = EOK; 822 addr = atoi((char *)argv->buffer); 823 } else { 915 824 rc = symtab_addr_lookup((char *) argv->buffer, &addr); 916 825 } 826 917 827 if (rc == ENOENT) 918 printf("Symbol %s not found.\n", (char *) argv->buffer); 919 else if (rc == EINVAL) 920 printf("Invalid address.\n"); 828 printf("Symbol %s not found.\n", argv->buffer); 921 829 else if (rc == EOVERFLOW) { 922 830 symtab_print_search((char *) argv->buffer); 923 printf("Duplicate symbol (be more specific) or address overflow.\n");831 printf("Duplicate symbol, be more specific.\n"); 924 832 } else if (rc == EOK) { 925 833 if (pointer) 926 834 addr = *(uintptr_t *) addr; 927 printf("Writing %#" PRIx 32" -> %p\n", arg1, (void *)addr);835 printf("Writing %#" PRIx64 " -> %p\n", arg1, addr); 928 836 *(uint32_t *) addr = arg1; 929 } else 837 } else { 930 838 printf("No symbol information available.\n"); 839 } 931 840 932 841 return 1; … … 939 848 * @return Always 1 940 849 */ 941 int cmd_slabs(cmd_arg_t *argv) 942 { 850 int cmd_slabs(cmd_arg_t * argv) { 943 851 slab_print_list(); 944 852 return 1; 945 853 } 946 854 947 /** Command for dumping sysinfo 855 856 /** Command for listings Thread information 948 857 * 949 858 * @param argv Ignores … … 951 860 * @return Always 1 952 861 */ 953 int cmd_sysinfo(cmd_arg_t *argv) 954 { 955 sysinfo_dump(NULL); 956 return 1; 957 } 958 959 /** Command for listing thread information 862 int cmd_threads(cmd_arg_t * argv) { 863 thread_print_list(); 864 return 1; 865 } 866 867 /** Command for listings Task information 868 * 869 * @param argv Ignores 870 * 871 * @return Always 1 872 */ 873 int cmd_tasks(cmd_arg_t * argv) { 874 task_print_list(); 875 return 1; 876 } 877 878 /** Command for listings Thread information 879 * 880 * @param argv Ignores 881 * 882 * @return Always 1 883 */ 884 int cmd_sched(cmd_arg_t * argv) { 885 sched_print_list(); 886 return 1; 887 } 888 889 /** Command for listing memory zones 960 890 * 961 891 * @param argv Ignored 962 892 * 963 * @return Always 1 964 */ 965 int cmd_threads(cmd_arg_t *argv) 966 { 967 if (str_cmp(flag_buf, "-a") == 0) 968 thread_print_list(true); 969 else if (str_cmp(flag_buf, "") == 0) 970 thread_print_list(false); 971 else 972 printf("Unknown argument \"%s\".\n", flag_buf); 973 974 return 1; 975 } 976 977 /** Command for listing task information 978 * 979 * @param argv Ignored 980 * 981 * @return Always 1 982 */ 983 int cmd_tasks(cmd_arg_t *argv) 984 { 985 if (str_cmp(flag_buf, "-a") == 0) 986 task_print_list(true); 987 else if (str_cmp(flag_buf, "") == 0) 988 task_print_list(false); 989 else 990 printf("Unknown argument \"%s\".\n", flag_buf); 991 992 return 1; 993 } 994 995 #ifdef CONFIG_UDEBUG 996 997 /** Command for printing thread stack trace 893 * return Always 1 894 */ 895 int cmd_zones(cmd_arg_t * argv) { 896 zone_print_list(); 897 return 1; 898 } 899 900 /** Command for memory zone details 998 901 * 999 902 * @param argv Integer argument from cmdline expected 1000 903 * 1001 904 * return Always 1 1002 * 1003 */ 1004 int cmd_btrace(cmd_arg_t *argv) 1005 { 1006 thread_stack_trace(argv[0].intval); 1007 return 1; 1008 } 1009 1010 #endif /* CONFIG_UDEBUG */ 1011 1012 /** Command for printing scheduler information 1013 * 1014 * @param argv Ignores 1015 * 1016 * @return Always 1 1017 */ 1018 int cmd_sched(cmd_arg_t *argv) 1019 { 1020 sched_print_list(); 1021 return 1; 1022 } 1023 1024 /** Command for listing memory zones 1025 * 1026 * @param argv Ignored 905 */ 906 int cmd_zone(cmd_arg_t * argv) { 907 zone_print_one(argv[0].intval); 908 return 1; 909 } 910 911 /** Command for printing task ipc details 912 * 913 * @param argv Integer argument from cmdline expected 1027 914 * 1028 915 * return Always 1 1029 916 */ 1030 int cmd_zones(cmd_arg_t *argv) 1031 { 1032 zones_print_list(); 1033 return 1; 1034 } 1035 1036 /** Command for memory zone details 1037 * 1038 * @param argv Integer argument from cmdline expected 1039 * 1040 * return Always 1 1041 */ 1042 int cmd_zone(cmd_arg_t *argv) 1043 { 1044 zone_print_one(argv[0].intval); 1045 return 1; 1046 } 1047 1048 /** Command for printing task IPC details 1049 * 1050 * @param argv Integer argument from cmdline expected 1051 * 1052 * return Always 1 1053 */ 1054 int cmd_ipc(cmd_arg_t *argv) 1055 { 917 int cmd_ipc(cmd_arg_t * argv) { 1056 918 ipc_print_task(argv[0].intval); 1057 919 return 1; 1058 920 } 1059 921 1060 /** Command for killing a task1061 *1062 * @param argv Integer argument from cmdline expected1063 *1064 * return 0 on failure, 1 on success.1065 */1066 int cmd_kill(cmd_arg_t *argv)1067 {1068 if (task_kill(argv[0].intval) != EOK)1069 return 0;1070 1071 return 1;1072 }1073 922 1074 923 /** Command for listing processors. … … 1114 963 1115 964 #ifdef CONFIG_TEST 965 /** Command for printing kernel tests list. 966 * 967 * @param argv Ignored. 968 * 969 * return Always 1. 970 */ 971 int cmd_tests(cmd_arg_t *argv) 972 { 973 size_t len = 0; 974 test_t *test; 975 for (test = tests; test->name != NULL; test++) { 976 if (str_length(test->name) > len) 977 len = str_length(test->name); 978 } 979 980 for (test = tests; test->name != NULL; test++) 981 printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)")); 982 983 printf("%-*s Run all safe tests\n", len, "*"); 984 return 1; 985 } 986 1116 987 static bool run_test(const test_t *test) 1117 988 { … … 1120 991 /* Update and read thread accounting 1121 992 for benchmarking */ 1122 irq_spinlock_lock(&TASK->lock, true); 1123 uint64_t ucycles0, kcycles0; 1124 task_get_accounting(TASK, &ucycles0, &kcycles0); 1125 irq_spinlock_unlock(&TASK->lock, true); 993 ipl_t ipl = interrupts_disable(); 994 spinlock_lock(&TASK->lock); 995 uint64_t t0 = task_get_accounting(TASK); 996 spinlock_unlock(&TASK->lock); 997 interrupts_restore(ipl); 1126 998 1127 999 /* Execute the test */ 1128 1000 test_quiet = false; 1129 c onst char *ret = test->entry();1001 char *ret = test->entry(); 1130 1002 1131 1003 /* Update and read thread accounting */ 1132 uint64_t ucycles1, kcycles1; 1133 irq_spinlock_lock(&TASK->lock, true); 1134 task_get_accounting(TASK, &ucycles1, &kcycles1); 1135 irq_spinlock_unlock(&TASK->lock, true); 1136 1137 uint64_t ucycles, kcycles; 1138 char usuffix, ksuffix; 1139 order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix); 1140 order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix); 1141 1142 printf("Time: %" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles\n", 1143 ucycles, usuffix, kcycles, ksuffix); 1004 ipl = interrupts_disable(); 1005 spinlock_lock(&TASK->lock); 1006 uint64_t dt = task_get_accounting(TASK) - t0; 1007 spinlock_unlock(&TASK->lock); 1008 interrupts_restore(ipl); 1009 1010 uint64_t cycles; 1011 char suffix; 1012 order(dt, &cycles, &suffix); 1013 1014 printf("Time: %" PRIu64 "%c cycles\n", cycles, suffix); 1144 1015 1145 1016 if (ret == NULL) { … … 1147 1018 return true; 1148 1019 } 1149 1020 1150 1021 printf("%s\n", ret); 1151 1022 return false; … … 1156 1027 uint32_t i; 1157 1028 bool ret = true; 1158 uint64_t ucycles, kcycles;1159 char usuffix, ksuffix;1029 uint64_t cycles; 1030 char suffix; 1160 1031 1161 1032 if (cnt < 1) … … 1173 1044 /* Update and read thread accounting 1174 1045 for benchmarking */ 1175 irq_spinlock_lock(&TASK->lock, true); 1176 uint64_t ucycles0, kcycles0; 1177 task_get_accounting(TASK, &ucycles0, &kcycles0); 1178 irq_spinlock_unlock(&TASK->lock, true); 1046 ipl_t ipl = interrupts_disable(); 1047 spinlock_lock(&TASK->lock); 1048 uint64_t t0 = task_get_accounting(TASK); 1049 spinlock_unlock(&TASK->lock); 1050 interrupts_restore(ipl); 1179 1051 1180 1052 /* Execute the test */ 1181 1053 test_quiet = true; 1182 c onst char *ret = test->entry();1054 char * ret = test->entry(); 1183 1055 1184 1056 /* Update and read thread accounting */ 1185 irq_spinlock_lock(&TASK->lock, true); 1186 uint64_t ucycles1, kcycles1; 1187 task_get_accounting(TASK, &ucycles1, &kcycles1); 1188 irq_spinlock_unlock(&TASK->lock, true); 1057 ipl = interrupts_disable(); 1058 spinlock_lock(&TASK->lock); 1059 uint64_t dt = task_get_accounting(TASK) - t0; 1060 spinlock_unlock(&TASK->lock); 1061 interrupts_restore(ipl); 1189 1062 1190 1063 if (ret != NULL) { … … 1194 1067 } 1195 1068 1196 data[i] = ucycles1 - ucycles0 + kcycles1 - kcycles0; 1197 order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix); 1198 order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix); 1199 printf("OK (%" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles)\n", 1200 ucycles, usuffix, kcycles, ksuffix); 1069 data[i] = dt; 1070 order(dt, &cycles, &suffix); 1071 printf("OK (%" PRIu64 "%c cycles)\n", cycles, suffix); 1201 1072 } 1202 1073 … … 1210 1081 } 1211 1082 1212 order _suffix(sum / (uint64_t) cnt, &ucycles, &usuffix);1213 printf("Average\t\t%" PRIu64 "%c\n", ucycles, usuffix);1083 order(sum / (uint64_t) cnt, &cycles, &suffix); 1084 printf("Average\t\t%" PRIu64 "%c\n", cycles, suffix); 1214 1085 } 1215 1086 … … 1219 1090 } 1220 1091 1221 static void list_tests(void) 1222 { 1223 size_t len = 0; 1224 test_t *test; 1225 1226 for (test = tests; test->name != NULL; test++) { 1227 if (str_length(test->name) > len) 1228 len = str_length(test->name); 1229 } 1230 1231 unsigned int _len = (unsigned int) len; 1232 if ((_len != len) || (((int) _len) < 0)) { 1233 printf("Command length overflow\n"); 1234 return; 1235 } 1236 1237 for (test = tests; test->name != NULL; test++) 1238 printf("%-*s %s%s\n", _len, test->name, test->desc, 1239 (test->safe ? "" : " (unsafe)")); 1240 1241 printf("%-*s Run all safe tests\n", _len, "*"); 1242 } 1243 1244 /** Command for listing and running kernel tests 1092 /** Command for returning kernel tests 1245 1093 * 1246 1094 * @param argv Argument vector. 1247 1095 * 1248 1096 * return Always 1. 1249 *1250 1097 */ 1251 1098 int cmd_test(cmd_arg_t *argv) … … 1261 1108 } 1262 1109 } 1263 } else if (str_cmp((char *) argv->buffer, "") != 0){1110 } else { 1264 1111 bool fnd = false; 1265 1112 … … 1274 1121 if (!fnd) 1275 1122 printf("Unknown test\n"); 1276 } else 1277 list_tests(); 1123 } 1278 1124 1279 1125 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.