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

Generated on Tue Sep 21 2021 12:25:47 for gem5 by doxygen 1.8.17