Changeset 5b7a107 in mainline
- Timestamp:
- 2011-01-27T16:52:14Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 875c629
- Parents:
- bf75e3cb (diff), df58e44 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- kernel/generic
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/debug.h
rbf75e3cb r5b7a107 55 55 do { \ 56 56 if (!(expr)) \ 57 panic_assert("%s", #expr); \ 57 panic_assert("%s() at %s:%u:\n%s", \ 58 __func__, __FILE__, __LINE__, #expr); \ 58 59 } while (0) 59 60 … … 72 73 do { \ 73 74 if (!(expr)) \ 74 panic_assert("%s, %s", #expr, msg); \ 75 panic_assert("%s() at %s:%u:\n%s, %s", \ 76 __func__, __FILE__, __LINE__, #expr, msg); \ 75 77 } while (0) 76 78 -
kernel/generic/include/proc/thread.h
rbf75e3cb r5b7a107 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(). … … 187 190 188 191 #ifdef CONFIG_UDEBUG 192 /** 193 * If true, the scheduler will print a stack trace 194 * to the kernel console upon scheduling this thread. 195 */ 196 bool btrace; 197 189 198 /** Debugging stuff */ 190 199 udebug_thread_t udebug; … … 237 246 extern bool thread_exists(thread_t *); 238 247 248 #ifdef CONFIG_UDEBUG 249 extern void thread_stack_trace(thread_id_t); 250 #endif 251 239 252 /** Fpu context slab cache. */ 240 253 extern slab_cache_t *fpu_context_slab; -
kernel/generic/src/console/cmd.c
rbf75e3cb r5b7a107 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 114 /* Data and methods for 'test' command. */ 110 115 static char test_buf[MAX_CMDLINE + 1]; 111 116 static int cmd_test(cmd_arg_t *argv); … … 119 124 static cmd_info_t test_info = { 120 125 .name = "test", 121 .description = " Print list ofkernel tests or run a test.",126 .description = "<test> List kernel tests or run a test.", 122 127 .func = cmd_test, 123 128 .argc = 1, … … 125 130 }; 126 131 132 /* Data and methods for 'bench' command. */ 127 133 static int cmd_bench(cmd_arg_t *argv); 128 134 static cmd_arg_t bench_argv[] = { … … 138 144 static cmd_info_t bench_info = { 139 145 .name = "bench", 140 .description = " Run kernel test as benchmark.",146 .description = "<test> <count> Run kernel test as benchmark.", 141 147 .func = cmd_bench, 142 148 .argc = 2, 143 149 .argv = bench_argv 144 150 }; 145 #endif 151 152 #endif /* CONFIG_TEST */ 146 153 147 154 /* Data and methods for 'description' command. */ 148 155 static int cmd_desc(cmd_arg_t *argv); 149 156 static void desc_help(void); 150 static char desc_buf[MAX_CMDLINE +1];157 static char desc_buf[MAX_CMDLINE + 1]; 151 158 static cmd_arg_t desc_argv = { 152 159 .type = ARG_TYPE_STRING, … … 156 163 static cmd_info_t desc_info = { 157 164 .name = "describe", 158 .description = " Describe specified command.",165 .description = "<command> Describe specified command.", 159 166 .help = desc_help, 160 167 .func = cmd_desc, … … 165 172 /* Data and methods for 'symaddr' command. */ 166 173 static int cmd_symaddr(cmd_arg_t *argv); 167 static char symaddr_buf[MAX_CMDLINE +1];174 static char symaddr_buf[MAX_CMDLINE + 1]; 168 175 static cmd_arg_t symaddr_argv = { 169 176 .type = ARG_TYPE_STRING, … … 173 180 static cmd_info_t symaddr_info = { 174 181 .name = "symaddr", 175 .description = " Return symbol address.",182 .description = "<symbol> Return symbol address.", 176 183 .func = cmd_symaddr, 177 184 .argc = 1, … … 179 186 }; 180 187 181 static char set_buf[MAX_CMDLINE+1]; 188 /* Data and methods for 'set4' command. */ 189 static char set_buf[MAX_CMDLINE + 1]; 182 190 static int cmd_set4(cmd_arg_t *argv); 183 191 static cmd_arg_t set4_argv[] = { … … 193 201 static cmd_info_t set4_info = { 194 202 .name = "set4", 195 .description = " set <dest_addr> <value> - 4byte version",203 .description = "<addr> <value> Set 4B memory location to a value.", 196 204 .func = cmd_set4, 197 205 .argc = 2, … … 213 221 static cmd_info_t call0_info = { 214 222 .name = "call0", 215 .description = " call0 <function> -> call function().",223 .description = "<function> Call function().", 216 224 .func = cmd_call0, 217 225 .argc = 1, … … 228 236 static cmd_info_t mcall0_info = { 229 237 .name = "mcall0", 230 .description = " mcall0 <function> -> call function() on each CPU.",238 .description = "<function> Call function() on each CPU.", 231 239 .func = cmd_mcall0, 232 240 .argc = 1, … … 250 258 static cmd_info_t call1_info = { 251 259 .name = "call1", 252 .description = " call1 <function> <arg1> -> call function(arg1).",260 .description = "<function> <arg1> Call function(arg1).", 253 261 .func = cmd_call1, 254 262 .argc = 2, … … 277 285 static cmd_info_t call2_info = { 278 286 .name = "call2", 279 .description = " call2 <function> <arg1> <arg2> -> call function(arg1,arg2).",287 .description = "<function> <arg1> <arg2> Call function(arg1, arg2).", 280 288 .func = cmd_call2, 281 289 .argc = 3, … … 310 318 static cmd_info_t call3_info = { 311 319 .name = "call3", 312 .description = " call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).",320 .description = "<function> <arg1> <arg2> <arg3> Call function(arg1, arg2, arg3).", 313 321 .func = cmd_call3, 314 322 .argc = 4, … … 340 348 cmd_info_t tlb_info = { 341 349 .name = "tlb", 342 .description = "Print TLB of current processor.",350 .description = "Print TLB of the current CPU.", 343 351 .help = NULL, 344 352 .func = cmd_tlb, … … 377 385 }; 378 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 */ 379 403 380 404 static int cmd_sched(cmd_arg_t *argv); 381 405 static cmd_info_t sched_info = { 382 406 .name = "scheduler", 383 .description = " List allscheduler information.",407 .description = "Show scheduler information.", 384 408 .func = cmd_sched, 385 409 .argc = 0 … … 406 430 static cmd_info_t zones_info = { 407 431 .name = "zones", 408 .description = "List ofmemory zones.",432 .description = "List memory zones.", 409 433 .func = cmd_zones, 410 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 411 449 }; 412 450 … … 418 456 static cmd_info_t ipc_info = { 419 457 .name = "ipc", 420 .description = " ipc <taskid> Show IPC information of giventask.",458 .description = "<taskid> Show IPC information of a task.", 421 459 .func = cmd_ipc, 422 460 .argc = 1, … … 431 469 static cmd_info_t kill_info = { 432 470 .name = "kill", 433 .description = " kill<taskid> Kill a task.",471 .description = "<taskid> Kill a task.", 434 472 .func = cmd_kill, 435 473 .argc = 1, 436 474 .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 475 }; 452 476 … … 482 506 &cpus_info, 483 507 &desc_info, 484 &reboot_info,485 &uptime_info,486 508 &halt_info, 487 509 &help_info, 488 510 &ipc_info, 489 511 &kill_info, 512 &physmem_info, 513 &reboot_info, 514 &sched_info, 490 515 &set4_info, 491 516 &slabs_info, 517 &symaddr_info, 492 518 &sysinfo_info, 493 &symaddr_info, 494 &sched_info, 519 &tasks_info, 495 520 &threads_info, 496 &tasks_info,497 &physmem_info,498 521 &tlb_info, 522 &uptime_info, 499 523 &version_info, 500 524 &zones_info, … … 504 528 &bench_info, 505 529 #endif 530 #ifdef CONFIG_UDEBUG 531 &btrace_info, 532 #endif 506 533 NULL 507 534 }; … … 530 557 } 531 558 } 532 533 559 534 560 /** List supported commands. … … 574 600 } 575 601 576 577 602 /** Reboot the system. 578 603 * … … 588 613 return 1; 589 614 } 590 591 615 592 616 /** Print system uptime information. … … 824 848 } 825 849 826 827 850 /** Print detailed description of 'describe' command. */ 828 851 void desc_help(void) … … 911 934 * @return Always 1 912 935 */ 913 int cmd_slabs(cmd_arg_t * 936 int cmd_slabs(cmd_arg_t *argv) 914 937 { 915 938 slab_print_list(); … … 923 946 * @return Always 1 924 947 */ 925 int cmd_sysinfo(cmd_arg_t * 948 int cmd_sysinfo(cmd_arg_t *argv) 926 949 { 927 950 sysinfo_dump(NULL); … … 929 952 } 930 953 931 932 /** Command for listings Thread information 954 /** Command for listing thread information 933 955 * 934 956 * @param argv Ignored … … 948 970 } 949 971 950 /** Command for listing s Task information972 /** Command for listing task information 951 973 * 952 974 * @param argv Ignored … … 966 988 } 967 989 968 /** Command for listings Thread information 990 #ifdef CONFIG_UDEBUG 991 992 /** Command for printing thread stack trace 993 * 994 * @param argv Integer argument from cmdline expected 995 * 996 * return Always 1 997 * 998 */ 999 int cmd_btrace(cmd_arg_t *argv) 1000 { 1001 thread_stack_trace(argv[0].intval); 1002 return 1; 1003 } 1004 1005 #endif /* CONFIG_UDEBUG */ 1006 1007 /** Command for printing scheduler information 969 1008 * 970 1009 * @param argv Ignores … … 972 1011 * @return Always 1 973 1012 */ 974 int cmd_sched(cmd_arg_t * 1013 int cmd_sched(cmd_arg_t *argv) 975 1014 { 976 1015 sched_print_list(); … … 984 1023 * return Always 1 985 1024 */ 986 int cmd_zones(cmd_arg_t * 1025 int cmd_zones(cmd_arg_t *argv) 987 1026 { 988 1027 zones_print_list(); … … 996 1035 * return Always 1 997 1036 */ 998 int cmd_zone(cmd_arg_t * 1037 int cmd_zone(cmd_arg_t *argv) 999 1038 { 1000 1039 zone_print_one(argv[0].intval); … … 1002 1041 } 1003 1042 1004 /** Command for printing task ipcdetails1043 /** Command for printing task IPC details 1005 1044 * 1006 1045 * @param argv Integer argument from cmdline expected … … 1008 1047 * return Always 1 1009 1048 */ 1010 int cmd_ipc(cmd_arg_t * 1049 int cmd_ipc(cmd_arg_t *argv) 1011 1050 { 1012 1051 ipc_print_task(argv[0].intval); … … 1020 1059 * return 0 on failure, 1 on success. 1021 1060 */ 1022 int cmd_kill(cmd_arg_t * 1061 int cmd_kill(cmd_arg_t *argv) 1023 1062 { 1024 1063 if (task_kill(argv[0].intval) != EOK) -
kernel/generic/src/proc/scheduler.c
rbf75e3cb r5b7a107 62 62 #include <print.h> 63 63 #include <debug.h> 64 65 static void before_task_runs(void); 66 static void before_thread_runs(void); 67 static void after_thread_ran(void); 64 #include <stacktrace.h> 65 68 66 static void scheduler_separated_stack(void); 69 67 … … 71 69 72 70 /** Carry out actions before new task runs. */ 73 void before_task_runs(void)71 static void before_task_runs(void) 74 72 { 75 73 before_task_runs_arch(); … … 80 78 * Perform actions that need to be 81 79 * taken before the newly selected 82 * t read is passed control.80 * thread is passed control. 83 81 * 84 82 * THREAD->lock is locked on entry 85 83 * 86 84 */ 87 void before_thread_runs(void)85 static void before_thread_runs(void) 88 86 { 89 87 before_thread_runs_arch(); 88 90 89 #ifdef CONFIG_FPU_LAZY 91 if (THREAD == CPU->fpu_owner)90 if (THREAD == CPU->fpu_owner) 92 91 fpu_enable(); 93 92 else … … 102 101 } 103 102 #endif 103 104 #ifdef CONFIG_UDEBUG 105 if (THREAD->btrace) { 106 istate_t *istate = THREAD->udebug.uspace_state; 107 if (istate != NULL) { 108 printf("Thread %" PRIu64 " stack trace:\n", THREAD->tid); 109 stack_trace_istate(istate); 110 } 111 112 THREAD->btrace = false; 113 } 114 #endif 104 115 } 105 116 … … 113 124 * 114 125 */ 115 void after_thread_ran(void)126 static void after_thread_ran(void) 116 127 { 117 128 after_thread_ran_arch(); … … 391 402 * possible destruction should thread_destroy() be called on this or any 392 403 * other processor while the scheduler is still using them. 393 *394 404 */ 395 405 if (old_task) … … 417 427 * The thread structure is kept allocated until 418 428 * somebody calls thread_detach() on it. 419 *420 429 */ 421 430 if (!irq_spinlock_trylock(&THREAD->join_wq.lock)) { 422 431 /* 423 432 * Avoid deadlock. 424 *425 433 */ 426 434 irq_spinlock_unlock(&THREAD->lock, false); … … 443 451 /* 444 452 * Prefer the thread after it's woken up. 445 *446 453 */ 447 454 THREAD->priority = -1; … … 451 458 * waitq_sleep(). Address of wq->lock is kept in 452 459 * THREAD->sleep_queue. 453 *454 460 */ 455 461 irq_spinlock_unlock(&THREAD->sleep_queue->lock, false); … … 461 467 /* 462 468 * Entering state is unexpected. 463 *464 469 */ 465 470 panic("tid%" PRIu64 ": unexpected state %s.", … … 480 485 481 486 /* 482 * If both the old and the new task are the same, lots of work is 483 * avoided. 484 * 487 * If both the old and the new task are the same, 488 * lots of work is avoided. 485 489 */ 486 490 if (TASK != THREAD->task) { … … 488 492 489 493 /* 490 * Note that it is possible for two tasks to share one address 491 * space. 492 ( 494 * Note that it is possible for two tasks 495 * to share one address space. 493 496 */ 494 497 if (old_as != new_as) { … … 496 499 * Both tasks and address spaces are different. 497 500 * Replace the old one with the new one. 498 *499 501 */ 500 502 as_switch(old_as, new_as); … … 527 529 * necessary, is to be mapped in before_thread_runs(). This 528 530 * function must be executed before the switch to the new stack. 529 *530 531 */ 531 532 before_thread_runs(); … … 534 535 * Copy the knowledge of CPU, TASK, THREAD and preemption counter to 535 536 * thread's stack. 536 *537 537 */ 538 538 the_copy(THE, (the_t *) THREAD->kstack); … … 658 658 /* 659 659 * Ready thread on local CPU 660 *661 660 */ 662 661 -
kernel/generic/src/proc/task.c
rbf75e3cb r5b7a107 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
rbf75e3cb r5b7a107 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) … … 350 350 351 351 #ifdef CONFIG_UDEBUG 352 /* Init debugging stuff */ 352 /* Initialize debugging stuff */ 353 thread->btrace = false; 353 354 udebug_thread_initialize(&thread->udebug); 354 355 #endif … … 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 #ifdef CONFIG_UDEBUG 755 756 void thread_stack_trace(thread_id_t thread_id) 757 { 758 irq_spinlock_lock(&threads_lock, true); 759 760 thread_t *thread = thread_find_by_id(thread_id); 761 if (thread == NULL) { 762 printf("No such thread.\n"); 763 irq_spinlock_unlock(&threads_lock, true); 764 return; 765 } 766 767 irq_spinlock_lock(&thread->lock, false); 768 769 /* 770 * Schedule a stack trace to be printed 771 * just before the thread is scheduled next. 772 * 773 * If the thread is sleeping then try to interrupt 774 * the sleep. Any request for printing an uspace stack 775 * trace from within the kernel should be always 776 * considered a last resort debugging means, therefore 777 * forcing the thread's sleep to be interrupted 778 * is probably justifiable. 779 */ 780 781 bool sleeping = false; 782 istate_t *istate = thread->udebug.uspace_state; 783 if (istate != NULL) { 784 printf("Scheduling thread stack trace.\n"); 785 thread->btrace = true; 786 if (thread->state == Sleeping) 787 sleeping = true; 788 } else 789 printf("Thread interrupt state not available.\n"); 790 791 irq_spinlock_unlock(&thread->lock, false); 792 793 if (sleeping) 794 waitq_interrupt_sleep(thread); 795 796 irq_spinlock_unlock(&threads_lock, true); 797 } 798 799 #endif /* CONFIG_UDEBUG */ 753 800 754 801 /** Process syscall to create new thread. … … 793 840 * has already been created. We need to undo its 794 841 * creation now. 795 *796 842 */ 797 843 … … 815 861 * THREAD_B events for threads that already existed 816 862 * and could be detected with THREAD_READ before. 817 *818 863 */ 819 864 udebug_thread_b_event_attach(thread, TASK); -
kernel/generic/src/synch/waitq.c
rbf75e3cb r5b7a107 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.