ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
Injector.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
6
7#ifndef NO_ETISS
9#include "etiss/Misc.h"
11#include "etiss/fault/Trigger.h"
12#include "etiss/fault/Action.h"
13#include "etiss/fault/Fault.h"
14#else
15#include "fault/Injector.h"
16#include "fault/Stressor.h"
17#include "fault/Trigger.h"
18#include "fault/Action.h"
19#include "fault/Fault.h"
20#endif
21
22#include <iostream>
23
24namespace etiss
25{
26
27namespace fault
28{
29
30int x;
32{
33 etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::Injector()"));
35}
36
38{
39 etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::freeFastFieldAccessPtr(void*)"));
40 etiss::log(etiss::VERBOSE, std::string("etiss::fault::Injector::freeFastFieldAccessPtr(void*) not implemented"));
41}
42
44{
45 etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::needsCallbacks()"));
47}
48
50{
51 bool ret = false;
52#if ETISS_DEBUG
53 etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::cycleAccurateCallback(time_ps=") +
54 std::to_string(time_ps) + ")");
55#endif
56 // copy pending triggers in a threadsafe manner to unknown triggers
58 {
59#if CXX0X_UP_SUPPORTED
60 std::lock_guard<std::mutex> lock(sync);
61#endif
63 pending_triggers.clear();
64 }
66 {
67#if CXX0X_UP_SUPPORTED
68 std::lock_guard<std::mutex> lock(sync);
69#endif
70 unknown_triggers.erase(std::remove_if(unknown_triggers.begin(), unknown_triggers.end(),
71 [&](const auto &unknown)
72 {
73 for (const auto &rm : remove_triggers)
74 {
75 if (unknown.second == rm.second)
76 return true;
77 }
78 return false;
79 }),
80 unknown_triggers.end());
81 remove_triggers.clear();
82 has_remove_triggers = false;
83 }
84 // check triggers
85 if (!unknown_triggers.empty())
86 {
87 for (auto &it : unknown_triggers)
88 {
89 if (it.first.check(time_ps, this))
90 { // trigger fired
91 // signal fired trigger
92 ret = true;
93 if (Stressor::firedTrigger(it.first, it.second, this, time_ps))
94 {
95 // explicitly remove triggers through Stressor::removeFault via Action::Type::EJECTION
96 }
97 }
98 }
99 }
100 return ret;
101}
102
103bool Injector::instructionAccurateCallback(uint64_t time_ps)
104{
105#if ETISS_DEBUG
106 etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::instructionAccurateCallback(time_ps=") +
107 std::to_string(time_ps) + ")");
108#endif
109 return cycleAccurateCallback(time_ps);
110}
111#if CXX0X_UP_SUPPORTED
112template <typename T>
116bool operator==(const std::shared_ptr<T> &p1, const T *const &p2)
117{
118 return p1.get() == p2;
119}
120#endif
121
122std::string Injector::getInjectorPath()
123{
124 std::string path;
125 ptr iptr = getParentInjector();
126 if (!iptr)
127 return path;
128
129 // Get Injector name
130 ptr cur;
131 for (const auto &name : iptr->listSubInjectors())
132 {
133 cur = iptr->getSubInjector(name);
134 if (cur == this)
135 {
136 path = name;
137 break;
138 }
139 }
140 if (!cur)
141 {
142#ifdef NO_ETISS
143 std::cout << "Injector::getInjectorPath: Failed to find injector" << std::endl;
144#else
145 etiss::log(etiss::ERROR, "Injector::getInjectorPath: Failed to find injector to create path name",
147#endif
148 return "";
149 }
150
151 // get names of parent VirtualStructs and combine them to path
152 cur = iptr;
153 iptr = iptr->getParentInjector();
154 while (iptr)
155 {
156 bool ok = false;
157 for (const auto &name : iptr->listSubInjectors())
158 {
159 ptr tmp = iptr->getSubInjector(name);
160 if (tmp == cur)
161 {
162 path = name + "::" + path;
163 ok = true;
164 break;
165 }
166 }
167 if (!ok)
168 {
169#ifdef NO_ETISS
170 std::cout << "Injector::getInjectorPath: Failed to find injector" << std::endl;
171#else
172 etiss::log(etiss::ERROR, "Injector::getInjectorPath: Failed to find injector to create path name",
174#endif
175 return "";
176 }
177 cur = iptr;
178 iptr = iptr->getParentInjector();
179 }
180
181 return path;
182}
183
184void Injector::addTrigger(const Trigger &t, int32_t fault_id)
185{
186 etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::addTrigger(Trigger&=") + t.toString() +
187 ", fault_id=" + std::to_string(fault_id) + ")");
188#if CXX0X_UP_SUPPORTED
189 std::lock_guard<std::mutex> lock(sync);
190#endif
191
192 // TODO: Commented out by MuellerGritschneder as it caused crash for time trigger
193 if (acceleratedTrigger(t, fault_id))
194 {
195
196 // trigger is handled internally without callbacks
197 }
198 else
199 {
200 pending_triggers.push_back(std::pair<Trigger, int32_t>(t, fault_id));
201 has_pending_triggers = true;
202 }
203}
204
205void Injector::removeTrigger(const Trigger &t, int32_t fault_id)
206{
207 etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::removeTrigger(Trigger&=") + t.toString() +
208 ", fault_id=" + std::to_string(fault_id) + ")");
209#if CXX0X_UP_SUPPORTED
210 std::lock_guard<std::mutex> lock(sync);
211#endif
212 remove_triggers.push_back(std::pair<Trigger, int32_t>(t, fault_id));
213 has_remove_triggers = true;
214}
215
216bool Injector::acceleratedTrigger(const etiss::fault::Trigger &t, int32_t fault_id)
217{
218 etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::acceleratedTrigger(Trigger&=") +
219 t.toString() + ", fault_id=" + std::to_string(fault_id) + ")");
220 return false;
221}
222
223} // namespace fault
224
225} // namespace etiss
contains an action class that describes actions associated with a fault
contains the fault container class that stores triggers and actions for fault injection
contains the fault injector interface class.
general configuration and logging
#define ETISS_SRCLOC
Definition Misc.h:202
contains the stressor class that loads and activates faults.
contains the Trigger class that defines conditions under which actions of a Fault need to be applied.
static __inline__ uint64_t
Definition arm_cde.h:31
static __inline__ int32_t
Definition arm_mve.h:51
#define unlikely(x)
Definition types.h:36
virtual ptr getParentInjector()=0
get a the parent injector (root returns 0).
virtual void freeFastFieldAccessPtr(void *)
MUST be called to cleanup a pointer acquired with fastFieldAccessPtr() default implementation is nop.
Definition Injector.cpp:37
virtual bool needsCallbacks()
Definition Injector.cpp:43
virtual ptr getSubInjector(const std::string &name)=0
get a sub injector.
std::list< std::pair< Trigger, int32_t > > remove_triggers
Triggers to synchronously remove on next callback (prio over pending)
Definition Injector.h:159
virtual std::list< std::string > listSubInjectors()=0
list all sub injectors.
std::list< std::pair< Trigger, int32_t > > unknown_triggers
Triggers to look at in callbacks.
Definition Injector.h:157
virtual bool cycleAccurateCallback(uint64_t time_ps)
Definition Injector.cpp:49
std::list< std::pair< Trigger, int32_t > > pending_triggers
Triggers which were just added.
Definition Injector.h:156
static bool firedTrigger(const Trigger &firedTrigger, int32_t fault_id, Injector *injector, uint64_t time_ps)
Checks if the given trigger is valid and calls applyAction.
Definition Stressor.cpp:353
std::string toString() const
operator<< can be used.
Definition Trigger.cpp:350
forwards: include/jit/*
Definition Benchmark.h:17
@ VERBOSE
Definition Misc.h:88
@ ERROR
Definition Misc.h:85
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:94