From 06ad44ee1e8b2e2e6dcfca206e5c29a62bf67f9b Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 5 Apr 2008 19:30:02 -0400 Subject: Introduce cpu_relax() and use it in busy loops. --- src/floppy.c | 14 ++++++++++---- src/kbd.c | 4 ++-- src/util.h | 5 +++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/floppy.c b/src/floppy.c index 0954720e..c27ee87a 100644 --- a/src/floppy.c +++ b/src/floppy.c @@ -117,9 +117,12 @@ floppy_prepare_controller(u8 drive) if (prev_reset == 0) { irq_enable(); u8 v; - do { + for (;;) { v = GET_BDA(floppy_recalibration_status); - } while ((v & FRS_TIMEOUT) == 0); + if (v & FRS_TIMEOUT) + break; + cpu_relax(); + } irq_disable(); v &= ~FRS_TIMEOUT; @@ -139,14 +142,17 @@ floppy_pio(u8 *cmd, u8 cmdlen) irq_enable(); u8 v; - do { + for (;;) { if (!GET_BDA(floppy_motor_counter)) { irq_disable(); floppy_reset_controller(); return DISK_RET_ETIMEOUT; } v = GET_BDA(floppy_recalibration_status); - } while (!(v & FRS_TIMEOUT)); + if (v & FRS_TIMEOUT) + break; + cpu_relax(); + } irq_disable(); v &= ~FRS_TIMEOUT; diff --git a/src/kbd.c b/src/kbd.c index 0e0dd5b7..3770305b 100644 --- a/src/kbd.c +++ b/src/kbd.c @@ -59,8 +59,8 @@ keyboard_init() if (inb(PORT_PS2_STATUS) & 0x01) { inb(PORT_PS2_DATA); max = 0x2000; - } } + } // Due to timer issues, and if the IPS setting is > 15000000, // the incoming keys might not be flushed here. That will @@ -193,7 +193,7 @@ dequeue_key(u8 *scan_code, u8 *ascii_code, u8 incr) break; if (!incr) return 0; - nop(); + cpu_relax(); } *ascii_code = GET_FARVAR(SEG_BDA, *(u8*)(buffer_head+0x400+0)); diff --git a/src/util.h b/src/util.h index dff1a116..344bcbc1 100644 --- a/src/util.h +++ b/src/util.h @@ -32,6 +32,11 @@ static inline void irq_restore(unsigned long flags) asm volatile("pushl %0 ; popfl" : : "g" (flags) : "memory", "cc"); } +static inline void cpu_relax(void) +{ + asm volatile("rep ; nop": : :"memory"); +} + static inline void nop(void) { asm volatile("nop"); -- cgit