gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  * Authors: Steve Reinhardt
30  */
31 
32 #ifndef __SIM_GLOBAL_EVENT_HH__
33 #define __SIM_GLOBAL_EVENT_HH__
34 
35 #include <mutex>
36 #include <vector>
37 
38 #include "base/barrier.hh"
39 #include "sim/eventq_impl.hh"
40 
62 class BaseGlobalEvent : public EventBase
63 {
64  private:
70  static std::mutex globalQMutex;
71 
72  protected:
73 
78  class BarrierEvent : public Event
79  {
80  protected:
82 
84  : Event(p, f), _globalEvent(global_event)
85  {
86  }
87 
88  ~BarrierEvent();
89 
90  friend class BaseGlobalEvent;
91 
93  {
94  // This method will be called from the process() method in
95  // the local barrier events
96  // (GlobalSyncEvent::BarrierEvent). The local event
97  // queues are always locked when servicing events (calling
98  // the process() method), which means that it will be
99  // locked when entering this method. We need to unlock it
100  // while waiting on the barrier to prevent deadlocks if
101  // another thread wants to lock the event queue.
103  return _globalEvent->barrier.wait();
104  }
105 
106  public:
107  virtual BaseGlobalEvent *globalEvent() { return _globalEvent; }
108  };
109 
113 
116 
117  public:
119 
120  virtual ~BaseGlobalEvent();
121 
122  virtual void process() = 0;
123 
124  virtual const char *description() const = 0;
125 
126  void schedule(Tick when);
127 
128  bool scheduled() const
129  {
130  bool sched = false;
131  for (uint32_t i = 0; i < numMainEventQueues; ++i) {
132  sched = sched || barrierEvent[i]->scheduled();
133  }
134 
135  return sched;
136  }
137 
138  Tick when() const
139  {
140  assert(numMainEventQueues > 0);
141  return barrierEvent[0]->when();
142  }
143 
144  void deschedule();
145  void reschedule(Tick when);
146 };
147 
148 
154 template <class Derived>
156 {
157  protected:
159  : BaseGlobalEvent(p, f)
160  {
161  for (int i = 0; i < numMainEventQueues; ++i)
162  barrierEvent[i] = new typename Derived::BarrierEvent(this, p, f);
163  }
164 };
165 
166 
175 class GlobalEvent : public BaseGlobalEventTemplate<GlobalEvent>
176 {
177  public:
179 
181  {
182  public:
183  void process();
184  BarrierEvent(Base *global_event, Priority p, Flags f)
185  : Base::BarrierEvent(global_event, p, f)
186  { }
187  };
188 
190  : Base(p, f)
191  { }
192 
194  : Base(p, f)
195  {
196  schedule(when);
197  }
198 
199  virtual void process() = 0;
200 };
201 
207 class GlobalSyncEvent : public BaseGlobalEventTemplate<GlobalSyncEvent>
208 {
209  public:
211 
213  {
214  public:
215  void process();
216  BarrierEvent(Base *global_event, Priority p, Flags f)
217  : Base::BarrierEvent(global_event, p, f)
218  { }
219  };
220 
222  : Base(p, f), repeat(0)
223  { }
224 
226  : Base(p, f), repeat(_repeat)
227  {
228  schedule(when);
229  }
230 
231  void process();
232 
233  const char *description() const;
234 
236 };
237 
238 
239 #endif // __SIM_GLOBAL_EVENT_HH__
const char * description() const
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
Definition: miscregs.hh:1378
GlobalSyncEvent(Tick when, Tick _repeat, Priority p, Flags f)
BaseGlobalEventTemplate(Priority p, Flags f)
virtual void process()=0
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:116
bool wait()
Definition: barrier.hh:65
BaseGlobalEvent * _globalEvent
Definition: global_event.hh:81
BarrierEvent(BaseGlobalEvent *global_event, Priority p, Flags f)
Definition: global_event.hh:83
STL vector class.
Definition: stl.hh:40
Tick when() const
bool scheduled() const
GlobalEvent(Priority p, Flags f)
Bitfield< 6 > f
Definition: miscregs.hh:1379
GlobalEvent(Tick when, Priority p, Flags f)
virtual const char * description() const =0
BaseGlobalEventTemplate< GlobalEvent > Base
uint64_t Tick
Tick count type.
Definition: types.hh:63
virtual void process()=0
EventQueue * curEventQueue()
Definition: eventq.hh:84
BarrierEvent(Base *global_event, Priority p, Flags f)
static std::mutex globalQMutex
Mutex variable for providing exculsive right to schedule global events.
Definition: global_event.hh:70
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:58
Definition: eventq.hh:185
GlobalSyncEvent(Priority p, Flags f)
BaseGlobalEvent(Priority p, Flags f)
Definition: global_event.cc:36
virtual ~BaseGlobalEvent()
Definition: global_event.cc:43
void release()
Managed event removed from the event queue.
Definition: eventq.hh:321
Common base class for GlobalEvent and GlobalSyncEvent.
Definition: global_event.hh:62
Common base class for Event and GlobalEvent, so they can share flag and priority definitions and acce...
Definition: eventq.hh:92
Temporarily release the event queue service lock.
Definition: eventq.hh:578
Bitfield< 0 > p
std::vector< BarrierEvent * > barrierEvent
The individual local event instances (one per thread/event queue).
The base class for the local events that will synchronize threads to perform the global event...
Definition: global_event.hh:78

Generated on Fri Jun 9 2017 13:03:51 for gem5 by doxygen 1.8.6