quic/qbox
Loading...
Searching...
No Matches
qkmulti-rolling.h
1/*
2 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 * Author: GreenSocs 2022
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef QKMULTI_ROLLING_H
9#define QKMULTI_ROLLING_H
10
11#ifndef SC_INCLUDE_DYNAMIC_PROCESSES
12#define SC_INCLUDE_DYNAMIC_PROCESSES
13#endif
14
15#include <systemc>
16
17#include <scp/report.h>
18
19#include <qkmulti-quantum.h>
20#include <semaphore.h>
21#include <libgsutils.h>
22
23namespace gs {
25{
26private:
27 async_event m_time_ev;
28 sc_core::sc_time m_next_time;
29 semaphore m_sem;
30
31 sc_core::sc_time get_next_time()
32 {
33 if (status != RUNNING) return sc_core::SC_ZERO_TIME;
34
35 sc_core::sc_time quantum = tlm_utils::tlm_quantumkeeper::get_global_quantum();
36 sc_core::sc_time next_event = sc_core::sc_time_to_pending_activity();
37 sc_core::sc_time quantum_boundary = sc_core::sc_time_stamp() + quantum - get_current_time();
38 if (sc_core::sc_pending_activity_at_current_time()) {
39 SCP_INFO("Libgssync") << "Pending activity now returning SC_ZERO_TIME";
40 m_tick.notify();
41 return sc_core::SC_ZERO_TIME;
42 } else if (sc_core::sc_pending_activity_at_future_time()) {
43 sc_core::sc_time ret = std::min(next_event, quantum_boundary);
44 SCP_INFO("Libgssync") << "Pending activity returning " << ret.to_string();
45 return ret;
46 } else {
47 SCP_INFO("Libgssync") << "No pending activity returning quantum boundary " << quantum_boundary.to_string();
48 return quantum_boundary;
49 }
50 }
51
52 void get_time_from_systemc()
53 {
54 m_next_time = get_next_time();
55 m_sem.notify();
56 }
57
58 virtual sc_core::sc_time time_to_sync() override
59 {
60 if (is_sysc_thread())
61 return get_next_time();
62 else {
63 m_time_ev.notify();
64 m_sem.wait();
65 return m_next_time;
66 }
67 }
68
69public:
70 tlm_quantumkeeper_multi_rolling(): m_time_ev(false)
71 {
72 sc_core::sc_spawn_options opt;
73 opt.spawn_method();
74 opt.set_sensitivity(&m_time_ev);
75 opt.dont_initialize();
76 sc_core::sc_spawn(sc_bind(&tlm_quantumkeeper_multi_rolling::get_time_from_systemc, this), "get_time_from_sysc",
77 &opt);
78 }
79};
80} // namespace gs
81#endif // QKMULTI_ROLLING_H
Definition target.h:160
Definition async_event.h:22
Definition semaphore.h:17
Definition qkmulti-quantum.h:15
Definition qkmulti-rolling.h:25
Tool which reads a Lua configuration file and sets parameters.
Definition biflow.cc:10