Ignore:
File:
1 edited

Legend:

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

    ra307beb r5ba201d  
    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 *
    6869 * @li the tasks_lock is held,
    6970 * @li the task's lock is held when task's lock is acquired before releasing
     
    99100        task_t *t = avltree_get_instance(node, task_t, tasks_tree_node);
    100101        unsigned *cnt = (unsigned *) arg;
    101 
     102       
    102103        if (t != TASK) {
    103104                (*cnt)++;
     
    107108                task_kill_internal(t);
    108109        }
    109 
    110         return true;    /* continue the walk */
     110       
     111        /* Continue the walk */
     112        return true;
    111113}
    112114
     
    115117{
    116118        unsigned tasks_left;
    117 
     119       
    118120        do { /* Repeat until there are any tasks except TASK */
    119121                /* Messing with task structures, avoid deadlock */
     
    138140        task_t *ta = obj;
    139141        int i;
    140 
     142       
    141143        atomic_set(&ta->refcount, 0);
    142144        atomic_set(&ta->lifecount, 0);
    143145        atomic_set(&ta->active_calls, 0);
    144 
     146       
    145147        spinlock_initialize(&ta->lock, "task_ta_lock");
    146148        mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
    147 
     149       
    148150        list_initialize(&ta->th_head);
    149151        list_initialize(&ta->sync_box_head);
    150 
     152       
    151153        ipc_answerbox_init(&ta->answerbox, ta);
    152154        for (i = 0; i < IPC_MAX_PHONES; i++)
    153155                ipc_phone_init(&ta->phones[i]);
    154 
     156       
    155157#ifdef CONFIG_UDEBUG
    156158        /* Init kbox stuff */
     
    159161        mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE);
    160162#endif
    161 
     163       
    162164        return 0;
    163165}
     
    165167/** Create new task with no threads.
    166168 *
    167  * @param as            Task's address space.
    168  * @param name          Symbolic name (a copy is made).
    169  *
    170  * @return              New task's structure.
     169 * @param as   Task's address space.
     170 * @param name Symbolic name (a copy is made).
     171 *
     172 * @return New task's structure.
    171173 *
    172174 */
     
    181183        memcpy(ta->name, name, TASK_NAME_BUFLEN);
    182184        ta->name[TASK_NAME_BUFLEN - 1] = 0;
    183 
     185       
    184186        ta->context = CONTEXT;
    185187        ta->capabilities = 0;
    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 
     188        ta->cycles = 0;
     189       
    196190#ifdef CONFIG_UDEBUG
    197191        /* Init debugging stuff */
    198192        udebug_task_init(&ta->udebug);
    199 
     193       
    200194        /* Init kbox stuff */
    201195        ta->kb.finished = false;
    202196#endif
    203 
     197       
    204198        if ((ipc_phone_0) &&
    205199            (context_check(ipc_phone_0->task->context, ta->context)))
    206200                ipc_phone_connect(&ta->phones[0], ipc_phone_0);
    207 
     201       
    208202        btree_create(&ta->futexes);
    209203       
     
    223217/** Destroy task.
    224218 *
    225  * @param t             Task to be destroyed.
     219 * @param t Task to be destroyed.
     220 *
    226221 */
    227222void task_destroy(task_t *t)
     
    233228        avltree_delete(&tasks_tree, &t->tasks_tree_node);
    234229        spinlock_unlock(&tasks_lock);
    235 
     230       
    236231        /*
    237232         * Perform architecture specific task destruction.
    238233         */
    239234        task_destroy_arch(t);
    240 
     235       
    241236        /*
    242237         * Free up dynamically allocated state.
    243238         */
    244239        btree_destroy(&t->futexes);
    245 
     240       
    246241        /*
    247242         * Drop our reference to the address space.
     
    256251/** Syscall for reading task ID from userspace.
    257252 *
    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.
     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 *
    262258 */
    263259unative_t sys_task_get_id(task_id_t *uspace_task_id)
     
    275271 * The name simplifies identifying the task in the task list.
    276272 *
    277  * @param name  The new name for the task. (typically the same
    278  *              as the command used to execute it).
     273 * @param name The new name for the task. (typically the same
     274 *             as the command used to execute it).
    279275 *
    280276 * @return 0 on success or an error code from @ref errno.h.
     277 *
    281278 */
    282279unative_t sys_task_set_name(const char *uspace_name, size_t name_len)
     
    284281        int rc;
    285282        char namebuf[TASK_NAME_BUFLEN];
    286 
     283       
    287284        /* Cap length of name and copy it from userspace. */
    288 
     285       
    289286        if (name_len > TASK_NAME_BUFLEN - 1)
    290287                name_len = TASK_NAME_BUFLEN - 1;
    291 
     288       
    292289        rc = copy_from_uspace(namebuf, uspace_name, name_len);
    293290        if (rc != 0)
    294291                return (unative_t) rc;
    295 
     292       
    296293        namebuf[name_len] = '\0';
    297294        str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf);
    298 
     295       
    299296        return EOK;
    300297}
     
    305302 * interrupts must be disabled.
    306303 *
    307  * @param id            Task ID.
    308  *
    309  * @return              Task structure address or NULL if there is no such task
    310  *                      ID.
    311  */
    312 task_t *task_find_by_id(task_id_t id) { avltree_node_t *node;
    313        
     304 * @param id Task ID.
     305 *
     306 * @return Task structure address or NULL if there is no such task
     307 *         ID.
     308 *
     309 */
     310task_t *task_find_by_id(task_id_t id)
     311{
     312        avltree_node_t *node;
    314313        node = avltree_search(&tasks_tree, (avltree_key_t) id);
    315 
     314       
    316315        if (node)
    317316                return avltree_get_instance(node, task_t, tasks_tree_node);
     317       
    318318        return NULL;
    319319}
     
    324324 * already disabled.
    325325 *
    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  */
    330 void 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;
     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 */
     332uint64_t task_get_accounting(task_t *t)
     333{
     334        /* Accumulated value of task */
     335        uint64_t ret = t->cycles;
    335336       
    336337        /* Current values of threads */
     
    344345                        if (thr == THREAD) {
    345346                                /* Update accounting of current thread */
    346                                 thread_update_accounting(false);
     347                                thread_update_accounting();
    347348                        }
    348                         uret += thr->ucycles;
    349                         kret += thr->kcycles;
     349                        ret += thr->cycles;
    350350                }
    351351                spinlock_unlock(&thr->lock);
    352352        }
    353353       
    354         *ucycles = uret;
    355         *kcycles = kret;
     354        return ret;
    356355}
    357356
     
    359358{
    360359        link_t *cur;
    361 
     360       
    362361        /*
    363362         * Interrupt all threads.
     
    387386 * It signals all the task's threads to bail it out.
    388387 *
    389  * @param id            ID of the task to be killed.
    390  *
    391  * @return              Zero on success or an error code from errno.h.
     388 * @param id ID of the task to be killed.
     389 *
     390 * @return Zero on success or an error code from errno.h.
     391 *
    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 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 
     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       
    435431#ifdef __64_BITS__
    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 
     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       
    442437        for (j = 0; j < IPC_MAX_PHONES; j++) {
    443438                if (t->phones[j].callee)
     
    445440        }
    446441        printf("\n");
    447                        
     442       
    448443        spinlock_unlock(&t->lock);
    449444        return true;
     
    458453        ipl = interrupts_disable();
    459454        spinlock_lock(&tasks_lock);
    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 
     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       
    468463#ifdef __64_BITS__
    469         printf("taskid name         ctx address            as                "
    470             " ucycles    kcycles    threads calls  callee\n");
    471         printf("------ ------------ --- ------------------ ------------------"
    472             " ---------- ---------- ---------- ------- ------ ------>\n");
    473 #endif
    474 
     464        printf("taskid name         ctx address            as                 "
     465            "cycles     threads calls  callee\n");
     466        printf("------ ------------ --- ------------------ ------------------ "
     467            "---------- ------- ------ ------>\n");
     468#endif
     469       
    475470        avltree_walk(&tasks_tree, task_print_walker, NULL);
    476 
     471       
    477472        spinlock_unlock(&tasks_lock);
    478473        interrupts_restore(ipl);
Note: See TracChangeset for help on using the changeset viewer.