Commit Graph

40 Commits

Author SHA1 Message Date
Andreas Kling
ee2bb98b88 Kernel: Increase default time slice to 20ms. 2019-02-07 11:53:45 +01:00
Andreas Kling
5582a0a254 Kernel: When a lock is busy, donate remaining process ticks to lock holder.
Since we know who's holding the lock, and we're gonna have to yield anyway,
we can just ask the scheduler to donate any remaining ticks to that process.
2019-02-07 11:14:58 +01:00
Andreas Kling
3fc3a8d7bc Kernel: Remove some unnecessary zero initialization now that BSS is cleared. 2019-02-07 10:31:32 +01:00
Andreas Kling
6cba80510e Kernel: Add a Finalizer process to take care of dying processes.
Instead of processes themselves getting scheduled to finish dying,
let's have a Finalizer process that wakes up whenever someone is dying.
This way we can do all kinds of lock-taking in process cleanup without
risking reentering the scheduler.
2019-02-06 18:45:21 +01:00
Andreas Kling
e05237485c Kernel: Various stability improvements.
- Don't cli() in Process::do_exec() unless current is execing.
  Eventually this should go away once the scheduler is less retarded
  in the face of interrupts.

- Improved memory access validation for ring0 processes.
  We now look at the kernel ELF header to determine if an access
  is appropriate. :^) It's very hackish but also kinda neat.

- Have Process::die() put the process into a new "Dying" state where
  it can still get scheduled but no signals will be dispatched.
  This way we can keep executing in die() but won't get our EIP
  hijacked by signal dispatch. The main problem here was that die()
  wanted to take various locks.
2019-02-06 17:34:27 +01:00
Andreas Kling
8cc6e304ca Kernel: Clean up around Scheduler::yield() a bit.
Also add assertion in Lock that the scheduler isn't currently active.
I've been seeing occasional fuckups that I suspect might be someone called
by the scheduler trying to take a busy lock.
2019-02-06 15:06:48 +01:00
Andreas Kling
b782055b96 Kernel: Add an InterruptFlagSaver helper class.
This is useful instead of InterruptDisabler in some cases.
2019-02-05 11:14:09 +01:00
Andreas Kling
0c38a4c30f WindowServer: Sever the WSWindow/Process link when the process dies.
This fixes a deadlock where the WindowServer would get stuck trying to
acquire a dead process's event stream lock.
2019-02-05 08:32:32 +01:00
Andreas Kling
d7307c3119 Kernel: Ignore SIGCHLD by default.
Also use an enum for the rather-confusing return value in dispatch_signal().
I will go through the rest of the signals and set them up with the
appropriate default dispositions at some other point.
2019-02-04 14:06:38 +01:00
Andreas Kling
c0cffe1134 Add a /bin/top program for process table monitoring.
It automagically computes %CPU usage based on the number of times a process
has been scheduled between samples. The colonel task is used as idle timer.
This is pretty cool. :^)
2019-02-04 10:28:12 +01:00
Andreas Kling
95c3442d59 Implement event loop timers.
GObjects can now register a timer with the GEventLoop. This will eventually
cause GTimerEvents to be dispatched to the GObject.

This needed a few supporting changes in the kernel:

- The PIT now ticks 1000 times/sec.
- select() now supports an arbitrary timeout.
- gettimeofday() now returns something in the tv_usec field.

With these changes, the clock window in guitest2 finally ticks on its own.
2019-02-01 03:50:06 +01:00
Andreas Kling
ffab6897aa Big, possibly complete sweep of naming changes. 2019-01-31 17:31:23 +01:00
Andreas Kling
dfdca9d2a7 Kernel: Implement lazy FPU state restore. 2019-01-25 07:52:44 +01:00
Andreas Kling
e911caeb10 Kernel: Fix dumb race in Scheduler::yield() debug code.
It was perfectly possible for Scheduler::yield() to get interrupted after
setting s_in_yield but before disabling interrupts.
2019-01-23 05:06:47 +01:00
Andreas Kling
4fef895eda Rework WindowServer to use select() in its main event loop.
The system can finally idle without burning CPU. :^)

There are some issues with scheduling making the mouse cursor sloppy
and unresponsive that need to be dealt with.
2019-01-16 17:20:58 +01:00
Andreas Kling
f7ca6d254d Tear out or duplicate what's unique for WindowServer from Widgets.
This turned into a huge refactoring that somehow also includes
making locks recursive/reentrant.
2019-01-16 16:03:50 +01:00
Andreas Kling
8ad2dfb6e1 Rename FileDescriptor::has_data_available_for_reading() -> can_read(). 2019-01-16 00:47:00 +01:00
Andreas Kling
10387beda7 Implement basic support for POSIX-style select().
Now we can block on both the PTY *and* the GUI event stream in Terminal.
2019-01-16 00:09:58 +01:00
Andreas Kling
e452303c66 Allow character devices to block write attempts until there is more space. 2019-01-15 09:17:22 +01:00
Andreas Kling
b0e3f73375 Start refactoring the windowing system to use an event loop.
Userspace programs can now open /dev/gui_events and read a stream of GUI_Event
structs one at a time.

I was stuck on a stupid problem where we'd reenter Scheduler::yield() due to
having one of the has_data_available_for_reading() implementations using locks.
2019-01-14 14:42:49 +01:00
Andreas Kling
7731aef7b2 Let the "reaped unparented process" messages go straight to the debugger. 2019-01-01 03:56:39 +01:00
Andreas Kling
033a42b580 The syncd loop can just be a lambda. 2018-12-24 23:10:48 +01:00
Andreas Kling
ec1c487dcd Yet another pass of style fixes. 2018-12-21 02:10:45 +01:00
Andreas Kling
e7cc08226f Implement basic support for times().
The kernel now bills processes for time spent in kernelspace and userspace
separately. The accounting is forwarded to the parent process in reap().

This makes the "time" builtin in bash work.
2018-12-03 01:14:19 +01:00
Andreas Kling
4bc87dc7b9 Share the "blocked-on file descriptor" number between read() and write().
A process can't be reading and writing at the same time, so it's fine for
them to share the variable for the blocked FD.
2018-12-03 00:42:48 +01:00
Andreas Kling
f6e27c2abe More coding style changes. 2018-12-03 00:39:25 +01:00
Andreas Kling
f5a83c4d8a Fix bug where a signal-interrupted waitpid() wouldn't return EINTR. 2018-11-28 23:30:49 +01:00
Andreas Kling
d90104f9e0 Let reap() communicate the dead process's exit status to the caller.
This way the scheduler doesn't need to plumb the exit status into the waiter.
We still plumb the waitee pid though, I don't love it but it can be fixed.
2018-11-28 22:01:24 +01:00
Andreas Kling
6cedb88153 Don't unblock a blocked process when it ignores a signal. 2018-11-16 21:14:25 +01:00
Andreas Kling
97c799576a Add close-on-exec flag for file descriptors.
I was surprised to find that dup()'ed fds don't share the close-on-exec flag.
That means it has to be stored separately from the FileDescriptor object.
2018-11-13 01:36:31 +01:00
Andreas Kling
f1404aa948 Add primitive FIFO and hook it up to sys$pipe().
It's now possible to do this in bash:

cat kernel.map | fgrep List

This is very cool! :^)
2018-11-12 01:28:46 +01:00
Andreas Kling
d5d45d1088 Rage hacking to get bash to run. It finally runs. So cool! :^) 2018-11-11 15:38:07 +01:00
Andreas Kling
e71cb1c56b Fix some paging related bugs exposed by the spawn stress test.
- Process::exec() needs to restore the original paging scope when called
  on a non-current process.
- Add missing InterruptDisabler guards around g_processes access.
- Only flush the TLB when modifying the active page tables.
2018-11-09 01:25:31 +01:00
Andreas Kling
e287f8ef3a The colonel task already had a halt loop.
Also don't reap() current in the scheduler, just wait until it's not current.
2018-11-08 00:30:35 +01:00
Andreas Kling
ac1d12465f Move timer tick handling into Scheduler. 2018-11-08 00:26:04 +01:00
Andreas Kling
1dbc340da8 Get rid of the undertaker and have waitpid() be the reaper.
For dead orphans, the scheduler calls reap().
2018-11-07 23:59:49 +01:00
Andreas Kling
f792349853 Unbreak sys$sigreturn() after colonel process changes. 2018-11-07 23:21:32 +01:00
Andreas Kling
43f40a3050 Finally unbreak the colonel process and make it the true idle process. 2018-11-07 23:14:56 +01:00
Andreas Kling
440029c9d1 Reduce number of passes in the scheduler by 2. 2018-11-07 22:24:20 +01:00
Andreas Kling
39d2fcbbee Move the scheduler code to its own class.
This is very mechanical.
2018-11-07 22:15:02 +01:00