Changes in kernel/generic/src/console/cmd.c [98000fb:40fb017] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/cmd.c
r98000fb r40fb017 46 46 #include <print.h> 47 47 #include <panic.h> 48 #include < arch/types.h>48 #include <typedefs.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 ing.h>53 #include <str.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> 68 69 #include <symtab.h> 69 70 #include <errno.h> … … 77 78 static cmd_info_t help_info = { 78 79 .name = "help", 79 .description = "List ofsupported commands.",80 .description = "List supported commands.", 80 81 .func = cmd_help, 81 82 .argc = 0 82 83 }; 83 84 85 /* Data and methods for 'reboot' command. */ 84 86 static int cmd_reboot(cmd_arg_t *argv); 85 87 static cmd_info_t reboot_info = { 86 88 .name = "reboot", 87 .description = "Reboot .",89 .description = "Reboot system.", 88 90 .func = cmd_reboot, 89 91 .argc = 0 90 92 }; 91 93 94 /* Data and methods for 'uptime' command. */ 92 95 static int cmd_uptime(cmd_arg_t *argv); 93 96 static cmd_info_t uptime_info = { 94 97 .name = "uptime", 95 .description = " Print uptime information.",98 .description = "Show system uptime.", 96 99 .func = cmd_uptime, 97 100 .argc = 0 98 101 }; 99 102 103 /* Data and methods for 'continue' command. */ 100 104 static int cmd_continue(cmd_arg_t *argv); 101 105 static cmd_info_t continue_info = { … … 107 111 108 112 #ifdef CONFIG_TEST 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 113 114 /* Data and methods for 'test' command. */ 117 115 static char test_buf[MAX_CMDLINE + 1]; 118 116 static int cmd_test(cmd_arg_t *argv); 119 117 static cmd_arg_t test_argv[] = { 120 118 { 121 .type = ARG_TYPE_STRING ,119 .type = ARG_TYPE_STRING_OPTIONAL, 122 120 .buffer = test_buf, 123 121 .len = sizeof(test_buf) … … 126 124 static cmd_info_t test_info = { 127 125 .name = "test", 128 .description = " Run kerneltest.",126 .description = "<test> List kernel tests or run a test.", 129 127 .func = cmd_test, 130 128 .argc = 1, … … 132 130 }; 133 131 132 /* Data and methods for 'bench' command. */ 134 133 static int cmd_bench(cmd_arg_t *argv); 135 134 static cmd_arg_t bench_argv[] = { … … 145 144 static cmd_info_t bench_info = { 146 145 .name = "bench", 147 .description = " Run kernel test as benchmark.",146 .description = "<test> <count> Run kernel test as benchmark.", 148 147 .func = cmd_bench, 149 148 .argc = 2, 150 149 .argv = bench_argv 151 150 }; 152 #endif 151 152 #endif /* CONFIG_TEST */ 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 = " Describe specified command.",165 .description = "<command> 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 = " Return symbol address.",182 .description = "<symbol> Return symbol address.", 183 183 .func = cmd_symaddr, 184 184 .argc = 1, … … 186 186 }; 187 187 188 static char set_buf[MAX_CMDLINE+1]; 188 /* Data and methods for 'set4' command. */ 189 static char set_buf[MAX_CMDLINE + 1]; 189 190 static int cmd_set4(cmd_arg_t *argv); 190 191 static cmd_arg_t set4_argv[] = { … … 200 201 static cmd_info_t set4_info = { 201 202 .name = "set4", 202 .description = " set <dest_addr> <value> - 4byte version",203 .description = "<addr> <value> Set 4B memory location to a value.", 203 204 .func = cmd_set4, 204 205 .argc = 2, … … 206 207 }; 207 208 208 /* Data and methods for 'call0' command. */209 /* Data and methods for 'call0' and 'mcall0' command. */ 209 210 static char call0_buf[MAX_CMDLINE + 1]; 210 211 static char carg1_buf[MAX_CMDLINE + 1]; … … 220 221 static cmd_info_t call0_info = { 221 222 .name = "call0", 222 .description = " call0 <function> -> call function().",223 .description = "<function> Call function().", 223 224 .func = cmd_call0, 224 225 .argc = 1, … … 235 236 static cmd_info_t mcall0_info = { 236 237 .name = "mcall0", 237 .description = " mcall0 <function> -> call function() on each CPU.",238 .description = "<function> Call function() on each CPU.", 238 239 .func = cmd_mcall0, 239 240 .argc = 1, … … 257 258 static cmd_info_t call1_info = { 258 259 .name = "call1", 259 .description = " call1 <function> <arg1> -> call function(arg1).",260 .description = "<function> <arg1> Call function(arg1).", 260 261 .func = cmd_call1, 261 262 .argc = 2, … … 284 285 static cmd_info_t call2_info = { 285 286 .name = "call2", 286 .description = " call2 <function> <arg1> <arg2> -> call function(arg1,arg2).",287 .description = "<function> <arg1> <arg2> Call function(arg1, arg2).", 287 288 .func = cmd_call2, 288 289 .argc = 3, … … 317 318 static cmd_info_t call3_info = { 318 319 .name = "call3", 319 .description = " call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).",320 .description = "<function> <arg1> <arg2> <arg3> Call function(arg1, arg2, arg3).", 320 321 .func = cmd_call3, 321 322 .argc = 4, … … 347 348 cmd_info_t tlb_info = { 348 349 .name = "tlb", 349 .description = "Print TLB of current processor.",350 .description = "Print TLB of the current CPU.", 350 351 .help = NULL, 351 352 .func = cmd_tlb, … … 354 355 }; 355 356 357 static char flag_buf[MAX_CMDLINE + 1]; 358 356 359 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 }; 357 365 static cmd_info_t threads_info = { 358 366 .name = "threads", 359 .description = "List all threads .",367 .description = "List all threads (use -a for additional information).", 360 368 .func = cmd_threads, 361 .argc = 0 369 .argc = 1, 370 .argv = &threads_argv 362 371 }; 363 372 364 373 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 }; 365 379 static cmd_info_t tasks_info = { 366 380 .name = "tasks", 367 .description = "List all tasks .",381 .description = "List all tasks (use -a for additional information).", 368 382 .func = cmd_tasks, 369 .argc = 0 370 }; 371 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 */ 372 403 373 404 static int cmd_sched(cmd_arg_t *argv); 374 405 static cmd_info_t sched_info = { 375 406 .name = "scheduler", 376 .description = " List allscheduler information.",407 .description = "Show scheduler information.", 377 408 .func = cmd_sched, 378 409 .argc = 0 … … 387 418 }; 388 419 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 = 0 426 }; 427 389 428 /* Data and methods for 'zones' command */ 390 429 static int cmd_zones(cmd_arg_t *argv); 391 430 static cmd_info_t zones_info = { 392 431 .name = "zones", 393 .description = "List ofmemory zones.",432 .description = "List memory zones.", 394 433 .func = cmd_zones, 395 434 .argc = 0 435 }; 436 437 /* Data and methods for 'zone' command */ 438 static int cmd_zone(cmd_arg_t *argv); 439 static cmd_arg_t zone_argv = { 440 .type = ARG_TYPE_INT, 441 }; 442 443 static cmd_info_t zone_info = { 444 .name = "zone", 445 .description = "<zone> Show memory zone structure.", 446 .func = cmd_zone, 447 .argc = 1, 448 .argv = &zone_argv 396 449 }; 397 450 … … 403 456 static cmd_info_t ipc_info = { 404 457 .name = "ipc", 405 .description = " ipc <taskid> Show IPC information of giventask.",458 .description = "<taskid> Show IPC information of a task.", 406 459 .func = cmd_ipc, 407 460 .argc = 1, … … 409 462 }; 410 463 411 /* Data and methods for ' zone' command */412 static int cmd_ zone(cmd_arg_t *argv);413 static cmd_arg_t zone_argv = {464 /* Data and methods for 'kill' command */ 465 static int cmd_kill(cmd_arg_t *argv); 466 static cmd_arg_t kill_argv = { 414 467 .type = ARG_TYPE_INT, 415 468 }; 416 417 static cmd_info_t zone_info = { 418 .name = "zone", 419 .description = "Show memory zone structure.", 420 .func = cmd_zone, 469 static cmd_info_t kill_info = { 470 .name = "kill", 471 .description = "<taskid> Kill a task.", 472 .func = cmd_kill, 421 473 .argc = 1, 422 .argv = & zone_argv474 .argv = &kill_argv 423 475 }; 424 476 … … 454 506 &cpus_info, 455 507 &desc_info, 456 &reboot_info,457 &uptime_info,458 508 &halt_info, 459 509 &help_info, 460 510 &ipc_info, 511 &kill_info, 512 &physmem_info, 513 &reboot_info, 514 &sched_info, 461 515 &set4_info, 462 516 &slabs_info, 463 517 &symaddr_info, 464 &sched_info, 518 &sysinfo_info, 519 &tasks_info, 465 520 &threads_info, 466 &tasks_info,467 &physmem_info,468 521 &tlb_info, 522 &uptime_info, 469 523 &version_info, 470 524 &zones_info, 471 525 &zone_info, 472 526 #ifdef CONFIG_TEST 473 &tests_info,474 527 &test_info, 475 528 &bench_info, 476 529 #endif 530 #ifdef CONFIG_UDEBUG 531 &btrace_info, 532 #endif 477 533 NULL 478 534 }; … … 486 542 void cmd_initialize(cmd_info_t *cmd) 487 543 { 488 spinlock_initialize(&cmd->lock, "cmd ");544 spinlock_initialize(&cmd->lock, "cmd.lock"); 489 545 link_initialize(&cmd->link); 490 546 } … … 497 553 for (i = 0; basic_commands[i]; i++) { 498 554 cmd_initialize(basic_commands[i]); 499 if (!cmd_register(basic_commands[i])) 500 printf("Cannot register command %s\n", basic_commands[i]->name); 501 } 502 } 503 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 } 504 564 505 565 /** List supported commands. … … 525 585 } 526 586 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 527 593 for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { 528 594 cmd_info_t *hlp; … … 530 596 531 597 spinlock_lock(&hlp->lock); 532 printf("%-*s %s\n", len, hlp->name, hlp->description);598 printf("%-*s %s\n", _len, hlp->name, hlp->description); 533 599 spinlock_unlock(&hlp->lock); 534 600 } … … 539 605 } 540 606 541 542 607 /** Reboot the system. 543 608 * … … 554 619 } 555 620 556 557 621 /** Print system uptime information. 558 622 * … … 566 630 567 631 /* This doesn't have to be very accurate */ 568 unative_t sec = uptime->seconds1;632 sysarg_t sec = uptime->seconds1; 569 633 570 634 printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n", … … 621 685 uintptr_t symaddr; 622 686 char *symbol; 623 unative_t (*fnc)(void);687 sysarg_t (*fnc)(void); 624 688 fncptr_t fptr; 625 689 int rc; … … 634 698 printf("Duplicate symbol, be more specific.\n"); 635 699 } else if (rc == EOK) { 636 fnc = (unative_t (*)(void)) arch_construct_function(&fptr, 700 ipl_t ipl; 701 702 ipl = interrupts_disable(); 703 fnc = (sysarg_t (*)(void)) arch_construct_function(&fptr, 637 704 (void *) symaddr, (void *) cmd_call0); 638 printf("Calling %s() (%p)\n", symbol, symaddr);705 printf("Calling %s() (%p)\n", symbol, (void *) symaddr); 639 706 printf("Result: %#" PRIxn "\n", fnc()); 707 interrupts_restore(ipl); 640 708 } else { 641 709 printf("No symbol information available.\n"); … … 652 720 */ 653 721 654 size_t i;722 unsigned int i; 655 723 for (i = 0; i < config.cpu_count; i++) { 656 724 if (!cpus[i].active) 657 725 continue; 658 726 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); 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 664 734 printf("cpu%u: ", i); 665 thread_ready(t); 666 thread_join(t); 667 thread_detach(t); 735 736 thread_ready(thread); 737 thread_join(thread); 738 thread_detach(thread); 668 739 } else 669 740 printf("Unable to create thread for cpu%u\n", i); … … 678 749 uintptr_t symaddr; 679 750 char *symbol; 680 unative_t (*fnc)(unative_t, ...);681 unative_t arg1 = argv[1].intval;751 sysarg_t (*fnc)(sysarg_t, ...); 752 sysarg_t arg1 = argv[1].intval; 682 753 fncptr_t fptr; 683 754 int rc; … … 692 763 printf("Duplicate symbol, be more specific.\n"); 693 764 } else if (rc == EOK) { 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); 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); 696 773 printf("Result: %#" PRIxn "\n", fnc(arg1)); 774 interrupts_restore(ipl); 697 775 } else { 698 776 printf("No symbol information available.\n"); … … 707 785 uintptr_t symaddr; 708 786 char *symbol; 709 unative_t (*fnc)(unative_t, unative_t, ...);710 unative_t arg1 = argv[1].intval;711 unative_t arg2 = argv[2].intval;787 sysarg_t (*fnc)(sysarg_t, sysarg_t, ...); 788 sysarg_t arg1 = argv[1].intval; 789 sysarg_t arg2 = argv[2].intval; 712 790 fncptr_t fptr; 713 791 int rc; … … 722 800 printf("Duplicate symbol, be more specific.\n"); 723 801 } else if (rc == EOK) { 724 fnc = (unative_t (*)(unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call2); 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); 725 808 printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n", 726 arg1, arg2, symaddr, symbol);809 arg1, arg2, (void *) symaddr, symbol); 727 810 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2)); 811 interrupts_restore(ipl); 728 812 } else { 729 813 printf("No symbol information available.\n"); … … 737 821 uintptr_t symaddr; 738 822 char *symbol; 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;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; 743 827 fncptr_t fptr; 744 828 int rc; … … 753 837 printf("Duplicate symbol, be more specific.\n"); 754 838 } else if (rc == EOK) { 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); 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); 758 847 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3)); 848 interrupts_restore(ipl); 759 849 } else { 760 850 printf("No symbol information available.\n"); … … 762 852 return 1; 763 853 } 764 765 854 766 855 /** Print detailed description of 'describe' command. */ … … 813 902 bool pointer = false; 814 903 int rc; 815 816 if (((char *) argv->buffer)[0] == '*') {904 905 if (((char *) argv->buffer)[0] == '*') { 817 906 rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr); 818 907 pointer = true; 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 { 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 824 915 rc = symtab_addr_lookup((char *) argv->buffer, &addr); 825 } 826 916 827 917 if (rc == ENOENT) 828 printf("Symbol %s not found.\n", argv->buffer); 918 printf("Symbol %s not found.\n", (char *) argv->buffer); 919 else if (rc == EINVAL) 920 printf("Invalid address.\n"); 829 921 else if (rc == EOVERFLOW) { 830 922 symtab_print_search((char *) argv->buffer); 831 printf("Duplicate symbol , be more specific.\n");923 printf("Duplicate symbol (be more specific) or address overflow.\n"); 832 924 } else if (rc == EOK) { 833 925 if (pointer) 834 926 addr = *(uintptr_t *) addr; 835 printf("Writing %#" PRIx 64 " -> %p\n", arg1,addr);927 printf("Writing %#" PRIx32" -> %p\n", arg1, (void *) addr); 836 928 *(uint32_t *) addr = arg1; 837 } else {929 } else 838 930 printf("No symbol information available.\n"); 839 }840 931 841 932 return 1; … … 848 939 * @return Always 1 849 940 */ 850 int cmd_slabs(cmd_arg_t * argv) { 941 int cmd_slabs(cmd_arg_t *argv) 942 { 851 943 slab_print_list(); 852 944 return 1; 853 945 } 854 946 855 856 /** Command for listings Thread information 947 /** Command for dumping sysinfo 857 948 * 858 949 * @param argv Ignores … … 860 951 * @return Always 1 861 952 */ 862 int cmd_threads(cmd_arg_t * argv) { 863 thread_print_list(); 864 return 1; 865 } 866 867 /** Command for listings Task information 953 int cmd_sysinfo(cmd_arg_t *argv) 954 { 955 sysinfo_dump(NULL); 956 return 1; 957 } 958 959 /** Command for listing thread information 960 * 961 * @param argv Ignored 962 * 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 998 * 999 * @param argv Integer argument from cmdline expected 1000 * 1001 * 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 868 1013 * 869 1014 * @param argv Ignores … … 871 1016 * @return Always 1 872 1017 */ 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) { 1018 int cmd_sched(cmd_arg_t *argv) 1019 { 885 1020 sched_print_list(); 886 1021 return 1; … … 893 1028 * return Always 1 894 1029 */ 895 int cmd_zones(cmd_arg_t * argv) { 896 zone_print_list(); 1030 int cmd_zones(cmd_arg_t *argv) 1031 { 1032 zones_print_list(); 897 1033 return 1; 898 1034 } … … 904 1040 * return Always 1 905 1041 */ 906 int cmd_zone(cmd_arg_t * argv) { 1042 int cmd_zone(cmd_arg_t *argv) 1043 { 907 1044 zone_print_one(argv[0].intval); 908 1045 return 1; 909 1046 } 910 1047 911 /** Command for printing task ipcdetails1048 /** Command for printing task IPC details 912 1049 * 913 1050 * @param argv Integer argument from cmdline expected … … 915 1052 * return Always 1 916 1053 */ 917 int cmd_ipc(cmd_arg_t * argv) { 1054 int cmd_ipc(cmd_arg_t *argv) 1055 { 918 1056 ipc_print_task(argv[0].intval); 919 1057 return 1; 920 1058 } 921 1059 1060 /** Command for killing a task 1061 * 1062 * @param argv Integer argument from cmdline expected 1063 * 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 } 922 1073 923 1074 /** Command for listing processors. … … 963 1114 964 1115 #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 987 1116 static bool run_test(const test_t *test) 988 1117 { … … 991 1120 /* Update and read thread accounting 992 1121 for benchmarking */ 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); 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); 998 1126 999 1127 /* Execute the test */ 1000 1128 test_quiet = false; 1001 c har *ret = test->entry();1129 const char *ret = test->entry(); 1002 1130 1003 1131 /* Update and read thread accounting */ 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); 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); 1015 1144 1016 1145 if (ret == NULL) { … … 1018 1147 return true; 1019 1148 } 1020 1149 1021 1150 printf("%s\n", ret); 1022 1151 return false; … … 1027 1156 uint32_t i; 1028 1157 bool ret = true; 1029 uint64_t cycles;1030 char suffix;1158 uint64_t ucycles, kcycles; 1159 char usuffix, ksuffix; 1031 1160 1032 1161 if (cnt < 1) … … 1044 1173 /* Update and read thread accounting 1045 1174 for benchmarking */ 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); 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); 1051 1179 1052 1180 /* Execute the test */ 1053 1181 test_quiet = true; 1054 c har *ret = test->entry();1182 const char *ret = test->entry(); 1055 1183 1056 1184 /* Update and read thread accounting */ 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); 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); 1062 1189 1063 1190 if (ret != NULL) { … … 1067 1194 } 1068 1195 1069 data[i] = dt; 1070 order(dt, &cycles, &suffix); 1071 printf("OK (%" PRIu64 "%c cycles)\n", cycles, suffix); 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); 1072 1201 } 1073 1202 … … 1081 1210 } 1082 1211 1083 order (sum / (uint64_t) cnt, &cycles, &suffix);1084 printf("Average\t\t%" PRIu64 "%c\n", cycles,suffix);1212 order_suffix(sum / (uint64_t) cnt, &ucycles, &usuffix); 1213 printf("Average\t\t%" PRIu64 "%c\n", ucycles, usuffix); 1085 1214 } 1086 1215 … … 1090 1219 } 1091 1220 1092 /** Command for returning kernel tests 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 1093 1245 * 1094 1246 * @param argv Argument vector. 1095 1247 * 1096 1248 * return Always 1. 1249 * 1097 1250 */ 1098 1251 int cmd_test(cmd_arg_t *argv) … … 1108 1261 } 1109 1262 } 1110 } else {1263 } else if (str_cmp((char *) argv->buffer, "") != 0) { 1111 1264 bool fnd = false; 1112 1265 … … 1121 1274 if (!fnd) 1122 1275 printf("Unknown test\n"); 1123 } 1276 } else 1277 list_tests(); 1124 1278 1125 1279 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.