gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
39namespace gem5
40{
41
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
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:
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
155template <class Derived>
157{
158 protected:
161 {
162 for (int i = 0; i < numMainEventQueues; ++i)
163 barrierEvent[i] = new typename Derived::BarrierEvent(this, p, f);
164 }
165
167};
168
169
178class GlobalEvent : public BaseGlobalEventTemplate<GlobalEvent>
179{
180 public:
182
184 {
185 public:
186 void process();
188 : Base::BarrierEvent(global_event, p, f)
189 { }
190 };
191
193 : Base(p, f)
194 { }
195
197 : Base(p, f)
198 {
199 schedule(when);
200 }
201
202 virtual void process() = 0;
203};
204
210class GlobalSyncEvent : public BaseGlobalEventTemplate<GlobalSyncEvent>
211{
212 public:
214
216 {
217 public:
218 void process();
220 : Base::BarrierEvent(global_event, p, f)
221 { }
222 };
223
225 : Base(p, f), repeat(0)
226 { }
227
229 : Base(p, f), repeat(_repeat)
230 {
231 schedule(when);
232 }
233
234 virtual ~GlobalSyncEvent (){}
235
236 void process();
237
238 const char *description() const;
239
241};
242
243} // namespace gem5
244
245#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.
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)
Common base class for GlobalEvent and GlobalSyncEvent.
virtual void process()=0
void schedule(Tick when)
BaseGlobalEvent(Priority p, Flags f)
static std::mutex globalQMutex
Mutex variable for providing exculsive right to schedule global events.
Barrier barrier
The barrier that all threads wait on before performing the global event.
virtual const char * description() const =0
std::vector< BarrierEvent * > barrierEvent
The individual local event instances (one per thread/event queue).
void reschedule(Tick when)
Common base class for Event and GlobalEvent, so they can share flag and priority definitions and acce...
Definition eventq.hh:100
void release()
Managed event removed from the event queue.
Definition eventq.cc:119
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:126
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 6 > f
Definition misc_types.hh:68
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Tick
Tick count type.
Definition types.hh:58
uint32_t numMainEventQueues
Current number of allocated main event queues.
Definition eventq.cc:56
EventQueue * curEventQueue()
Definition eventq.hh:91

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0