feat: add PS/2 keyboard interrupt driver#2532
Conversation
7c21b3f to
5d35a06
Compare
There was a problem hiding this comment.
Benchmark Results
Details
| Benchmark | Current: 153302f | Previous: 2e23902 | Performance Ratio |
|---|---|---|---|
| startup_benchmark Build Time | 81.54 s |
80.34 s |
1.01 ❗ |
| startup_benchmark File Size | 0.80 MB |
0.80 MB |
1.00 ❗ |
| Startup Time - 1 core | 0.74 s (±0.02 s) |
0.75 s (±0.02 s) |
1.00 |
| Startup Time - 2 cores | 0.74 s (±0.02 s) |
0.74 s (±0.02 s) |
1.01 |
| Startup Time - 4 cores | 0.75 s (±0.04 s) |
0.74 s (±0.02 s) |
1.02 |
| multithreaded_benchmark Build Time | 82.65 s |
82.11 s |
1.01 ❗ |
| multithreaded_benchmark File Size | 0.86 MB |
0.86 MB |
1.00 ❗ |
| Multithreaded Pi Efficiency - 2 Threads | 86.93 % (±5.48 %) |
85.89 % (±6.61 %) |
1.01 |
| Multithreaded Pi Efficiency - 4 Threads | 42.83 % (±2.51 %) |
43.43 % (±2.56 %) |
0.99 |
| Multithreaded Pi Efficiency - 8 Threads | 24.84 % (±1.40 %) |
25.76 % (±1.53 %) |
0.96 |
| micro_benchmarks Build Time | 82.58 s |
80.40 s |
1.03 ❗ |
| micro_benchmarks File Size | 0.86 MB |
0.86 MB |
1.00 ❗ |
| Scheduling time - 1 thread | 62.12 ticks (±2.40 ticks) |
62.65 ticks (±4.06 ticks) |
0.99 |
| Scheduling time - 2 threads | 34.11 ticks (±4.17 ticks) |
34.08 ticks (±4.10 ticks) |
1.00 |
| Micro - Time for syscall (getpid) | 3.39 ticks (±0.47 ticks) |
3.45 ticks (±0.58 ticks) |
0.98 |
| Memcpy speed - (built_in) block size 4096 | 82125.64 MByte/s (±56878.20 MByte/s) |
82448.38 MByte/s (±56997.13 MByte/s) |
1.00 |
| Memcpy speed - (built_in) block size 1048576 | 30357.34 MByte/s (±24500.01 MByte/s) |
30585.98 MByte/s (±24707.84 MByte/s) |
0.99 |
| Memcpy speed - (built_in) block size 16777216 | 26948.19 MByte/s (±22286.99 MByte/s) |
26340.06 MByte/s (±21720.96 MByte/s) |
1.02 |
| Memset speed - (built_in) block size 4096 | 82538.30 MByte/s (±57151.08 MByte/s) |
82292.76 MByte/s (±56891.50 MByte/s) |
1.00 |
| Memset speed - (built_in) block size 1048576 | 31096.80 MByte/s (±24932.98 MByte/s) |
31323.85 MByte/s (±25145.86 MByte/s) |
0.99 |
| Memset speed - (built_in) block size 16777216 | 27684.14 MByte/s (±22734.82 MByte/s) |
27104.68 MByte/s (±22209.94 MByte/s) |
1.02 |
| Memcpy speed - (rust) block size 4096 | 75107.74 MByte/s (±52373.82 MByte/s) |
74097.96 MByte/s (±51811.44 MByte/s) |
1.01 |
| Memcpy speed - (rust) block size 1048576 | 30402.19 MByte/s (±24619.41 MByte/s) |
30361.60 MByte/s (±24602.37 MByte/s) |
1.00 |
| Memcpy speed - (rust) block size 16777216 | 25863.16 MByte/s (±21294.74 MByte/s) |
27625.34 MByte/s (±22806.88 MByte/s) |
0.94 |
| Memset speed - (rust) block size 4096 | 75045.73 MByte/s (±52336.97 MByte/s) |
74373.47 MByte/s (±51976.48 MByte/s) |
1.01 |
| Memset speed - (rust) block size 1048576 | 31143.13 MByte/s (±25047.95 MByte/s) |
31110.89 MByte/s (±25033.24 MByte/s) |
1.00 |
| Memset speed - (rust) block size 16777216 | 26626.58 MByte/s (±21794.27 MByte/s) |
28386.93 MByte/s (±23265.03 MByte/s) |
0.94 |
| alloc_benchmarks Build Time | 78.60 s |
74.76 s |
1.05 ❗ |
| alloc_benchmarks File Size | 0.87 MB |
0.87 MB |
1.00 ❗ |
| Allocations - Allocation success | 91.31 % |
91.31 % |
1 |
| Allocations - Deallocation success | 100.00 % |
100.00 % |
1 |
| Allocations - Pre-fail Allocations | 61.44 % |
61.44 % |
1 |
| Allocations - Average Allocation time | 7755.99 Ticks (±144.27 Ticks) |
5860.58 Ticks (±98.43 Ticks) |
1.32 ❗ |
| Allocations - Average Allocation time (no fail) | 8221.42 Ticks (±152.18 Ticks) |
6554.81 Ticks (±92.86 Ticks) |
1.25 ❗ |
| Allocations - Average Deallocation time | 1433.12 Ticks (±505.07 Ticks) |
1805.01 Ticks (±250.35 Ticks) |
0.79 |
| mutex_benchmark Build Time | 77.70 s |
79.82 s |
0.97 ❗ |
| mutex_benchmark File Size | 0.86 MB |
0.86 MB |
1.00 ❗ |
| Mutex Stress Test Average Time per Iteration - 1 Threads | 12.14 ns (±0.40 ns) |
12.10 ns (±0.41 ns) |
1.00 |
| Mutex Stress Test Average Time per Iteration - 2 Threads | 42.14 ns (±1.99 ns) |
40.26 ns (±1.68 ns) |
1.05 |
This comment was automatically generated by workflow using github-action-benchmark.
2c424d5 to
f6c859b
Compare
mkroening
left a comment
There was a problem hiding this comment.
Thanks for the PR! :)
I was wondering why implement drivers for legacy devices instead of USB keyboards (xhci, usb-oxide, embassy-usb). I guess it is because of simplicity.
It would be great to discuss the high-level application-facing API, since that is the hardest to change once merged.
| ## Enables the PS/2 keyboard driver. | ||
| ## | ||
| ## This is only useful on PCs (x86-64). | ||
| keyboard = [] |
There was a problem hiding this comment.
Could you rename this to pc-keyboard? Also, please make sure that the docs don't imply that this is needed for keyboard support in general. Serial-based keyboard support is separate from this. Similar to the framebuffer, please also put a disclaimer that this does not make the kernel use the driver and instead exposes an API for applications that need to be ported.
| } | ||
|
|
||
| pub(crate) fn install_handlers(handlers: InterruptHandlerMap) { | ||
| pub(crate) fn install_handlers(#[allow(unused_mut)] mut handlers: InterruptHandlerMap) { |
There was a problem hiding this comment.
Please move the allow to the function level instead of having it inline like this.
| pub(crate) fn install_handlers(#[allow(unused_mut)] mut handlers: InterruptHandlerMap) { | ||
| #[cfg(feature = "keyboard")] | ||
| { | ||
| use crate::arch::kernel::keyboard::get_keyboard_handler; |
There was a problem hiding this comment.
| use crate::arch::kernel::keyboard::get_keyboard_handler; | |
| use crate::arch::kernel::keyboard::get_keyboard_handler; | |
| data_port.write(config); | ||
| cmd_port.write(PS2_CMD_ENABLE_KEYBOARD); | ||
| } | ||
| fn keyboard_handler() { |
There was a problem hiding this comment.
Please move the handler to the top level outside of this function.
| while (cmd_port.read() & PS2_BUFFER_FULL) != 0 { | ||
| let _ = data_port.read(); | ||
| } |
There was a problem hiding this comment.
Why do we discard the device buffer instead of filling our read buffer?
| let mut cmd_port = Port::<u8>::new(PS2_CMD_PORT); | ||
| let mut data_port = Port::<u8>::new(PS2_DATA_PORT); |
There was a problem hiding this comment.
Do you think an abstraction similar to the proposal for BGA would make sense?
struct Ps2;
impl Ps2 {
fn read_data() -> u8;
fn write_data(data: u8);
fn status() -> u8;
fn command(command: u8);
}| /// Pops a scancode from the keyboard buffer, returning None if the buffer is empty. | ||
| pub fn pop_scancode() -> Option<u8> { |
There was a problem hiding this comment.
A scancode can never be zero, right? Returning Option<NonZero<u8>> would be preferable in that case.
| #[cfg(all(target_arch = "x86_64", feature = "keyboard"))] | ||
| #[hermit_macro::system] | ||
| #[unsafe(no_mangle)] | ||
| pub extern "C" fn sys_read_keyboard() -> u8 { | ||
| crate::kernel::keyboard::pop_scancode().unwrap_or(0) | ||
| } |
There was a problem hiding this comment.
I am not too sure about this API. Is the application supposed to busy loop on this and retrieve one event at a time?
What about doing something similar to Linux's event device (evdev) interface (Linux docs)? Reading from /dev/input/event0 would then fill a user buffer with input events and blocks if no events are there unless opened with O_NONBLOCK.
f6c859b to
0a1c568
Compare
0a1c568 to
a7180a7
Compare
a7180a7 to
153302f
Compare
This feature adds support for the PS2 legacy keyboard in Qemu x86_64.
Currently it does:
The systemcall returns 0 if the keyboard feature is disabled.
I have only tested this feature with C programs on a Mac using Qemu.