scc 2026.07
SystemC components library
global_time_keeper.h
1#ifndef __SCC_TLM_QK_GLOBAL_TIME_KEEPER_H__
2#define __SCC_TLM_QK_GLOBAL_TIME_KEEPER_H__
3
4#include "types.h"
5#include <deque>
6
7namespace tlm {
8namespace scc {
9namespace qk {
11//
22struct global_time_keeper {
23 friend class sc_time_syncronizer;
28 const sc_core::sc_time sc_time_step = 1_ms;
34 static global_time_keeper& get() {
35 static global_time_keeper keeper;
36 return keeper;
37 }
38
43 inline uint64_t get_client_min_time_ticks() { return client_min_time; }
50 inline uint64_t get_client_max_time_ticks(size_t idx) { return client_max_time; }
57 inline void update_client_time_ticks(size_t idx, uint64_t tick) {
58 client_coms_channels[idx].client2time_keeper.push(std::move(comms_entry{tick, std::move(callback_task())}));
59 update_it.store(true);
60 std::unique_lock<std::mutex> lk(upd_mtx);
61 update.notify_all();
62 }
63
70 inline void schedule_task(size_t idx, std::packaged_task<sc_core::sc_time(void)>&& task, uint64_t when) {
71 client_coms_channels[idx].client2time_keeper.push(std::move(comms_entry{when, std::move(task)}));
72 update_it.store(true);
73 std::unique_lock<std::mutex> lk(upd_mtx);
74 update.notify_all();
75 }
76
81 inline uint64_t get_sc_time_ticks() { return sc_kernel_time.load(); }
87 inline void update_sc_time_ticks(uint64_t tick) {
88 sc_coms_channel.client2time_keeper.push(std::move(comms_entry{tick, std::move(callback_task())}));
89 update_it.store(true);
90 std::unique_lock<std::mutex> lk(upd_mtx);
91 update.notify_all();
92 }
93
94protected:
96
98
100
102
103 void start();
104
105 size_t get_channel_index();
106
107 void sync_local_times();
108
109 std::atomic<bool> stop_it{false};
110 std::atomic<bool> update_it{false};
111 std::atomic_uint64_t client_min_time;
112 std::atomic_uint64_t client_max_time;
113 std::atomic_uint64_t sc_kernel_time;
114 std::mutex upd_mtx;
115 std::condition_variable update;
116 thread_comms_channel sc_coms_channel{-1ULL};
117 std::deque<thread_comms_channel> client_coms_channels;
119 bool started = false;
120};
121} // namespace qk
122} // namespace scc
123} // namespace tlm
124#endif // __SCC_TLM_QK_GLOBAL_TIME_KEEPER_H__
SCC TLM utilities.
Definition axis_tlm.h:56
SystemC TLM.
Definition dmi_mgr.h:19
Definition types.h:24
the global time keeper, a singleton
uint64_t get_client_max_time_ticks(size_t idx)
Get the maximum time ticks a client thread is allowed to advance.
void update_client_time_ticks(size_t idx, uint64_t tick)
updates the global time keeper with the local time ticks of a clinet thread
uint64_t get_sc_time_ticks()
Get the maximum sc time ticks a client thread is allowed to advance.
static global_time_keeper & get()
the singleton getter
void update_sc_time_ticks(uint64_t tick)
updates the global time keeper with the local time ticks of the SystemC thread
uint64_t get_client_min_time_ticks()
Get the minimum time ticks of all client threads (not SystemC).
void schedule_task(size_t idx, std::packaged_task< sc_core::sc_time(void)> &&task, uint64_t when)
updates the global time keeper with the local time ticks of a clinet thread and schedules a task at t...
const sc_core::sc_time sc_time_step
the maximum timestep the simulator is allowed to do if there are no future events