gem5  v22.0.0.1
tlm_quantumkeeper.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 #ifndef __SYSTEMC_EXT_TLM_UTILS_TLM_QUANTUMKEEPER_H__
21 #define __SYSTEMC_EXT_TLM_UTILS_TLM_QUANTUMKEEPER_H__
22 
23 #include "../core/sc_time.hh"
24 
25 namespace tlm_utils
26 {
27 
28 // tlm_quantumkeeper class
29 //
30 // The tlm_quantumkeeper class is used to keep track of the local time in
31 // an initiator (how much it has run ahead of the SystemC time), to
32 // synchronize with SystemC time etc.
33 class tlm_quantumkeeper
34 {
35  public:
36  //
37  // Static setters/getters for the global quantum value.
38  //
39  // The global quantum is the maximum time an initiator can run ahead of
40  // SystemC time. All initiators will synchronize on timing points that are
41  // multiples of the global quantum value.
42  //
43  static void
45  {
47  }
48 
49  static const sc_core::sc_time &
51  {
53  }
54 
55  public:
58  {}
59 
60  virtual ~tlm_quantumkeeper() {}
61 
62  // Increment the local time (the time the initiator is ahead of the
63  // systemC time) After incrementing the local time an initiator should
64  // check (with the need_sync method) if a sync is required.
65  virtual void inc(const sc_core::sc_time &t) { m_local_time += t; }
66 
67  // Sets the local time (the time the initiator is ahead of the
68  // systemC time) After changing the local time an initiator should
69  // check (with the need_sync method) if a sync is required.
70  virtual void set(const sc_core::sc_time &t) { m_local_time = t; }
71 
72  // Checks if a sync to systemC is required for this initiator. This will
73  // be the case if the local time becomes greater than the local (current)
74  // quantum value for this initiator.
75  virtual bool
76  need_sync() const
77  {
79  }
80 
81  // Synchronize to systemC. This call will do a wait for the time the
82  // initiator was running ahead of systemC time and reset the
83  // tlm_quantumkeeper.
84  virtual void
85  sync()
86  {
88  reset();
89  }
90 
91  // Non-virtual convenience method to set the local time and sync only if
92  // needed
93  void
95  {
96  set(t);
97  if (need_sync())
98  sync();
99  }
100 
101  // Resets the local time to SC_ZERO_TIME and computes the value of the
102  // next local quantum. This method should be called by an initiator after
103  // a wait because of a synchronization request by a target (TLM_ACCEPTED,
104  // or TLM_UPDATED).
105  virtual void
106  reset()
107  {
110  }
111 
112  // Helper function to get the current systemC time, taken the local time
113  // into account. The current systemC time is calculated as the time
114  // returned by sc_time_stamp incremeneted with the time the initiator is
115  // running ahead.
116  virtual sc_core::sc_time
117  get_current_time() const
118  {
120  }
121 
122  // Helper functions to get the time the initiator is running ahead of
123  // systenC (local time). This time should be passed to a target in the
124  // nb_transport call
125  virtual sc_core::sc_time
126  get_local_time() const
127  {
128  return m_local_time;
129  }
130 
131  protected:
132  // Calculate the next local quantum for this initiator.
133  //
134  // The method can be overloaded in a derived object if an initiator wants
135  // to use another local quantum. This derived object should also take the
136  // global quantum into account. It's local quantum should not be set to a
137  // value that is larger than the quantum returned by the
138  // compute_local_quantum of the tlm_global_quantum singleton.
139  virtual sc_core::sc_time
141  {
143  }
144 
145  protected:
148 };
149 
150 } // namespace tlm_utils
151 
152 #endif /* __SYSTEMC_EXT_TLM_UTILS_TLM_QUANTUMKEEPER_H__ */
tlm_utils::tlm_quantumkeeper::set
virtual void set(const sc_core::sc_time &t)
Definition: tlm_quantumkeeper.h:104
sc_core
Definition: messages.cc:31
tlm_utils::tlm_quantumkeeper::tlm_quantumkeeper
tlm_quantumkeeper()
Definition: tlm_quantumkeeper.h:90
sc_core::SC_ZERO_TIME
const sc_time SC_ZERO_TIME
Definition: sc_time.cc:290
tlm_utils::tlm_quantumkeeper::get_global_quantum
static const sc_core::sc_time & get_global_quantum()
Definition: tlm_quantumkeeper.h:84
gem5::VegaISA::t
Bitfield< 51 > t
Definition: pagetable.hh:56
tlm::tlm_global_quantum::get
const sc_core::sc_time & get() const
Definition: global_quantum.hh:90
tlm_utils::tlm_quantumkeeper::inc
virtual void inc(const sc_core::sc_time &t)
Definition: tlm_quantumkeeper.h:99
tlm_utils::tlm_quantumkeeper::m_next_sync_point
sc_core::sc_time m_next_sync_point
Definition: tlm_quantumkeeper.h:180
sc_core::sc_time
Definition: sc_time.hh:49
tlm_utils::tlm_quantumkeeper::need_sync
virtual bool need_sync() const
Definition: tlm_quantumkeeper.h:110
tlm_utils::tlm_quantumkeeper::m_local_time
sc_core::sc_time m_local_time
Definition: tlm_quantumkeeper.h:181
tlm_utils::tlm_quantumkeeper::reset
virtual void reset()
Definition: tlm_quantumkeeper.h:140
tlm_utils::tlm_quantumkeeper::get_current_time
virtual sc_core::sc_time get_current_time() const
Definition: tlm_quantumkeeper.h:151
tlm_utils::tlm_quantumkeeper::set_and_sync
void set_and_sync(const sc_core::sc_time &t)
Definition: tlm_quantumkeeper.h:128
tlm_utils
Definition: convenience_socket_bases.h:29
tlm_utils::tlm_quantumkeeper::~tlm_quantumkeeper
virtual ~tlm_quantumkeeper()
Definition: tlm_quantumkeeper.h:94
tlm_utils::tlm_quantumkeeper::set_global_quantum
static void set_global_quantum(const sc_core::sc_time &t)
Definition: tlm_quantumkeeper.h:78
tlm::tlm_global_quantum::instance
static tlm_global_quantum & instance()
Definition: global_quantum.cc:49
sc_core::wait
void wait()
Definition: sc_module.cc:653
tlm::tlm_global_quantum::set
void set(const sc_core::sc_time &t)
Definition: global_quantum.hh:89
tlm::tlm_global_quantum::compute_local_quantum
sc_core::sc_time compute_local_quantum()
Definition: global_quantum.cc:56
tlm_utils::tlm_quantumkeeper::get_local_time
virtual sc_core::sc_time get_local_time() const
Definition: tlm_quantumkeeper.h:160
tlm_utils::tlm_quantumkeeper::sync
virtual void sync()
Definition: tlm_quantumkeeper.h:119
sc_core::sc_time_stamp
const sc_time & sc_time_stamp()
Definition: sc_main.cc:127
tlm_utils::tlm_quantumkeeper::compute_local_quantum
virtual sc_core::sc_time compute_local_quantum()
Definition: tlm_quantumkeeper.h:174

Generated on Sat Jun 18 2022 08:12:34 for gem5 by doxygen 1.8.17