Maintain process execution and system time.
This commit is contained in:
parent
dbe8dafaac
commit
1c64a7fda1
|
@ -145,6 +145,8 @@ public:
|
||||||
kthread_mutex_t user_timers_lock;
|
kthread_mutex_t user_timers_lock;
|
||||||
UserTimer user_timers[PROCESS_TIMER_NUM_MAX];
|
UserTimer user_timers[PROCESS_TIMER_NUM_MAX];
|
||||||
Timer alarm_timer;
|
Timer alarm_timer;
|
||||||
|
Clock execute_clock;
|
||||||
|
Clock system_clock;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int Execute(const char* programname, const uint8_t* program,
|
int Execute(const char* programname, const uint8_t* program,
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
namespace Sortix {
|
namespace Sortix {
|
||||||
class Clock;
|
class Clock;
|
||||||
|
class Process;
|
||||||
} // namespace Sortix
|
} // namespace Sortix
|
||||||
|
|
||||||
namespace Sortix {
|
namespace Sortix {
|
||||||
|
@ -42,7 +43,8 @@ namespace Time {
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void Start();
|
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);
|
struct timespec Get(clockid_t clock);
|
||||||
Clock* GetClock(clockid_t clock);
|
Clock* GetClock(clockid_t clock);
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include <sortix/kernel/scheduler.h>
|
#include <sortix/kernel/scheduler.h>
|
||||||
#include <sortix/kernel/process.h>
|
#include <sortix/kernel/process.h>
|
||||||
#include <sortix/kernel/thread.h>
|
#include <sortix/kernel/thread.h>
|
||||||
|
#include <sortix/kernel/time.h>
|
||||||
|
|
||||||
#include <sortix/clock.h>
|
#include <sortix/clock.h>
|
||||||
#include <sortix/signal.h>
|
#include <sortix/signal.h>
|
||||||
|
@ -130,6 +131,7 @@ namespace Sortix
|
||||||
pid = AllocatePID();
|
pid = AllocatePID();
|
||||||
uid = euid = 0;
|
uid = euid = 0;
|
||||||
gid = egid = 0;
|
gid = egid = 0;
|
||||||
|
Time::InitializeProcessClocks(this);
|
||||||
alarm_timer.Attach(Time::GetClock(CLOCK_MONOTONIC));
|
alarm_timer.Attach(Time::GetClock(CLOCK_MONOTONIC));
|
||||||
Put(this);
|
Put(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <sortix/kernel/copy.h>
|
#include <sortix/kernel/copy.h>
|
||||||
#include <sortix/kernel/interrupt.h>
|
#include <sortix/kernel/interrupt.h>
|
||||||
#include <sortix/kernel/clock.h>
|
#include <sortix/kernel/clock.h>
|
||||||
|
#include <sortix/kernel/process.h>
|
||||||
#include <sortix/kernel/time.h>
|
#include <sortix/kernel/time.h>
|
||||||
#include <sortix/kernel/scheduler.h>
|
#include <sortix/kernel/scheduler.h>
|
||||||
|
|
||||||
|
@ -76,10 +77,14 @@ struct timespec Get(clockid_t clockid)
|
||||||
return timespec_nul();
|
return timespec_nul();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnTick(struct timespec tick_period)
|
void OnTick(struct timespec tick_period, bool system_mode)
|
||||||
{
|
{
|
||||||
realtime_clock->Advance(tick_period);
|
realtime_clock->Advance(tick_period);
|
||||||
uptime_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()
|
void Init()
|
||||||
|
|
|
@ -30,10 +30,11 @@
|
||||||
|
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include <sortix/kernel/clock.h>
|
#include <sortix/kernel/clock.h>
|
||||||
|
#include <sortix/kernel/cpu.h>
|
||||||
#include <sortix/kernel/interrupt.h>
|
#include <sortix/kernel/interrupt.h>
|
||||||
|
#include <sortix/kernel/process.h>
|
||||||
#include <sortix/kernel/scheduler.h>
|
#include <sortix/kernel/scheduler.h>
|
||||||
#include <sortix/kernel/time.h>
|
#include <sortix/kernel/time.h>
|
||||||
#include <sortix/kernel/cpu.h>
|
|
||||||
|
|
||||||
namespace Sortix {
|
namespace Sortix {
|
||||||
namespace Time {
|
namespace Time {
|
||||||
|
@ -78,7 +79,7 @@ static uint16_t tick_divisor;
|
||||||
|
|
||||||
static void OnIRQ0(CPU::InterruptRegisters* regs, void* /*user*/)
|
static void OnIRQ0(CPU::InterruptRegisters* regs, void* /*user*/)
|
||||||
{
|
{
|
||||||
OnTick(tick_period);
|
OnTick(tick_period, !regs->InUserspace());
|
||||||
Scheduler::Switch(regs);
|
Scheduler::Switch(regs);
|
||||||
|
|
||||||
// TODO: There is a horrible bug that causes Sortix to only receive
|
// 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);
|
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()
|
void Start()
|
||||||
{
|
{
|
||||||
// Handle timer interrupts if they arrive.
|
// Handle timer interrupts if they arrive.
|
||||||
|
|
Loading…
Reference in New Issue