gem5  v22.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/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
virtual ~BaseGlobalEvent()
Definition: global_event.cc:46
void schedule(Tick when)
Definition: global_event.cc:56
BaseGlobalEvent(Priority p, Flags f)
Definition: global_event.cc:39
static std::mutex globalQMutex
Mutex variable for providing exculsive right to schedule global events.
Definition: global_event.hh:71
std::vector< BarrierEvent * > barrierEvent
The individual local event instances (one per thread/event queue).
void reschedule(Tick when)
bool scheduled() const
static const FlagsType AutoDelete
Definition: eventq.hh:107
Queue of events sorted in time order.
Definition: eventq.hh:623
void handleAsyncInsertions()
Function for moving events from the async_queue to the main queue.
Definition: eventq.cc:432
bool isFlagSet(Flags _flags) const
Definition: eventq.hh:321
const char * description() const
Global events and related declarations.
int8_t Priority
Definition: eventq.hh:123
Bitfield< 27 > q
Definition: misc_types.hh:55
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 56 > f
Definition: pagetable.hh:53
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
uint64_t Tick
Tick count type.
Definition: types.hh:58
EventQueue * curEventQueue()
Definition: eventq.hh:88
uint32_t numMainEventQueues
Current number of allocated main event queues.
Definition: eventq.cc:56
std::vector< EventQueue * > mainEventQueue
Array for main event queues.
Definition: eventq.cc:57

Generated on Wed Dec 21 2022 10:22:39 for gem5 by doxygen 1.9.1