Ignore:
File:
1 edited

Legend:

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

    r5ba201d ra307beb  
    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->cycles = 0;
    189        
     186        ta->ucycles = 0;
     187        ta->kcycles = 0;
     188
     189        ta->ipc_info.call_sent = 0;
     190        ta->ipc_info.call_recieved = 0;
     191        ta->ipc_info.answer_sent = 0;
     192        ta->ipc_info.answer_recieved = 0;
     193        ta->ipc_info.irq_notif_recieved = 0;
     194        ta->ipc_info.forwarded = 0;
     195
    190196#ifdef CONFIG_UDEBUG
    191197        /* Init debugging stuff */
    192198        udebug_task_init(&ta->udebug);
    193        
     199
    194200        /* Init kbox stuff */
    195201        ta->kb.finished = false;
    196202#endif
    197        
     203
    198204        if ((ipc_phone_0) &&
    199205            (context_check(ipc_phone_0->task->context, ta->context)))
    200206                ipc_phone_connect(&ta->phones[0], ipc_phone_0);
    201        
     207
    202208        btree_create(&ta->futexes);
    203209       
     
    217223/** Destroy task.
    218224 *
    219  * @param t Task to be destroyed.
    220  *
     225 * @param t             Task to be destroyed.
    221226 */
    222227void task_destroy(task_t *t)
     
    228233        avltree_delete(&tasks_tree, &t->tasks_tree_node);
    229234        spinlock_unlock(&tasks_lock);
    230        
     235
    231236        /*
    232237         * Perform architecture specific task destruction.
    233238         */
    234239        task_destroy_arch(t);
    235        
     240
    236241        /*
    237242         * Free up dynamically allocated state.
    238243         */
    239244        btree_destroy(&t->futexes);
    240        
     245
    241246        /*
    242247         * Drop our reference to the address space.
     
    251256/** Syscall for reading task ID from userspace.
    252257 *
    253  * @param uspace_task_id Userspace address of 8-byte buffer
    254  *                       where to store current task ID.
    255  *
    256  * @return Zero on success or an error code from @ref errno.h.
    257  *
     258 * @param               uspace_task_id userspace address of 8-byte buffer
     259 *                      where to store current task ID.
     260 *
     261 * @return              Zero on success or an error code from @ref errno.h.
    258262 */
    259263unative_t sys_task_get_id(task_id_t *uspace_task_id)
     
    271275 * The name simplifies identifying the task in the task list.
    272276 *
    273  * @param name The new name for the task. (typically the same
    274  *             as the command used to execute it).
     277 * @param name  The new name for the task. (typically the same
     278 *              as the command used to execute it).
    275279 *
    276280 * @return 0 on success or an error code from @ref errno.h.
    277  *
    278281 */
    279282unative_t sys_task_set_name(const char *uspace_name, size_t name_len)
     
    281284        int rc;
    282285        char namebuf[TASK_NAME_BUFLEN];
    283        
     286
    284287        /* Cap length of name and copy it from userspace. */
    285        
     288
    286289        if (name_len > TASK_NAME_BUFLEN - 1)
    287290                name_len = TASK_NAME_BUFLEN - 1;
    288        
     291
    289292        rc = copy_from_uspace(namebuf, uspace_name, name_len);
    290293        if (rc != 0)
    291294                return (unative_t) rc;
    292        
     295
    293296        namebuf[name_len] = '\0';
    294297        str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf);
    295        
     298
    296299        return EOK;
    297300}
     
    302305 * interrupts must be disabled.
    303306 *
    304  * @param id Task ID.
    305  *
    306  * @return Task structure address or NULL if there is no such task
    307  *         ID.
    308  *
    309  */
    310 task_t *task_find_by_id(task_id_t id)
    311 {
    312         avltree_node_t *node;
     307 * @param id            Task ID.
     308 *
     309 * @return              Task structure address or NULL if there is no such task
     310 *                      ID.
     311 */
     312task_t *task_find_by_id(task_id_t id) { avltree_node_t *node;
     313       
    313314        node = avltree_search(&tasks_tree, (avltree_key_t) id);
    314        
     315
    315316        if (node)
    316317                return avltree_get_instance(node, task_t, tasks_tree_node);
    317        
    318318        return NULL;
    319319}
     
    324324 * already disabled.
    325325 *
    326  * @param t Pointer to task.
    327  *
    328  * @return Number of cycles used by the task and all its threads
    329  *         so far.
    330  *
    331  */
    332 uint64_t task_get_accounting(task_t *t)
    333 {
    334         /* Accumulated value of task */
    335         uint64_t ret = t->cycles;
     326 * @param t             Pointer to thread.
     327 * @param ucycles       Out pointer to sum of all user cycles.
     328 * @param kcycles       Out pointer to sum of all kernel cycles.
     329 */
     330void task_get_accounting(task_t *t, uint64_t *ucycles, uint64_t *kcycles)
     331{
     332        /* Accumulated values of task */
     333        uint64_t uret = t->ucycles;
     334        uint64_t kret = t->kcycles;
    336335       
    337336        /* Current values of threads */
     
    345344                        if (thr == THREAD) {
    346345                                /* Update accounting of current thread */
    347                                 thread_update_accounting();
     346                                thread_update_accounting(false);
    348347                        }
    349                         ret += thr->cycles;
     348                        uret += thr->ucycles;
     349                        kret += thr->kcycles;
    350350                }
    351351                spinlock_unlock(&thr->lock);
    352352        }
    353353       
    354         return ret;
     354        *ucycles = uret;
     355        *kcycles = kret;
    355356}
    356357
     
    358359{
    359360        link_t *cur;
    360        
     361
    361362        /*
    362363         * Interrupt all threads.
     
    386387 * It signals all the task's threads to bail it out.
    387388 *
    388  * @param id ID of the task to be killed.
    389  *
    390  * @return Zero on success or an error code from errno.h.
    391  *
     389 * @param id            ID of the task to be killed.
     390 *
     391 * @return              Zero on success or an error code from errno.h.
    392392 */
    393393int task_kill(task_id_t id)
     
    416416        task_t *t = avltree_get_instance(node, task_t, tasks_tree_node);
    417417        int j;
    418        
     418               
    419419        spinlock_lock(&t->lock);
    420        
    421         uint64_t cycles;
    422         char suffix;
    423         order(task_get_accounting(t), &cycles, &suffix);
    424        
    425 #ifdef __32_BITS__
    426         printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64
    427             "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles,
    428             suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls));
    429 #endif
    430        
     420                       
     421        uint64_t ucycles;
     422        uint64_t kcycles;
     423        char usuffix, ksuffix;
     424        task_get_accounting(t, &ucycles, &kcycles);
     425        order(ucycles, &ucycles, &usuffix);
     426        order(kcycles, &kcycles, &ksuffix);
     427
     428#ifdef __32_BITS__     
     429        printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64 "%c %9"
     430                PRIu64 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as,
     431                ucycles, usuffix, kcycles, ksuffix, atomic_get(&t->refcount),
     432                atomic_get(&t->active_calls));
     433#endif
     434
    431435#ifdef __64_BITS__
    432         printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64
    433             "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles,
    434             suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls));
    435 #endif
    436        
     436        printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64 "%c %9"
     437                PRIu64 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as,
     438                ucycles, usuffix, kcycles, ksuffix, atomic_get(&t->refcount),
     439                atomic_get(&t->active_calls));
     440#endif
     441
    437442        for (j = 0; j < IPC_MAX_PHONES; j++) {
    438443                if (t->phones[j].callee)
     
    440445        }
    441446        printf("\n");
    442        
     447                       
    443448        spinlock_unlock(&t->lock);
    444449        return true;
     
    453458        ipl = interrupts_disable();
    454459        spinlock_lock(&tasks_lock);
    455        
    456 #ifdef __32_BITS__
    457         printf("taskid name         ctx address    as         "
    458             "cycles     threads calls  callee\n");
    459         printf("------ ------------ --- ---------- ---------- "
    460             "---------- ------- ------ ------>\n");
    461 #endif
    462        
     460
     461#ifdef __32_BITS__     
     462        printf("taskid name         ctx address    as        "
     463            " ucycles    kcycles    threads calls  callee\n");
     464        printf("------ ------------ --- ---------- ----------"
     465            " ---------- ---------- ------- ------ ------>\n");
     466#endif
     467
    463468#ifdef __64_BITS__
    464         printf("taskid name         ctx address            as                 "
    465             "cycles     threads calls  callee\n");
    466         printf("------ ------------ --- ------------------ ------------------ "
    467             "---------- ------- ------ ------>\n");
    468 #endif
    469        
     469        printf("taskid name         ctx address            as                "
     470            " ucycles    kcycles    threads calls  callee\n");
     471        printf("------ ------------ --- ------------------ ------------------"
     472            " ---------- ---------- ---------- ------- ------ ------>\n");
     473#endif
     474
    470475        avltree_walk(&tasks_tree, task_print_walker, NULL);
    471        
     476
    472477        spinlock_unlock(&tasks_lock);
    473478        interrupts_restore(ipl);
Note: See TracChangeset for help on using the changeset viewer.