Subversion Repositories HelenOS

Rev

Rev 3386 | Rev 4327 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3386 Rev 4153
Line 50... Line 50...
50
#include <ipc/ipc.h>
50
#include <ipc/ipc.h>
51
#include <ipc/ipcrsc.h>
51
#include <ipc/ipcrsc.h>
52
#include <print.h>
52
#include <print.h>
53
#include <errno.h>
53
#include <errno.h>
54
#include <func.h>
54
#include <func.h>
-
 
55
#include <string.h>
55
#include <syscall/copy.h>
56
#include <syscall/copy.h>
56
 
57
 
57
/** Spinlock protecting the tasks_tree AVL tree. */
58
/** Spinlock protecting the tasks_tree AVL tree. */
58
SPINLOCK_INITIALIZE(tasks_lock);
59
SPINLOCK_INITIALIZE(tasks_lock);
59
 
60
 
Line 128... Line 129...
128
}
129
}
129
 
130
 
130
/** Create new task with no threads.
131
/** Create new task with no threads.
131
 *
132
 *
132
 * @param as        Task's address space.
133
 * @param as        Task's address space.
133
 * @param name      Symbolic name.
134
 * @param name      Symbolic name (a copy is made).
134
 *
135
 *
135
 * @return      New task's structure.
136
 * @return      New task's structure.
136
 *
137
 *
137
 */
138
 */
138
task_t *task_create(as_t *as, char *name)
139
task_t *task_create(as_t *as, char *name)
Line 146... Line 147...
146
    task_create_arch(ta);
147
    task_create_arch(ta);
147
 
148
 
148
    spinlock_initialize(&ta->lock, "task_ta_lock");
149
    spinlock_initialize(&ta->lock, "task_ta_lock");
149
    list_initialize(&ta->th_head);
150
    list_initialize(&ta->th_head);
150
    ta->as = as;
151
    ta->as = as;
-
 
152
 
-
 
153
    memcpy(ta->name, name, TASK_NAME_BUFLEN);
151
    ta->name = name;
154
    ta->name[TASK_NAME_BUFLEN - 1] = '\0';
-
 
155
 
152
    atomic_set(&ta->refcount, 0);
156
    atomic_set(&ta->refcount, 0);
153
    atomic_set(&ta->lifecount, 0);
157
    atomic_set(&ta->lifecount, 0);
154
    ta->context = CONTEXT;
158
    ta->context = CONTEXT;
155
 
159
 
156
    ta->capabilities = 0;
160
    ta->capabilities = 0;
157
    ta->cycles = 0;
161
    ta->cycles = 0;
-
 
162
 
-
 
163
#ifdef CONFIG_UDEBUG
-
 
164
    /* Init debugging stuff */
-
 
165
    udebug_task_init(&ta->udebug);
158
   
166
 
-
 
167
    /* Init kbox stuff */
-
 
168
    ipc_answerbox_init(&ta->kb.box, ta);
-
 
169
    ta->kb.thread = NULL;
-
 
170
    mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE);
-
 
171
    ta->kb.finished = false;
-
 
172
#endif
-
 
173
 
159
    ipc_answerbox_init(&ta->answerbox, ta);
174
    ipc_answerbox_init(&ta->answerbox, ta);
160
    for (i = 0; i < IPC_MAX_PHONES; i++)
175
    for (i = 0; i < IPC_MAX_PHONES; i++)
161
        ipc_phone_init(&ta->phones[i]);
176
        ipc_phone_init(&ta->phones[i]);
162
    if ((ipc_phone_0) && (context_check(ipc_phone_0->task->context,
177
    if ((ipc_phone_0) && (context_check(ipc_phone_0->task->context,
163
        ta->context)))
178
        ta->context)))
Line 233... Line 248...
233
     */
248
     */
234
    return (unative_t) copy_to_uspace(uspace_task_id, &TASK->taskid,
249
    return (unative_t) copy_to_uspace(uspace_task_id, &TASK->taskid,
235
        sizeof(TASK->taskid));
250
        sizeof(TASK->taskid));
236
}
251
}
237
 
252
 
-
 
253
/** Syscall for setting the task name.
-
 
254
 *
-
 
255
 * The name simplifies identifying the task in the task list.
-
 
256
 *
-
 
257
 * @param name  The new name for the task. (typically the same
-
 
258
 *      as the command used to execute it).
-
 
259
 *
-
 
260
 * @return 0 on success or an error code from @ref errno.h.
-
 
261
 */
-
 
262
unative_t sys_task_set_name(const char *uspace_name, size_t name_len)
-
 
263
{
-
 
264
    int rc;
-
 
265
    char namebuf[TASK_NAME_BUFLEN];
-
 
266
 
-
 
267
    /* Cap length of name and copy it from userspace. */
-
 
268
 
-
 
269
    if (name_len > TASK_NAME_BUFLEN - 1)
-
 
270
        name_len = TASK_NAME_BUFLEN - 1;
-
 
271
 
-
 
272
    rc = copy_from_uspace(namebuf, uspace_name, name_len);
-
 
273
    if (rc != 0)
-
 
274
        return (unative_t) rc;
-
 
275
 
-
 
276
    namebuf[name_len] = '\0';
-
 
277
    strncpy(TASK->name, namebuf, TASK_NAME_BUFLEN);
-
 
278
 
-
 
279
    return EOK;
-
 
280
}
-
 
281
 
238
/** Find task structure corresponding to task ID.
282
/** Find task structure corresponding to task ID.
239
 *
283
 *
240
 * The tasks_lock must be already held by the caller of this function and
284
 * The tasks_lock must be already held by the caller of this function and
241
 * interrupts must be disabled.
285
 * interrupts must be disabled.
242
 *
286
 *
Line 323... Line 367...
323
    for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) {
367
    for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) {
324
        thread_t *thr;
368
        thread_t *thr;
325
        bool sleeping = false;
369
        bool sleeping = false;
326
       
370
       
327
        thr = list_get_instance(cur, thread_t, th_link);
371
        thr = list_get_instance(cur, thread_t, th_link);
328
           
372
       
329
        spinlock_lock(&thr->lock);
373
        spinlock_lock(&thr->lock);
330
        thr->interrupted = true;
374
        thr->interrupted = true;
331
        if (thr->state == Sleeping)
375
        if (thr->state == Sleeping)
332
            sleeping = true;
376
            sleeping = true;
333
        spinlock_unlock(&thr->lock);
377
        spinlock_unlock(&thr->lock);
Line 351... Line 395...
351
    uint64_t cycles;
395
    uint64_t cycles;
352
    char suffix;
396
    char suffix;
353
    order(task_get_accounting(t), &cycles, &suffix);
397
    order(task_get_accounting(t), &cycles, &suffix);
354
 
398
 
355
#ifdef __32_BITS__  
399
#ifdef __32_BITS__  
356
    printf("%-6" PRIu64 " %-10s %-3" PRIu32 " %10p %10p %9" PRIu64
400
    printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64
357
        "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles,
401
        "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles,
358
        suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls));
402
        suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls));
359
#endif
403
#endif
360
 
404
 
361
#ifdef __64_BITS__
405
#ifdef __64_BITS__
362
    printf("%-6" PRIu64 " %-10s %-3" PRIu32 " %18p %18p %9" PRIu64
406
    printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64
363
        "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles,
407
        "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles,
364
        suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls));
408
        suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls));
365
#endif
409
#endif
366
 
410
 
367
    for (j = 0; j < IPC_MAX_PHONES; j++) {
411
    for (j = 0; j < IPC_MAX_PHONES; j++) {
Line 382... Line 426...
382
    /* Messing with task structures, avoid deadlock */
426
    /* Messing with task structures, avoid deadlock */
383
    ipl = interrupts_disable();
427
    ipl = interrupts_disable();
384
    spinlock_lock(&tasks_lock);
428
    spinlock_lock(&tasks_lock);
385
 
429
 
386
#ifdef __32_BITS__  
430
#ifdef __32_BITS__  
387
    printf("taskid name       ctx address    as         "
431
    printf("taskid name         ctx address    as         "
388
        "cycles     threads calls  callee\n");
432
        "cycles     threads calls  callee\n");
389
    printf("------ ---------- --- ---------- ---------- "
433
    printf("------ ------------ --- ---------- ---------- "
390
        "---------- ------- ------ ------>\n");
434
        "---------- ------- ------ ------>\n");
391
#endif
435
#endif
392
 
436
 
393
#ifdef __64_BITS__
437
#ifdef __64_BITS__
394
    printf("taskid name       ctx address            as                 "
438
    printf("taskid name         ctx address            as                 "
395
        "cycles     threads calls  callee\n");
439
        "cycles     threads calls  callee\n");
396
    printf("------ ---------- --- ------------------ ------------------ "
440
    printf("------ ------------ --- ------------------ ------------------ "
397
        "---------- ------- ------ ------>\n");
441
        "---------- ------- ------ ------>\n");
398
#endif
442
#endif
399
 
443
 
400
    avltree_walk(&tasks_tree, task_print_walker, NULL);
444
    avltree_walk(&tasks_tree, task_print_walker, NULL);
401
 
445