1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * Authors: Gabe Black 28 */ 29 30#include "systemc/core/event.hh" 31 32#include <algorithm> 33#include <cstring> 34#include <utility> 35 36#include "base/logging.hh" 37#include "sim/core.hh" 38#include "systemc/core/module.hh" 39#include "systemc/core/scheduler.hh" 40 41namespace sc_gem5 42{ 43 44Event::Event(sc_core::sc_event *_sc_event) : Event(_sc_event, "") {} 45 46Event::Event(sc_core::sc_event *_sc_event, const char *_basename) :
| 1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * Authors: Gabe Black 28 */ 29 30#include "systemc/core/event.hh" 31 32#include <algorithm> 33#include <cstring> 34#include <utility> 35 36#include "base/logging.hh" 37#include "sim/core.hh" 38#include "systemc/core/module.hh" 39#include "systemc/core/scheduler.hh" 40 41namespace sc_gem5 42{ 43 44Event::Event(sc_core::sc_event *_sc_event) : Event(_sc_event, "") {} 45 46Event::Event(sc_core::sc_event *_sc_event, const char *_basename) :
|
47 _sc_event(_sc_event), _basename(_basename), delayedNotifyEvent(this)
| 47 _sc_event(_sc_event), _basename(_basename), 48 delayedNotify([this]() { this->notify(); })
|
48{ 49 Module *p = currentModule(); 50 51 if (p) 52 parent = p->obj()->sc_obj(); 53 else if (scheduler.current()) 54 parent = scheduler.current(); 55 else 56 parent = nullptr; 57 58 if (parent) { 59 Object *obj = Object::getFromScObject(parent); 60 obj->addChildEvent(_sc_event); 61 } else { 62 topLevelEvents.emplace(topLevelEvents.end(), _sc_event); 63 } 64 65 if (parent) 66 _name = std::string(parent->name()) + "." + _basename; 67 else 68 _name = _basename; 69 70 allEvents.emplace(allEvents.end(), _sc_event); 71 72 // Determine if we're in the hierarchy (created once initialization starts 73 // means no). 74} 75 76Event::~Event() 77{ 78 if (parent) { 79 Object *obj = Object::getFromScObject(parent); 80 obj->delChildEvent(_sc_event); 81 } else { 82 EventsIt it = find(topLevelEvents.begin(), topLevelEvents.end(), 83 _sc_event); 84 assert(it != topLevelEvents.end()); 85 std::swap(*it, topLevelEvents.back()); 86 topLevelEvents.pop_back(); 87 } 88 89 EventsIt it = findEvent(_name); 90 std::swap(*it, allEvents.back()); 91 allEvents.pop_back(); 92
| 49{ 50 Module *p = currentModule(); 51 52 if (p) 53 parent = p->obj()->sc_obj(); 54 else if (scheduler.current()) 55 parent = scheduler.current(); 56 else 57 parent = nullptr; 58 59 if (parent) { 60 Object *obj = Object::getFromScObject(parent); 61 obj->addChildEvent(_sc_event); 62 } else { 63 topLevelEvents.emplace(topLevelEvents.end(), _sc_event); 64 } 65 66 if (parent) 67 _name = std::string(parent->name()) + "." + _basename; 68 else 69 _name = _basename; 70 71 allEvents.emplace(allEvents.end(), _sc_event); 72 73 // Determine if we're in the hierarchy (created once initialization starts 74 // means no). 75} 76 77Event::~Event() 78{ 79 if (parent) { 80 Object *obj = Object::getFromScObject(parent); 81 obj->delChildEvent(_sc_event); 82 } else { 83 EventsIt it = find(topLevelEvents.begin(), topLevelEvents.end(), 84 _sc_event); 85 assert(it != topLevelEvents.end()); 86 std::swap(*it, topLevelEvents.back()); 87 topLevelEvents.pop_back(); 88 } 89 90 EventsIt it = findEvent(_name); 91 std::swap(*it, allEvents.back()); 92 allEvents.pop_back(); 93
|
93 if (delayedNotifyEvent.scheduled()) 94 scheduler.deschedule(&delayedNotifyEvent);
| 94 if (delayedNotify.scheduled()) 95 scheduler.deschedule(&delayedNotify);
|
95} 96 97const std::string & 98Event::name() const 99{ 100 return _name; 101} 102 103const std::string & 104Event::basename() const 105{ 106 return _basename; 107} 108 109bool 110Event::inHierarchy() const 111{ 112 return _name.length() != 0; 113} 114 115sc_core::sc_object * 116Event::getParentObject() const 117{ 118 return parent; 119} 120 121void 122Event::notify() 123{ 124 auto local_sensitivities = sensitivities; 125 for (auto s: local_sensitivities) 126 s->notify(this); 127} 128 129void
| 96} 97 98const std::string & 99Event::name() const 100{ 101 return _name; 102} 103 104const std::string & 105Event::basename() const 106{ 107 return _basename; 108} 109 110bool 111Event::inHierarchy() const 112{ 113 return _name.length() != 0; 114} 115 116sc_core::sc_object * 117Event::getParentObject() const 118{ 119 return parent; 120} 121 122void 123Event::notify() 124{ 125 auto local_sensitivities = sensitivities; 126 for (auto s: local_sensitivities) 127 s->notify(this); 128} 129 130void
|
130Event::delayedNotify() 131{ 132 scheduler.eventHappened(); 133 notify(); 134} 135 136void
| |
137Event::notify(const sc_core::sc_time &t) 138{
| 131Event::notify(const sc_core::sc_time &t) 132{
|
139 //XXX We're assuming the systemc time resolution is in ps. 140 Tick new_tick = t.value() * SimClock::Int::ps + scheduler.getCurTick(); 141 if (delayedNotifyEvent.scheduled()) { 142 Tick old_tick = delayedNotifyEvent.when(); 143 144 if (new_tick >= old_tick)
| 133 if (delayedNotify.scheduled()) { 134 if (scheduler.delayed(t) >= delayedNotify.when())
|
145 return; 146
| 135 return; 136
|
147 scheduler.deschedule(&delayedNotifyEvent);
| 137 scheduler.deschedule(&delayedNotify);
|
148 }
| 138 }
|
149 150 scheduler.schedule(&delayedNotifyEvent, new_tick);
| 139 scheduler.schedule(&delayedNotify, t);
|
151} 152 153void 154Event::cancel() 155{
| 140} 141 142void 143Event::cancel() 144{
|
156 if (delayedNotifyEvent.scheduled()) 157 scheduler.deschedule(&delayedNotifyEvent);
| 145 if (delayedNotify.scheduled()) 146 scheduler.deschedule(&delayedNotify);
|
158} 159 160bool 161Event::triggered() const 162{ 163 return false; 164} 165 166Events topLevelEvents; 167Events allEvents; 168 169EventsIt 170findEvent(const std::string &name) 171{ 172 EventsIt it; 173 for (it = allEvents.begin(); it != allEvents.end(); it++) 174 if (!strcmp((*it)->name(), name.c_str())) 175 break; 176 177 return it; 178} 179 180} // namespace sc_gem5
| 147} 148 149bool 150Event::triggered() const 151{ 152 return false; 153} 154 155Events topLevelEvents; 156Events allEvents; 157 158EventsIt 159findEvent(const std::string &name) 160{ 161 EventsIt it; 162 for (it = allEvents.begin(); it != allEvents.end(); it++) 163 if (!strcmp((*it)->name(), name.c_str())) 164 break; 165 166 return it; 167} 168 169} // namespace sc_gem5
|