TEMU  4.4
The Terma Emulator
Scheduler.h
Go to the documentation of this file.
1 //===-- temu-c/Scheduler.h - TEMU Scheduler API -----------------*- C++ -*-===//
2 //
3 // TEMU: The Terma Emulator
4 // (c) Terma 2023
5 // Authors: Mattias Holm <maho (at) terma.com>
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef TEMU_SCHEDULER_H
9 #define TEMU_SCHEDULER_H
10 #include <stdint.h>
11 #include "temu-c/Support/Attributes.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 typedef struct temu_TimeSource temu_TimeSource;
18 typedef struct temu_Object temu_Object;
19 
20 typedef enum temu_ExecutionState {
24 } temu_ExecutionState;
25 
26 
27 /*!
28  * Run the current scheduler for a fixed number of steps
29  *
30  * \param steps Time in steps (in scheduler units).
31  */
33 
34 
35 /*!
36  * Run the current scheduler for a fixed time
37  *
38  * \param secs Time in simulated seconds
39  */
40 TEMU_API void temu_runForTime(double secs);
41 
42 /*!
43  * Run the current scheduler forever
44  */
45 TEMU_API void temu_run();
46 
47 /*!
48  * Step a processor in the current scheduler
49  *
50  * Note that, the other processors may run if the step exceeds the quanta.
51  * The step function currently runs processors in sequence,
52  * it is not running processors in parallel.
53  * This means that stepping is always deterministic.
54  *
55  * \param cpu The processor to step
56  * \param steps The number of steps or instructions to execute
57  */
59 
60 /*!
61  * Stop the current scheduler
62  *
63  * The function signals the scheduler to stop,
64  * and then waits until the scheduler is in the stopped state.
65  */
66 TEMU_API void temu_stop();
67 /*!
68  * Stop the current scheduler
69  *
70  * The function returns immediately, before the scheduler has stopped.
71  * The function is suitable for use in e.g. signal handlers.
72  */
74 
75 /*!
76  * Get the current execution status of TEMU
77  *
78  * \result Current execution status
79  */
80 
81 TEMU_API temu_ExecutionState temu_getExecutionState();
82 
83 /*!
84  * Get the number of processors in the global scheduler.
85  *
86  * \result Number of processors in global scheduler.
87  */
89 
90 /*!
91  * Get processor in global scheduler
92  * \param cpu Processor number to get
93  * \result Processor pointer as a time source.
94  */
95 TEMU_API temu_TimeSource* temu_getScheduledProcessor(unsigned cpu);
96 
97 /*!
98  * Serialize execution for some time when notification is triggered
99  * \param notificationSource Object emitting notification.
100  * \param notificationName Name of notification to intercept.
101  * \param seconds Number of seconds (simulated time, for which to serialize execution).
102  */
103 TEMU_API void
105  const char *notificationName, double seconds);
106 
107 
108 /*!
109  * Experimental function to get the accumulated nanoseconds for the scheduler.
110  *
111  * To enable sampling the Scheduler-object's `measureTime` property must be set.
112  * \result Accumulated nanoseconds of which temu_run* functions have run.
113  */
114 TEMU_API uint64_t temu_schedulerGetAccumulatedTime();
115 /*!
116  * Experimental function to get the accumulated nanoseconds
117  * for the scheduler synchronization.
118  *
119  * To enable sampling, the Scheduler-object's `measureTime` property must be set.
120  * \result Accumulated nanoseconds of which synchronisation code was run.
121  */
122 TEMU_API uint64_t temu_schedulerGetSyncTime(unsigned threadId);
123 
124 /*!
125  * Experimental function to get the accumulated nanoseconds
126  * for the scheduler barrier waits.
127  *
128  * The wait time, includes both the actual barrier and the synchronization time.
129  *
130  * So the true wait time is the wait - sync time.
131  *
132  * To enable sampling, the Scheduler-object's `measureTime` property must be set.
133  * \result Accumulated nanoseconds of which the wait was run.
134  */
135 TEMU_API uint64_t temu_schedulerGetWaitTime(unsigned threadId);
136 
137 /*!
138  * Experimental function to set thread affinity for the scheduler.
139  *
140  * The function should be called before setting the number of threads,
141  * as threads automatically set the affinity if the hostCore is zero or above.
142  *
143  * \param threadId Thread ID starting with 0 to the number of threads
144  * set for the scheduler.
145  * \param hostCore Host core id to bind thread to. Negative to not set affintity.
146  */
148 
149 /*!
150  * Experimental function to get the thread affinity for the scheduler.
151  *
152  * \param threadId Thread ID starting with 0 to the number of threads
153  * set for the scheduler.
154  * \result Affinity value, -1 implies not set. Other values indicate HOST CPUID.
155  */
156 TEMU_API int64_t temu_schedulerGetAffinity(unsigned threadId);
157 
158 
159 #ifdef __cplusplus
160 } // extern c
161 #endif
162 
163 #endif /* ! TEMU_REGISTER_H */
temu_run
TEMU_API void temu_run()
temu_step
TEMU_API void temu_step(temu_TimeSource *cpu, int steps)
temu_runForTime
TEMU_API void temu_runForTime(double secs)
temu_getScheduledProcessorCount
TEMU_API unsigned temu_getScheduledProcessorCount()
temu_ExecutionState
temu_ExecutionState
Definition: Scheduler.h:20
temu_stop
TEMU_API void temu_stop()
teES_Stopped
@ teES_Stopped
Definition: Scheduler.h:21
temu_schedulerSetAffinity
TEMU_API void temu_schedulerSetAffinity(unsigned threadId, int hostCore)
temu_serializeOnNotification
TEMU_API void temu_serializeOnNotification(temu_Object *notificationSource, const char *notificationName, double seconds)
teES_Running
@ teES_Running
Definition: Scheduler.h:22
teES_Stepping
@ teES_Stepping
Definition: Scheduler.h:23
temu_Object
struct temu_Object temu_Object
Definition: Scheduler.h:18
temu_asyncStop
TEMU_API void temu_asyncStop()
temu_TimeSource
struct temu_TimeSource temu_TimeSource
Definition: Scheduler.h:17
temu_runForSteps
TEMU_API void temu_runForSteps(int64_t steps)