MOS Source Code
Loading...
Searching...
No Matches
tasks.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2// Special processes: (pid 0: idle, pid 1: init, pid 2: kthreadd)
3
7#include "mos/syslog/printk.h"
9
12#include <mos/misc/panic.h>
14#include <mos/tasks/process.h>
16#include <mos/tasks/thread.h>
17#include <mos_stdlib.h>
18
19#define PROCESS_HASHTABLE_SIZE 512
20#define THREAD_HASHTABLE_SIZE 512
21
25
26static void dump_process(void)
27{
29 {
31 pr_info("process %pp ", (void *) proc);
32 if (proc->parent)
33 pr_info2("parent %pp ", (void *) proc->parent);
34 else
35 pr_info2("parent <none> ");
37 }
38 else
39 {
40 pr_warn("no current thread");
41 }
42}
43
44MOS_PANIC_HOOK(dump_process, "Dump current process");
45
51
52// ! sysfs support
53
54bool _process_do_print(uintn key, void *val, void *data)
55{
56 MOS_UNUSED(key);
57 sysfs_file_t *f = data;
58 process_t *proc = val;
59 sysfs_printf(f, "%pp, parent=%pp, main_thread=%pt, exit_status=%d\n", (void *) proc, (void *) proc->parent, (void *) proc->main_thread, proc->exit_status);
60 return true;
61}
62
63bool _thread_do_print(uintn key, void *val, void *data)
64{
65 MOS_UNUSED(key);
66 sysfs_file_t *f = data;
67 thread_t *thread = val;
68 sysfs_printf(f, "%pt, state=%c, mode=%s, owner=%pp, stack=%p (%zu bytes)\n", (void *) thread, thread_state_str(thread->state),
69 thread->mode == THREAD_MODE_KERNEL ? "kernel" : "user", (void *) thread->owner, (void *) thread->u_stack.top, thread->u_stack.capacity);
70 return true;
71}
72
74{
76 return true;
77}
78
80{
82 return true;
83}
84
89
MOSAPI int __pure hashmap_simple_key_compare(uintn key1, uintn key2)
MOSAPI hash_t __pure hashmap_identity_hash(uintn key)
MOSAPI void hashmap_init(hashmap_t *map, size_t capacity, hashmap_hash_t hash_func, hashmap_key_compare_t compare_func)
Definition hashmap.c:24
MOSAPI void hashmap_foreach(hashmap_t *map, hashmap_foreach_func_t func, void *data)
Definition hashmap.c:146
slab_t * process_cache
Definition tasks.c:22
@ THREAD_MODE_KERNEL
Definition task_types.h:21
#define MOS_UNUSED(x)
Definition mos_global.h:64
#define MOS_PANIC_HOOK(_f, _name)
Definition panic.h:33
#define NULL
Definition pb_syshdr.h:46
#define current_thread
Definition platform.h:30
#define current_process
Definition platform.h:31
#define pr_info2(fmt,...)
Definition printk.h:36
#define pr_warn(fmt,...)
Definition printk.h:38
#define pr_info(fmt,...)
Definition printk.h:35
void process_dump_mmaps(const process_t *process)
Definition process.c:365
hashmap_t process_table
Definition process.c:34
char thread_state_str(thread_state_t state)
Definition schedule.c:14
#define SLAB_AUTOINIT(name, var, type)
size_t capacity
Definition stack.h:18
process_t * parent
Definition task_types.h:47
thread_t * main_thread
Definition task_types.h:56
u32 exit_status
exit status
Definition task_types.h:52
Definition slab.h:45
thread_mode mode
user-mode thread or kernel-mode
Definition task_types.h:81
downwards_stack_t u_stack
user-mode stack
Definition task_types.h:84
process_t * owner
Definition task_types.h:79
thread_state_t state
thread state
Definition task_types.h:83
ssize_t sysfs_printf(sysfs_file_t *file, const char *fmt,...)
Definition sysfs.c:73
#define SYSFS_RO_ITEM(_name, _show_fn)
Definition sysfs.h:48
#define SYSFS_AUTOREGISTER(sysfs_name, sysfs_items)
bool _process_do_print(uintn key, void *val, void *data)
Definition tasks.c:54
#define PROCESS_HASHTABLE_SIZE
Definition tasks.c:19
#define THREAD_HASHTABLE_SIZE
Definition tasks.c:20
static sysfs_item_t task_sysfs_items[]
Definition tasks.c:85
bool _thread_do_print(uintn key, void *val, void *data)
Definition tasks.c:63
static bool tasks_sysfs_process_list(sysfs_file_t *f)
Definition tasks.c:73
void tasks_init()
Definition tasks.c:46
static void dump_process(void)
Definition tasks.c:26
slab_t * thread_cache
Definition tasks.c:22
static bool tasks_sysfs_thread_list(sysfs_file_t *f)
Definition tasks.c:79
hashmap_t thread_table
Definition thread.c:23
unsigned long uintn
Definition types.h:30