gem5  v20.0.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 
60 class BaseGlobalEvent : public EventBase
61 {
62  private:
68  static std::mutex globalQMutex;
69 
70  protected:
71 
76  class BarrierEvent : public Event
77  {
78  protected:
80 
82  : Event(p, f), _globalEvent(global_event)
83  {
84  }
85 
86  ~BarrierEvent();
87 
88  friend class BaseGlobalEvent;
89 
91  {
92  // This method will be called from the process() method in
93  // the local barrier events
94  // (GlobalSyncEvent::BarrierEvent). The local event
95  // queues are always locked when servicing events (calling
96  // the process() method), which means that it will be
97  // locked when entering this method. We need to unlock it
98  // while waiting on the barrier to prevent deadlocks if
99  // another thread wants to lock the event queue.
101  return _globalEvent->barrier.wait();
102  }
103 
104  public:
105  virtual BaseGlobalEvent *globalEvent() { return _globalEvent; }
106  };
107 
111 
114 
115  public:
117 
118  virtual ~BaseGlobalEvent();
119 
120  virtual void process() = 0;
121 
122  virtual const char *description() const = 0;
123 
124  void schedule(Tick when);
125 
126  bool scheduled() const
127  {
128  bool sched = false;
129  for (uint32_t i = 0; i < numMainEventQueues; ++i) {
130  sched = sched || barrierEvent[i]->scheduled();
131  }
132 
133  return sched;
134  }
135 
136  Tick when() const
137  {
138  assert(numMainEventQueues > 0);
139  return barrierEvent[0]->when();
140  }
141 
142  void deschedule();
143  void reschedule(Tick when);
144 };
145 
146 
152 template <class Derived>
154 {
155  protected:
157  : BaseGlobalEvent(p, f)
158  {
159  for (int i = 0; i < numMainEventQueues; ++i)
160  barrierEvent[i] = new typename Derived::BarrierEvent(this, p, f);
161  }
162 };
163 
164 
173 class GlobalEvent : public BaseGlobalEventTemplate<GlobalEvent>
174 {
175  public:
177 
179  {
180  public:
181  void process();
182  BarrierEvent(Base *global_event, Priority p, Flags f)
183  : Base::BarrierEvent(global_event, p, f)
184  { }
185  };
186 
188  : Base(p, f)
189  { }
190 
192  : Base(p, f)
193  {
194  schedule(when);
195  }
196 
197  virtual void process() = 0;
198 };
199 
205 class GlobalSyncEvent : public BaseGlobalEventTemplate<GlobalSyncEvent>
206 {
207  public:
209 
211  {
212  public:
213  void process();
214  BarrierEvent(Base *global_event, Priority p, Flags f)
215  : Base::BarrierEvent(global_event, p, f)
216  { }
217  };
218 
220  : Base(p, f), repeat(0)
221  { }
222 
224  : Base(p, f), repeat(_repeat)
225  {
226  schedule(when);
227  }
228 
229  void process();
230 
231  const char *description() const;
232 
234 };
235 
236 
237 #endif // __SIM_GLOBAL_EVENT_HH__
BarrierEvent(Base *global_event, Priority p, Flags f)
Funky intermediate class to support CRTP so that we can have a common constructor to create the local...
Bitfield< 7 > i
GlobalSyncEvent(Tick when, Tick _repeat, Priority p, Flags f)
BaseGlobalEventTemplate(Priority p, Flags f)
virtual BaseGlobalEvent * globalEvent()
If this is part of a GlobalEvent, return the pointer to the Global Event.
Barrier barrier
The barrier that all threads wait on before performing the global event.
A special global event that synchronizes all threads and forces them to process asynchronously enqueu...
int8_t Priority
Definition: eventq.hh:118
bool wait()
Definition: barrier.hh:63
Tick when() const
BaseGlobalEvent * _globalEvent
Definition: global_event.hh:79
virtual void process()=0
BarrierEvent(BaseGlobalEvent *global_event, Priority p, Flags f)
Definition: global_event.hh:81
STL vector class.
Definition: stl.hh:37
GlobalEvent(Priority p, Flags f)
Bitfield< 6 > f
GlobalEvent(Tick when, Priority p, Flags f)
bool scheduled() const
BaseGlobalEventTemplate< GlobalEvent > Base
uint64_t Tick
Tick count type.
Definition: types.hh:61
EventQueue * curEventQueue()
Definition: eventq.hh:83
BarrierEvent(Base *global_event, Priority p, Flags f)
virtual const char * description() const
Return a C string describing the event.
Definition: eventq.cc:372
static std::mutex globalQMutex
Mutex variable for providing exculsive right to schedule global events.
Definition: global_event.hh:68
BaseGlobalEventTemplate< GlobalSyncEvent > Base
The main global event class.
void schedule(Tick when)
Definition: global_event.cc:53
void reschedule(Tick when)
Definition: global_event.cc:97
uint32_t numMainEventQueues
Current number of allocated main event queues.
Definition: eventq.cc:55
Definition: eventq.hh:246
GlobalSyncEvent(Priority p, Flags f)
virtual ~BaseGlobalEvent()
Definition: global_event.cc:43
void release()
Managed event removed from the event queue.
Definition: eventq.hh:387
Common base class for GlobalEvent and GlobalSyncEvent.
Definition: global_event.hh:60
Common base class for Event and GlobalEvent, so they can share flag and priority definitions and acce...
Definition: eventq.hh:91
Temporarily release the event queue service lock.
Definition: eventq.hh:715
Bitfield< 0 > p
std::vector< BarrierEvent * > barrierEvent
The individual local event instances (one per thread/event queue).
Tick when() const
Get the time that the event is scheduled.
Definition: eventq.hh:500
The base class for the local events that will synchronize threads to perform the global event...
Definition: global_event.hh:76

Generated on Mon Jun 8 2020 15:45:13 for gem5 by doxygen 1.8.13