Explorar o código

Improve mouse and radeon performance

Johannes Zellner hai 1 mes
pai
achega
488ea7cb0e
Modificáronse 11 ficheiros con 63 adicións e 27 borrados
  1. 3 3
      Makefile
  2. 4 3
      fbtext.c
  3. 3 1
      mouse.c
  4. 24 6
      process.c
  5. 5 0
      process.h
  6. 1 1
      switch.S
  7. 2 8
      syscall.c
  8. 2 3
      terminal.c
  9. 7 0
      vga.c
  10. 4 0
      vga.h
  11. 8 2
      wm.c

+ 3 - 3
Makefile

@@ -35,7 +35,7 @@ font_8x8.o: font_8x8.c font_8x8.h
 fbtext.o: fbtext.c fbtext.h font_8x8.h vga.h
 	$(CC) $(CFLAGS) -o $@ $<
 
-terminal.o: terminal.c terminal.h screen.h vfs.h fat.h blkdev.h io.h dbg.h idle.h kexec.h process.h timer.h
+terminal.o: terminal.c terminal.h screen.h vfs.h fat.h blkdev.h io.h dbg.h kexec.h process.h timer.h
 	$(CC) $(CFLAGS) -o $@ $<
 
 wm.o: wm.c wm.h terminal.h screen.h fbtext.h idle.h io.h mouse.h process.h rtc.h timer.h version.h vga.h
@@ -203,7 +203,7 @@ timer.o: timer.S
 switch.o: switch.S
 	$(AS) $(ASFLAGS) -o $@ $<
 
-process.o: process.c process.h io.h kmalloc.h mm.h serial.h idle.h
+process.o: process.c process.h io.h kmalloc.h mm.h serial.h idle.h timer.h
 	$(CC) $(CFLAGS) -o $@ $<
 
 mm.o: mm.c mm.h
@@ -221,7 +221,7 @@ elf.o: elf.c elf.h mm.h paging.h
 tss.o: tss.c tss.h
 	$(CC) $(CFLAGS) -o $@ $<
 
-syscall.o: syscall.c syscall.h idle.h io.h process.h timer.h
+syscall.o: syscall.c syscall.h io.h process.h timer.h
 	$(CC) $(CFLAGS) -o $@ $<
 
 syscall_stub.o: syscall_stub.S

+ 4 - 3
fbtext.c

@@ -170,7 +170,7 @@ void fbtext_draw_cells(const unsigned short *cells, unsigned int cols, unsigned
 				rf, gf, bf, rb, gb, bb, ROW_HEIGHT, 0);
 		}
 	}
-	vga_fb_mark_dirty_rect(y0, rows * ROW_HEIGHT);
+	vga_fb_mark_dirty_rect_xy(y0, rows * ROW_HEIGHT, x0, x0 + cols * 8);
 }
 
 void fbtext_draw_cells_clip(const unsigned short *cells, unsigned int cols, unsigned int rows,
@@ -202,8 +202,9 @@ void fbtext_draw_cells_clip(const unsigned short *cells, unsigned int cols, unsi
 				rf, gf, bf, rb, gb, bb, ROW_HEIGHT, 0);
 		}
 	}
-	vga_fb_mark_dirty_rect(y0 + (unsigned int)row0 * ROW_HEIGHT,
-		(unsigned int)(row1 - row0) * ROW_HEIGHT);
+	vga_fb_mark_dirty_rect_xy(y0 + (unsigned int)row0 * ROW_HEIGHT,
+		(unsigned int)(row1 - row0) * ROW_HEIGHT,
+		x0 + (unsigned int)col0 * 8, x0 + (unsigned int)col1 * 8);
 }
 
 void fbtext_scroll_up_one_line(void)

+ 3 - 1
mouse.c

@@ -213,7 +213,9 @@ static void mouse_cursor_setup(void)
 
 static int mouse_intellimouse_init(void)
 {
-	static const unsigned char rates[] = { 0xC8, 0x64, 0x50, 0x32 };
+	/* First three rates are the Intellimouse enable magic (200/100/80);
+	   the last is the final report rate.  0xC8 = 200 Hz for a smooth cursor. */
+	static const unsigned char rates[] = { 0xC8, 0x64, 0x50, 0xC8 };
 	unsigned int i;
 	for (i = 0; i < sizeof(rates); i++) {
 		if (mouse_send_cmd_ack(0xF3) != 0)

+ 24 - 6
process.c

@@ -8,6 +8,7 @@
 #include "mm.h"
 #include "paging.h"
 #include "serial.h"
+#include "timer.h"
 
 struct process *procs;               /* dynamically-sized process table */
 volatile unsigned int current_pid;
@@ -387,6 +388,13 @@ void schedule(void)
 		}
 	}
 
+	/* Wake sleeping processes whose deadline has passed. */
+	for (i = 0; i < proc_cap; i++) {
+		if (procs[i].state == PROC_SLEEPING &&
+		    (int)(procs[i].wake_ms - get_ticks_ms()) <= 0)
+			procs[i].state = PROC_READY;
+	}
+
 	/* Mark current as READY (it was RUNNING). */
 	if (procs[current_pid].state == PROC_RUNNING)
 		procs[current_pid].state = PROC_READY;
@@ -472,23 +480,33 @@ int process_kill(unsigned int pid)
 	return -1;
 }
 
-/* Return 1 if a process with `pid` is still runnable (READY/RUNNING). */
+/* Return 1 if a process with `pid` is still alive (READY/RUNNING/SLEEPING). */
 int process_is_alive(unsigned int pid)
 {
 	unsigned int i;
 	for (i = 0; i < proc_cap; i++)
 		if (procs[i].pid == pid &&
 		    (procs[i].state == PROC_READY ||
-		     procs[i].state == PROC_RUNNING))
+		     procs[i].state == PROC_RUNNING ||
+		     procs[i].state == PROC_SLEEPING))
 			return 1;
 	return 0;
 }
 
-/* Wait (yield) until the process with `pid` has exited.  The scheduler
- * preempts us every timeslice so the child runs and process_exit() reaps
- * it to PROC_UNUSED. */
+/* Block the current process for `ms` milliseconds.  Marks it sleeping and
+ * yields to the scheduler; it is woken when its deadline passes. */
+void process_sleep_ms(unsigned int ms)
+{
+	procs[current_pid].wake_ms = get_ticks_ms() + ms;
+	procs[current_pid].state = PROC_SLEEPING;
+	__asm__ volatile ("sti");  /* re-enable IRQs so the PIT can switch us out */
+	while (procs[current_pid].state == PROC_SLEEPING)
+		cpu_idle();
+}
+
+/* Wait (yield) until the process with `pid` has exited. */
 void process_wait(unsigned int pid)
 {
 	while (process_is_alive(pid))
-		cpu_idle();
+		process_sleep_ms(10);
 }

+ 5 - 0
process.h

@@ -14,6 +14,7 @@
 #define PROC_READY   1
 #define PROC_RUNNING 2
 #define PROC_DEAD    3
+#define PROC_SLEEPING 4
 
 #define TIMESLICE_TICKS 20 /* context switch every 20 ms (PIT @ 1 kHz) */
 
@@ -30,6 +31,7 @@ struct process {
 	unsigned int stack_base;     /* page to free on exit, or 0 (bootstrap/fallback) */
 	unsigned int cr3;            /* physical address of this process's page dir */
 	unsigned int kstack_top;     /* ring-0 stack top (for TSS esp0) */
+	unsigned int wake_ms;        /* tick deadline when PROC_SLEEPING */
 };
 
 /* User-mode virtual address layout (ring-3 processes). */
@@ -57,4 +59,7 @@ int  process_kill(unsigned int pid);
 int  process_is_alive(unsigned int pid);
 void process_wait(unsigned int pid);
 
+/* Block the current process for `ms` milliseconds (yields the CPU). */
+void process_sleep_ms(unsigned int ms);
+
 #endif

+ 1 - 1
switch.S

@@ -27,7 +27,7 @@
 .equ PCB_ESP,   0
 .equ PCB_CR3,   32
 .equ PCB_KSTACK_TOP, 36
-.equ PCB_SIZE,  40      /* sizeof(struct process): 4+4+4+12+4+4+4+4 = 40 */
+.equ PCB_SIZE,  44      /* sizeof(struct process): 4+4+4+12+4+4+4+4+4 = 44 */
 
 .equ TIMESLICE, 20
 .equ FLUSH_INTERVAL, 33 /* 1000Hz PIT / 30Hz flush ≈ 33 ticks */

+ 2 - 8
syscall.c

@@ -1,7 +1,6 @@
 /* Syscall dispatcher: services int 0x80 requests from ring-3. */
 
 #include "syscall.h"
-#include "idle.h"
 #include "io.h"
 #include "process.h"
 #include "serial.h"
@@ -18,14 +17,9 @@ int syscall_dispatch(int num, int a1, int a2, int a3)
 		return 0;
 	case SYS_GET_TICKS_MS:
 		return (int)get_ticks_ms();
-	case SYS_SLEEP_MS: {
-		unsigned int start = get_ticks_ms();
-		unsigned int ms = (unsigned int)a1;
-		__asm__ volatile ("sti");  /* re-enable IRQs so hlt wakes on the PIT */
-		while (get_ticks_ms() - start < ms)
-			cpu_idle();
+	case SYS_SLEEP_MS:
+		process_sleep_ms((unsigned int)a1);
 		return 0;
-	}
 	case SYS_EXIT:
 		process_exit();   /* never returns */
 		return 0;

+ 2 - 3
terminal.c

@@ -3,7 +3,6 @@
 
 #include "io.h"
 #include "dbg.h"
-#include "idle.h"
 #include "kexec.h"
 #include "process.h"
 #include "terminal.h"
@@ -901,7 +900,7 @@ void term_run(struct term *t)
 				t->fg_pid = -1;
 				term_print_prompt(t, 0);
 			} else {
-				cpu_idle();
+				process_sleep_ms(10);
 			}
 			continue;
 		}
@@ -1159,7 +1158,7 @@ void term_run(struct term *t)
 				}
 			}
 		} else {
-			cpu_idle();
+			process_sleep_ms(10);
 		}
 	}
 }

+ 7 - 0
vga.c

@@ -499,6 +499,13 @@ void vga_fb_mark_dirty_rect(unsigned int y, unsigned int h)
 	mark_dirty_rect(y, h);
 }
 
+/* Mark rows dirty, limited to the horizontal span [x0, x1). */
+void vga_fb_mark_dirty_rect_xy(unsigned int y, unsigned int h,
+			       unsigned int x0, unsigned int x1)
+{
+	mark_dirty_rect_xy(y, h, x0, x1);
+}
+
 void vga_fb_clear_dirty(void)
 {
 	clear_dirty_rows();

+ 4 - 0
vga.h

@@ -60,6 +60,10 @@ int vga_shadow_is_active(void);
 /* Mark rows dirty for direct buffer manipulators (e.g. fbtext_scroll). */
 void vga_fb_mark_dirty_rect(unsigned int y, unsigned int h);
 
+/* Mark rows dirty, limited to the horizontal span [x0, x1). */
+void vga_fb_mark_dirty_rect_xy(unsigned int y, unsigned int h,
+			       unsigned int x0, unsigned int x1);
+
 /* Clear the dirty-row bitmap (so only explicitly re-marked rows get flushed). */
 void vga_fb_clear_dirty(void);
 

+ 8 - 2
wm.c

@@ -303,8 +303,14 @@ static void wm_drag_shadow(struct window *w, unsigned int ox, unsigned int oy,
 	else if (dx < 0)
 		wm_redraw_sliver(nx + w->pw, oy, (unsigned int)(-dx), w->ph);
 
-	/* Mark the swept band so the flush copies the moved window + sliver. */
-	vga_fb_mark_dirty_rect(y0, y1 - y0);
+	/* Mark the swept band so the flush copies the moved window + sliver.
+	   Limit the horizontal span to the window's swept x-range so the flush
+	   copies only ~pw columns instead of the full framebuffer width. */
+	{
+		unsigned int x0 = (ox < nx) ? ox : nx;
+		unsigned int x1 = ((ox > nx) ? ox : nx) + w->pw;
+		vga_fb_mark_dirty_rect_xy(y0, y1 - y0, x0, x1);
+	}
 	mouse_redraw_cursor();
 }