gem5  v22.1.0.0
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__
bool wait()
Definition: barrier.hh:66
Funky intermediate class to support CRTP so that we can have a common constructor to create the local...
BaseGlobalEventTemplate(Priority p, Flags f)
The base class for the local events that will synchronize threads to perform the global event.
Definition: global_event.hh:80
virtual BaseGlobalEvent * globalEvent()
If this is part of a GlobalEvent, return the pointer to the Global Event.
BarrierEvent(BaseGlobalEvent *global_event, Priority p, Flags f)
Definition: global_event.hh:84
Common base class for GlobalEvent and GlobalSyncEvent.
Definition: global_event.hh:64
virtual void process()=0
virtual ~BaseGlobalEvent()
Definition: global_event.cc:46
void schedule(Tick when)
Definition: global_event.cc:56
BaseGlobalEvent(Priority p, Flags f)
Definition: global_event.cc:39
virtual const char * description() const =0
static std::mutex globalQMutex
Mutex variable for providing exculsive right to schedule global events.
Definition: global_event.hh:71
Barrier barrier
The barrier that all threads wait on before performing the global event.
std::vector< BarrierEvent * > barrierEvent
The individual local event instances (one per thread/event queue).
void reschedule(Tick when)
bool scheduled() const
Common base class for Event and GlobalEvent, so they can share flag and priority definitions and acce...
Definition: eventq.hh:97
void release()
Managed event removed from the event queue.
Definition: eventq.hh:392
BarrierEvent(Base *global_event, Priority p, Flags f)
The main global event class.
virtual void process()=0
GlobalEvent(Tick when, Priority p, Flags f)
GlobalEvent(Priority p, Flags f)
BaseGlobalEventTemplate< GlobalEvent > Base
BarrierEvent(Base *global_event, Priority p, Flags f)
A special global event that synchronizes all threads and forces them to process asynchronously enqueu...
const char * description() const
GlobalSyncEvent(Priority p, Flags f)
GlobalSyncEvent(Tick when, Tick _repeat, Priority p, Flags f)
BaseGlobalEventTemplate< GlobalSyncEvent > Base
STL vector class.
Definition: stl.hh:37
int8_t Priority
Definition: eventq.hh:123
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 56 > f
Definition: pagetable.hh:53
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Tick
Tick count type.
Definition: types.hh:58
EventQueue * curEventQueue()
Definition: eventq.hh:88
uint32_t numMainEventQueues
Current number of allocated main event queues.
Definition: eventq.cc:56

Generated on Wed Dec 21 2022 10:22:39 for gem5 by doxygen 1.9.1