From 1c64a7fda11beb70fbe6662ed517cecde1c1b581 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 15 May 2013 00:45:04 +0200 Subject: [PATCH] Maintain process execution and system time. --- sortix/include/sortix/kernel/process.h | 2 ++ sortix/include/sortix/kernel/time.h | 4 +++- sortix/process.cpp | 2 ++ sortix/time.cpp | 7 ++++++- sortix/x86-family/time.cpp | 14 ++++++++++++-- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/sortix/include/sortix/kernel/process.h b/sortix/include/sortix/kernel/process.h index 988602d1..376e06b3 100644 --- a/sortix/include/sortix/kernel/process.h +++ b/sortix/include/sortix/kernel/process.h @@ -145,6 +145,8 @@ public: kthread_mutex_t user_timers_lock; UserTimer user_timers[PROCESS_TIMER_NUM_MAX]; Timer alarm_timer; + Clock execute_clock; + Clock system_clock; public: int Execute(const char* programname, const uint8_t* program, diff --git a/sortix/include/sortix/kernel/time.h b/sortix/include/sortix/kernel/time.h index f16b71bf..03c67573 100644 --- a/sortix/include/sortix/kernel/time.h +++ b/sortix/include/sortix/kernel/time.h @@ -35,6 +35,7 @@ namespace Sortix { class Clock; +class Process; } // namespace Sortix namespace Sortix { @@ -42,7 +43,8 @@ namespace Time { void Init(); void Start(); -void OnTick(struct timespec tick_period); +void OnTick(struct timespec tick_period, bool system_mode); +void InitializeProcessClocks(Process* process); struct timespec Get(clockid_t clock); Clock* GetClock(clockid_t clock); diff --git a/sortix/process.cpp b/sortix/process.cpp index cf79dfde..450b0687 100644 --- a/sortix/process.cpp +++ b/sortix/process.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -130,6 +131,7 @@ namespace Sortix pid = AllocatePID(); uid = euid = 0; gid = egid = 0; + Time::InitializeProcessClocks(this); alarm_timer.Attach(Time::GetClock(CLOCK_MONOTONIC)); Put(this); } diff --git a/sortix/time.cpp b/sortix/time.cpp index e0f578f1..090203b6 100644 --- a/sortix/time.cpp +++ b/sortix/time.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -76,10 +77,14 @@ struct timespec Get(clockid_t clockid) return timespec_nul(); } -void OnTick(struct timespec tick_period) +void OnTick(struct timespec tick_period, bool system_mode) { realtime_clock->Advance(tick_period); uptime_clock->Advance(tick_period); + Process* process = CurrentProcess(); + process->execute_clock.Advance(tick_period); + if ( system_mode ) + process->system_clock.Advance(tick_period); } void Init() diff --git a/sortix/x86-family/time.cpp b/sortix/x86-family/time.cpp index 258fdc0b..9596a4ae 100644 --- a/sortix/x86-family/time.cpp +++ b/sortix/x86-family/time.cpp @@ -30,10 +30,11 @@ #include #include +#include #include +#include #include #include -#include namespace Sortix { namespace Time { @@ -78,7 +79,7 @@ static uint16_t tick_divisor; static void OnIRQ0(CPU::InterruptRegisters* regs, void* /*user*/) { - OnTick(tick_period); + OnTick(tick_period, !regs->InUserspace()); Scheduler::Switch(regs); // TODO: There is a horrible bug that causes Sortix to only receive @@ -108,6 +109,15 @@ void CPUInit() uptime_clock->Set(&nul_time, &tick_period); } +void InitializeProcessClocks(Process* process) +{ + struct timespec nul_time = timespec_nul(); + process->execute_clock.SetCallableFromInterrupts(true); + process->execute_clock.Set(&nul_time, &tick_period); + process->system_clock.SetCallableFromInterrupts(true); + process->system_clock.Set(&nul_time, &tick_period); +} + void Start() { // Handle timer interrupts if they arrive.