source: mainline/kernel/generic/src/proc/task.c@ 77a0119

Last change on this file since 77a0119 was f35749e, checked in by Jiri Svoboda <jiri@…>, 4 months ago

System restart via shutdown -r

  • Property mode set to 100644
File size: 16.1 KB
RevLine 
[f761f1eb]1/*
[f35749e]2 * Copyright (c) 2025 Jiri Svoboda
[278b4a30]3 * Copyright (c) 2010 Jakub Jermar
[f761f1eb]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
[174156fd]30/** @addtogroup kernel_generic_proc
[b45c443]31 * @{
32 */
33
[9179d0a]34/**
[b45c443]35 * @file
[5ba201d]36 * @brief Task management.
[9179d0a]37 */
38
[63e27ef]39#include <assert.h>
[f761f1eb]40#include <proc/thread.h>
41#include <proc/task.h>
[20d50a1]42#include <mm/as.h>
[085d973]43#include <mm/slab.h>
[31d8e10]44#include <atomic.h>
[f761f1eb]45#include <synch/spinlock.h>
[5573942]46#include <synch/waitq.h>
[f761f1eb]47#include <arch.h>
[05882233]48#include <barrier.h>
[5c9a08b]49#include <adt/list.h>
[ef1eab7]50#include <adt/odict.h>
[3f74275]51#include <cap/cap.h>
[6d9c49a]52#include <ipc/ipc.h>
[c98e6ee]53#include <ipc/ipcrsc.h>
[5d0500c]54#include <ipc/event.h>
[bab75df6]55#include <stdio.h>
[7509ddc]56#include <errno.h>
[b2e121a]57#include <halt.h>
[19f857a]58#include <str.h>
[e3c762cd]59#include <syscall/copy.h>
[95ad426]60#include <macros.h>
[8e5e78f]61
[ef1eab7]62/** Spinlock protecting the @c tasks ordered dictionary. */
[da1bafb]63IRQ_SPINLOCK_INITIALIZE(tasks_lock);
[88169d9]64
[88cc71c0]65/** Ordered dictionary of active tasks by task ID.
66 *
67 * Members are task_t structures.
[88169d9]68 *
[ef1eab7]69 * The task is guaranteed to exist after it was found in the @c tasks
70 * dictionary as long as:
[5ba201d]71 *
[88169d9]72 * @li the tasks_lock is held,
[6f4495f5]73 * @li the task's lock is held when task's lock is acquired before releasing
74 * tasks_lock or
[7bb6b06]75 * @li the task's refcount is greater than 0
[88169d9]76 *
77 */
[ef1eab7]78odict_t tasks;
[88169d9]79
[286e03d]80static task_id_t task_counter = 0;
[70527f1]81
[82d515e9]82static slab_cache_t *task_cache;
[103de761]83
[121966e]84/* Forward declarations. */
85static void task_kill_internal(task_t *);
[b7fd2a0]86static errno_t tsk_constructor(void *, unsigned int);
[ef1eab7]87static size_t tsk_destructor(void *);
88
89static void *tasks_getkey(odlink_t *);
90static int tasks_cmp(void *, void *);
[121966e]91
[da1bafb]92/** Initialize kernel tasks support.
93 *
94 */
[f761f1eb]95void task_init(void)
96{
[43114c5]97 TASK = NULL;
[ef1eab7]98 odict_initialize(&tasks, tasks_getkey, tasks_cmp);
[82d515e9]99 task_cache = slab_cache_create("task_t", sizeof(task_t), 0,
[49115ac]100 tsk_constructor, tsk_destructor, 0);
[b76a2217]101}
102
[da1bafb]103/** Kill all tasks except the current task.
104 *
105 */
[f35749e]106void task_done(task_t *cur_task)
[f74bbaf]107{
[da1bafb]108 size_t tasks_left;
[ef1eab7]109 task_t *task;
[2f2beb4]110
[cdc4334]111 if (ipc_box_0) {
112 task_t *task_0 = ipc_box_0->task;
113 ipc_box_0 = NULL;
[f35749e]114
[2f2beb4]115 /*
116 * The first task is held by kinit(), we need to release it or
117 * it will never finish cleanup.
118 */
119 task_release(task_0);
120 }
[a35b458]121
[da1bafb]122 /* Repeat until there are any tasks except TASK */
123 do {
[121966e]124#ifdef CONFIG_DEBUG
125 printf("Killing tasks... ");
126#endif
[da1bafb]127 irq_spinlock_lock(&tasks_lock, true);
[121966e]128 tasks_left = 0;
[ef1eab7]129
[aab5e46]130 task = task_first();
131 while (task != NULL) {
[f35749e]132 if (task != cur_task) {
[ef1eab7]133 tasks_left++;
134#ifdef CONFIG_DEBUG
135 printf("[%" PRIu64 "] ", task->taskid);
136#endif
137 task_kill_internal(task);
138 }
139
[aab5e46]140 task = task_next(task);
[ef1eab7]141 }
142
[da1bafb]143 irq_spinlock_unlock(&tasks_lock, true);
[a35b458]144
[121966e]145 thread_sleep(1);
[a35b458]146
[f74bbaf]147#ifdef CONFIG_DEBUG
[121966e]148 printf("\n");
149#endif
[da1bafb]150 } while (tasks_left > 0);
[f74bbaf]151}
[70527f1]152
[b7fd2a0]153errno_t tsk_constructor(void *obj, unsigned int kmflags)
[59ee56f]154{
[da1bafb]155 task_t *task = (task_t *) obj;
[c46bfbc]156
[b7fd2a0]157 errno_t rc = caps_task_alloc(task);
[c46bfbc]158 if (rc != EOK)
159 return rc;
[a35b458]160
[e3306d04]161 atomic_store(&task->lifecount, 0);
[a35b458]162
[da1bafb]163 irq_spinlock_initialize(&task->lock, "task_t_lock");
[a35b458]164
[55b77d9]165 list_initialize(&task->threads);
[a35b458]166
[da1bafb]167 ipc_answerbox_init(&task->answerbox, task);
[a35b458]168
[86939b1]169 spinlock_initialize(&task->active_calls_lock, "active_calls_lock");
170 list_initialize(&task->active_calls);
[a35b458]171
[59ee56f]172#ifdef CONFIG_UDEBUG
173 /* Init kbox stuff */
[da1bafb]174 task->kb.thread = NULL;
175 ipc_answerbox_init(&task->kb.box, task);
176 mutex_initialize(&task->kb.cleanup_lock, MUTEX_PASSIVE);
[59ee56f]177#endif
[a35b458]178
[7f11dc6]179 return EOK;
[59ee56f]180}
181
[49115ac]182size_t tsk_destructor(void *obj)
183{
184 task_t *task = (task_t *) obj;
[a35b458]185
[3f74275]186 caps_task_free(task);
[49115ac]187 return 0;
188}
189
[814c4f5]190/** Create new task with no threads.
[70527f1]191 *
[5ba201d]192 * @param as Task's address space.
193 * @param name Symbolic name (a copy is made).
[70527f1]194 *
[5ba201d]195 * @return New task's structure.
[70527f1]196 *
197 */
[a000878c]198task_t *task_create(as_t *as, const char *name)
[f761f1eb]199{
[abf6c01]200 task_t *task = (task_t *) slab_alloc(task_cache, FRAME_ATOMIC);
201 if (!task)
[6a32cc5f]202 return NULL;
[a35b458]203
[07d4271]204 refcount_init(&task->refcount);
205
[da1bafb]206 task_create_arch(task);
[a35b458]207
[da1bafb]208 task->as = as;
209 str_cpy(task->name, TASK_NAME_BUFLEN, name);
[a35b458]210
[473d5d2]211 task->container = CONTAINER;
[719a208]212 task->perms = 0;
[da1bafb]213 task->ucycles = 0;
214 task->kcycles = 0;
[7ad17de]215
[3f74275]216 caps_task_init(task);
[e9d15d9]217
[da1bafb]218 task->ipc_info.call_sent = 0;
[be06914]219 task->ipc_info.call_received = 0;
[da1bafb]220 task->ipc_info.answer_sent = 0;
[be06914]221 task->ipc_info.answer_received = 0;
222 task->ipc_info.irq_notif_received = 0;
[da1bafb]223 task->ipc_info.forwarded = 0;
[5d0500c]224
225 event_task_init(task);
[a35b458]226
[c33f39f]227 task->answerbox.active = true;
228
[40eab9f]229 task->debug_sections = NULL;
230
[9a1b20c]231#ifdef CONFIG_UDEBUG
232 /* Init debugging stuff */
[da1bafb]233 udebug_task_init(&task->udebug);
[a35b458]234
[9a1b20c]235 /* Init kbox stuff */
[c33f39f]236 task->kb.box.active = true;
[da1bafb]237 task->kb.finished = false;
[9a1b20c]238#endif
[a35b458]239
[cdc4334]240 if ((ipc_box_0) &&
241 (container_check(ipc_box_0->task->container, task->container))) {
[eadaeae8]242 cap_phone_handle_t phone_handle;
[334c103]243 errno_t rc = phone_alloc(task, true, &phone_handle, NULL);
[09d01f2]244 if (rc != EOK) {
[6a32cc5f]245 task->as = NULL;
246 task_destroy_arch(task);
247 slab_free(task_cache, task);
248 return NULL;
249 }
[a35b458]250
[48bcf49]251 kobject_t *phone_obj = kobject_get(task, phone_handle,
252 KOBJECT_TYPE_PHONE);
[cdc4334]253 (void) ipc_phone_connect(phone_obj->phone, ipc_box_0);
[05ffb41]254 }
[a35b458]255
[da1bafb]256 irq_spinlock_lock(&tasks_lock, true);
[a35b458]257
[da1bafb]258 task->taskid = ++task_counter;
[ef1eab7]259 odlink_initialize(&task->ltasks);
260 odict_insert(&task->ltasks, &tasks, NULL);
[a35b458]261
[da1bafb]262 irq_spinlock_unlock(&tasks_lock, true);
[a35b458]263
[da1bafb]264 return task;
[f761f1eb]265}
266
[7509ddc]267/** Destroy task.
268 *
[da1bafb]269 * @param task Task to be destroyed.
[5ba201d]270 *
[7509ddc]271 */
[07d4271]272static void task_destroy(task_t *task)
[7509ddc]273{
[ea7890e7]274 /*
[ca4c5596]275 * Remove the task from the task odict.
[ea7890e7]276 */
[da1bafb]277 irq_spinlock_lock(&tasks_lock, true);
[ef1eab7]278 odict_remove(&task->ltasks);
[da1bafb]279 irq_spinlock_unlock(&tasks_lock, true);
[a35b458]280
[ea7890e7]281 /*
282 * Perform architecture specific task destruction.
283 */
[da1bafb]284 task_destroy_arch(task);
[a35b458]285
[ea7890e7]286 /*
287 * Drop our reference to the address space.
288 */
[da1bafb]289 as_release(task->as);
[a35b458]290
[82d515e9]291 slab_free(task_cache, task);
[7509ddc]292}
293
[278b4a30]294/** Hold a reference to a task.
295 *
296 * Holding a reference to a task prevents destruction of that task.
297 *
[da1bafb]298 * @param task Task to be held.
299 *
[278b4a30]300 */
[da1bafb]301void task_hold(task_t *task)
[278b4a30]302{
[07d4271]303 refcount_up(&task->refcount);
[278b4a30]304}
305
306/** Release a reference to a task.
307 *
308 * The last one to release a reference to a task destroys the task.
309 *
[da1bafb]310 * @param task Task to be released.
311 *
[278b4a30]312 */
[da1bafb]313void task_release(task_t *task)
[278b4a30]314{
[07d4271]315 if (refcount_down(&task->refcount))
[da1bafb]316 task_destroy(task);
[278b4a30]317}
318
[dd8d5a7]319#ifdef __32_BITS__
320
321/** Syscall for reading task ID from userspace (32 bits)
[ec55358]322 *
[dd8d5a7]323 * @param uspace_taskid Pointer to user-space buffer
324 * where to store current task ID.
[5ba201d]325 *
326 * @return Zero on success or an error code from @ref errno.h.
[ec55358]327 *
328 */
[5a5269d]329sys_errno_t sys_task_get_id(uspace_ptr_sysarg64_t uspace_taskid)
[ec55358]330{
331 /*
[814c4f5]332 * No need to acquire lock on TASK because taskid remains constant for
333 * the lifespan of the task.
[ec55358]334 */
[b7fd2a0]335 return (sys_errno_t) copy_to_uspace(uspace_taskid, &TASK->taskid,
[6f4495f5]336 sizeof(TASK->taskid));
[ec55358]337}
338
[dd8d5a7]339#endif /* __32_BITS__ */
340
341#ifdef __64_BITS__
342
343/** Syscall for reading task ID from userspace (64 bits)
344 *
345 * @return Current task ID.
346 *
347 */
348sysarg_t sys_task_get_id(void)
349{
350 /*
351 * No need to acquire lock on TASK because taskid remains constant for
352 * the lifespan of the task.
353 */
354 return TASK->taskid;
355}
356
357#endif /* __64_BITS__ */
358
[bc18d63]359/** Syscall for setting the task name.
360 *
361 * The name simplifies identifying the task in the task list.
362 *
[5ba201d]363 * @param name The new name for the task. (typically the same
364 * as the command used to execute it).
[bc18d63]365 *
366 * @return 0 on success or an error code from @ref errno.h.
[5ba201d]367 *
[bc18d63]368 */
[5a5269d]369sys_errno_t sys_task_set_name(const uspace_ptr_char uspace_name, size_t name_len)
[bc18d63]370{
371 char namebuf[TASK_NAME_BUFLEN];
[a35b458]372
[bc18d63]373 /* Cap length of name and copy it from userspace. */
374 if (name_len > TASK_NAME_BUFLEN - 1)
375 name_len = TASK_NAME_BUFLEN - 1;
[a35b458]376
[b7fd2a0]377 errno_t rc = copy_from_uspace(namebuf, uspace_name, name_len);
[a53ed3a]378 if (rc != EOK)
[b7fd2a0]379 return (sys_errno_t) rc;
[a35b458]380
[f4b1535]381 namebuf[name_len] = '\0';
[a35b458]382
[577f042a]383 /*
384 * As the task name is referenced also from the
385 * threads, lock the threads' lock for the course
386 * of the update.
387 */
[a35b458]388
[577f042a]389 irq_spinlock_lock(&tasks_lock, true);
390 irq_spinlock_lock(&TASK->lock, false);
[a35b458]391
[577f042a]392 /* Set task name */
[f4b1535]393 str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf);
[a35b458]394
[577f042a]395 irq_spinlock_unlock(&TASK->lock, false);
396 irq_spinlock_unlock(&tasks_lock, true);
[a35b458]397
[bc18d63]398 return EOK;
399}
400
[1e9f8ab]401/** Syscall to forcefully terminate a task
402 *
403 * @param uspace_taskid Pointer to task ID in user space.
404 *
405 * @return 0 on success or an error code from @ref errno.h.
406 *
407 */
[5a5269d]408sys_errno_t sys_task_kill(uspace_ptr_task_id_t uspace_taskid)
[1e9f8ab]409{
410 task_id_t taskid;
[b7fd2a0]411 errno_t rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(taskid));
[a53ed3a]412 if (rc != EOK)
[b7fd2a0]413 return (sys_errno_t) rc;
[a35b458]414
[b7fd2a0]415 return (sys_errno_t) task_kill(taskid);
[1e9f8ab]416}
417
[9a8d91b]418/** Find task structure corresponding to task ID.
419 *
[5ba201d]420 * @param id Task ID.
421 *
[07d4271]422 * @return Task reference or NULL if there is no such task ID.
[9a8d91b]423 *
424 */
[5ba201d]425task_t *task_find_by_id(task_id_t id)
426{
[07d4271]427 task_t *task = NULL;
428
429 irq_spinlock_lock(&tasks_lock, true);
[1d432f9]430
[ef1eab7]431 odlink_t *odlink = odict_find_eq(&tasks, &id, NULL);
[07d4271]432 if (odlink != NULL) {
433 task = odict_get_instance(odlink, task_t, ltasks);
[a35b458]434
[07d4271]435 /*
436 * The directory of tasks can't hold a reference, since that would
437 * prevent task from ever being destroyed. That means we have to
438 * check for the case where the task is already being destroyed, but
439 * not yet removed from the directory.
440 */
441 if (!refcount_try_up(&task->refcount))
442 task = NULL;
443 }
444
445 irq_spinlock_unlock(&tasks_lock, true);
446
447 return task;
[9a8d91b]448}
449
[aab5e46]450/** Get count of tasks.
451 *
452 * @return Number of tasks in the system
453 */
454size_t task_count(void)
455{
456 assert(interrupts_disabled());
457 assert(irq_spinlock_locked(&tasks_lock));
458
459 return odict_count(&tasks);
460}
461
462/** Get first task (task with lowest ID).
463 *
464 * @return Pointer to first task or @c NULL if there are none.
465 */
466task_t *task_first(void)
467{
468 odlink_t *odlink;
469
470 assert(interrupts_disabled());
471 assert(irq_spinlock_locked(&tasks_lock));
472
473 odlink = odict_first(&tasks);
474 if (odlink == NULL)
475 return NULL;
476
477 return odict_get_instance(odlink, task_t, ltasks);
478}
479
480/** Get next task (with higher task ID).
481 *
482 * @param cur Current task
483 * @return Pointer to next task or @c NULL if there are no more tasks.
484 */
485task_t *task_next(task_t *cur)
486{
487 odlink_t *odlink;
488
489 assert(interrupts_disabled());
490 assert(irq_spinlock_locked(&tasks_lock));
491
492 odlink = odict_next(&cur->ltasks, &tasks);
493 if (odlink == NULL)
494 return NULL;
495
496 return odict_get_instance(odlink, task_t, ltasks);
497}
498
[0313ff0]499/** Get accounting data of given task.
500 *
[1d432f9]501 * Note that task lock of 'task' must be already held and interrupts must be
[814c4f5]502 * already disabled.
[0313ff0]503 *
[da1bafb]504 * @param task Pointer to the task.
[88dea9d]505 * @param ucycles Out pointer to sum of all user cycles.
506 * @param kcycles Out pointer to sum of all kernel cycles.
[0313ff0]507 *
508 */
[da1bafb]509void task_get_accounting(task_t *task, uint64_t *ucycles, uint64_t *kcycles)
[0313ff0]510{
[63e27ef]511 assert(interrupts_disabled());
512 assert(irq_spinlock_locked(&task->lock));
[1d432f9]513
[a2a00e8]514 /* Accumulated values of task */
[da1bafb]515 uint64_t uret = task->ucycles;
516 uint64_t kret = task->kcycles;
[a35b458]517
[0313ff0]518 /* Current values of threads */
[feeac0d]519 list_foreach(task->threads, th_link, thread_t, thread) {
[62b6d17]520 /* Process only counted threads */
[da1bafb]521 if (!thread->uncounted) {
522 if (thread == THREAD) {
[6f4495f5]523 /* Update accounting of current thread */
[a2a00e8]524 thread_update_accounting(false);
[da1bafb]525 }
[a35b458]526
[11909ce3]527 uret += atomic_time_read(&thread->ucycles);
528 kret += atomic_time_read(&thread->kcycles);
[62b6d17]529 }
[0313ff0]530 }
[a35b458]531
[a2a00e8]532 *ucycles = uret;
533 *kcycles = kret;
[0313ff0]534}
535
[da1bafb]536static void task_kill_internal(task_t *task)
[121966e]537{
[07d4271]538 irq_spinlock_lock(&task->lock, true);
[a35b458]539
[121966e]540 /*
541 * Interrupt all threads.
542 */
[a35b458]543
[feeac0d]544 list_foreach(task->threads, th_link, thread_t, thread) {
[111b9b9]545 thread_interrupt(thread);
[121966e]546 }
[a35b458]547
[07d4271]548 irq_spinlock_unlock(&task->lock, true);
[121966e]549}
550
[7509ddc]551/** Kill task.
[ea7890e7]552 *
553 * This function is idempotent.
554 * It signals all the task's threads to bail it out.
[7509ddc]555 *
[5ba201d]556 * @param id ID of the task to be killed.
557 *
558 * @return Zero on success or an error code from errno.h.
[7509ddc]559 *
560 */
[b7fd2a0]561errno_t task_kill(task_id_t id)
[7509ddc]562{
[9b6aae6]563 if (id == 1)
564 return EPERM;
[a35b458]565
[da1bafb]566 task_t *task = task_find_by_id(id);
[07d4271]567 if (!task)
[7509ddc]568 return ENOENT;
[a35b458]569
[da1bafb]570 task_kill_internal(task);
[07d4271]571 task_release(task);
[da1bafb]572 return EOK;
[7509ddc]573}
574
[5bcf1f9]575/** Kill the currently running task.
576 *
577 * @param notify Send out fault notifications.
578 *
579 * @return Zero on success or an error code from errno.h.
580 *
581 */
582void task_kill_self(bool notify)
583{
584 /*
585 * User space can subscribe for FAULT events to take action
586 * whenever a task faults (to take a dump, run a debugger, etc.).
587 * The notification is always available, but unless udebug is enabled,
588 * that's all you get.
[ae7d03c]589 */
[5bcf1f9]590 if (notify) {
[f9061b4]591 /* Notify the subscriber that a fault occurred. */
592 if (event_notify_3(EVENT_FAULT, false, LOWER32(TASK->taskid),
593 UPPER32(TASK->taskid), (sysarg_t) THREAD) == EOK) {
[5bcf1f9]594#ifdef CONFIG_UDEBUG
595 /* Wait for a debugging session. */
596 udebug_thread_fault();
597#endif
598 }
599 }
[a35b458]600
[5bcf1f9]601 task_kill_internal(TASK);
602 thread_exit();
603}
604
605/** Process syscall to terminate the current task.
606 *
607 * @param notify Send out fault notifications.
608 *
609 */
[b7fd2a0]610sys_errno_t sys_task_exit(sysarg_t notify)
[5bcf1f9]611{
612 task_kill_self(notify);
[88e43bc]613 unreachable();
[5bcf1f9]614}
615
[ef1eab7]616static void task_print(task_t *task, bool additional)
[b76a2217]617{
[da1bafb]618 irq_spinlock_lock(&task->lock, false);
[a35b458]619
[a2a00e8]620 uint64_t ucycles;
621 uint64_t kcycles;
[1ba37fa]622 char usuffix, ksuffix;
[da1bafb]623 task_get_accounting(task, &ucycles, &kcycles);
[e535eeb]624 order_suffix(ucycles, &ucycles, &usuffix);
625 order_suffix(kcycles, &kcycles, &ksuffix);
[a35b458]626
[da1bafb]627#ifdef __32_BITS__
[ef1eab7]628 if (additional)
[077842c]629 printf("%-8" PRIu64 " %9zu", task->taskid,
[07d4271]630 atomic_load(&task->lifecount));
[c0f13d2]631 else
632 printf("%-8" PRIu64 " %-14s %-5" PRIu32 " %10p %10p"
633 " %9" PRIu64 "%c %9" PRIu64 "%c\n", task->taskid,
[473d5d2]634 task->name, task->container, task, task->as,
[c0f13d2]635 ucycles, usuffix, kcycles, ksuffix);
[52755f1]636#endif
[a35b458]637
[52755f1]638#ifdef __64_BITS__
[ef1eab7]639 if (additional)
[7e752b2]640 printf("%-8" PRIu64 " %9" PRIu64 "%c %9" PRIu64 "%c "
[077842c]641 "%9zu\n", task->taskid, ucycles, usuffix, kcycles,
[07d4271]642 ksuffix, atomic_load(&task->lifecount));
[c0f13d2]643 else
644 printf("%-8" PRIu64 " %-14s %-5" PRIu32 " %18p %18p\n",
[473d5d2]645 task->taskid, task->name, task->container, task, task->as);
[52755f1]646#endif
[a35b458]647
[da1bafb]648 irq_spinlock_unlock(&task->lock, false);
[b76a2217]649}
650
[c0f13d2]651/** Print task list
652 *
653 * @param additional Print additional information.
654 *
655 */
656void task_print_list(bool additional)
[37c57f2]657{
[f74bbaf]658 /* Messing with task structures, avoid deadlock */
[da1bafb]659 irq_spinlock_lock(&tasks_lock, true);
[a35b458]660
[5ba201d]661#ifdef __32_BITS__
[c0f13d2]662 if (additional)
[48dcc69]663 printf("[id ] [threads] [calls] [callee\n");
[c0f13d2]664 else
[473d5d2]665 printf("[id ] [name ] [ctn] [address ] [as ]"
[c0f13d2]666 " [ucycles ] [kcycles ]\n");
[52755f1]667#endif
[a35b458]668
[52755f1]669#ifdef __64_BITS__
[c0f13d2]670 if (additional)
[be06914]671 printf("[id ] [ucycles ] [kcycles ] [threads] [calls]"
[c0f13d2]672 " [callee\n");
673 else
[473d5d2]674 printf("[id ] [name ] [ctn] [address ]"
[c0f13d2]675 " [as ]\n");
[52755f1]676#endif
[a35b458]677
[ef1eab7]678 task_t *task;
679
[aab5e46]680 task = task_first();
681 while (task != NULL) {
[ef1eab7]682 task_print(task, additional);
[aab5e46]683 task = task_next(task);
[ef1eab7]684 }
[a35b458]685
[da1bafb]686 irq_spinlock_unlock(&tasks_lock, true);
[37c57f2]687}
[7509ddc]688
[ef1eab7]689/** Get key function for the @c tasks ordered dictionary.
690 *
691 * @param odlink Link
692 * @return Pointer to task ID cast as 'void *'
693 */
694static void *tasks_getkey(odlink_t *odlink)
695{
696 task_t *task = odict_get_instance(odlink, task_t, ltasks);
697 return (void *) &task->taskid;
698}
699
700/** Key comparison function for the @c tasks ordered dictionary.
701 *
702 * @param a Pointer to thread A ID
703 * @param b Pointer to thread B ID
704 * @return -1, 0, 1 iff ID A is less than, equal to, greater than B
705 */
706static int tasks_cmp(void *a, void *b)
707{
708 task_id_t ida = *(task_id_t *)a;
709 task_id_t idb = *(task_id_t *)b;
710
711 if (ida < idb)
712 return -1;
713 else if (ida == idb)
714 return 0;
715 else
716 return +1;
717}
718
[cc73a8a1]719/** @}
[b45c443]720 */
Note: See TracBrowser for help on using the repository browser.