Changeset a074b4f in mainline


Ignore:
Timestamp:
2010-01-23T19:19:18Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
03333bc
Parents:
336db295
Message:

Implement fault notifications and task monitoring service.

Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • HelenOS.config

    r336db295 ra074b4f  
    486486% Mount /data on startup
    487487! [CONFIG_START_BD=y] CONFIG_MOUNT_DATA (n/y)
     488
     489% Verbose task dumps
     490! CONFIG_VERBOSE_DUMPS (n/y)
  • boot/Makefile.common

    r336db295 ra074b4f  
    5656        $(USPACEDIR)/srv/fs/devfs/devfs \
    5757        $(USPACEDIR)/srv/fs/tmpfs/tmpfs \
    58         $(USPACEDIR)/srv/fs/fat/fat
     58        $(USPACEDIR)/srv/fs/fat/fat \
     59        $(USPACEDIR)/srv/taskmon/taskmon
    5960
    6061RD_APPS = \
  • kernel/generic/include/interrupt.h

    r336db295 ra074b4f  
    4646typedef void (* iroutine)(int n, istate_t *istate);
    4747
    48 #define fault_if_from_uspace(istate, fmt, ...) \
    49 { \
    50         if (istate_from_uspace(istate)) { \
    51                 task_t *task = TASK; \
    52                 printf("Task %s (%" PRIu64 ") killed due to an exception at " \
    53                     "program counter %p.\n", task->name, task->taskid, istate_get_pc(istate)); \
    54                 stack_trace_istate(istate); \
    55                 printf("Kill message: " fmt "\n", ##__VA_ARGS__); \
    56                 task_kill(task->taskid); \
    57                 thread_exit(); \
    58         } \
    59 }
    60 
     48extern void fault_if_from_uspace(istate_t *istate, char *fmt, ...);
    6149extern iroutine exc_register(int n, const char *name, iroutine f);
    6250extern void exc_dispatch(int n, istate_t *t);
  • kernel/generic/include/ipc/event_types.h

    r336db295 ra074b4f  
    3737
    3838typedef enum event_type {
     39        /** New data available in kernel log */
    3940        EVENT_KLOG = 0,
     41        /** Returning from kernel console to userspace */
    4042        EVENT_KCONSOLE,
     43        /** A thread has faulted and will be terminated */
     44        EVENT_FAULT,
    4145        EVENT_END
    4246} event_type_t;
  • kernel/generic/include/udebug/udebug.h

    r336db295 ra074b4f  
    153153
    154154#include <synch/mutex.h>
     155#include <synch/condvar.h>
    155156#include <arch/interrupt.h>
    156157#include <atomic.h>
     
    195196        bool stoppable;         /**< thread is stoppable */
    196197        bool active;            /**< thread is in a debugging session */
     198        condvar_t active_cv;
    197199} udebug_thread_t;
    198200
  • kernel/generic/src/interrupt/interrupt.c

    r336db295 ra074b4f  
    4444#include <console/console.h>
    4545#include <console/cmd.h>
     46#include <ipc/event.h>
     47#include <synch/mutex.h>
     48#include <time/delay.h>
     49#include <macros.h>
    4650#include <panic.h>
    4751#include <print.h>
     
    107111        fault_if_from_uspace(istate, "Unhandled exception %d.", n);
    108112        panic("Unhandled exception %d.", n);
     113}
     114
     115/** Terminate thread and task if exception came from userspace. */
     116void fault_if_from_uspace(istate_t *istate, char *fmt, ...)
     117{
     118        task_t *task = TASK;
     119        va_list args;
     120
     121        if (!istate_from_uspace(istate))
     122                return;
     123
     124        printf("Task %s (%" PRIu64 ") killed due to an exception at "
     125            "program counter %p.\n", task->name, task->taskid,
     126            istate_get_pc(istate));
     127
     128        stack_trace_istate(istate);
     129
     130        printf("Kill message: ");
     131        va_start(args, fmt);
     132        vprintf(fmt, args);
     133        va_end(args);
     134        printf("\n");
     135
     136        if (event_is_subscribed(EVENT_FAULT)) {
     137                event_notify_3(EVENT_FAULT, LOWER32(TASK->taskid),
     138                    UPPER32(TASK->taskid), (unative_t) THREAD);
     139        }
     140
     141#ifdef CONFIG_UDEBUG
     142        /* Wait until a debugger attends to us. */
     143        mutex_lock(&THREAD->udebug.lock);
     144        while (!THREAD->udebug.active)
     145                condvar_wait(&THREAD->udebug.active_cv, &THREAD->udebug.lock);
     146        mutex_unlock(&THREAD->udebug.lock);
     147
     148        udebug_stoppable_begin();
     149        udebug_stoppable_end();
     150
     151        /* Make sure the debugging session is over before proceeding. */
     152        mutex_lock(&THREAD->udebug.lock);
     153        while (THREAD->udebug.active)
     154                condvar_wait(&THREAD->udebug.active_cv, &THREAD->udebug.lock);
     155        mutex_unlock(&THREAD->udebug.lock);
     156#endif
     157
     158        task_kill(task->taskid);
     159        thread_exit();
    109160}
    110161
  • kernel/generic/src/udebug/udebug.c

    r336db295 ra074b4f  
    6969        mutex_initialize(&ut->lock, MUTEX_PASSIVE);
    7070        waitq_initialize(&ut->go_wq);
     71        condvar_initialize(&ut->active_cv);
    7172
    7273        ut->go_call = NULL;
     
    446447                                waitq_wakeup(&t->udebug.go_wq, WAKEUP_FIRST);
    447448                        }
     449                        mutex_unlock(&t->udebug.lock);
     450                        condvar_broadcast(&t->udebug.active_cv);
     451                } else {
     452                        mutex_unlock(&t->udebug.lock);
    448453                }
    449                 mutex_unlock(&t->udebug.lock);
    450454        }
    451455
  • kernel/generic/src/udebug/udebug_ops.c

    r336db295 ra074b4f  
    209209
    210210                mutex_lock(&t->udebug.lock);
    211                 if ((t->flags & THREAD_FLAG_USPACE) != 0)
     211                if ((t->flags & THREAD_FLAG_USPACE) != 0) {
    212212                        t->udebug.active = true;
    213                 mutex_unlock(&t->udebug.lock);
     213                        mutex_unlock(&t->udebug.lock);
     214                        condvar_broadcast(&t->udebug.active_cv);
     215                } else {
     216                        mutex_unlock(&t->udebug.lock);
     217                }
    214218        }
    215219
  • uspace/Makefile

    r336db295 ra074b4f  
    4848        srv/loader \
    4949        srv/ns \
     50        srv/taskmon \
    5051        srv/vfs \
    5152        srv/bd/ata_bd \
  • uspace/app/init/init.c

    r336db295 ra074b4f  
    257257       
    258258        spawn("/srv/devfs");
     259        spawn("/srv/taskmon");
    259260       
    260261        if (!mount_devfs()) {
  • uspace/app/taskdump/taskdump.c

    r336db295 ra074b4f  
    4747#define LINE_BYTES 16
    4848
    49 
    5049#define DBUF_SIZE 4096
    5150static uint8_t data_buf[DBUF_SIZE];
     
    222221        printf("Threads:\n");
    223222        for (i = 0; i < n_threads; i++) {
    224                 printf(" [%d] (hash 0x%lx)\n", 1+i, thash_buf[i]);
     223                printf(" [%d] hash: 0x%lx\n", 1+i, thash_buf[i]);
    225224        }
    226225        putchar('\n');
Note: See TracChangeset for help on using the changeset viewer.