gem5  v20.1.0.0
global_event.cc
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 #include "sim/global_event.hh"
31 
32 #include "sim/core.hh"
33 
35 
37  : barrier(numMainEventQueues),
38  barrierEvent(numMainEventQueues, NULL)
39 {
40 }
41 
42 
44 {
45  // see GlobalEvent::BarrierEvent::~BarrierEvent() comments
46  if (barrierEvent[0] != NULL) {
47  for (int i = 0; i < numMainEventQueues; ++i)
48  delete barrierEvent[i];
49  }
50 }
51 
52 
54 {
55  // This function is scheduling a global event, which actually is a
56  // set of local events, one event on each eventq. Global events need
57  // to have a total order. A thread cannot start executing events that
58  // follow a global event till all other threads have executed that global
59  // event as well. If global events were not in a total order, a deadlock
60  // would occur for there will be two threads who would be waiting for
61  // each other to execute the global events they themselves have executed.
62  //
63  // To ensure this total order, we do two things.
64  // First, before scheduling any global event, a thread needs to acquire
65  // the lock globalQMutex. This ensures that only one thread can schedule
66  // global events at any given time.
67  // Second, the local events corresponding to a global event are always
68  // first inserted in to the asyncq, irrespective of whether or not the
69  // thread scheduling the event owns the eventq on which the event is
70  // being scheduled. Thus global events have the same order in the asyncq
71  // of each thread. When they are inserted in the actual eventq, the
72  // comparators in the Event class ensure that the total order is
73  // maintained.
74 
75  globalQMutex.lock();
76 
77  for (int i = 0; i < numMainEventQueues; ++i) {
78  mainEventQueue[i]->schedule(barrierEvent[i], when, true);
79  }
80 
81  globalQMutex.unlock();
82 }
83 
85 {
87  for (uint32_t i = 0; i < numMainEventQueues; ++i) {
88  if (barrierEvent[i]->scheduled()) {
90  mainEventQueue[i]->deschedule(barrierEvent[i]);
91  }
92  }
93 
95 }
96 
98 {
99  // Read the comment in the schedule() function above.
100  globalQMutex.lock();
101 
102  for (uint32_t i = 0; i < numMainEventQueues; ++i) {
103  if (barrierEvent[i]->scheduled())
104  mainEventQueue[i]->reschedule(barrierEvent[i], when);
105  else
106  mainEventQueue[i]->schedule(barrierEvent[i], when, true);
107  }
108 
109  globalQMutex.unlock();
110 }
111 
113 {
114  // if AutoDelete is set, local events will get deleted in event
115  // loop, but we need to delete GlobalEvent object too... so let
116  // the local event in slot 0 do it
117  if (isFlagSet(AutoDelete) && _globalEvent->barrierEvent[0] == this) {
118  // set backpointer to NULL so that global event knows not to
119  // turn around and recursively delete local events
120  _globalEvent->barrierEvent[0] = NULL;
121  delete _globalEvent;
122  }
123 }
124 
125 
126 void
128 {
129  // wait for all queues to arrive at barrier, then process event
130  if (globalBarrier()) {
131  _globalEvent->process();
132  }
133 
134  // second barrier to force all queues to wait for event processing
135  // to finish before continuing
136  globalBarrier();
137 }
138 
139 
140 void
142 {
143  // wait for all queues to arrive at barrier, then process event
144  if (globalBarrier()) {
145  _globalEvent->process();
146  }
147 
148  // second barrier to force all queues to wait for event processing
149  // to finish before continuing
150  globalBarrier();
152 }
153 
154 void
156 {
157  if (repeat) {
158  schedule(curTick() + repeat);
159  }
160 }
161 
162 const char *
164 {
165  return "GlobalSyncEvent";
166 }
EventBase::AutoDelete
static const FlagsType AutoDelete
Definition: eventq.hh:102
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
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
ArmISA::q
Bitfield< 27 > q
Definition: miscregs_types.hh:52
BaseGlobalEvent::barrierEvent
std::vector< BarrierEvent * > barrierEvent
The individual local event instances (one per thread/event queue).
Definition: global_event.hh:113
BaseGlobalEvent::deschedule
void deschedule()
Definition: global_event.cc:84
GlobalSyncEvent::BarrierEvent::process
void process()
Definition: global_event.cc:141
mainEventQueue
vector< EventQueue * > mainEventQueue
Array for main event queues.
Definition: eventq.cc:56
BaseGlobalEvent::when
Tick when() const
Definition: global_event.hh:136
BaseGlobalEvent::reschedule
void reschedule(Tick when)
Definition: global_event.cc:97
EventQueue::handleAsyncInsertions
void handleAsyncInsertions()
Function for moving events from the async_queue to the main queue.
Definition: eventq.cc:435
curEventQueue
EventQueue * curEventQueue()
Definition: eventq.hh:83
Event::isFlagSet
bool isFlagSet(Flags _flags) const
Definition: eventq.hh:316
core.hh
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
GlobalSyncEvent::process
void process()
Definition: global_event.cc:155
BaseGlobalEvent::scheduled
bool scheduled() const
Definition: global_event.hh:126
BaseGlobalEvent::BarrierEvent::~BarrierEvent
~BarrierEvent()
Definition: global_event.cc:112
BaseGlobalEvent::schedule
void schedule(Tick when)
Definition: global_event.cc:53
EventBase::Priority
int8_t Priority
Definition: eventq.hh:118
EventQueue
Queue of events sorted in time order.
Definition: eventq.hh:617
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
global_event.hh
BaseGlobalEvent::globalQMutex
static std::mutex globalQMutex
Mutex variable for providing exculsive right to schedule global events.
Definition: global_event.hh:68
ArmISA::f
Bitfield< 6 > f
Definition: miscregs_types.hh:64
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45

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