MOS Source Code
Loading...
Searching...
No Matches
tasks.cpp
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
8
11#include <mos/misc/panic.hpp>
13#include <mos/tasks/process.hpp>
15#include <mos/tasks/thread.hpp>
16#include <mos_stdlib.hpp>
17
18#define PROCESS_HASHTABLE_SIZE 512
19#define THREAD_HASHTABLE_SIZE 512
20
21static void dump_process(void)
22{
24 {
25 auto proc = current_process;
26 pr_info("process %pp ", proc);
27 if (proc->parent)
28 pr_info2("parent %pp ", proc->parent);
29 else
30 pr_info2("parent <none> ");
32 }
33 else
34 {
35 pr_warn("no current thread");
36 }
37}
38
39MOS_PANIC_HOOK(dump_process, "Dump current process");
40
41// ! sysfs support
42
44{
45 for (const auto &[pid, proc] : ProcessTable)
46 sysfs_printf(f, "%pp, parent=%pp, main_thread=%pt, exit_status=%d\n", proc, proc->parent, proc->main_thread, proc->exit_status);
47
48 return true;
49}
50
52{
53 for (const auto &[tid, thread] : thread_table)
54 sysfs_printf(f, "%pt, state=%c, mode=%s, owner=%pp, stack=" PTR_FMT " (%zu bytes)\n", thread, thread_state_str(thread->state),
55 thread->mode == THREAD_MODE_KERNEL ? "kernel" : "user", thread->owner, thread->u_stack.top, thread->u_stack.capacity);
56 return true;
57}
58
63
@ THREAD_MODE_KERNEL
#define MOS_PANIC_HOOK(_f, _name)
Definition panic.hpp:33
#define current_thread
Definition platform.hpp:32
#define current_process
Definition platform.hpp:33
#define pr_info2(fmt,...)
Definition printk.hpp:36
#define pr_warn(fmt,...)
Definition printk.hpp:38
#define pr_info(fmt,...)
Definition printk.hpp:35
void process_dump_mmaps(const Process *process)
Definition process.cpp:368
mos::HashMap< pid_t, Process * > ProcessTable
Definition process.cpp:36
char thread_state_str(thread_state_t state)
Definition schedule.cpp:14
ssize_t sysfs_printf(sysfs_file_t *file, const char *fmt,...)
Definition sysfs.cpp:74
#define SYSFS_RO_ITEM(_name, _show_fn)
Definition sysfs.hpp:42
#define SYSFS_AUTOREGISTER(sysfs_name, sysfs_items)
static sysfs_item_t task_sysfs_items[]
Definition tasks.cpp:59
static bool tasks_sysfs_process_list(sysfs_file_t *f)
Definition tasks.cpp:43
static void dump_process(void)
Definition tasks.cpp:21
static bool tasks_sysfs_thread_list(sysfs_file_t *f)
Definition tasks.cpp:51
mos::HashMap< tid_t, Thread * > thread_table
Definition thread.cpp:24
#define PTR_FMT
Definition types.h:29