Changeset 875c629 in mainline for kernel/generic/src/proc/thread.c


Ignore:
Timestamp:
2011-01-27T17:19:49Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
577f042a, f579760
Parents:
bf75e3cb (diff), 5b7a107 (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.
Message:

merge 'btrace' kernel console command (a last resort debugging means for printing uspace stack traces from within kernel console)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/thread.c

    rbf75e3cb r875c629  
    239239 * Switch thread to the ready state.
    240240 *
    241  * @param t Thread to make ready.
     241 * @param thread Thread to make ready.
    242242 *
    243243 */
     
    246246        irq_spinlock_lock(&thread->lock, true);
    247247       
    248         ASSERT(!(thread->state == Ready));
     248        ASSERT(thread->state != Ready);
    249249       
    250250        int i = (thread->priority < RQ_COUNT - 1)
     
    350350       
    351351#ifdef CONFIG_UDEBUG
    352         /* Init debugging stuff */
     352        /* Initialize debugging stuff */
     353        thread->btrace = false;
    353354        udebug_thread_initialize(&thread->udebug);
    354355#endif
     
    535536/** Detach thread.
    536537 *
    537  * Mark the thread as detached, if the thread is already in the Lingering
    538  * state, deallocate its resources.
     538 * Mark the thread as detached. If the thread is already
     539 * in the Lingering state, deallocate its resources.
    539540 *
    540541 * @param thread Thread to be detached.
     
    740741        ASSERT(interrupts_disabled());
    741742        ASSERT(irq_spinlock_locked(&threads_lock));
    742 
     743       
    743744        thread_iterator_t iterator;
    744745       
     
    751752}
    752753
     754#ifdef CONFIG_UDEBUG
     755
     756void 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 */
    753800
    754801/** Process syscall to create new thread.
     
    793840                                 * has already been created. We need to undo its
    794841                                 * creation now.
    795                                  *
    796842                                 */
    797843                               
     
    815861                 * THREAD_B events for threads that already existed
    816862                 * and could be detected with THREAD_READ before.
    817                  *
    818863                 */
    819864                udebug_thread_b_event_attach(thread, TASK);
Note: See TracChangeset for help on using the changeset viewer.