mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Implement CLOCK_THREAD_CPUTIME_ID and CLOCK_THREAD_SYSTIME_ID.
This commit is contained in:
parent
af9cc8ed05
commit
ff8b2be515
6 changed files with 28 additions and 3 deletions
|
@ -32,6 +32,7 @@
|
||||||
#include <sortix/sigset.h>
|
#include <sortix/sigset.h>
|
||||||
#include <sortix/stack.h>
|
#include <sortix/stack.h>
|
||||||
|
|
||||||
|
#include <sortix/kernel/clock.h>
|
||||||
#include <sortix/kernel/kthread.h>
|
#include <sortix/kernel/kthread.h>
|
||||||
#include <sortix/kernel/registers.h>
|
#include <sortix/kernel/registers.h>
|
||||||
#include <sortix/kernel/scheduler.h>
|
#include <sortix/kernel/scheduler.h>
|
||||||
|
@ -83,6 +84,8 @@ public:
|
||||||
bool kernelstackmalloced;
|
bool kernelstackmalloced;
|
||||||
bool pledged_destruction;
|
bool pledged_destruction;
|
||||||
bool force_no_signals;
|
bool force_no_signals;
|
||||||
|
Clock execute_clock;
|
||||||
|
Clock system_clock;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void HandleSignal(struct interrupt_context* intctx);
|
void HandleSignal(struct interrupt_context* intctx);
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
namespace Sortix {
|
namespace Sortix {
|
||||||
class Clock;
|
class Clock;
|
||||||
class Process;
|
class Process;
|
||||||
|
class Thread;
|
||||||
} // namespace Sortix
|
} // namespace Sortix
|
||||||
|
|
||||||
namespace Sortix {
|
namespace Sortix {
|
||||||
|
@ -42,6 +43,7 @@ void Init();
|
||||||
void Start();
|
void Start();
|
||||||
void OnTick(struct timespec tick_period, bool system_mode);
|
void OnTick(struct timespec tick_period, bool system_mode);
|
||||||
void InitializeProcessClocks(Process* process);
|
void InitializeProcessClocks(Process* process);
|
||||||
|
void InitializeThreadClocks(Thread* thread);
|
||||||
struct timespec Get(clockid_t clock);
|
struct timespec Get(clockid_t clock);
|
||||||
Clock* GetClock(clockid_t clock);
|
Clock* GetClock(clockid_t clock);
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,6 @@ Process::Process()
|
||||||
// alarm_timer initialized in member constructor.
|
// alarm_timer initialized in member constructor.
|
||||||
// execute_clock initialized in member constructor.
|
// execute_clock initialized in member constructor.
|
||||||
// system_clock initialized in member constructor.
|
// system_clock initialized in member constructor.
|
||||||
// execute_clock initialized in member constructor.
|
|
||||||
// child_execute_clock initialized in member constructor.
|
// child_execute_clock initialized in member constructor.
|
||||||
// child_system_clock initialized in member constructor.
|
// child_system_clock initialized in member constructor.
|
||||||
Time::InitializeProcessClocks(this);
|
Time::InitializeProcessClocks(this);
|
||||||
|
|
|
@ -97,6 +97,9 @@ Thread::Thread()
|
||||||
sigemptyset(&signal_mask);
|
sigemptyset(&signal_mask);
|
||||||
memset(&signal_stack, 0, sizeof(signal_stack));
|
memset(&signal_stack, 0, sizeof(signal_stack));
|
||||||
signal_stack.ss_flags = SS_DISABLE;
|
signal_stack.ss_flags = SS_DISABLE;
|
||||||
|
// execute_clock initialized in member constructor.
|
||||||
|
// system_clock initialized in member constructor.
|
||||||
|
Time::InitializeThreadClocks(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread::~Thread()
|
Thread::~Thread()
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include <sortix/kernel/process.h>
|
#include <sortix/kernel/process.h>
|
||||||
#include <sortix/kernel/scheduler.h>
|
#include <sortix/kernel/scheduler.h>
|
||||||
#include <sortix/kernel/syscall.h>
|
#include <sortix/kernel/syscall.h>
|
||||||
|
#include <sortix/kernel/thread.h>
|
||||||
#include <sortix/kernel/time.h>
|
#include <sortix/kernel/time.h>
|
||||||
|
|
||||||
namespace Sortix {
|
namespace Sortix {
|
||||||
|
@ -59,6 +60,8 @@ Clock* GetClock(clockid_t clock)
|
||||||
case CLOCK_PROCESS_SYSTIME_ID: return &CurrentProcess()->system_clock;
|
case CLOCK_PROCESS_SYSTIME_ID: return &CurrentProcess()->system_clock;
|
||||||
case CLOCK_CHILD_CPUTIME_ID: return &CurrentProcess()->child_execute_clock;
|
case CLOCK_CHILD_CPUTIME_ID: return &CurrentProcess()->child_execute_clock;
|
||||||
case CLOCK_CHILD_SYSTIME_ID: return &CurrentProcess()->child_system_clock;
|
case CLOCK_CHILD_SYSTIME_ID: return &CurrentProcess()->child_system_clock;
|
||||||
|
case CLOCK_THREAD_CPUTIME_ID: return &CurrentThread()->execute_clock;
|
||||||
|
case CLOCK_THREAD_SYSTIME_ID: return &CurrentThread()->system_clock;
|
||||||
default: return errno = ENOTSUP, (Clock*) NULL;
|
default: return errno = ENOTSUP, (Clock*) NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,12 +82,17 @@ 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();
|
Thread* thread = CurrentThread();
|
||||||
|
Process* process = thread->process;
|
||||||
|
thread->execute_clock.Advance(tick_period);
|
||||||
process->execute_clock.Advance(tick_period);
|
process->execute_clock.Advance(tick_period);
|
||||||
process->child_execute_clock.Advance(tick_period);
|
process->child_execute_clock.Advance(tick_period);
|
||||||
if ( system_mode )
|
if ( system_mode )
|
||||||
process->system_clock.Advance(tick_period),
|
{
|
||||||
|
thread->system_clock.Advance(tick_period);
|
||||||
|
process->system_clock.Advance(tick_period);
|
||||||
process->child_system_clock.Advance(tick_period);
|
process->child_system_clock.Advance(tick_period);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <sortix/kernel/kernel.h>
|
#include <sortix/kernel/kernel.h>
|
||||||
#include <sortix/kernel/process.h>
|
#include <sortix/kernel/process.h>
|
||||||
#include <sortix/kernel/scheduler.h>
|
#include <sortix/kernel/scheduler.h>
|
||||||
|
#include <sortix/kernel/thread.h>
|
||||||
#include <sortix/kernel/time.h>
|
#include <sortix/kernel/time.h>
|
||||||
|
|
||||||
namespace Sortix {
|
namespace Sortix {
|
||||||
|
@ -125,6 +126,15 @@ void InitializeProcessClocks(Process* process)
|
||||||
process->child_system_clock.SetCallableFromInterrupts(true);
|
process->child_system_clock.SetCallableFromInterrupts(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InitializeThreadClocks(Thread* thread)
|
||||||
|
{
|
||||||
|
struct timespec nul_time = timespec_nul();
|
||||||
|
thread->execute_clock.SetCallableFromInterrupts(true);
|
||||||
|
thread->execute_clock.Set(&nul_time, &tick_period);
|
||||||
|
thread->system_clock.SetCallableFromInterrupts(true);
|
||||||
|
thread->system_clock.Set(&nul_time, &tick_period);
|
||||||
|
}
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
// Handle timer interrupts if they arrive.
|
// Handle timer interrupts if they arrive.
|
||||||
|
|
Loading…
Add table
Reference in a new issue