Commit Graph

56 Commits

Author SHA1 Message Date
Andreas Kling
cd348918f9 Kernel/x86: Move Processor::{leave,clear}_critical() out of line
I don't think this code needs to be ALWAYS_INLINE, and moving it out
of line will make backtraces nicer.
2022-08-18 00:58:34 +02:00
Timon Kruiper
9413fe9fe5 Kernel: Add interrupt related functions to Processor class
This adds {enable, disable}_interrupts() and are_interrupts_enabled()
to the Processor class, and also implements them for x86(_64) and
aarch64.
2022-06-02 13:14:12 +01:00
Jesse Buhagiar
964f8fbf3a Kernel: Implement AVX XSAVE support
This adds some new buffers to the `FPUState` struct, which contains
enough space for the `xsave` instruction to run. This instruction writes
the upper part of the x86 SIMD registers (YMM0-15) to a seperate
256-byte area, as well as an "xsave header" describing the region.

If the underlying processor supports AVX, the `fxsave` instruction is no
longer used, as `xsave` itself implictly saves all of the SSE and x87
registers.

Co-authored-by: Leon Albrecht <leon.a@serenityos.org>
2022-05-15 12:25:23 +02:00
Linus Groh
afce63fffc Kernel: Move feature string building to ProcessorInfo
Other than a dmesgln(), ProcessorInfo is the only user of this function
and is already responsible for building other CPUID-related strings.
2022-04-03 23:20:33 +02:00
James Mintram
d3b6201b40 Kernel: Make PageDirectory.cpp compile on aarch64 2022-04-02 19:34:20 -07:00
James Mintram
783a44b18e Kernel: Make PhysicalRegion.cpp compile on aarch64 2022-04-02 19:34:20 -07:00
James Mintram
627fd231d5 Kernel: Make Region.cpp compile on aarch64 2022-04-02 19:34:20 -07:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Linus Groh
bc7ec02a82 Kernel: Implement CPUFeature as an ArbitrarySizedEnum
This will make it possible to add many, many more CPU features - more
than the current limit 32 and later limit of 64 if we stick with an enum
class to be specific :^)
2022-03-27 18:54:56 +02:00
Hendiadyoin1
150e6a59c0 Kernel: Add and use bitwise operators to CPUFeature 2022-03-22 18:20:01 +00:00
Idan Horowitz
f4875b9967 Kernel: Add Processor::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz
1aad64fbe4 Kernel: Workaround QEMU hypervisor.framework CPUID max leaf bug
This works around issue #10382 until it is fixed on QEMU's side.
Patch from Anonymous.
2022-02-11 02:45:34 +02:00
Tom
6e46e21c42 Kernel: Implement Page Attribute Table (PAT) support and Write-Combine
This allows us to enable Write-Combine on e.g. framebuffers,
significantly improving performance on bare metal.

To keep things simple we right now only use one of up to three bits
(bit 7 in the PTE), which maps to the PA4 entry in the PAT MSR, which
we set to the Write-Combine mode on each CPU at boot time.
2022-01-26 09:21:04 +02:00
Idan Horowitz
0142f33ddc Kernel: Make Processor::capture_stack_trace fallible using ErrorOr 2022-01-16 01:01:08 +02:00
Idan Horowitz
03b7352286 Kernel: Specify inline capacity of return type in capture_stack_trace
Since the inline capacity of the Vector return type was not specified
explicitly, the vector was automatically copied to a 0-length inline
capacity one, essentially eliminating the optimization.
2022-01-16 01:01:08 +02:00
Brian Gianforcaro
faf1fa0a84 Kernel: Convert Processor::features_string() API to KString 2022-01-12 13:03:44 +01:00
Idan Horowitz
4f551f54c4 Kernel: Align GDT to the size of a Descriptor
This is not actually required by the specification, but it means we
will take the aligned fast-path in QEMU.
2022-01-04 19:08:07 +02:00
Daniel Bertalan
fcdd202741 Kernel: Return the actual number of CPU cores that we have
... instead of returning the maximum number of Processor objects that we
can allocate.

Some ports (e.g. gdb) rely on this information to determine the number
of worker threads to spawn. When gdb spawned 64 threads, the kernel
could not cope with generating backtraces for it, which prevented us
from debugging it properly.

This commit also removes the confusingly named
`Processor::processor_count` function so that this mistake can't happen
again.
2021-12-29 03:17:41 -08:00
Owen Smith
e6df1c9988 Kernel: Implement and use the syscall/sysret instruction pair on x86_64 2021-12-28 23:15:38 +01:00
Hendiadyoin1
3f434506f5 Kernel: Extract ProcessorSpecificDataID from from Arch/Processor.h 2021-12-11 13:23:27 -08:00
Hendiadyoin1
556b516182 Kernel: Extract DeferredCallEntry from Arch/Processor.h 2021-12-11 13:23:27 -08:00
James Mintram
e20884dc0c Kernel: Add an x86 include check+error in x86/Processor.h 2021-12-01 11:22:04 -08:00
Andrew Kaster
65edc62c02 Kernel: Resolve clang-tidy readability-make-member-function-const
... In files included from Kernel/Thread.cpp or Kernel/Process.cpp

Some places the warning is suppressed, because we do not want a const
object do have non-const access to the returned sub-object.
2021-11-14 22:52:35 +01:00
Andrew Kaster
a92132e44a Kernel: Resolve clang-tidy readability-implicit-bool-conversion warnings
... In files included from Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-14 22:52:35 +01:00
James Mintram
545ce5b595 Kernel: Add per platform Processor.h headers
The platform independent Processor.h file includes the shared processor
code and includes the specific platform header file.

All references to the Arch/x86/Processor.h file have been replaced with
a reference to Arch/Processor.h.
2021-10-14 01:23:08 +01:00
Idan Horowitz
900fac27c6 Kernel: Add Processor::time_spent_idle() 2021-10-07 21:09:38 +02:00
Idan Horowitz
cd975668d6 Kernel: Detect and store the virtual address bit width during CPU init 2021-10-05 02:07:43 +02:00
Idan Horowitz
bc7b0a8986 Kernel: Replace inline assembly for turning on IA32_EFER.NXE with MSR
This fixes a triple fault that occurs when compiling serenity with
the i686 clang toolchain. (The underlying issue is that the old inline
assembly did not specify that it clobbered the eax/ecx/edx registers
and as such the compiler assumed they were not changed and used their
values across it)

Co-authored-by: Brian Gianforcaro <bgianf@serenityos.org>
2021-09-10 22:58:08 +03:00
Tom
8a258edfd6 Kernel: Add x2APIC support
This allows addressing all cores on more modern processors. For now,
we still have a hardcoded limit of 64 due to s_processors being a
static array.
2021-09-04 22:22:58 +02:00
Daniel Bertalan
779cf49f38 Kernel: Fix Clang not initializing s_bsp_processor correctly
Initializing the variable this way fixes a kernel panic in Clang where
the object was zero-initialized, so the `m_in_scheduler` contained the
wrong value. GCC got it right, but we're better off making this change,
as leaving uninitialized fields in constant-initialized objects can
cause other weird situations like this. Also, initializing only a single
field to a non-zero value isn't worth the cost of no longer fitting in
`.bss`.

Another two variables suffer from the same problem, even though their
values are supposed to be zero. Removing these causes the
`_GLOBAL_sub_I_` function to no longer be generated and the (not
handled) `.init_array` section to be omitted.
2021-08-30 13:20:34 +02:00
Andreas Kling
d9da513959 Kernel: Move "in-scheduler" flag from SchedulerData to Processor
This avoids a race between getting the processor-specific SchedulerData
and accessing it. (Switching to a different CPU in that window means
that we're operating on the wrong SchedulerData.)

Co-authored-by: Tom <tomut@yahoo.com>
2021-08-29 12:43:39 +02:00
Andreas Kling
05e1b196e9 Kernel: Make Processor::clean_fpu_state() static
This function returns the same identical FPU state for all CPU's, so
there's no point requiring a Processor instance.
2021-08-23 00:02:09 +02:00
Andreas Kling
1b9916439f Kernel: Make Processor::platform_string() return StringView 2021-08-23 00:02:09 +02:00
Andreas Kling
dea93a8bb9 Kernel: Rename Processor::id() => current_id()
And let id() be the non-static version that gives you the ID of a
Processor object.
2021-08-23 00:02:09 +02:00
Andreas Kling
d60635cb9d Kernel: Convert Processor::in_irq() to static current_in_irq()
This closes the race window between Processor::current() and a context
switch happening before in_irq().
2021-08-23 00:02:09 +02:00
Andreas Kling
0a02496f04 Kernel/SMP: Change critical sections to not disable interrupts
Leave interrupts enabled so that we can still process IRQs. Critical
sections should only prevent preemption by another thread.

Co-authored-by: Tom <tomut@yahoo.com>
2021-08-10 02:49:37 +02:00
Andreas Kling
9babb92a4b Kernel/SMP: Make entering/leaving critical sections multi-processor safe
By making these functions static we close a window where we could get
preempted after calling Processor::current() and move to another
processor.

Co-authored-by: Tom <tomut@yahoo.com>
2021-08-10 02:49:37 +02:00
Andreas Kling
74e6a70958 Kernel/SMP: Don't process SMP messages in non-SMP mode
Processing SMP messages outside of non-SMP mode is a waste of time,
and now that we don't rely on the side effects of calling the message
processing function, let's stop calling it entirely. :^)
2021-08-09 13:39:08 +02:00
Andreas Kling
f3fed411d4 Kernel: Rename Processor::smp_queue_message() => smp_enqueue_message() 2021-08-09 11:46:30 +02:00
Andreas Kling
46215a8183 Kernel: Add Processor::pause() and use it to give the CPU a rest
On x86, the "pause" instruction is a "spin loop hint".
2021-08-09 11:46:30 +02:00
Andreas Kling
93d98d4976 Kernel: Move Kernel/Memory/ code into Kernel::Memory namespace 2021-08-06 14:05:58 +02:00
Andreas Kling
84d3428ab3 Kernel: Remove a handful of unused member functions in Processor 2021-07-27 14:38:04 +02:00
Andreas Kling
1e43292c3b Kernel: Introduce ProcessorSpecific<T> for per-CPU data structures
To add a new per-CPU data structure, add an ID for it to the
ProcessorSpecificDataID enum.

Then call ProcessorSpecific<T>::initialize() when you are ready to
construct the per-CPU data structure on the current CPU. It can then
be accessed via ProcessorSpecific<T>::get().

This patch replaces the existing hard-coded mechanisms for Scheduler
and MemoryManager per-CPU data structure.
2021-07-27 14:32:30 +02:00
Gunnar Beutner
741ca5477c Kernel: Fix {read,write}_gs_ptr() for 64-bit addresses 2021-07-18 17:31:13 +02:00
Jean-Baptiste Boric
528574d958 Kernel: Detect and display CPUID Hyper-V data 2021-07-14 13:52:34 +02:00
Jean-Baptiste Boric
b22357b17b Kernel: Detect and display CPUID hypervisor signature 2021-07-14 13:52:34 +02:00
Andreas Kling
98080497d2 Kernel: Use Forward.h headers more 2021-07-11 14:14:51 +02:00
Hendiadyoin1
9b7e48c6bd Kernel: Replace raw asm functions with naked ones 2021-07-05 16:40:00 +02:00
Gunnar Beutner
52f9aaa823 Kernel: Use the GS segment for the per-CPU struct
Right now we're using the FS segment for our per-CPU struct. On x86_64
there's an instruction to switch between a kernel and usermode GS
segment (swapgs) which we could use.

This patch doesn't update the rest of the code to use swapgs but it
prepares for that by using the GS segment instead of the FS segment.
2021-07-02 23:33:17 +02:00
Gunnar Beutner
a8587fbfb9 Kernel: Use FlatPtr for register-sized values 2021-06-28 22:29:28 +02:00