Ignore:
File:
1 edited

Legend:

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

    re535eeb r19f857a  
    3333/**
    3434 * @file
    35  * @brief Task management.
     35 * @brief       Task management.
    3636 */
    3737
     
    6666 * The task is guaranteed to exist after it was found in the tasks_tree as
    6767 * long as:
    68  *
    6968 * @li the tasks_lock is held,
    7069 * @li the task's lock is held when task's lock is acquired before releasing
     
    10099        task_t *t = avltree_get_instance(node, task_t, tasks_tree_node);
    101100        unsigned *cnt = (unsigned *) arg;
    102        
     101
    103102        if (t != TASK) {
    104103                (*cnt)++;
     
    108107                task_kill_internal(t);
    109108        }
    110        
    111         /* Continue the walk */
    112         return true;
     109
     110        return true;    /* continue the walk */
    113111}
    114112
     
    117115{
    118116        unsigned tasks_left;
    119        
     117
    120118        do { /* Repeat until there are any tasks except TASK */
    121119                /* Messing with task structures, avoid deadlock */
     
    140138        task_t *ta = obj;
    141139        int i;
    142        
     140
    143141        atomic_set(&ta->refcount, 0);
    144142        atomic_set(&ta->lifecount, 0);
    145143        atomic_set(&ta->active_calls, 0);
    146        
     144
    147145        spinlock_initialize(&ta->lock, "task_ta_lock");
    148146        mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
    149        
     147
    150148        list_initialize(&ta->th_head);
    151149        list_initialize(&ta->sync_box_head);
    152        
     150
    153151        ipc_answerbox_init(&ta->answerbox, ta);
    154152        for (i = 0; i < IPC_MAX_PHONES; i++)
    155153                ipc_phone_init(&ta->phones[i]);
    156        
     154
    157155#ifdef CONFIG_UDEBUG
    158156        /* Init kbox stuff */
     
    161159        mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE);
    162160#endif
    163        
     161
    164162        return 0;
    165163}
     
    167165/** Create new task with no threads.
    168166 *
    169  * @param as   Task's address space.
    170  * @param name Symbolic name (a copy is made).
    171  *
    172  * @return New task's structure.
     167 * @param as            Task's address space.
     168 * @param name          Symbolic name (a copy is made).
     169 *
     170 * @return              New task's structure.
    173171 *
    174172 */
     
    183181        memcpy(ta->name, name, TASK_NAME_BUFLEN);
    184182        ta->name[TASK_NAME_BUFLEN - 1] = 0;
    185        
     183
    186184        ta->context = CONTEXT;
    187185        ta->capabilities = 0;
    188         ta->ucycles = 0;
    189         ta->kcycles = 0;
    190 
    191         ta->ipc_info.call_sent = 0;
    192         ta->ipc_info.call_recieved = 0;
    193         ta->ipc_info.answer_sent = 0;
    194         ta->ipc_info.answer_recieved = 0;
    195         ta->ipc_info.irq_notif_recieved = 0;
    196         ta->ipc_info.forwarded = 0;
     186        ta->cycles = 0;
    197187
    198188#ifdef CONFIG_UDEBUG
    199189        /* Init debugging stuff */
    200190        udebug_task_init(&ta->udebug);
    201        
     191
    202192        /* Init kbox stuff */
    203193        ta->kb.finished = false;
    204194#endif
    205        
     195
    206196        if ((ipc_phone_0) &&
    207197            (context_check(ipc_phone_0->task->context, ta->context)))
    208198                ipc_phone_connect(&ta->phones[0], ipc_phone_0);
    209        
     199
    210200        btree_create(&ta->futexes);
    211201       
     
    225215/** Destroy task.
    226216 *
    227  * @param t Task to be destroyed.
    228  *
     217 * @param t             Task to be destroyed.
    229218 */
    230219void task_destroy(task_t *t)
     
    236225        avltree_delete(&tasks_tree, &t->tasks_tree_node);
    237226        spinlock_unlock(&tasks_lock);
    238        
     227
    239228        /*
    240229         * Perform architecture specific task destruction.
    241230         */
    242231        task_destroy_arch(t);
    243        
     232
    244233        /*
    245234         * Free up dynamically allocated state.
    246235         */
    247236        btree_destroy(&t->futexes);
    248        
     237
    249238        /*
    250239         * Drop our reference to the address space.
     
    259248/** Syscall for reading task ID from userspace.
    260249 *
    261  * @param uspace_task_id Userspace address of 8-byte buffer
    262  *                       where to store current task ID.
    263  *
    264  * @return Zero on success or an error code from @ref errno.h.
    265  *
     250 * @param               uspace_task_id userspace address of 8-byte buffer
     251 *                      where to store current task ID.
     252 *
     253 * @return              Zero on success or an error code from @ref errno.h.
    266254 */
    267255unative_t sys_task_get_id(task_id_t *uspace_task_id)
     
    279267 * The name simplifies identifying the task in the task list.
    280268 *
    281  * @param name The new name for the task. (typically the same
    282  *             as the command used to execute it).
     269 * @param name  The new name for the task. (typically the same
     270 *              as the command used to execute it).
    283271 *
    284272 * @return 0 on success or an error code from @ref errno.h.
    285  *
    286273 */
    287274unative_t sys_task_set_name(const char *uspace_name, size_t name_len)
     
    289276        int rc;
    290277        char namebuf[TASK_NAME_BUFLEN];
    291        
     278
    292279        /* Cap length of name and copy it from userspace. */
    293        
     280
    294281        if (name_len > TASK_NAME_BUFLEN - 1)
    295282                name_len = TASK_NAME_BUFLEN - 1;
    296        
     283
    297284        rc = copy_from_uspace(namebuf, uspace_name, name_len);
    298285        if (rc != 0)
    299286                return (unative_t) rc;
    300        
     287
    301288        namebuf[name_len] = '\0';
    302289        str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf);
    303        
     290
    304291        return EOK;
    305292}
     
    310297 * interrupts must be disabled.
    311298 *
    312  * @param id Task ID.
    313  *
    314  * @return Task structure address or NULL if there is no such task ID.
    315  *
    316  */
    317 task_t *task_find_by_id(task_id_t id)
    318 {
    319         avltree_node_t *node =
    320             avltree_search(&tasks_tree, (avltree_key_t) id);
    321        
     299 * @param id            Task ID.
     300 *
     301 * @return              Task structure address or NULL if there is no such task
     302 *                      ID.
     303 */
     304task_t *task_find_by_id(task_id_t id) { avltree_node_t *node;
     305       
     306        node = avltree_search(&tasks_tree, (avltree_key_t) id);
     307
    322308        if (node)
    323309                return avltree_get_instance(node, task_t, tasks_tree_node);
    324        
    325310        return NULL;
    326311}
     
    331316 * already disabled.
    332317 *
    333  * @param t       Pointer to thread.
    334  * @param ucycles Out pointer to sum of all user cycles.
    335  * @param kcycles Out pointer to sum of all kernel cycles.
    336  *
    337  */
    338 void task_get_accounting(task_t *t, uint64_t *ucycles, uint64_t *kcycles)
    339 {
    340         /* Accumulated values of task */
    341         uint64_t uret = t->ucycles;
    342         uint64_t kret = t->kcycles;
     318 * @param t             Pointer to thread.
     319 *
     320 * @return              Number of cycles used by the task and all its threads
     321 *                      so far.
     322 */
     323uint64_t task_get_accounting(task_t *t)
     324{
     325        /* Accumulated value of task */
     326        uint64_t ret = t->cycles;
    343327       
    344328        /* Current values of threads */
     
    352336                        if (thr == THREAD) {
    353337                                /* Update accounting of current thread */
    354                                 thread_update_accounting(false);
     338                                thread_update_accounting();
    355339                        }
    356                         uret += thr->ucycles;
    357                         kret += thr->kcycles;
     340                        ret += thr->cycles;
    358341                }
    359342                spinlock_unlock(&thr->lock);
    360343        }
    361344       
    362         *ucycles = uret;
    363         *kcycles = kret;
     345        return ret;
    364346}
    365347
     
    367349{
    368350        link_t *cur;
    369        
     351
    370352        /*
    371353         * Interrupt all threads.
     
    395377 * It signals all the task's threads to bail it out.
    396378 *
    397  * @param id ID of the task to be killed.
    398  *
    399  * @return Zero on success or an error code from errno.h.
    400  *
     379 * @param id            ID of the task to be killed.
     380 *
     381 * @return              Zero on success or an error code from errno.h.
    401382 */
    402383int task_kill(task_id_t id)
     
    425406        task_t *t = avltree_get_instance(node, task_t, tasks_tree_node);
    426407        int j;
    427        
     408               
    428409        spinlock_lock(&t->lock);
    429        
    430         uint64_t ucycles;
    431         uint64_t kcycles;
    432         char usuffix, ksuffix;
    433         task_get_accounting(t, &ucycles, &kcycles);
    434         order_suffix(ucycles, &ucycles, &usuffix);
    435         order_suffix(kcycles, &kcycles, &ksuffix);
    436        
     410                       
     411        uint64_t cycles;
     412        char suffix;
     413        order(task_get_accounting(t), &cycles, &suffix);
     414
    437415#ifdef __32_BITS__     
    438         printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64 "%c %9"
    439                 PRIu64 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as,
    440                 ucycles, usuffix, kcycles, ksuffix, atomic_get(&t->refcount),
    441                 atomic_get(&t->active_calls));
    442 #endif
    443        
     416        printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64
     417            "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles,
     418            suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls));
     419#endif
     420
    444421#ifdef __64_BITS__
    445         printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64 "%c %9"
    446                 PRIu64 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as,
    447                 ucycles, usuffix, kcycles, ksuffix, atomic_get(&t->refcount),
    448                 atomic_get(&t->active_calls));
    449 #endif
    450        
     422        printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64
     423            "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles,
     424            suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls));
     425#endif
     426
    451427        for (j = 0; j < IPC_MAX_PHONES; j++) {
    452428                if (t->phones[j].callee)
     
    454430        }
    455431        printf("\n");
    456        
     432                       
    457433        spinlock_unlock(&t->lock);
    458434        return true;
     
    467443        ipl = interrupts_disable();
    468444        spinlock_lock(&tasks_lock);
    469        
    470 #ifdef __32_BITS__
    471         printf("taskid name         ctx address    as        "
    472             " ucycles    kcycles    threads calls  callee\n");
    473         printf("------ ------------ --- ---------- ----------"
    474             " ---------- ---------- ------- ------ ------>\n");
    475 #endif
    476        
     445
     446#ifdef __32_BITS__     
     447        printf("taskid name         ctx address    as         "
     448            "cycles     threads calls  callee\n");
     449        printf("------ ------------ --- ---------- ---------- "
     450            "---------- ------- ------ ------>\n");
     451#endif
     452
    477453#ifdef __64_BITS__
    478         printf("taskid name         ctx address            as                "
    479             " ucycles    kcycles    threads calls  callee\n");
    480         printf("------ ------------ --- ------------------ ------------------"
    481             " ---------- ---------- ---------- ------- ------ ------>\n");
    482 #endif
    483        
     454        printf("taskid name         ctx address            as                 "
     455            "cycles     threads calls  callee\n");
     456        printf("------ ------------ --- ------------------ ------------------ "
     457            "---------- ------- ------ ------>\n");
     458#endif
     459
    484460        avltree_walk(&tasks_tree, task_print_walker, NULL);
    485        
     461
    486462        spinlock_unlock(&tasks_lock);
    487463        interrupts_restore(ipl);
Note: See TracChangeset for help on using the changeset viewer.