Commit Graph

65 Commits

Author SHA1 Message Date
Matthew Leach
bf4d1dbac4 process: make Tid globally unique
Make the `Tid` globally unique, rather than `Tgid` creating a new number
space. This allows ptrace to differentiate between threads when using
`-f` on a program which spawns threads.
2026-03-23 06:08:21 +00:00
Matthew Leach
aaac9ffd2c sched: eliminate CUR_TASK_PTR
Replace `CUR_TASK_PTR` with `ProcessCtx`. This allows differentiation
between functions that access process context (take in `ProcessCtx` as a
parameter) and those that don't.

When creating a new class of scheduleable tasks (softirqs, kthreads),
this ensure that those functions cannot call context-sensitive
functions.
2026-03-19 20:58:15 +00:00
Matthew Leach
a8aef0483f Merge pull request #259 from arihant2math/proc-exe 2026-03-18 06:43:08 +00:00
Ashwin Naren
267af05a9b implement procs_running and procs_blocked in /proc/stat 2026-03-15 19:23:23 -07:00
Ashwin Naren
a3d85ced59 implement /proc/<pid>/exe 2026-03-12 10:33:30 -07:00
Matthew Leach
5ebfc29cd2 sched: introduce Work as the unified scheduleable unit
Refactor the scheduler so all scheduleable work is wrapped in Arc<Work>,
replacing the previous per-CPU wait_q design where sleeping tasks were
bound to a specific CPU. Wakers now hold direct Arc<Work> references and
can re-enqueue tasks on any CPU upon wakeup.

Key changes:

- Add Work struct wrapping OwnedTask with an AtomicTaskState and
  scheduler metadata (SchedulerData), replacing the old SchedulableTask.
  Remove Task::state (Arc<SpinLock<TaskState>>). Work::state is now the
  single source of truth for task state.

- Rewrite the run queue using BinaryHeap-based eligible/ineligible split
  (EEVDF) with a dedicated VClock, replacing the BTreeMap linear scan.
  Extract vclock into its own module.

- Rewrite wakers to hold Arc<Work> directly instead of looking up tasks
  by TaskDescriptor from TASK_LIST.

- Replace lock-based sleep transitions in uspc_ret with atomic CAS
  (try_sleep_current) that correctly detects concurrent Woken state.

- Simplify least-tasked-CPU metric to use only run-queue weight, since
  sleeping tasks are no longer bound to any CPU.

- Add current_work() accessor.
2026-03-12 10:53:22 +00:00
Matthew Leach
ce156c1bd8 Merge pull request #255 from arihant2math/fix-uart-freeze 2026-03-08 05:36:24 +00:00
Ashwin Naren
0d466dce19 finish implementation of arm GIC v2 driver 2026-03-07 18:40:40 -08:00
Ashwin Naren
50dcaf2f14 proper draining of uart 2026-03-07 18:00:07 -08:00
Ashwin Naren
3760868d83 remove old framebuffer debugging logic 2026-03-07 17:39:57 -08:00
Ashwin Naren
83ec279895 Merge pull request #254 from hexagonal-sun/dont-override-probe-fns
drivers: init: don't override probe_fns
2026-03-07 15:28:27 -08:00
Matthew Leach
9fc7066eff drivers: init: don't override probe_fns
If multiple drivers are associated with a compatible string, don't
override an existing probe_fn. Instead, store a list of associated
probe_fns. Once a probe_fn has claimed the device stop calling the
associated probe chain.
2026-03-07 20:08:14 +00:00
Ashwin Naren
54265fdae0 support for ARM PL031 RTC 2026-03-06 23:51:04 -08:00
Matthew Leach
4a98779020 Add virtio-rng driver and ProbeError::NoMatch for silent probe skipping
Add a virtio-rng entropy source driver that registers with the kernel
RNG subsystem. Introduce `ProbeError::NoMatch` so virtio drivers can
silently reject empty or wrong-type MMIO slots without spamming the boot
log with fatal errors or leaving devices stuck in the deferred queue.
2026-03-07 07:33:31 +00:00
Matthew Leach
65517c6641 Add BLAKE2s entropy pool with per-CPU ChaCha20 CSPRNG
Replace the single `SmallRng` with a proper two-layer RNG architecture:

- Global BLAKE2s-256 entropy pool that accumulates entropy and gates
  seed extraction behind a 256-bit threshold.
- Per-CPU ChaCha20Rng instances that are lazily seeded from the pool on
  first use and periodically reseed every 1 MB by XOR-ing a fresh BLAKE2
  extract with 32 bytes of their own output.

The /dev/random chardev uses fill_random_bytes directly instead of
routing through the syscall layer.
2026-03-07 07:33:15 +00:00
Ashwin Naren
64f320c7c7 fix clippy again 2026-03-06 19:46:38 -08:00
Ashwin Naren
f7757325ca fix panic if no display exists 2026-03-04 12:13:01 -08:00
Ashwin Naren
697254d7a9 address review 2026-03-04 12:13:01 -08:00
Ashwin Naren
4588e61aef GPU support with virtio driver 2026-03-04 12:13:01 -08:00
Ashwin Naren
edca499714 distinguish between file permissions and file mode 2026-03-02 11:53:06 -08:00
Ashwin Naren
ce27c4bc36 add find_process_by_tgid 2026-02-28 17:09:07 -08:00
Matthew Leach
95dbf4f4f2 drviers: chrdev: random: new
Add a new chardev which implements /dev/random.
2026-02-25 15:23:18 -08:00
Ashwin Naren
df6b32fbf8 partial proc fd file support 2026-02-19 12:50:31 -08:00
Ashwin Naren
f1c0cba3b8 statfs 2026-02-09 16:59:15 -08:00
Ashwin Naren
75afc15bc7 fix typo 2026-02-07 18:26:28 -08:00
Ashwin Naren
479926f767 stub cgroup fs 2026-02-07 18:25:30 -08:00
Ashwin Naren
c394e18231 tmp 2026-02-07 00:20:37 -08:00
Ashwin Naren
62709be4d6 cmdline inode 2026-01-30 19:36:42 -08:00
Ashwin Naren
17b347cdc4 naming changes 2026-01-27 00:31:47 -08:00
Ashwin Naren
04f015848b percpu refactor 2026-01-27 00:31:47 -08:00
Ashwin Naren
7c7776ba7b working top
implements enough of procfs for `top` to run
2026-01-27 00:31:47 -08:00
Matthew Leach
87fe041ba0 procfs: implement /proc/<PID>/maps
Implement the `maps` file which shows a process's VMA entries. Example
output:

```
[root@moss-machine /]# cat /proc/1/maps
500000000000-500000117000 r-xp 0000000000                    /bin/bash
50000012b000-500000130000 r--p 000011b000                    /bin/bash
500000130000-50000013e000 rw-p 0000120000                    /bin/bash
700000000000-70000002b000 r-xp 0000000000                    /lib/ld-linux-aarch64.so.1
70000003e000-700000040000 r--p 000002e000                    /lib/ld-linux-aarch64.so.1
700000040000-700000042000 rw-p 0000030000                    /lib/ld-linux-aarch64.so.1
7fffff510000-7fffff585000 r-xp 0000000000                    /usr/lib/libncursesw.so.6
7fffff585000-7fffff59b000 ---p 0000075000                    /usr/lib/libncursesw.so.6
7fffff59b000-7fffff5a0000 r--p 000007b000                    /usr/lib/libncursesw.so.6
7fffff5a0000-7fffff5a1000 rw-p 0000080000                    /usr/lib/libncursesw.so.6
7fffff5b0000-7fffff760000 r-xp 0000000000                    /usr/lib/libc.so.6
7fffff760000-7fffff76d000 ---p 00001b0000                    /usr/lib/libc.so.6
7fffff76d000-7fffff770000 r--p 00001bd000                    /usr/lib/libc.so.6
7fffff770000-7fffff772000 rw-p 00001c0000                    /usr/lib/libc.so.6
7fffff772000-7fffff779000 rw-p 0000000000
7fffff780000-7fffff7d9000 r-xp 0000000000                    /usr/lib/libreadline.so.8
7fffff7d9000-7fffff7ed000 ---p 0000059000                    /usr/lib/libreadline.so.8
7fffff7ed000-7fffff7f0000 r--p 000005d000                    /usr/lib/libreadline.so.8
7fffff7f0000-7fffff7f6000 rw-p 0000060000                    /usr/lib/libreadline.so.8
7fffff7f6000-7fffff7fb000 rw-p 0000000000
7fffff800000-800000063000 rw-p 0000000000                    [stack]
```
2026-01-27 06:10:43 +00:00
Ashwin Naren
d386b8ba36 post rebase fixes 2026-01-25 10:50:02 -08:00
Ashwin Naren
d8c77ebca7 procfs bugfixes 2026-01-25 10:50:02 -08:00
Ashwin Naren
2d34ebcef9 procfs refactor 2026-01-25 10:50:02 -08:00
Ashwin Naren
c5a0976a73 track stime and utime
Tracks stime and utime for processes and tasks. Reports the times through procfs and `sys_clock_gettime`.
2026-01-25 10:50:02 -08:00
Matthew Leach
3aca7b2122 devfs: set attr id the same as the inode id
Ensure that the ID of the attr contains the ID of the devfs inode,
instead of the default value.
2026-01-25 10:29:43 -08:00
Ashwin Naren
aa5a9c7b79 fix typos 2026-01-23 01:26:04 -08:00
Ashwin Naren
92efb4cee7 enforce semicolon_if_nothing_returned and uninlined_format_args 2026-01-23 01:26:04 -08:00
Ashwin Naren
e7a0ec6801 fix proc fs crashing 2026-01-16 15:51:35 -08:00
Ashwin Naren
ff13b392f1 some support for ext4 writing 2026-01-13 16:47:51 -08:00
Matthew Leach
57e0aa364c process: task_group: implement pg priority
Currently, each task implements it's own priority value. In Linux, each
thread group (process) has a default process which all tasks in that
group inherit. Tasks can, however, override the default process
priority.

Implement that logic here which also fixes the current compilation error
on master.
2026-01-02 18:16:11 -08:00
Ashwin Naren
b5138c30f9 working ext4 2026-01-02 17:01:02 -08:00
Matthew Leach
b8bcbfe91b Merge pull request #116 from hexagonal-sun/implement-ownedtask
process: split `Task` into `Task` (shared) and `OwnedTask` (local)
2026-01-02 17:37:43 +00:00
Ashwin Naren
2383bf99bb support stat in procfs 2026-01-01 16:44:55 -08:00
Matthew Leach
35efecad76 process: split Task into Task (shared) and OwnedTask (local)
This commit refactors the core process representation to decouple
"Identity/Resources" from "Execution/Scheduling". Previously, a
monolithic `Task` struct wrapped in `Arc<SpinLock<>>` caused lock
contention during hot scheduling paths and conflated shared state with
CPU-local state.

The `Task` struct has been split into:

1. `Task` (Shared): Holds process-wide resources (VM, FileTable,
Credentials). Managed via `Arc` and internal fine-grained locking.

2. `OwnedTask` (Private): Holds execution state (Context, v_runtime,
signal mask). Strictly owned by a specific CPU (via the Scheduler) and
accessed lock-free.

Key changes:

* Scheduler:
  chedState` now owns tasks via `Box<OwnedTask>`.
  - Transitions between `run_queue` and `running_task` involve strictly
    moving ownership of the Box, ensuring pointer stability.
  - The EEVDF comparison logic now explicitly handles comparisons
    between the queued candidates and the currently running task (which is
    not in the queue).

* Current Task Access:
  - `current()` now returns a `CurrentTaskGuard` which:
    1. Disables preemption (preventing context switches while holding
       the reference).
    2. Performs a runtime borrow check (panic on double-mutable borrow).
    3. Dereferences a cached Per-CPU raw pointer for O(1) access.
2026-01-01 22:54:43 +00:00
Matthew Leach
992fe21844 Merge pull request #113 from hexagonal-sun/make-task-list-arc-task
process: `TASK_LIST`: point to `Task` struct
2025-12-29 20:38:56 +00:00
Ashwin Naren
c816054d36 Support cwd symlink in procfs (#101)
Support cwd symlink in procfs
2025-12-29 20:35:31 +00:00
Matthew Leach
9e80a6ae8a process: TASK_LIST: point to Task struct
Make the global `TASK_LIST` struct be a collection of `Task`s, rather
than `task.state` struct members. This allows other cores to access to
any shared task state easily.
2025-12-29 20:28:00 +00:00
Matthew Leach
e2e7cdaeec timer: use a per-cpu wakeup queue
Currently, a global wakeup queue is used for all CPUs on the system.
This leads to inefficient behavior regarding preemption. When the
scheduler requests a preemption event, it is inserted into a global list
alongside events from all other CPUs.

When processing IRQs, there is no guarantee which CPU will handle the
timer interrupt. If the current CPU processes a preemption event
intended for a different CPU, it must signal the target CPU via an IPI.
This causes a severe bottleneck, as one CPU may end up distributing
preemption events for the entire system.

Fix this by implementing a per-cpu wakeup queue. Preemption events are
now strictly scheduled for the current CPU, ensuring they are handled
locally by the core that scheduled them. This significantly simplifies
the preemption logic and eliminates the need for IPIs to signal
preemption events.
2025-12-28 23:51:51 -08:00