aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMarvin Borner2021-04-27 23:01:51 +0200
committerMarvin Borner2021-04-27 23:01:51 +0200
commit51a80930a9bc25fae0728994cab1e0df3b63ef48 (patch)
treee08c4f8fdc3a73cca3a291ab901c2bcf6dac453e /kernel
parent977e62973abda3dd9fe5cb3462fc87d273ba63e3 (diff)
Huge compositor, timer and yielding improvements
Diffstat (limited to 'kernel')
-rw-r--r--kernel/drivers/rtc.c2
-rw-r--r--kernel/drivers/timer.c18
-rw-r--r--kernel/features/io.c6
-rw-r--r--kernel/features/proc.c11
-rw-r--r--kernel/inc/proc.h1
5 files changed, 33 insertions, 5 deletions
diff --git a/kernel/drivers/rtc.c b/kernel/drivers/rtc.c
index 01d65f4..2da61da 100644
--- a/kernel/drivers/rtc.c
+++ b/kernel/drivers/rtc.c
@@ -66,6 +66,6 @@ struct rtc rtc_read(void)
u32 rtc_stamp(void)
{
struct rtc rtc = rtc_read();
- return timer_get() + rtc.second + rtc.minute * 60 + rtc.hour * 360 + rtc.day * 360 * 24 +
+ return rtc.second + rtc.minute * 60 + rtc.hour * 360 + rtc.day * 360 * 24 +
rtc.year * 360 * 24 * 365;
}
diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c
index 294df84..176b499 100644
--- a/kernel/drivers/timer.c
+++ b/kernel/drivers/timer.c
@@ -57,14 +57,26 @@ CLEAR void scheduler_disable(void)
irq_install_handler(0, timer_handler);
}
+static struct timer timer_struct(void)
+{
+ struct proc *proc = proc_current();
+ struct timer timer = {
+ .rtc = rtc_stamp(),
+ .ticks.user = proc->ticks.user,
+ .ticks.kernel = proc->ticks.kernel,
+ .time = timer_get(),
+ };
+ return timer;
+}
+
static res timer_read(void *buf, u32 offset, u32 count)
{
UNUSED(offset);
- u32 stamp = rtc_stamp();
- memcpy_user(buf, &stamp, MIN(count, sizeof(stamp)));
+ struct timer timer = timer_struct();
+ memcpy_user(buf, &timer, MIN(count, sizeof(timer)));
- return MIN(count, sizeof(stamp));
+ return MIN(count, sizeof(timer));
}
// Install timer handler into IRQ0
diff --git a/kernel/features/io.c b/kernel/features/io.c
index da179ab..ac599e2 100644
--- a/kernel/features/io.c
+++ b/kernel/features/io.c
@@ -182,6 +182,9 @@ void io_unblock(enum io_type io)
free(listener);
iterator = next;
}
+
+ if (proc_idle())
+ proc_yield();
}
void io_unblock_pid(u32 pid)
@@ -200,6 +203,9 @@ void io_unblock_pid(u32 pid)
iterator = next;
}
}
+
+ if (proc_idle())
+ proc_yield();
}
CLEAR void io_install(struct boot_info *boot)
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index b47df0b..70f2efc 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -91,6 +91,15 @@ u8 proc_super(void)
return 0; // Should never happen
}
+u8 proc_idle(void)
+{
+ struct proc *proc = proc_current();
+ if (proc)
+ return proc == idle_proc->data;
+ else
+ return 0;
+}
+
struct proc *proc_from_pid(u32 pid)
{
struct node *iterator = NULL;
@@ -144,7 +153,6 @@ void proc_exit(struct proc *proc, struct regs *r, s32 status)
if (!running || !list_remove(proc_list_running, running)) {
struct node *blocked = list_first_data(proc_list_blocked, proc);
assert(blocked && list_remove(proc_list_blocked, blocked));
- // Idle procs can't be killed -> assertion failure.
}
if (current->data == proc) {
@@ -182,6 +190,7 @@ void proc_exit(struct proc *proc, struct regs *r, s32 status)
void proc_yield(void)
{
+ // TODO: Fix yielding without debug mode (File size?! Regs?! IDK?!)
proc_reset_quantum(PROC(current));
__asm__ volatile("int $127");
}
diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h
index 5b8fbea..877e53e 100644
--- a/kernel/inc/proc.h
+++ b/kernel/inc/proc.h
@@ -61,6 +61,7 @@ void proc_init(void);
void proc_print(void);
struct proc *proc_current(void);
u8 proc_super(void);
+u8 proc_idle(void);
struct proc *proc_from_pid(u32 pid);
void proc_exit(struct proc *proc, struct regs *r, s32 status) NONNULL;
void proc_yield(void);