gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
global_event.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2013 Advanced Micro Devices, Inc.
3  * Copyright (c) 2013 Mark D. Hill and David A. Wood
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef __SIM_GLOBAL_EVENT_HH__
31 #define __SIM_GLOBAL_EVENT_HH__
32 
33 #include <mutex>
34 #include <vector>
35 
36 #include "base/barrier.hh"
37 #include "sim/eventq.hh"
38 
39 namespace gem5
40 {
41 
63 class BaseGlobalEvent : public EventBase
64 {
65  private:
71  static std::mutex globalQMutex;
72 
73  protected:
74 
79  class BarrierEvent : public Event
80  {
81  protected:
83 
85  : Event(p, f), _globalEvent(global_event)
86  {
87  }
88 
89  ~BarrierEvent();
90 
91  friend class BaseGlobalEvent;
92 
94  {
95  // This method will be called from the process() method in
96  // the local barrier events
97  // (GlobalSyncEvent::BarrierEvent). The local event
98  // queues are always locked when servicing events (calling
99  // the process() method), which means that it will be
100  // locked when entering this method. We need to unlock it
101  // while waiting on the barrier to prevent deadlocks if
102  // another thread wants to lock the event queue.
104  return _globalEvent->barrier.wait();
105  }
106 
107  public:
108  virtual BaseGlobalEvent *globalEvent() { return _globalEvent; }
109  };
110 
114 
117 
118  public:
120 
121  virtual ~BaseGlobalEvent();
122 
123  virtual void process() = 0;
124 
125  virtual const char *description() const = 0;
126 
127  void schedule(Tick when);
128 
129  bool scheduled() const
130  {
131  bool sched = false;
132  for (uint32_t i = 0; i < numMainEventQueues; ++i) {
133  sched = sched || barrierEvent[i]->scheduled();
134  }
135 
136  return sched;
137  }
138 
139  Tick when() const
140  {
141  assert(numMainEventQueues > 0);
142  return barrierEvent[0]->when();
143  }
144 
145  void deschedule();
146  void reschedule(Tick when);
147 };
148 
149 
155 template <class Derived>
157 {
158  protected:
160  : BaseGlobalEvent(p, f)
161  {
162  for (int i = 0; i < numMainEventQueues; ++i)
163  barrierEvent[i] = new typename Derived::BarrierEvent(this, p, f);
164  }
165 
167 };
168 
169 
178 class GlobalEvent : public BaseGlobalEventTemplate<GlobalEvent>
179 {
180  public:
182 
184  {
185  public:
186  void process();
187  BarrierEvent(Base *global_event, Priority p, Flags f)
188  : Base::BarrierEvent(global_event, p, f)
189  { }
190  };
191 
193  : Base(p, f)
194  { }
195 
197  : Base(p, f)
198  {
199  schedule(when);
200  }
201 
202  virtual void process() = 0;
203 };
204 
210 class GlobalSyncEvent : public BaseGlobalEventTemplate<GlobalSyncEvent>
211 {
212  public:
214 
216  {
217  public:
218  void process();
219  BarrierEvent(Base *global_event, Priority p, Flags f)
220  : Base::BarrierEvent(global_event, p, f)
221  { }
222  };
223 
225  : Base(p, f), repeat(0)
226  { }
227 
229  : Base(p, f), repeat(_repeat)
230  {
231  schedule(when);
232  }
233 
234  virtual ~GlobalSyncEvent (){}
235 
236  void process();
237 
238  const char *description() const;
239 
241 };
242 
243 } // namespace gem5
244 
245 #endif // __SIM_GLOBAL_EVENT_HH__
gem5::GlobalSyncEvent
A special global event that synchronizes all threads and forces them to process asynchronously enqueu...
Definition: global_event.hh:210
gem5::BaseGlobalEvent::description
virtual const char * description() const =0
gem5::GlobalEvent::GlobalEvent
GlobalEvent(Priority p, Flags f)
Definition: global_event.hh:192
gem5::BaseGlobalEvent::BaseGlobalEvent
BaseGlobalEvent(Priority p, Flags f)
Definition: global_event.cc:39
gem5::VegaISA::f
Bitfield< 56 > f
Definition: pagetable.hh:53
gem5::EventQueue::ScopedRelease
Definition: eventq.hh:709
gem5::GlobalSyncEvent::GlobalSyncEvent
GlobalSyncEvent(Tick when, Tick _repeat, Priority p, Flags f)
Definition: global_event.hh:228
gem5::GlobalSyncEvent::Base
BaseGlobalEventTemplate< GlobalSyncEvent > Base
Definition: global_event.hh:213
gem5::GlobalSyncEvent::BarrierEvent::process
void process()
Definition: global_event.cc:144
gem5::Barrier::wait
bool wait()
Definition: barrier.hh:66
gem5::BaseGlobalEvent::schedule
void schedule(Tick when)
Definition: global_event.cc:56
gem5::GlobalSyncEvent::~GlobalSyncEvent
virtual ~GlobalSyncEvent()
Definition: global_event.hh:234
gem5::GlobalEvent::GlobalEvent
GlobalEvent(Tick when, Priority p, Flags f)
Definition: global_event.hh:196
gem5::BaseGlobalEvent::barrier
Barrier barrier
The barrier that all threads wait on before performing the global event.
Definition: global_event.hh:113
gem5::BaseGlobalEvent::reschedule
void reschedule(Tick when)
Definition: global_event.cc:100
gem5::GlobalEvent::process
virtual void process()=0
std::vector
STL vector class.
Definition: stl.hh:37
gem5::BaseGlobalEvent::~BaseGlobalEvent
virtual ~BaseGlobalEvent()
Definition: global_event.cc:46
gem5::Event::release
void release()
Managed event removed from the event queue.
Definition: eventq.cc:119
gem5::GlobalEvent::BarrierEvent
Definition: global_event.hh:183
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::BaseGlobalEvent::scheduled
bool scheduled() const
Definition: global_event.hh:129
barrier.hh
gem5::BaseGlobalEvent::BarrierEvent::BarrierEvent
BarrierEvent(BaseGlobalEvent *global_event, Priority p, Flags f)
Definition: global_event.hh:84
gem5::BaseGlobalEvent::BarrierEvent::globalBarrier
bool globalBarrier()
Definition: global_event.hh:93
gem5::Flags< FlagsType >
gem5::BaseGlobalEvent
Common base class for GlobalEvent and GlobalSyncEvent.
Definition: global_event.hh:63
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::GlobalEvent::Base
BaseGlobalEventTemplate< GlobalEvent > Base
Definition: global_event.hh:181
gem5::Event
Definition: eventq.hh:254
gem5::BaseGlobalEvent::barrierEvent
std::vector< BarrierEvent * > barrierEvent
The individual local event instances (one per thread/event queue).
Definition: global_event.hh:116
gem5::GlobalEvent::BarrierEvent::process
void process()
Definition: global_event.cc:130
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::GlobalEvent::BarrierEvent::BarrierEvent
BarrierEvent(Base *global_event, Priority p, Flags f)
Definition: global_event.hh:187
gem5::BaseGlobalEventTemplate::BaseGlobalEventTemplate
BaseGlobalEventTemplate(Priority p, Flags f)
Definition: global_event.hh:159
gem5::GlobalSyncEvent::BarrierEvent::BarrierEvent
BarrierEvent(Base *global_event, Priority p, Flags f)
Definition: global_event.hh:219
gem5::BaseGlobalEvent::when
Tick when() const
Definition: global_event.hh:139
gem5::GlobalSyncEvent::description
const char * description() const
Definition: global_event.cc:166
gem5::GlobalEvent
The main global event class.
Definition: global_event.hh:178
gem5::BaseGlobalEventTemplate
Funky intermediate class to support CRTP so that we can have a common constructor to create the local...
Definition: global_event.hh:156
gem5::BaseGlobalEvent::globalQMutex
static std::mutex globalQMutex
Mutex variable for providing exculsive right to schedule global events.
Definition: global_event.hh:71
gem5::Barrier
Definition: barrier.hh:46
gem5::BaseGlobalEvent::deschedule
void deschedule()
Definition: global_event.cc:87
gem5::BaseGlobalEvent::BarrierEvent::~BarrierEvent
~BarrierEvent()
Definition: global_event.cc:115
gem5::curEventQueue
EventQueue * curEventQueue()
Definition: eventq.hh:91
gem5::EventBase::Priority
int8_t Priority
Definition: eventq.hh:126
gem5::numMainEventQueues
uint32_t numMainEventQueues
Current number of allocated main event queues.
Definition: eventq.cc:56
gem5::GlobalSyncEvent::process
void process()
Definition: global_event.cc:158
gem5::BaseGlobalEvent::process
virtual void process()=0
gem5::BaseGlobalEventTemplate::~BaseGlobalEventTemplate
virtual ~BaseGlobalEventTemplate()
Definition: global_event.hh:166
gem5::GlobalSyncEvent::BarrierEvent
Definition: global_event.hh:215
gem5::EventBase
Common base class for Event and GlobalEvent, so they can share flag and priority definitions and acce...
Definition: eventq.hh:99
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::BaseGlobalEvent::BarrierEvent::_globalEvent
BaseGlobalEvent * _globalEvent
Definition: global_event.hh:82
gem5::GlobalSyncEvent::GlobalSyncEvent
GlobalSyncEvent(Priority p, Flags f)
Definition: global_event.hh:224
gem5::BaseGlobalEvent::BarrierEvent::globalEvent
virtual BaseGlobalEvent * globalEvent()
If this is part of a GlobalEvent, return the pointer to the Global Event.
Definition: global_event.hh:108
gem5::GlobalSyncEvent::repeat
Tick repeat
Definition: global_event.hh:240
gem5::BaseGlobalEvent::BarrierEvent
The base class for the local events that will synchronize threads to perform the global event.
Definition: global_event.hh:79
eventq.hh

Generated on Sun Jul 30 2023 01:56:59 for gem5 by doxygen 1.8.17