ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
Injector.cpp
Go to the documentation of this file.
1 /*
2 
3  @copyright
4 
5  <pre>
6 
7  Copyright 2018 Infineon Technologies AG
8 
9  This file is part of ETISS tool, see <https://github.com/tum-ei-eda/etiss>.
10 
11  The initial version of this software has been created with the funding support by the German Federal
12  Ministry of Education and Research (BMBF) in the project EffektiV under grant 01IS13022.
13 
14  Redistribution and use in source and binary forms, with or without modification, are permitted
15  provided that the following conditions are met:
16 
17  1. Redistributions of source code must retain the above copyright notice, this list of conditions and
18  the following disclaimer.
19 
20  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
21  and the following disclaimer in the documentation and/or other materials provided with the distribution.
22 
23  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
24  or promote products derived from this software without specific prior written permission.
25 
26  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
27  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
29  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  POSSIBILITY OF SUCH DAMAGE.
34 
35  </pre>
36 
37  @author Chair of Electronic Design Automation, TUM
38 
39  @version 0.1
40 
41 */
42 
43 #ifndef NO_ETISS
44 #include "etiss/fault/Injector.h"
45 #include "etiss/Misc.h"
46 #include "etiss/fault/Stressor.h"
47 #else
48 #include "fault/Injector.h"
49 #include "fault/Stressor.h"
50 #endif
51 
52 #include <iostream>
53 
54 namespace etiss
55 {
56 
57 namespace fault
58 {
59 
60 int x;
62 {
63  etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::Injector()"));
64  has_pending_triggers = false;
65 }
66 
68 {
69  etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::freeFastFieldAccessPtr(void*)"));
70  etiss::log(etiss::INFO, std::string("etiss::fault::Injector::freeFastFieldAccessPtr(void*) not implemented"));
71 }
72 
74 {
75  etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::needsCallbacks()"));
76  return has_pending_triggers;
77 }
78 
80 {
81  bool ret = false;
82 #if ETISS_DEBUG
83  etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::cycleAccurateCallback(time_ps=") +
84  std::to_string(time_ps) + ")");
85 #endif
86  // copy pending triggers in a threadsafe manner to unknown triggers
88  {
89 #if CXX0X_UP_SUPPORTED
90  std::lock_guard<std::mutex> lock(sync);
91 #endif
93  pending_triggers.clear();
94  }
95  // check triggers
96  if (!unknown_triggers.empty())
97  {
98  for (std::list<std::pair<Trigger, int32_t>>::iterator iter = unknown_triggers.begin();
99  iter != unknown_triggers.end();)
100  {
101  if (iter->first.fired(time_ps, this))
102  { // trigger fired
103  // signal fired trigger
104  ret = true;
105  if (Stressor::firedTrigger(iter->first, iter->second, this, time_ps))
106  {
107  // remove fired trigger
108  unknown_triggers.erase(iter++);
109  }
110  else
111  {
112  ++iter;
113  }
114  }
115  else
116  {
117  ++iter;
118  }
119  }
120  }
121  return ret;
122 }
124 {
125 #if ETISS_DEBUG
126  etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::instructionAccurateCallback(time_ps=") +
127  std::to_string(time_ps) + ")");
128 #endif
129  return cycleAccurateCallback(time_ps);
130 }
131 #if CXX0X_UP_SUPPORTED
132 template <typename T>
136 bool operator==(const std::shared_ptr<T> &p1, const T *const &p2)
137 {
138  return p1.get() == p2;
139 }
140 #endif
141 
143 {
144  std::string path;
145  ptr iptr = getParentInjector();
146  if (!iptr)
147  return path;
148 
149  // Get Injector name
150  ptr cur;
151  for (const auto &name : iptr->listSubInjectors())
152  {
153  cur = iptr->getSubInjector(name);
154  if (cur == this)
155  {
156  path = name;
157  break;
158  }
159  }
160  if (!cur)
161  {
162 #ifdef NO_ETISS
163  std::cout << "Injector::getInjectorPath: Failed to find injector" << std::endl;
164 #else
165  etiss::log(etiss::ERROR, "Injector::getInjectorPath: Failed to find injector to create path name",
166  ETISS_SRCLOC);
167 #endif
168  return "";
169  }
170 
171  // get names of parent VirtualStructs and combine them to path
172  cur = iptr;
173  iptr = iptr->getParentInjector();
174  while (iptr)
175  {
176  bool ok = false;
177  for (const auto &name : iptr->listSubInjectors())
178  {
179  ptr tmp = iptr->getSubInjector(name);
180  if (tmp == cur)
181  {
182  path = name + "::" + path;
183  ok = true;
184  break;
185  }
186  }
187  if (!ok)
188  {
189 #ifdef NO_ETISS
190  std::cout << "Injector::getInjectorPath: Failed to find injector" << std::endl;
191 #else
192  etiss::log(etiss::ERROR, "Injector::getInjectorPath: Failed to find injector to create path name",
193  ETISS_SRCLOC);
194 #endif
195  return "";
196  }
197  cur = iptr;
198  iptr = iptr->getParentInjector();
199  }
200 
201  return path;
202 }
203 
204 void Injector::addTrigger(const Trigger &t, int32_t fault_id)
205 {
206  etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::addTrigger(Trigger&=") + t.toString() +
207  ", fault_id=" + std::to_string(fault_id) + ")");
208 #if CXX0X_UP_SUPPORTED
209  std::lock_guard<std::mutex> lock(sync);
210 #endif
211 
212  // TODO: Commented out by MuellerGritschneder as it caused crash for time trigger
213  if (acceleratedTrigger(t, fault_id))
214  {
215 
216  // trigger is handled internally without callbacks
217  }
218  else
219  {
220  pending_triggers.push_back(std::pair<Trigger, int32_t>(t, fault_id));
221  has_pending_triggers = true;
222  }
223 }
224 
226 {
227  etiss::log(etiss::VERBOSE, std::string("Called etiss::fault::Injector::acceleratedTrigger(Trigger&=") +
228  t.toString() + ", fault_id=" + std::to_string(fault_id) + ")");
229  return false;
230 }
231 
232 } // namespace fault
233 
234 } // namespace etiss
contains the fault injector interface class.
general configuration and logging
#define ETISS_SRCLOC
Definition: Misc.h:239
contains the stressor class that loads and activates faults.
static __inline__ uint64_t
Definition: arm_cde.h:31
static __inline__ int32_t
Definition: arm_mve.h:51
virtual bool acceleratedTrigger(const etiss::fault::Trigger &, int32_t fault_id)
Definition: Injector.cpp:225
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:67
virtual bool needsCallbacks()
Definition: Injector.cpp:73
virtual std::string getInjectorPath()
returns the path of the current object.
Definition: Injector.cpp:142
virtual ptr getSubInjector(const std::string &name)=0
get a sub injector.
virtual std::list< std::string > listSubInjectors()=0
list all sub injectors.
volatile bool has_pending_triggers
Definition: Injector.h:178
std::list< std::pair< Trigger, int32_t > > unknown_triggers
> Triggers which were just added
Definition: Injector.h:180
virtual bool instructionAccurateCallback(uint64_t time_ps)
Definition: Injector.cpp:123
virtual bool cycleAccurateCallback(uint64_t time_ps)
Definition: Injector.cpp:79
std::list< std::pair< Trigger, int32_t > > pending_triggers
Definition: Injector.h:179
void addTrigger(const Trigger &t, int32_t fault_id)
> Triggers to look at in callbacks
Definition: Injector.cpp:204
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:198
std::string toString() const
operator<< can be used.
Definition: Trigger.cpp:352
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition: Benchmark.h:53
@ INFO
Definition: Misc.h:129
@ VERBOSE
Definition: Misc.h:130
@ ERROR
Definition: Misc.h:127
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition: Misc.cpp:125