disable fxsave temporarily and fix preempt frequency being too high

emulators just spend all their time in the timer routine...
This commit is contained in:
2023-10-19 17:33:09 +02:00
parent 12ee6f929a
commit 167eb32caf
4 changed files with 24 additions and 28 deletions

View File

@@ -294,28 +294,22 @@ void switch_task(struct task_frame *cur_frame) {
}
void switch_task_int(struct task_frame *cur_frame) {
static uint64_t lastSwitchMicros = 0;
uint64_t curMicros = micros;
assert2(!are_interrupts_enabled(), "Switching tasks with enabled interrupts!");
if ((curMicros - lastSwitchMicros) > 1) {
struct TaskListNode *node = WaitingTasks.cur;
struct TaskListNode *node = WaitingTasks.cur;
while (node) {
if (node->task->sleep_until <= curMicros && node->task->state == TS_TO_SLEEP) {
assert2(node->task->sleep_until, "Sleeping until 0?");
node->task->sleep_until = 0;
node->task->state = TS_RUNNING;
append_task_node(&NextTasks, pop_front_node(&WaitingTasks));
node = WaitingTasks.cur;
} else {
break;
}
while (node) {
if (node->task->sleep_until <= micros && node->task->state == TS_TO_SLEEP) {
assert2(node->task->sleep_until, "Sleeping until 0?");
node->task->sleep_until = 0;
node->task->state = TS_RUNNING;
append_task_node(&NextTasks, pop_front_node(&WaitingTasks));
node = WaitingTasks.cur;
} else {
break;
}
switch_task(cur_frame);
lastSwitchMicros = curMicros;
}
switch_task(cur_frame);
}
void wait_m_on_self(struct Mutex *m) {

View File

@@ -1,5 +1,10 @@
[BITS 64]
; =!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!
; FIXME: CMake doesn't detect changes to this file!
; OBJECT_DEPENDS also doesn't seem to work...
; =!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!
; TODO: This is probably not enough
%macro pushaq 0
push rax
@@ -25,8 +30,8 @@
add rsi, 32
mov rdi, 0xFFFFFFFFFFFFFFF0
and rsi, rdi
fxsave [rsi]
; TODO: Fix!!
; fxsave [rsi]
%endmacro
%macro popaq 0
@@ -38,7 +43,7 @@
mov rdi, 0xFFFFFFFFFFFFFFF0
and rsi, rdi
fxrstor [rsi]
; fxrstor [rsi]
add rsp, 512
pop r15

View File

@@ -9,7 +9,6 @@
volatile uint64_t ticks;
volatile uint64_t micros;
volatile uint64_t millis;
unsigned read_pit_count(void) {
unsigned count = 0;
@@ -37,9 +36,10 @@ void set_pit_count(unsigned count) {
}
// Very rough but I don't care right now
#define RELOAD_VAL 2
#define FREQ = (1193182 / (RELOAD_VAL))
#define MICROS_PER_TICK 1
// About 1000 HZ freq
#define RELOAD_VAL 1193
#define FREQ (1193182 / (RELOAD_VAL))
#define MICROS_PER_TICK (1000000 / (FREQ))
void init_timer() {
outb(0x43, 0b00110100);
@@ -50,6 +50,4 @@ void init_timer() {
void timer_tick() {
ticks++;
micros += MICROS_PER_TICK;
if (micros % 1000 == 0)
millis++;
}

View File

@@ -9,7 +9,6 @@
extern volatile uint64_t ticks;
extern volatile uint64_t micros;
extern volatile uint64_t millis;
void init_timer();
void timer_tick();