Skip to content

feat: add PS/2 keyboard interrupt driver - #2532

Merged
jounathaen merged 1 commit into
hermit-os:mainfrom
GloriousAlpaca:pr-keyboard-clean
Aug 26, 2026
Merged

feat: add PS/2 keyboard interrupt driver#2532
jounathaen merged 1 commit into
hermit-os:mainfrom
GloriousAlpaca:pr-keyboard-clean

Conversation

@GloriousAlpaca

Copy link
Copy Markdown

This feature adds support for the PS2 legacy keyboard in Qemu x86_64.
Currently it does:

  1. A minimized hardware initialization (e.g. flush the output buffer) to use the keyboard, according to the standards for the Intel 8042 chip: Link to OSDev
  2. Install an interrupt handler, which is done in the install_handlers function in interrupt.rs, as it is a hardware interrupt but does not belong in the pci interrupt handlers list (legacy device).
  3. Add a systemcall to pop the last scancode out of the keyboard input ringbuffer (which currently has a length of 256). The Ringbuffer also uses Atomics, to prevent races and deadlocks.
    The systemcall returns 0 if the keyboard feature is disabled.

I have only tested this feature with C programs on a Mac using Qemu.

@mkroening mkroening self-assigned this Jul 6, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark Results

Details
Benchmark Current: 009e0fa Previous: 2e23902 Performance Ratio
startup_benchmark Build Time 94.03 s 80.34 s 1.17
startup_benchmark File Size 0.78 MB 0.80 MB 0.98
Startup Time - 1 core 0.73 s (±0.01 s) 0.75 s (±0.02 s) 0.98
Startup Time - 2 cores 0.75 s (±0.02 s) 0.74 s (±0.02 s) 1.02
Startup Time - 4 cores 0.75 s (±0.02 s) 0.74 s (±0.02 s) 1.01
multithreaded_benchmark Build Time 92.15 s 82.11 s 1.12
multithreaded_benchmark File Size 0.85 MB 0.86 MB 0.99
Multithreaded Pi Efficiency - 2 Threads 68.86 % (±6.84 %) 85.89 % (±6.61 %) 0.80
Multithreaded Pi Efficiency - 4 Threads 41.27 % (±3.19 %) 43.43 % (±2.56 %) 0.95
Multithreaded Pi Efficiency - 8 Threads 20.47 % (±2.26 %) 25.76 % (±1.53 %) 0.79
micro_benchmarks Build Time 230.67 s 80.40 s 2.87
micro_benchmarks File Size 0.85 MB 0.86 MB 0.99
Scheduling time - 1 thread 174.95 ticks (±29.16 ticks) 62.65 ticks (±4.06 ticks) 2.79
Scheduling time - 2 threads 104.43 ticks (±17.43 ticks) 34.08 ticks (±4.10 ticks) 3.06
Micro - Time for syscall (getpid) 11.67 ticks (±5.17 ticks) 3.45 ticks (±0.58 ticks) 3.38
Memcpy speed - (built_in) block size 4096 57620.52 MByte/s (±40209.45 MByte/s) 82448.38 MByte/s (±56997.13 MByte/s) 0.70
Memcpy speed - (built_in) block size 1048576 13035.39 MByte/s (±10702.55 MByte/s) 30585.98 MByte/s (±24707.84 MByte/s) 0.43
Memcpy speed - (built_in) block size 16777216 8683.79 MByte/s (±7320.87 MByte/s) 26340.06 MByte/s (±21720.96 MByte/s) 0.33
Memset speed - (built_in) block size 4096 57675.08 MByte/s (±40240.78 MByte/s) 82292.76 MByte/s (±56891.50 MByte/s) 0.70
Memset speed - (built_in) block size 1048576 13288.17 MByte/s (±10842.44 MByte/s) 31323.85 MByte/s (±25145.86 MByte/s) 0.42
Memset speed - (built_in) block size 16777216 8768.49 MByte/s (±7352.66 MByte/s) 27104.68 MByte/s (±22209.94 MByte/s) 0.32
Memcpy speed - (rust) block size 4096 52630.28 MByte/s (±37945.91 MByte/s) 74097.96 MByte/s (±51811.44 MByte/s) 0.71
Memcpy speed - (rust) block size 1048576 14597.29 MByte/s (±11963.08 MByte/s) 30361.60 MByte/s (±24602.37 MByte/s) 0.48
Memcpy speed - (rust) block size 16777216 9126.75 MByte/s (±7795.73 MByte/s) 27625.34 MByte/s (±22806.88 MByte/s) 0.33
Memset speed - (rust) block size 4096 53095.69 MByte/s (±38194.93 MByte/s) 74373.47 MByte/s (±51976.48 MByte/s) 0.71
Memset speed - (rust) block size 1048576 14932.49 MByte/s (±12129.44 MByte/s) 31110.89 MByte/s (±25033.24 MByte/s) 0.48
Memset speed - (rust) block size 16777216 9168.78 MByte/s (±7807.16 MByte/s) 28386.93 MByte/s (±23265.03 MByte/s) 0.32
alloc_benchmarks Build Time 227.75 s 74.76 s 3.05
alloc_benchmarks File Size 0.86 MB 0.87 MB 0.98
Allocations - Allocation success 91.38 % 91.31 % 1.00
Allocations - Deallocation success 100.00 % 100.00 % 1
Allocations - Pre-fail Allocations 61.60 % 61.44 % 1.00
Allocations - Average Allocation time 26526.86 Ticks (±1686.33 Ticks) 5860.58 Ticks (±98.43 Ticks) 4.53
Allocations - Average Allocation time (no fail) 27931.14 Ticks (±2119.52 Ticks) 6554.81 Ticks (±92.86 Ticks) 4.26
Allocations - Average Deallocation time 8635.95 Ticks (±1791.85 Ticks) 1805.01 Ticks (±250.35 Ticks) 4.78
mutex_benchmark Build Time 218.27 s 79.82 s 2.73
mutex_benchmark File Size 0.85 MB 0.86 MB 0.99
Mutex Stress Test Average Time per Iteration - 1 Threads 35.90 ns (±6.85 ns) 12.10 ns (±0.41 ns) 2.97
Mutex Stress Test Average Time per Iteration - 2 Threads 31.92 ns (±8.67 ns) 40.26 ns (±1.68 ns) 0.79

This comment was automatically generated by workflow using github-action-benchmark.

@GloriousAlpaca
GloriousAlpaca force-pushed the pr-keyboard-clean branch 2 times, most recently from 2c424d5 to f6c859b Compare July 6, 2026 16:30

@mkroening mkroening left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Cargo.toml Outdated
Comment thread Cargo.toml Outdated
Comment thread src/syscalls/system.rs Outdated
Comment thread src/arch/x86_64/kernel/interrupts.rs Outdated
Comment thread src/arch/x86_64/kernel/interrupts.rs Outdated
Comment thread src/arch/x86_64/kernel/pc_keyboard.rs Outdated
Comment thread src/arch/x86_64/kernel/pc_keyboard.rs Outdated
Comment thread src/arch/x86_64/kernel/pc_keyboard.rs Outdated
Comment thread src/arch/x86_64/kernel/pc_keyboard.rs Outdated
Comment thread src/syscalls/system.rs Outdated
@GloriousAlpaca
GloriousAlpaca force-pushed the pr-keyboard-clean branch 3 times, most recently from a7180a7 to 153302f Compare July 17, 2026 14:24
Comment thread src/arch/x86_64/kernel/pc_keyboard.rs Outdated
Comment thread src/arch/x86_64/kernel/pc_keyboard.rs Outdated
Comment thread src/arch/x86_64/kernel/pc_keyboard.rs Outdated
Comment thread src/arch/x86_64/kernel/pc_keyboard.rs Outdated
Comment thread Cargo.toml Outdated
@GloriousAlpaca
GloriousAlpaca force-pushed the pr-keyboard-clean branch 4 times, most recently from 452458e to 9afbade Compare August 11, 2026 13:53
Comment thread src/arch/x86_64/kernel/pc_keyboard.rs
Comment thread src/syscalls/system.rs
Comment thread src/syscalls/system.rs
Comment thread src/syscalls/system.rs
Comment thread src/arch/x86_64/kernel/pc_keyboard.rs Outdated
Comment thread src/arch/x86_64/kernel/pc_keyboard.rs Outdated
Comment thread src/syscalls/system.rs
Comment thread src/syscalls/system.rs
Comment thread src/arch/x86_64/kernel/pc_keyboard.rs Outdated
@jounathaen
jounathaen dismissed mkroening’s stale review August 26, 2026 12:26

All requested changes were implemented

@jounathaen
jounathaen enabled auto-merge August 26, 2026 12:31
@jounathaen
jounathaen added this pull request to the merge queue Aug 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Aug 26, 2026
@jounathaen
jounathaen added this pull request to the merge queue Aug 26, 2026
Merged via the queue into hermit-os:main with commit 573acc1 Aug 26, 2026
39 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants