Commit Graph

739 Commits

Author SHA1 Message Date
71cd7af17b [kutil] Add sorted insert to kutil::vector
Added a sorted insert to vector, as well as cleaning up and extending
the removal functions.
2020-09-07 16:59:21 -07:00
8490472581 [kutil] Fix failing heap allocator tests
The tests clearly haven't even been built in a while. I've added a
helper script to the project root. Also added a kassert() handler that
will allow tests to catch or fail on asserts.
2020-09-07 16:56:07 -07:00
8534d8d3c5 [kernel] Add endpoint object and related syscalls
The endpoint object adds synchronous IPC. Also added the wait-type of
'object' to threads.
2020-09-07 01:09:56 -07:00
53d260cc6e [kernel] Allow unmapping non-fully-mapped areas
The buffer cache will try to clean up a returned buffer by unmapping it,
but it may have only been committed without ever getting mapped. Allow
for page_out to handle non-fully mapped regions.
2020-09-06 16:31:02 -07:00
53a4682418 [kernel] Fix current thread deletion bug
Defer from calling process::thread_exited() in scheduler::prune() if the
thread in question is the currently-executing thread, so that we don't
blow away the stack we're executing on. The next call to prune will pick
up the exited thread.
2020-09-06 15:01:24 -07:00
42455873ff [kernel] Make stdout channel available to processes
The "fake" stdout channel is now being passed in the new j6_process_init
structure to processes, and nulldrv now uses it to print a message to
the console.
2020-08-30 18:47:14 -07:00
724b846ee4 [kernel] Make channels stream based
Multiple changes regarding channels. Mainly channels are now stream
based and can handle partial reads or writes. Channels now use the
kernel buffers area with the related buffer_cache. Added a fake stdout
stream channel and kernel task to read its contents to the screen in
preparation for handing channels as stdin/stdout to processes.
2020-08-30 18:04:19 -07:00
f27b133089 [kernel] Rename stack_cache to buffer_cache
Renamed and genericized the stack_cache class to manage any address
range area of buffers or memory regions. Removed singleton and created
some globals that map to different address regions (kernel stacks,
kernel buffers).

Tags: vmem virtual memeory
2020-08-30 17:59:13 -07:00
773617cbf3 [libc] Created syscall trampolines in libc
Using syscalls.inc (moved to src/include) generate trampoline functions
for directly calling syscalls with libc functions.
2020-08-23 18:14:45 -07:00
44e29b3c4a [build] Fix dump_cc_run not creating bash scripts
It was the difference between > and >>
2020-08-23 17:43:18 -07:00
95a35cd0bf [libc] Bring libc in-tree
Moving libc from its separate repo into this one, minor resulting build
fixes, and a hacky way to add -I for libc headers in builds.
2020-08-23 17:21:08 -07:00
28b800a497 [kernel] Initialize logger task after symbols init
In case something blows up when initializing kernel tasks, make sure
symbol table init is done beforehand.
2020-08-23 17:18:45 -07:00
838776d7df [kernel] Fix bug in vmem commit
When committing an area of vmem and splitting from a larger block, the
block that is returned was set to the unknown state, and the leading
block was incorrectly set to the desired state.

Also remove extra unused thread ctor.
2020-08-23 17:11:46 -07:00
e19fa377d7 [kernel] Remove old unused process.*
These files are not included in the build, but had not been removed.
2020-08-23 17:10:14 -07:00
d63a30728c [kernel] Add get_caller function
Added a function to get the callsite of the current function invocation.
2020-08-22 16:34:58 -07:00
4819920b4e [kutil] Add unreserve/uncommit to vm_space
Added the functionality for unreseve and uncommit to vm_space. Also
added the documented but not implemented ability to pass a 0 address to
get any address region with the given size.
2020-08-16 17:19:17 -07:00
bbb9aae198 [kernel] Use symbol table in stack traces
Now using the symbol table built by build_symbol_table.py in the kernel
when printing stack traces.
2020-08-09 17:27:51 -07:00
0d94776c46 [build] Remove makest from build script
Removing the outdated reference to makest from the build scripts, which
should have been removed as part of the build_symbol_table.py change.
2020-08-09 17:23:14 -07:00
565a5ee960 [makerd] Fix argc bug
Makerd was improperly checking argc for its usage.
2020-08-06 21:12:36 -07:00
e7f9d8f1d7 [scripts] Add symbol table building script
Create a script that builds a simple-to-read symbol table from the
output of `nm`. Include running that script over the kernel in the
build, and including that output in the initrd.

Tags: callstack debugging
2020-08-06 21:11:19 -07:00
55bc49598e [kernel] Assert all PDs exist in kernel space
The bootloader now creates all PD tables in kernel space, so remove
memory_bootstrap.cpp code that dealt with cases where there was no PD
for a given range, and kassert that all PDs exist.

Also deal with the case where the final PD exists, which never committed
the last address range.
2020-08-06 19:07:51 -07:00
579eaaf4a0 [kernel] Move kernel stacks out of the heap
We were previously allocating kernel stacks as large objects on the
heap. Now keep track of areas of the kernel stack area that are in use,
and allocate them from there. Also required actually implementing
vm_space::commit(). This still needs more work.
2020-08-02 18:15:28 -07:00
b98334db28 [kernel] Don't keep creating new processes for kernel tasks
The scheduler was making new process objects every time it made kernel
task threads. Don't do that.
2020-08-02 18:13:09 -07:00
e1b1b5d357 [kernel] Don't double-construct the scheduler
The scheduler singleton was getting constructed twice, once at static
time and then again in main(). Make the singleton a pointer so we only
construct it once.
2020-08-02 18:11:09 -07:00
cf582c4ce4 [boot] Add PD tables for all kernel PML4 entries
Process PML4s all point their high (kernelspace) entries at the same set
of PDs, but that copying only happens on process creation. New PDs added
to the kernel PML4 won't get shared among other PML4s. This change
instantiates empty PDs for all PML4 entries in the higher half to make
sure this can't happen.
2020-08-02 18:06:41 -07:00
911b4c0b10 [kutil] Fix a bug with order ignoring header size
When moving heap allocation order calculation to use __builtin_clz, we
based that calculation off of the length requested, not the totla length
including the memory header size.
2020-08-02 16:54:06 -07:00
94c1f0d3fc [kutil] Calculate block-size order with clz
Previously we were using a less efficient loop method of finding the
appropriate block size order, now we use __builtin_clz, which should use
the CPU's clz instruction if it's available.
2020-07-30 19:54:25 -07:00
73221dfe34 [kutil] Rename 'size' to 'order' when meaning 2^N
Heap allocator is a buddy allocator that deals with power-of-two block
sizes. Previously it referred to both a number of bytes and an order of
magnitude as a 'size'. Rename functions and variables referring to
orders of magnitude to 'order'.

Tags: pedantry
2020-07-30 19:41:41 -07:00
4ffd4949ca [kernel] Clean up threads' kernel stacks on exit
Add a destructor to threads in order to deallocate their kernel stacks.
2020-07-30 19:32:31 -07:00
3f137805bc [kutil] Tracks allocated size in heap allocator
Add a member that keeps track of allocated size to the heap allocator.
This isn't exposed, but is handy for debugging.
2020-07-30 19:30:53 -07:00
6a00057817 [kernel] Remove process startup_bonus to timeslice
Previously we added startup_bonus to work around a segfault happening
when we preemted a newly created process instead of letting it give up
the CPU. Bug is not longer occuring, though that makes me nervous.
2020-07-30 19:11:51 -07:00
58bc5acb1e [kernel] Add object_signal system call
Add a system call to assert signals on a given object, only within the
range of user-settable signals. Also made object_wait return
immediately if any of the given signals are already set.
2020-07-26 18:03:30 -07:00
d3e9d92466 [kernel] Add channel objects
Add the channel object for sending messages between threads. Currently
no good of passing channels to other threads, but global variables in a
single process work. Currently channels are slow and do double copies,
need to refine more.

Tags: ipc
2020-07-26 17:29:11 -07:00
ae3290c53d [kernel] Add userspace threading
Implement the syscalls necessary for threads to create other threads in
their same process. This involved rearranging a number of syscalls, as
well as implementing object_wait and a basic implementation of a
process' list of handles.
2020-07-26 16:02:38 -07:00
4cf222a5bb [kernel] Remove getpid and fork system calls
The getpid and fork system calls were stubbed out previously, this
commit removes them and adds process_koid as a getpid replacement.
2020-07-19 17:15:36 -07:00
c3abe035c8 [kernel] Remove thread_data pointer from TCB
The TCB is always stored at a constant offset within the thread object.
So instead of carrying an extra pointer, just implement thread::from_tcb
to get the thread.
2020-07-19 17:01:15 -07:00
ef5c333030 [kernel] Create process kernel object
Re-implent the concept of processes as separate from threads, and as a
kobject API object. Also improve scheduler::prune which was doing some
unnecessary iterations.
2020-07-19 16:47:18 -07:00
f4cbb9498f [kernel] Fix clock period vs frequency error
Calling `spinwait()` was hanging due to improper computation of the
clock rate because justin did a dumb at math. Also the period can be
greater than 1ns, so the clock's units were updated to microseconds.
2020-07-12 17:43:37 -07:00
794c86f9b4 [kernel] Add thead kobject class
Add the thread kernel API object and move the scheduler to use threads
instead of processes for scheduling and task switching.
2020-07-12 16:07:20 -07:00
Justin C. Miller
8687fe3786 [boot] Zero extra memory in loaded sections
When loading ELF headers (as opposed to sections), the `file_size` of
the data may be smaller than the `mem_size` of the section to be loaded
in memory. Don't blindly copy `mem_size` bytes from the ELF file, but
instead only `file_size`, then zero the rest.

Tags: elf loader
2020-07-04 18:20:49 -07:00
Justin C. Miller
0a28d2db07 [kernel] Update scheduler policies
A few updates to scheduler policies:
* Grant processes a startup timeslice bonus for time spent loading the
  process
* Grant processes a small fraction of a timeslice for yielding the CPU
  with time left
2020-07-03 15:21:03 -07:00
Justin C. Miller
6c468a134b [kernel] Add HPET support, create clock class
Create a clock class which can be queried for current timestamp in
nanoseconds. Also implements a simple HPET class as one possible clock
source.

Tags: time
2020-06-28 17:49:31 -07:00
Justin C. Miller
9b67f87062 [kernel] Add external/ to kernel includes
In order to support future changes, the kernel should also be able to
include from the external/ tree.
2020-06-28 11:51:51 -07:00
Justin C. Miller
b4adc29d7f [kernel] Give scheduler better history tracking
The scheduler again tracks remaining timeslice. Timeslices are bigger,
but once a process uses all of its timeslice, it's demoted and
replenished at the next priority. The scheduler also tracks the last
time a process ran, and promotes it if it's been starved for twice its
full timeslice.

TODO: replenish a small amount of timeslice each time a process is run,
so that more interactive processes keep their priorities.
2020-06-05 00:15:03 -07:00
Justin C. Miller
a10aca573d [kernel] Change to one-shot timer scheduler
Instead of many timer interrupts and decrementing a process' remaining
quanta, change to setting a single timer for when a process should be
preempted. If it uses its whole timeslice, demote it. If it uses less
than half before blocking, promote it. Determine timeslice based on
priority as well.

This change also required changing the apic timer interface to be purely
interval (in microseconds) based instead of its previous interval/tick
hybrid.
2020-06-03 20:56:59 -07:00
Justin C. Miller
ea1224e213 [kernel] Fix scheduler clock bug
The fake clock in the scheduler wasn't getting initialized, so sleeps in
the test userspace programs were returning immediately.
2020-06-02 23:46:03 -07:00
Justin C. Miller
64ad65fa1b [kernel] Fix logger task's bip buffer
The bip buffer implementation was not initializing it's write-state
member, which was causing logs to always fail when the logger was not in
immediate mode.
2020-06-02 20:30:07 -07:00
Justin C. Miller
b881b2639d [kernel] Remove last of old allocator interface
Removing the `allocator.h` file defining the `kutil::allocator`
interface, now that explicit allocators are not being passed around.
Also removed the unused `frame_allocator::raw_allocator` class and
`kutil::invalid_allocator` object.

Tags: memory
2020-06-01 23:40:19 -07:00
Justin C. Miller
a5f72edf82 [kernel] Add in_hv cpu "feature" flag
Reformat the cpu_features.inc file and add the `in_hv` feature that is
supposedly set by hypervisors when running in emulation. QEMU does not
set it.

Tags: cpuid
2020-06-01 23:33:30 -07:00
Justin C. Miller
ea2a3e6f16 [kutil] Remove ctor workaround in slab_allocated
Before global constructors were working, I had added a hack to zero out
the static vector member of in `slab_allocated`. Now that they are
working, this can be removed.
2020-06-01 00:36:34 -07:00