gem5  v21.1.0.2
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 };
166 
167 
176 class GlobalEvent : public BaseGlobalEventTemplate<GlobalEvent>
177 {
178  public:
180 
182  {
183  public:
184  void process();
185  BarrierEvent(Base *global_event, Priority p, Flags f)
186  : Base::BarrierEvent(global_event, p, f)
187  { }
188  };
189 
191  : Base(p, f)
192  { }
193 
195  : Base(p, f)
196  {
197  schedule(when);
198  }
199 
200  virtual void process() = 0;
201 };
202 
208 class GlobalSyncEvent : public BaseGlobalEventTemplate<GlobalSyncEvent>
209 {
210  public:
212 
214  {
215  public:
216  void process();
217  BarrierEvent(Base *global_event, Priority p, Flags f)
218  : Base::BarrierEvent(global_event, p, f)
219  { }
220  };
221 
223  : Base(p, f), repeat(0)
224  { }
225 
227  : Base(p, f), repeat(_repeat)
228  {
229  schedule(when);
230  }
231 
232  void process();
233 
234  const char *description() const;
235 
237 };
238 
239 } // namespace gem5
240 
241 #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:208
gem5::BaseGlobalEvent::description
virtual const char * description() const =0
gem5::GlobalEvent::GlobalEvent
GlobalEvent(Priority p, Flags f)
Definition: global_event.hh:190
gem5::BaseGlobalEvent::BaseGlobalEvent
BaseGlobalEvent(Priority p, Flags f)
Definition: global_event.cc:39
gem5::EventQueue::ScopedRelease
Definition: eventq.hh:716
gem5::GlobalSyncEvent::GlobalSyncEvent
GlobalSyncEvent(Tick when, Tick _repeat, Priority p, Flags f)
Definition: global_event.hh:226
gem5::GlobalSyncEvent::Base
BaseGlobalEventTemplate< GlobalSyncEvent > Base
Definition: global_event.hh:211
gem5::GlobalSyncEvent::BarrierEvent::process
void process()
Definition: global_event.cc:144
gem5::Barrier::wait
bool wait()
Definition: barrier.hh:66
gem5::ArmISA::f
Bitfield< 6 > f
Definition: misc_types.hh:67
gem5::BaseGlobalEvent::schedule
void schedule(Tick when)
Definition: global_event.cc:56
gem5::GlobalEvent::GlobalEvent
GlobalEvent(Tick when, Priority p, Flags f)
Definition: global_event.hh:194
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.hh:392
gem5::GlobalEvent::BarrierEvent
Definition: global_event.hh:181
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
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::GlobalEvent::Base
BaseGlobalEventTemplate< GlobalEvent > Base
Definition: global_event.hh:179
gem5::Event
Definition: eventq.hh:251
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::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
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:185
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:217
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:176
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:88
gem5::EventBase::Priority
int8_t Priority
Definition: eventq.hh:123
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::GlobalSyncEvent::BarrierEvent
Definition: global_event.hh:213
gem5::EventBase
Common base class for Event and GlobalEvent, so they can share flag and priority definitions and acce...
Definition: eventq.hh:96
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::BaseGlobalEvent::BarrierEvent::_globalEvent
BaseGlobalEvent * _globalEvent
Definition: global_event.hh:82
gem5::GlobalSyncEvent::GlobalSyncEvent
GlobalSyncEvent(Priority p, Flags f)
Definition: global_event.hh:222
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:236
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 Tue Sep 21 2021 12:25:47 for gem5 by doxygen 1.8.17