Skip to content

Commit

Permalink
stop idle loop when async io triggers interrupt (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
copy committed Apr 26, 2024
1 parent 90b2505 commit cc08b8e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/browser/starter.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function V86(options)
"microtick": v86.microtick,
"get_rand_int": function() { return v86util.get_rand_int(); },
"apic_acknowledge_irq": function() { return cpu.devices.apic.acknowledge_irq(); },
"stop_idling": function() { return cpu.stop_idling(); },

"io_port_read8": function(addr) { return cpu.io.port_read8(addr); },
"io_port_read16": function(addr) { return cpu.io.port_read16(addr); },
Expand Down Expand Up @@ -654,7 +655,7 @@ V86.prototype.zstd_decompress_worker = async function(decompressed_size, src)
const env = Object.fromEntries([
"cpu_exception_hook", "run_hardware_timers",
"cpu_event_halt", "microtick", "get_rand_int",
"apic_acknowledge_irq",
"apic_acknowledge_irq", "stop_idling",
"io_port_read8", "io_port_read16", "io_port_read32",
"io_port_write8", "io_port_write16", "io_port_write32",
"mmap_read8", "mmap_read16", "mmap_read32",
Expand Down
4 changes: 2 additions & 2 deletions src/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@


/** @constructor */
function CPU(bus, wm, next_tick_immediately)
function CPU(bus, wm, stop_idling)
{
this.next_tick_immediately = next_tick_immediately;
this.stop_idling = stop_idling;
this.wm = wm;
this.wasm_patch();
this.create_jit_imports();
Expand Down
6 changes: 5 additions & 1 deletion src/rust/cpu/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {
pub fn run_hardware_timers(acpi_enabled: bool, t: f64) -> f64;
pub fn cpu_event_halt();
pub fn apic_acknowledge_irq() -> i32;
pub fn stop_idling();

pub fn io_port_read8(port: i32) -> i32;
pub fn io_port_read16(port: i32) -> i32;
Expand Down Expand Up @@ -4210,7 +4211,10 @@ pub unsafe fn handle_irqs() {

unsafe fn pic_call_irq(interrupt_nr: u8) {
*previous_ip = *instruction_pointer; // XXX: What if called after instruction (port IO)
*in_hlt = false;
if *in_hlt {
stop_idling();
*in_hlt = false;
}
call_interrupt_vector(interrupt_nr as i32, false, None);
}

Expand Down

0 comments on commit cc08b8e

Please sign in to comment.