gem5  v20.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 
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__
GlobalEvent::BarrierEvent::BarrierEvent
BarrierEvent(Base *global_event, Priority p, Flags f)
Definition: global_event.hh:182
BaseGlobalEvent::description
virtual const char * description() const =0
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
BaseGlobalEvent::~BaseGlobalEvent
virtual ~BaseGlobalEvent()
Definition: global_event.cc:43
Flags< FlagsType >
BaseGlobalEvent::BarrierEvent::_globalEvent
BaseGlobalEvent * _globalEvent
Definition: global_event.hh:79
BaseGlobalEventTemplate
Funky intermediate class to support CRTP so that we can have a common constructor to create the local...
Definition: global_event.hh:153
BaseGlobalEventTemplate::BaseGlobalEventTemplate
BaseGlobalEventTemplate(Priority p, Flags f)
Definition: global_event.hh:156
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
BaseGlobalEvent::barrierEvent
std::vector< BarrierEvent * > barrierEvent
The individual local event instances (one per thread/event queue).
Definition: global_event.hh:113
std::vector
STL vector class.
Definition: stl.hh:37
GlobalSyncEvent::repeat
Tick repeat
Definition: global_event.hh:233
BaseGlobalEvent::process
virtual void process()=0
BaseGlobalEvent::BarrierEvent::globalEvent
virtual BaseGlobalEvent * globalEvent()
If this is part of a GlobalEvent, return the pointer to the Global Event.
Definition: global_event.hh:105
BaseGlobalEvent::deschedule
void deschedule()
Definition: global_event.cc:84
GlobalEvent::process
virtual void process()=0
barrier.hh
GlobalSyncEvent::BarrierEvent::process
void process()
Definition: global_event.cc:141
EventQueue::ScopedRelease
Definition: eventq.hh:709
GlobalSyncEvent
A special global event that synchronizes all threads and forces them to process asynchronously enqueu...
Definition: global_event.hh:205
GlobalSyncEvent::GlobalSyncEvent
GlobalSyncEvent(Priority p, Flags f)
Definition: global_event.hh:219
GlobalEvent::BarrierEvent
Definition: global_event.hh:178
BaseGlobalEvent::when
Tick when() const
Definition: global_event.hh:136
GlobalSyncEvent::BarrierEvent::BarrierEvent
BarrierEvent(Base *global_event, Priority p, Flags f)
Definition: global_event.hh:214
BaseGlobalEvent::reschedule
void reschedule(Tick when)
Definition: global_event.cc:97
GlobalEvent::GlobalEvent
GlobalEvent(Priority p, Flags f)
Definition: global_event.hh:187
GlobalEvent::GlobalEvent
GlobalEvent(Tick when, Priority p, Flags f)
Definition: global_event.hh:191
Event
Definition: eventq.hh:246
GlobalEvent::Base
BaseGlobalEventTemplate< GlobalEvent > Base
Definition: global_event.hh:176
BaseGlobalEvent::barrier
Barrier barrier
The barrier that all threads wait on before performing the global event.
Definition: global_event.hh:110
curEventQueue
EventQueue * curEventQueue()
Definition: eventq.hh:83
BaseGlobalEvent::BarrierEvent
The base class for the local events that will synchronize threads to perform the global event.
Definition: global_event.hh:76
GlobalSyncEvent::description
const char * description() const
Definition: global_event.cc:163
GlobalEvent::BarrierEvent::process
void process()
Definition: global_event.cc:127
BaseGlobalEvent::BaseGlobalEvent
BaseGlobalEvent(Priority p, Flags f)
Definition: global_event.cc:36
Event::release
void release()
Managed event removed from the event queue.
Definition: eventq.hh:387
GlobalSyncEvent::process
void process()
Definition: global_event.cc:155
GlobalSyncEvent::GlobalSyncEvent
GlobalSyncEvent(Tick when, Tick _repeat, Priority p, Flags f)
Definition: global_event.hh:223
BaseGlobalEvent::scheduled
bool scheduled() const
Definition: global_event.hh:126
BaseGlobalEvent::BarrierEvent::~BarrierEvent
~BarrierEvent()
Definition: global_event.cc:112
BaseGlobalEvent::BarrierEvent::BarrierEvent
BarrierEvent(BaseGlobalEvent *global_event, Priority p, Flags f)
Definition: global_event.hh:81
EventBase
Common base class for Event and GlobalEvent, so they can share flag and priority definitions and acce...
Definition: eventq.hh:91
BaseGlobalEvent::schedule
void schedule(Tick when)
Definition: global_event.cc:53
GlobalSyncEvent::BarrierEvent
Definition: global_event.hh:210
GlobalSyncEvent::Base
BaseGlobalEventTemplate< GlobalSyncEvent > Base
Definition: global_event.hh:208
EventBase::Priority
int8_t Priority
Definition: eventq.hh:118
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
numMainEventQueues
uint32_t numMainEventQueues
Current number of allocated main event queues.
Definition: eventq.cc:55
BaseGlobalEvent::BarrierEvent::globalBarrier
bool globalBarrier()
Definition: global_event.hh:90
GlobalEvent
The main global event class.
Definition: global_event.hh:173
BaseGlobalEvent
Common base class for GlobalEvent and GlobalSyncEvent.
Definition: global_event.hh:60
Barrier::wait
bool wait()
Definition: barrier.hh:63
BaseGlobalEvent::globalQMutex
static std::mutex globalQMutex
Mutex variable for providing exculsive right to schedule global events.
Definition: global_event.hh:68
Barrier
Definition: barrier.hh:43
ArmISA::f
Bitfield< 6 > f
Definition: miscregs_types.hh:64
eventq.hh

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17