The Pedigree Project 0.1
kernel/machine/hosted/SchedulerTimer.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef KERNEL_MACHINE_HOSTED_SCHEDULERTIMER_H
21#define KERNEL_MACHINE_HOSTED_SCHEDULERTIMER_H
22#include "pedigree/kernel/machine/IrqManager.h"
23#include "pedigree/kernel/machine/SchedulerIrqHandler.h"
24#include "pedigree/kernel/machine/SchedulerTimer.h"
25#include "pedigree/kernel/machine/SchedulerTimerHandlerSlot.h"
26#include "pedigree/kernel/processor/IoPort.h"
27#include "pedigree/kernel/processor/state.h"
28
29#include <config.h>
30
31#include "TickSource.h"
32
37 public:
39 inline static HostedSchedulerTimer& instance() {
40 return m_Instance;
41 }
42
43 //
44 // SchedulerTimer interface
45 //
46 virtual bool registerHandler(SchedulerTimerHandler* handler);
47 uint64_t nominalQuantumNs() const override;
48
49 virtual bool removeHandler(SchedulerTimerHandler* handler);
50
55 void uninitialise();
56
57#if HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS
58 using HardContextHook = void (*)(uint64_t, InterruptState&);
59
61 static EXPORTED_PUBLIC void setHardContextHookForTest(HardContextHook hook);
63 static EXPORTED_PUBLIC uintptr_t sourceForTest();
65 static EXPORTED_PUBLIC SchedulerTimerHandler* publishedHandlerForTest();
67 static EXPORTED_PUBLIC size_t activeDispatchesForTest();
69 static EXPORTED_PUBLIC bool directRoutePublishedForTest();
71 static EXPORTED_PUBLIC bool queueTickForTest();
72#endif
73
74 protected:
78 virtual ~HostedSchedulerTimer();
79
80 private:
87
88 //
89 // SchedulerIrqHandler interface
90 //
91 virtual void schedulerIrq(irq_id_t number, InterruptState& state);
92
93 irq_id_t m_IrqId;
94 HostedTickSource m_TickSource;
95
98
99 bool m_bInitialized;
100
101#if HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS
102 static HardContextHook m_HardContextHook;
103#endif
104
107};
108
111#endif
HostedSchedulerTimer() INITIALISATION_ONLY
bool initialise() INITIALISATION_ONLY
virtual bool registerHandler(SchedulerTimerHandler *handler)
virtual bool removeHandler(SchedulerTimerHandler *handler)
static HostedSchedulerTimer & instance()