Changeset df58e44 in mainline
- Timestamp:
- 2011-01-27T16:36:35Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5b7a107
- Parents:
- 0843f02
- Location:
- kernel/generic
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/proc/thread.h
r0843f02 rdf58e44 91 91 92 92 /** Function implementing the thread. */ 93 void (* 93 void (*thread_code)(void *); 94 94 /** Argument passed to thread_code() function. */ 95 95 void *thread_arg; 96 96 97 97 /** 98 * From here, the stored context is restored when the thread is99 * scheduled.98 * From here, the stored context is restored 99 * when the thread is scheduled. 100 100 */ 101 101 context_t saved_context; 102 /** 103 * From here, the stored timeout context is restored when sleep times 104 * out. 102 103 /** 104 * From here, the stored timeout context 105 * is restored when sleep times out. 105 106 */ 106 107 context_t sleep_timeout_context; 107 /** 108 * From here, the stored interruption context is restored when sleep is 109 * interrupted. 108 109 /** 110 * From here, the stored interruption context 111 * is restored when sleep is interrupted. 110 112 */ 111 113 context_t sleep_interruption_context; … … 125 127 */ 126 128 bool in_copy_from_uspace; 129 127 130 /** 128 131 * True if this thread is executing copy_to_uspace(). … … 136 139 */ 137 140 bool interrupted; 141 142 /** 143 * If true, the scheduler will print a stack trace 144 * to the kernel console upon scheduling this thread. 145 */ 146 bool btrace; 138 147 139 148 /** If true, thread_join_timeout() cannot be used on this thread. */ … … 236 245 extern void thread_update_accounting(bool); 237 246 extern bool thread_exists(thread_t *); 247 extern void thread_stack_trace(thread_id_t); 238 248 239 249 /** Fpu context slab cache. */ -
kernel/generic/src/console/cmd.c
r0843f02 rdf58e44 78 78 static cmd_info_t help_info = { 79 79 .name = "help", 80 .description = "List ofsupported commands.",80 .description = "List supported commands.", 81 81 .func = cmd_help, 82 82 .argc = 0 83 83 }; 84 84 85 /* Data and methods for 'reboot' command. */ 85 86 static int cmd_reboot(cmd_arg_t *argv); 86 87 static cmd_info_t reboot_info = { 87 88 .name = "reboot", 88 .description = "Reboot .",89 .description = "Reboot system.", 89 90 .func = cmd_reboot, 90 91 .argc = 0 91 92 }; 92 93 94 /* Data and methods for 'uptime' command. */ 93 95 static int cmd_uptime(cmd_arg_t *argv); 94 96 static cmd_info_t uptime_info = { 95 97 .name = "uptime", 96 .description = " Print uptime information.",98 .description = "Show system uptime.", 97 99 .func = cmd_uptime, 98 100 .argc = 0 99 101 }; 100 102 103 /* Data and methods for 'continue' command. */ 101 104 static int cmd_continue(cmd_arg_t *argv); 102 105 static cmd_info_t continue_info = { … … 108 111 109 112 #ifdef CONFIG_TEST 113 /* Data and methods for 'test' command. */ 110 114 static char test_buf[MAX_CMDLINE + 1]; 111 115 static int cmd_test(cmd_arg_t *argv); … … 119 123 static cmd_info_t test_info = { 120 124 .name = "test", 121 .description = " Print list ofkernel tests or run a test.",125 .description = "<test> List kernel tests or run a test.", 122 126 .func = cmd_test, 123 127 .argc = 1, … … 125 129 }; 126 130 131 /* Data and methods for 'bench' command. */ 127 132 static int cmd_bench(cmd_arg_t *argv); 128 133 static cmd_arg_t bench_argv[] = { … … 138 143 static cmd_info_t bench_info = { 139 144 .name = "bench", 140 .description = " Run kernel test as benchmark.",145 .description = "<test> <count> Run kernel test as benchmark.", 141 146 .func = cmd_bench, 142 147 .argc = 2, … … 148 153 static int cmd_desc(cmd_arg_t *argv); 149 154 static void desc_help(void); 150 static char desc_buf[MAX_CMDLINE +1];155 static char desc_buf[MAX_CMDLINE + 1]; 151 156 static cmd_arg_t desc_argv = { 152 157 .type = ARG_TYPE_STRING, … … 156 161 static cmd_info_t desc_info = { 157 162 .name = "describe", 158 .description = " Describe specified command.",163 .description = "<command> Describe specified command.", 159 164 .help = desc_help, 160 165 .func = cmd_desc, … … 165 170 /* Data and methods for 'symaddr' command. */ 166 171 static int cmd_symaddr(cmd_arg_t *argv); 167 static char symaddr_buf[MAX_CMDLINE +1];172 static char symaddr_buf[MAX_CMDLINE + 1]; 168 173 static cmd_arg_t symaddr_argv = { 169 174 .type = ARG_TYPE_STRING, … … 173 178 static cmd_info_t symaddr_info = { 174 179 .name = "symaddr", 175 .description = " Return symbol address.",180 .description = "<symbol> Return symbol address.", 176 181 .func = cmd_symaddr, 177 182 .argc = 1, … … 179 184 }; 180 185 181 static char set_buf[MAX_CMDLINE+1]; 186 /* Data and methods for 'set4' command. */ 187 static char set_buf[MAX_CMDLINE + 1]; 182 188 static int cmd_set4(cmd_arg_t *argv); 183 189 static cmd_arg_t set4_argv[] = { … … 193 199 static cmd_info_t set4_info = { 194 200 .name = "set4", 195 .description = " set <dest_addr> <value> - 4byte version",201 .description = "<addr> <value> Set 4B memory location to a value.", 196 202 .func = cmd_set4, 197 203 .argc = 2, … … 213 219 static cmd_info_t call0_info = { 214 220 .name = "call0", 215 .description = " call0 <function> -> call function().",221 .description = "<function> Call function().", 216 222 .func = cmd_call0, 217 223 .argc = 1, … … 228 234 static cmd_info_t mcall0_info = { 229 235 .name = "mcall0", 230 .description = " mcall0 <function> -> call function() on each CPU.",236 .description = "<function> Call function() on each CPU.", 231 237 .func = cmd_mcall0, 232 238 .argc = 1, … … 250 256 static cmd_info_t call1_info = { 251 257 .name = "call1", 252 .description = " call1 <function> <arg1> -> call function(arg1).",258 .description = "<function> <arg1> Call function(arg1).", 253 259 .func = cmd_call1, 254 260 .argc = 2, … … 277 283 static cmd_info_t call2_info = { 278 284 .name = "call2", 279 .description = " call2 <function> <arg1> <arg2> -> call function(arg1,arg2).",285 .description = "<function> <arg1> <arg2> Call function(arg1, arg2).", 280 286 .func = cmd_call2, 281 287 .argc = 3, … … 310 316 static cmd_info_t call3_info = { 311 317 .name = "call3", 312 .description = " call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).",318 .description = "<function> <arg1> <arg2> <arg3> Call function(arg1, arg2, arg3).", 313 319 .func = cmd_call3, 314 320 .argc = 4, … … 340 346 cmd_info_t tlb_info = { 341 347 .name = "tlb", 342 .description = "Print TLB of current processor.",348 .description = "Print TLB of the current CPU.", 343 349 .help = NULL, 344 350 .func = cmd_tlb, … … 377 383 }; 378 384 385 /* Data and methods for 'btrace' command */ 386 static int cmd_btrace(cmd_arg_t *argv); 387 static cmd_arg_t btrace_argv = { 388 .type = ARG_TYPE_INT, 389 }; 390 static cmd_info_t btrace_info = { 391 .name = "btrace", 392 .description = "<threadid> Show thread stack trace.", 393 .func = cmd_btrace, 394 .argc = 1, 395 .argv = &btrace_argv 396 }; 379 397 380 398 static int cmd_sched(cmd_arg_t *argv); 381 399 static cmd_info_t sched_info = { 382 400 .name = "scheduler", 383 .description = " List allscheduler information.",401 .description = "Show scheduler information.", 384 402 .func = cmd_sched, 385 403 .argc = 0 … … 406 424 static cmd_info_t zones_info = { 407 425 .name = "zones", 408 .description = "List ofmemory zones.",426 .description = "List memory zones.", 409 427 .func = cmd_zones, 410 428 .argc = 0 429 }; 430 431 /* Data and methods for 'zone' command */ 432 static int cmd_zone(cmd_arg_t *argv); 433 static cmd_arg_t zone_argv = { 434 .type = ARG_TYPE_INT, 435 }; 436 437 static cmd_info_t zone_info = { 438 .name = "zone", 439 .description = "<zone> Show memory zone structure.", 440 .func = cmd_zone, 441 .argc = 1, 442 .argv = &zone_argv 411 443 }; 412 444 … … 418 450 static cmd_info_t ipc_info = { 419 451 .name = "ipc", 420 .description = " ipc <taskid> Show IPC information of giventask.",452 .description = "<taskid> Show IPC information of a task.", 421 453 .func = cmd_ipc, 422 454 .argc = 1, … … 431 463 static cmd_info_t kill_info = { 432 464 .name = "kill", 433 .description = " kill<taskid> Kill a task.",465 .description = "<taskid> Kill a task.", 434 466 .func = cmd_kill, 435 467 .argc = 1, 436 468 .argv = &kill_argv 437 };438 439 /* Data and methods for 'zone' command */440 static int cmd_zone(cmd_arg_t *argv);441 static cmd_arg_t zone_argv = {442 .type = ARG_TYPE_INT,443 };444 445 static cmd_info_t zone_info = {446 .name = "zone",447 .description = "Show memory zone structure.",448 .func = cmd_zone,449 .argc = 1,450 .argv = &zone_argv451 469 }; 452 470 … … 474 492 475 493 static cmd_info_t *basic_commands[] = { 494 &btrace_info, 476 495 &call0_info, 477 496 &mcall0_info, … … 482 501 &cpus_info, 483 502 &desc_info, 484 &reboot_info,485 &uptime_info,486 503 &halt_info, 487 504 &help_info, 488 505 &ipc_info, 489 506 &kill_info, 507 &physmem_info, 508 &reboot_info, 509 &sched_info, 490 510 &set4_info, 491 511 &slabs_info, 512 &symaddr_info, 492 513 &sysinfo_info, 493 &symaddr_info, 494 &sched_info, 514 &tasks_info, 495 515 &threads_info, 496 &tasks_info,497 &physmem_info,498 516 &tlb_info, 517 &uptime_info, 499 518 &version_info, 500 519 &zones_info, … … 531 550 } 532 551 533 534 552 /** List supported commands. 535 553 * … … 574 592 } 575 593 576 577 594 /** Reboot the system. 578 595 * … … 588 605 return 1; 589 606 } 590 591 607 592 608 /** Print system uptime information. … … 824 840 } 825 841 826 827 842 /** Print detailed description of 'describe' command. */ 828 843 void desc_help(void) … … 911 926 * @return Always 1 912 927 */ 913 int cmd_slabs(cmd_arg_t * 928 int cmd_slabs(cmd_arg_t *argv) 914 929 { 915 930 slab_print_list(); … … 923 938 * @return Always 1 924 939 */ 925 int cmd_sysinfo(cmd_arg_t * 940 int cmd_sysinfo(cmd_arg_t *argv) 926 941 { 927 942 sysinfo_dump(NULL); … … 929 944 } 930 945 931 932 /** Command for listings Thread information 946 /** Command for listing thread information 933 947 * 934 948 * @param argv Ignored … … 948 962 } 949 963 950 /** Command for listing s Task information964 /** Command for listing task information 951 965 * 952 966 * @param argv Ignored … … 966 980 } 967 981 968 /** Command for listings Thread information 982 /** Command for printing thread stack trace 983 * 984 * @param argv Integer argument from cmdline expected 985 * 986 * return Always 1 987 * 988 */ 989 int cmd_btrace(cmd_arg_t *argv) 990 { 991 thread_stack_trace(argv[0].intval); 992 return 1; 993 } 994 995 /** Command for printing scheduler information 969 996 * 970 997 * @param argv Ignores … … 972 999 * @return Always 1 973 1000 */ 974 int cmd_sched(cmd_arg_t * 1001 int cmd_sched(cmd_arg_t *argv) 975 1002 { 976 1003 sched_print_list(); … … 984 1011 * return Always 1 985 1012 */ 986 int cmd_zones(cmd_arg_t * 1013 int cmd_zones(cmd_arg_t *argv) 987 1014 { 988 1015 zones_print_list(); … … 996 1023 * return Always 1 997 1024 */ 998 int cmd_zone(cmd_arg_t * 1025 int cmd_zone(cmd_arg_t *argv) 999 1026 { 1000 1027 zone_print_one(argv[0].intval); … … 1002 1029 } 1003 1030 1004 /** Command for printing task ipcdetails1031 /** Command for printing task IPC details 1005 1032 * 1006 1033 * @param argv Integer argument from cmdline expected … … 1008 1035 * return Always 1 1009 1036 */ 1010 int cmd_ipc(cmd_arg_t * 1037 int cmd_ipc(cmd_arg_t *argv) 1011 1038 { 1012 1039 ipc_print_task(argv[0].intval); … … 1020 1047 * return 0 on failure, 1 on success. 1021 1048 */ 1022 int cmd_kill(cmd_arg_t * 1049 int cmd_kill(cmd_arg_t *argv) 1023 1050 { 1024 1051 if (task_kill(argv[0].intval) != EOK) -
kernel/generic/src/proc/scheduler.c
r0843f02 rdf58e44 62 62 #include <print.h> 63 63 #include <debug.h> 64 #include <stacktrace.h> 64 65 65 66 static void scheduler_separated_stack(void); … … 77 78 * Perform actions that need to be 78 79 * taken before the newly selected 79 * t read is passed control.80 * thread is passed control. 80 81 * 81 82 * THREAD->lock is locked on entry … … 87 88 88 89 #ifdef CONFIG_FPU_LAZY 89 if (THREAD == CPU->fpu_owner)90 if (THREAD == CPU->fpu_owner) 90 91 fpu_enable(); 91 92 else … … 100 101 } 101 102 #endif 103 104 if (THREAD->btrace) { 105 istate_t *istate = THREAD->udebug.uspace_state; 106 if (istate != NULL) { 107 printf("Thread %" PRIu64 " stack trace:\n", THREAD->tid); 108 stack_trace_istate(istate); 109 } 110 111 THREAD->btrace = false; 112 } 102 113 } 103 114 … … 645 656 /* 646 657 * Ready thread on local CPU 647 *648 658 */ 649 659 -
kernel/generic/src/proc/task.c
r0843f02 rdf58e44 449 449 static void task_kill_internal(task_t *task) 450 450 { 451 irq_spinlock_lock(&task->lock, false); 452 irq_spinlock_lock(&threads_lock, false); 453 454 /* 455 * Interrupt all threads. 456 */ 457 451 458 link_t *cur; 452 453 /*454 * Interrupt all threads.455 */456 irq_spinlock_lock(&task->lock, false);457 459 for (cur = task->th_head.next; cur != &task->th_head; cur = cur->next) { 458 460 thread_t *thread = list_get_instance(cur, thread_t, th_link); … … 471 473 } 472 474 475 irq_spinlock_unlock(&threads_lock, false); 473 476 irq_spinlock_unlock(&task->lock, false); 474 477 } -
kernel/generic/src/proc/thread.c
r0843f02 rdf58e44 239 239 * Switch thread to the ready state. 240 240 * 241 * @param t Thread to make ready.241 * @param thread Thread to make ready. 242 242 * 243 243 */ … … 246 246 irq_spinlock_lock(&thread->lock, true); 247 247 248 ASSERT( !(thread->state == Ready));248 ASSERT(thread->state != Ready); 249 249 250 250 int i = (thread->priority < RQ_COUNT - 1) … … 338 338 339 339 thread->interrupted = false; 340 thread->btrace = false; 340 341 thread->detached = false; 341 342 waitq_initialize(&thread->join_wq); … … 535 536 /** Detach thread. 536 537 * 537 * Mark the thread as detached , if the thread is already in the Lingering538 * state, deallocate its resources.538 * Mark the thread as detached. If the thread is already 539 * in the Lingering state, deallocate its resources. 539 540 * 540 541 * @param thread Thread to be detached. … … 740 741 ASSERT(interrupts_disabled()); 741 742 ASSERT(irq_spinlock_locked(&threads_lock)); 742 743 743 744 thread_iterator_t iterator; 744 745 … … 751 752 } 752 753 754 void thread_stack_trace(thread_id_t thread_id) 755 { 756 irq_spinlock_lock(&threads_lock, true); 757 758 thread_t *thread = thread_find_by_id(thread_id); 759 if (thread == NULL) { 760 printf("No such thread.\n"); 761 irq_spinlock_unlock(&threads_lock, true); 762 return; 763 } 764 765 irq_spinlock_lock(&thread->lock, false); 766 767 /* 768 * Schedule a stack trace to be printed 769 * just before the thread is scheduled next. 770 * 771 * If the thread is sleeping then try to interrupt 772 * the sleep. Any request for printing an uspace stack 773 * trace from within the kernel should be always 774 * considered a last resort debugging means, therefore 775 * forcing the thread's sleep to be interrupted 776 * is probably justifiable. 777 */ 778 779 bool sleeping = false; 780 istate_t *istate = thread->udebug.uspace_state; 781 if (istate != NULL) { 782 printf("Scheduling thread stack trace.\n"); 783 thread->btrace = true; 784 if (thread->state == Sleeping) 785 sleeping = true; 786 } else 787 printf("Thread interrupt state not available.\n"); 788 789 irq_spinlock_unlock(&thread->lock, false); 790 791 if (sleeping) 792 waitq_interrupt_sleep(thread); 793 794 irq_spinlock_unlock(&threads_lock, true); 795 } 753 796 754 797 /** Process syscall to create new thread. … … 793 836 * has already been created. We need to undo its 794 837 * creation now. 795 *796 838 */ 797 839 … … 815 857 * THREAD_B events for threads that already existed 816 858 * and could be detected with THREAD_READ before. 817 *818 859 */ 819 860 udebug_thread_b_event_attach(thread, TASK); -
kernel/generic/src/synch/waitq.c
r0843f02 rdf58e44 127 127 /** Interrupt sleeping thread. 128 128 * 129 * This routine attempts to interrupt a thread from its sleep in a waitqueue. 130 * If the thread is not found sleeping, no action is taken. 129 * This routine attempts to interrupt a thread from its sleep in 130 * a waitqueue. If the thread is not found sleeping, no action 131 * is taken. 132 * 133 * The threads_lock must be already held and interrupts must be 134 * disabled upon calling this function. 131 135 * 132 136 * @param thread Thread to be interrupted. … … 138 142 DEADLOCK_PROBE_INIT(p_wqlock); 139 143 140 irq_spinlock_lock(&threads_lock, true); 141 if (!thread_exists(thread)) 142 goto out; 144 /* 145 * The thread is quaranteed to exist because 146 * threads_lock is held. 147 */ 143 148 144 149 grab_locks: … … 150 155 /* 151 156 * The sleep cannot be interrupted. 152 *153 157 */ 154 158 irq_spinlock_unlock(&thread->lock, false); 155 goto out;159 return; 156 160 } 157 161 158 162 if (!irq_spinlock_trylock(&wq->lock)) { 163 /* Avoid deadlock */ 159 164 irq_spinlock_unlock(&thread->lock, false); 160 165 DEADLOCK_PROBE(p_wqlock, DEADLOCK_THRESHOLD); 161 /* Avoid deadlock */162 166 goto grab_locks; 163 167 } … … 173 177 irq_spinlock_unlock(&wq->lock, false); 174 178 } 179 175 180 irq_spinlock_unlock(&thread->lock, false); 176 181 177 182 if (do_wakeup) 178 183 thread_ready(thread); 179 180 out:181 irq_spinlock_unlock(&threads_lock, true);182 184 } 183 185 … … 370 372 * If the thread was already interrupted, 371 373 * don't go to sleep at all. 372 *373 374 */ 374 375 if (THREAD->interrupted) { … … 381 382 * Set context that will be restored if the sleep 382 383 * of this thread is ever interrupted. 383 *384 384 */ 385 385 THREAD->sleep_interruptible = true;
Note:
See TracChangeset
for help on using the changeset viewer.