mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Maintain process execution and system time.
This commit is contained in:
parent
dbe8dafaac
commit
1c64a7fda1
5 changed files with 25 additions and 4 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <sortix/kernel/scheduler.h>
|
||||
#include <sortix/kernel/process.h>
|
||||
#include <sortix/kernel/thread.h>
|
||||
#include <sortix/kernel/time.h>
|
||||
|
||||
#include <sortix/clock.h>
|
||||
#include <sortix/signal.h>
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <sortix/kernel/copy.h>
|
||||
#include <sortix/kernel/interrupt.h>
|
||||
#include <sortix/kernel/clock.h>
|
||||
#include <sortix/kernel/process.h>
|
||||
#include <sortix/kernel/time.h>
|
||||
#include <sortix/kernel/scheduler.h>
|
||||
|
||||
|
@ -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()
|
||||
|
|
|
@ -30,10 +30,11 @@
|
|||
|
||||
#include <sortix/kernel/platform.h>
|
||||
#include <sortix/kernel/clock.h>
|
||||
#include <sortix/kernel/cpu.h>
|
||||
#include <sortix/kernel/interrupt.h>
|
||||
#include <sortix/kernel/process.h>
|
||||
#include <sortix/kernel/scheduler.h>
|
||||
#include <sortix/kernel/time.h>
|
||||
#include <sortix/kernel/cpu.h>
|
||||
|
||||
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.
|
||||
|
|
Loading…
Add table
Reference in a new issue