Rev 3623 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3623 | Rev 4377 | ||
---|---|---|---|
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 148... | Line 149... | ||
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; |
151 | 152 | ||
152 | memcpy(ta->name, name, TASK_NAME_BUFLEN); |
153 | memcpy(ta->name, name, TASK_NAME_BUFLEN); |
153 | ta->name[TASK_NAME_BUFLEN - 1] = '\0'; |
154 | ta->name[TASK_NAME_BUFLEN - 1] = 0; |
154 | 155 | ||
155 | atomic_set(&ta->refcount, 0); |
156 | atomic_set(&ta->refcount, 0); |
156 | atomic_set(&ta->lifecount, 0); |
157 | atomic_set(&ta->lifecount, 0); |
157 | ta->context = CONTEXT; |
158 | ta->context = CONTEXT; |
158 | 159 | ||
Line 247... | Line 248... | ||
247 | */ |
248 | */ |
248 | return (unative_t) copy_to_uspace(uspace_task_id, &TASK->taskid, |
249 | return (unative_t) copy_to_uspace(uspace_task_id, &TASK->taskid, |
249 | sizeof(TASK->taskid)); |
250 | sizeof(TASK->taskid)); |
250 | } |
251 | } |
251 | 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 | str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf); |
|
- | 278 | ||
- | 279 | return EOK; |
|
- | 280 | } |
|
- | 281 | ||
252 | /** Find task structure corresponding to task ID. |
282 | /** Find task structure corresponding to task ID. |
253 | * |
283 | * |
254 | * 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 |
255 | * interrupts must be disabled. |
285 | * interrupts must be disabled. |
256 | * |
286 | * |
Line 337... | Line 367... | ||
337 | 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) { |
338 | thread_t *thr; |
368 | thread_t *thr; |
339 | bool sleeping = false; |
369 | bool sleeping = false; |
340 | 370 | ||
341 | thr = list_get_instance(cur, thread_t, th_link); |
371 | thr = list_get_instance(cur, thread_t, th_link); |
342 | 372 | ||
343 | spinlock_lock(&thr->lock); |
373 | spinlock_lock(&thr->lock); |
344 | thr->interrupted = true; |
374 | thr->interrupted = true; |
345 | if (thr->state == Sleeping) |
375 | if (thr->state == Sleeping) |
346 | sleeping = true; |
376 | sleeping = true; |
347 | spinlock_unlock(&thr->lock); |
377 | spinlock_unlock(&thr->lock); |
Line 365... | Line 395... | ||
365 | uint64_t cycles; |
395 | uint64_t cycles; |
366 | char suffix; |
396 | char suffix; |
367 | order(task_get_accounting(t), &cycles, &suffix); |
397 | order(task_get_accounting(t), &cycles, &suffix); |
368 | 398 | ||
369 | #ifdef __32_BITS__ |
399 | #ifdef __32_BITS__ |
370 | printf("%-6" PRIu64 " %-10s %-3" PRIu32 " %10p %10p %9" PRIu64 |
400 | printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64 |
371 | "%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, |
372 | suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls)); |
402 | suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls)); |
373 | #endif |
403 | #endif |
374 | 404 | ||
375 | #ifdef __64_BITS__ |
405 | #ifdef __64_BITS__ |
376 | printf("%-6" PRIu64 " %-10s %-3" PRIu32 " %18p %18p %9" PRIu64 |
406 | printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64 |
377 | "%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, |
378 | suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls)); |
408 | suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls)); |
379 | #endif |
409 | #endif |
380 | 410 | ||
381 | for (j = 0; j < IPC_MAX_PHONES; j++) { |
411 | for (j = 0; j < IPC_MAX_PHONES; j++) { |
Line 396... | Line 426... | ||
396 | /* Messing with task structures, avoid deadlock */ |
426 | /* Messing with task structures, avoid deadlock */ |
397 | ipl = interrupts_disable(); |
427 | ipl = interrupts_disable(); |
398 | spinlock_lock(&tasks_lock); |
428 | spinlock_lock(&tasks_lock); |
399 | 429 | ||
400 | #ifdef __32_BITS__ |
430 | #ifdef __32_BITS__ |
401 | printf("taskid name ctx address as " |
431 | printf("taskid name ctx address as " |
402 | "cycles threads calls callee\n"); |
432 | "cycles threads calls callee\n"); |
403 | printf("------ ---------- --- ---------- ---------- " |
433 | printf("------ ------------ --- ---------- ---------- " |
404 | "---------- ------- ------ ------>\n"); |
434 | "---------- ------- ------ ------>\n"); |
405 | #endif |
435 | #endif |
406 | 436 | ||
407 | #ifdef __64_BITS__ |
437 | #ifdef __64_BITS__ |
408 | printf("taskid name ctx address as " |
438 | printf("taskid name ctx address as " |
409 | "cycles threads calls callee\n"); |
439 | "cycles threads calls callee\n"); |
410 | printf("------ ---------- --- ------------------ ------------------ " |
440 | printf("------ ------------ --- ------------------ ------------------ " |
411 | "---------- ------- ------ ------>\n"); |
441 | "---------- ------- ------ ------>\n"); |
412 | #endif |
442 | #endif |
413 | 443 | ||
414 | avltree_walk(&tasks_tree, task_print_walker, NULL); |
444 | avltree_walk(&tasks_tree, task_print_walker, NULL); |
415 | 445 |