Commit graph

4963 commits

Author SHA1 Message Date
x-yl 42c5df7256 Kernel: Fix inverted check in VirtIOConsolePort
We should really only try to open if we're closed. Oops :P
2021-07-14 12:33:07 +02:00
Tom d7e5521a04 Kernel: Ignore subsequent calls to Process::die
It's possible that another thread might try to exit the process just
about the same time another thread does the same, or a crash happens.
Also, we may not be able to kill all other threads instantly as they
may be blocked in the kernel (though in this case they would get killed
before ever returning back to user mode. So keep track of whether
Process::die was already called and ignore it on subsequent calls.

Fixes #8485
2021-07-14 12:30:41 +02:00
Hendiadyoin1 d761c5024b AK: Generalize ByteReader
Also use it instead of CPU.h's possibly_unaligned_data interface
2021-07-14 11:26:34 +04:30
Andreas Kling c42807e3dc Kernel: Remove debug spam when PhysicalRegion::take_free_page() fails
We can have multiple PhysicalRegions (often the case when there is a
huge amount of RAM) so we really shouldn't print a debug message any
time someone tries to allocate from one. They will move on to another
region anyway.
2021-07-14 01:37:31 +02:00
Andreas Kling 5c24d18923 Kernel: Fix logic error in PhysicalRegion::contains()
This was incorrectly returning true for the address one byte past the
end of the region.
2021-07-14 01:37:19 +02:00
Andreas Kling 6cc1247395 Kernel: Cut allocation size for physical buddy bitmaps in half
We were allocating twice as much memory as we needed for these bitmaps
due to a silly typo. Found by tomuta trying to boot with 24 GiB of RAM.
2021-07-13 23:47:49 +02:00
Andreas Kling d8ff46594a Kernel: Re-add accidentally removed friendship
PageDirectory and MemoryManager need to remain friends, for now..
2021-07-13 23:21:22 +02:00
Andreas Kling de4ba1f39b Kernel: Remove some friendships and make some classes non-copy/moveable 2021-07-13 23:19:00 +02:00
Andreas Kling 424afdd72b Kernel: Remove some unnecessary includes in VM/Physical* 2021-07-13 23:11:06 +02:00
Andreas Kling 0a21d421d9 Kernel: Print a summary of physical zones during boot
Let's not print out every single zone, since that gets very noisy on
machines with a lot of RAM. :^)
2021-07-13 23:08:45 +02:00
Andreas Kling bf5e4326ac Kernel: Fix bogus address calculation in initialize_physical_pages()
We were incorrectly using sizeof(PhysicalPageEntry) for some address
calculations instead of sizeof(PageTableEntry).

It still worked correctly because they happen to be the same size.
2021-07-13 23:08:45 +02:00
Andreas Kling e323942623 Kernel: Only loop through usable zones when allocating >1 physical page
We still have to loop here, since a zone can be "usable" while not
being able to satisfy a multi-page allocation request.
2021-07-13 23:08:45 +02:00
Andreas Kling 379bcd26e4 Kernel: Avoid O(n) loop over zones when allocating from PhysicalRegion
We now keep all the PhysicalZones on one of two intrusive lists within
the PhysicalRegion.

The "usable" list contains all zones that can be allocated from,
and the "full" list contains all zones with no free pages.
2021-07-13 23:08:45 +02:00
Andreas Kling 9ae067aa7f Kernel: Make PhysicalRegion eternally allocated 2021-07-13 22:40:25 +02:00
Andreas Kling 959ceb4424 Kernel: Remove PhysicalRegion::finalize_capacity()
There's no reason to delay calculating the capacity (total page count)
of each PhysicalRegion. Just do it in the constructor.
2021-07-13 22:40:25 +02:00
Andreas Kling 5171249540 Kernel: Simplify the way PhysicalRegions are constructed
Instead of creating a PhysicalRegion and then expanding it over and
over as we traverse the memory map on boot, we now compute the final
size of the contiguous physical range up front, and *then* create a
PhysicalRegion object.
2021-07-13 22:40:25 +02:00
Andreas Kling 479df315d2 Kernel: Make PhysicalZone an eternally allocated object
Until we start supporting hot-pluggable RAM, these will not be freed
or reallocated during the kernel's lifetime. :^)
2021-07-13 22:40:25 +02:00
Andreas Kling 6ea5db20ff Kernel: Remove unused used/free pages API's from PhysicalRegion 2021-07-13 22:40:25 +02:00
Andreas Kling be90e51355 Kernel: Remove API for requesting physical allocation alignment
Nobody was using this API to request anythign about `PAGE_SIZE`
alignment, so let's get rid of it for now. We can reimplement it if
we end up needing it.

Also note that it wasn't actually used anywhere.
2021-07-13 22:40:25 +02:00
Andreas Kling ba87571366 Kernel: Implement zone-based buddy allocator for physical memory
The previous allocator was very naive and kept the state of all pages
in one big bitmap. When allocating, we had to scan through the bitmap
until we found an unset bit.

This patch introduces a new binary buddy allocator that manages the
physical memory pages.

Each PhysicalRegion is divided into zones (PhysicalZone) of 16MB each.
Any extra pages at the end of physical RAM that don't fit into a 16MB
zone are turned into 15 or fewer 1MB zones.

Each zone starts out with one full-sized block, which is then
recursively subdivided into halves upon allocation, until a block of
the request size can be returned.

There are more opportunities for improvement here: the way zone objects
are allocated and stored is non-optimal. Same goes for the allocation
of buddy block state bitmaps.
2021-07-13 22:40:25 +02:00
Tom b919789db2 Kernel: Kill user mode threads that are marked to die
Threads that don't make syscalls still need to be killed, and we can
do that at any time we want so long the thread is in user mode and
not somehow blocked (e.g. page fault).
2021-07-13 20:23:10 +02:00
Tom fa8fe40266 Revert "Kernel: Make sure threads which don't do any syscalls are t..."
This reverts commit 3c3a1726df.

We cannot blindly kill threads just because they're not executing in a
system call. Being blocked (including in a page fault) needs proper
unblocking and potentially kernel stack cleanup before we can mark a
thread as Dying.

Fixes #8691
2021-07-13 20:23:10 +02:00
Liav A 2a1bf53435 Kernel/Graphics: Move Bochs graphics related code into a separate folder 2021-07-12 22:53:08 +02:00
Liav A 3fee1cbe66 Kernel/Graphics: Remove unnecessary Bochs.h file
Nobody excepts BochsGraphicsAdapter code uses these definitions, so
let's put them back into the BochsGraphicsAdapter.cpp file.
2021-07-12 22:53:08 +02:00
Tom 026ffa343d Kernel: Allow Lock to block from BlockCondition
This enables the Lock class to block a thread even while the thread is
working on a BlockCondition. A thread can still only be either blocked
by a Lock or a BlockCondition.

This also establishes a linked list of threads that are blocked by a
Lock and unblocking directly unlocks threads and wakes them directly.
2021-07-12 11:27:18 +02:00
Tom d9fb93c5ce Kernel: Fix deadlock cancelling timer
It's possible that a timer may have been queued to be executed by
the timer irq handler, but if we're in a critical section on the
same processor and are trying to cancel that timer, we would spin
forever waiting for it to be executed.
2021-07-12 11:27:18 +02:00
Tom 6938be00f1 Kernel: Initialize threading and process management earlier
This re-arranges the order of how things are initialized so that we
try to initialize process and thread management earlier. This is
neccessary because a lot of the code uses the Lock class, which really
needs to have a running scheduler in place so that we can properly
preempt.

This also enables us to potentially initialize some things in parallel.
2021-07-12 11:27:18 +02:00
Andreas Kling c2792212f4 Kernel: Remove "supervisor" bit from PhysicalPage
Instead of each PhysicalPage knowing whether it comes from the
supervisor pages or from the user pages, we can just check in both
sets when freeing a page.

It's just a handful of pointer range checks, nothing expensive.
2021-07-12 11:09:42 +02:00
Tom 9318d9f284 Kernel: Fix allocating VMObject from page array
The VMObject constructor takes the size in bytes.

Fixes #8670
2021-07-12 10:45:53 +02:00
Brian Gianforcaro 84b4b9447d Kernel: Move new process registration out of Space spinlock scope
There appears to be no reason why the process registration needs
to happen under the space spin lock. As the first thread is not started
yet it should be completely uncontested, but it's still bad practice.
2021-07-12 10:20:21 +02:00
Tom 60a559af7e Kernel: Avoid unnecessary context switch when no other thread is ready
If no other thread is ready to be run we don't need to switch to the
idle thread and wait for the next timer interrupt. We can just give
the thread another timeslice and keep it running.
2021-07-12 10:19:31 +02:00
Andreas Kling 2dfdaafb23 Kernel: Use "new (nothrow)" for SharedInodeVMObject 2021-07-11 21:56:26 +02:00
Brian Gianforcaro 425195e93f Kernel: Standardize the header include style to 'include <Kernel/...>'
This is the overwhelming standard in the project, but there were some
cases in the kernel which were not following it, lets fix those cases!
2021-07-11 21:37:38 +02:00
Brian Gianforcaro 6f408e7f0d Kernel: Remove unused header includes in root kernel tree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro 28cf9ffe90 Kernel: Remove unused header includes in Bus subtree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro 187a8f6896 Kernel: Remove unused header includes in ACPI subtree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro 661809408e Kernel: Remove unused header includes in Heap subtree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro abe72ede7a Kernel: Remove unused header includes in Graphics subtree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro 9814082b5e Kernel: Remove unused header includes in Interrupts subtree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro 8211aee4b5 Kernel: Remove unused header includes in TTY subtree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro e18be7f5c7 Kernel: Remove unused header includes in Storage subtree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro da665077ce Kernel: Remove unused header includes in Arch subtree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro 1c43836990 Kernel: Remove unused header includes in FileSystem subtree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro 5743561d32 Kernel: Remove unused header includes in Net subtree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro ea238e7ac3 Kernel: Remove unused header includes in Devices subtree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro b1740e410b Kernel: Remove unused header includes in Time subtree 2021-07-11 21:37:38 +02:00
Brian Gianforcaro 9044e21ed4 Kernel: Remove unused header includes in VM subtree 2021-07-11 21:37:38 +02:00
Liav A a8c35b6a93 Kernel: Fix condition on whether to initialize a display adapter or not 2021-07-11 21:16:33 +02:00
Liav A b882e5ff6b Kernel/Graphics: Move Intel graphics related code to a separate folder 2021-07-11 21:16:33 +02:00
Andrew Kaster da0095855e Kernel: Print end-inclusive ranges in MemoryManager initialization
This brings the physical and virtual addresses printed to dmesg more in
line with inclusive ranges printed elsewhere in the project.
2021-07-11 19:42:00 +02:00