-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathStressor.cpp
284 lines (245 loc) · 9.41 KB
/
Stressor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
@copyright
<pre>
Copyright 2018 Infineon Technologies AG
This file is part of ETISS tool, see <https://github.com/tum-ei-eda/etiss>.
The initial version of this software has been created with the funding support by the German Federal
Ministry of Education and Research (BMBF) in the project EffektiV under grant 01IS13022.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
</pre>
@author Chair of Electronic Design Automation, TUM
@version 0.1
*/
#ifndef NO_ETISS
#include "etiss/fault/Stressor.h"
#include "etiss/Misc.h"
#include "etiss/fault/Injector.h"
#else
#include "fault/Injector.h"
#include "fault/Stressor.h"
#endif
#include <fstream>
#include <iostream>
#include <map>
#if CXX0X_UP_SUPPORTED
#include <mutex>
#endif
namespace etiss
{
namespace fault
{
#if CXX0X_UP_SUPPORTED
static std::mutex &faults_sync()
{
static std::mutex mu;
return mu;
}
#endif
// Map with all faults found in XML file
static std::map<int32_t, Fault> &faults()
{
static std::map<int32_t, Fault> map;
return map;
}
bool Stressor::loadXML(const std::string &file, const int coreID)
{
#ifdef NO_ETISS
std::cout << std::string("Called etiss::fault::Stressor::loadXML(file=") + file + std::string(")") << std::endl;
#else
etiss::log(etiss::INFO, std::string("Called etiss::fault::Stressor::loadXML(file=") + file + std::string(")"));
#endif
coreIDActuallXML = coreID;
// Vector which gets the faults of the xml file
std::vector<Fault> faults;
// open and parse file
std::ifstream in;
in.open(file.c_str());
if (!in.is_open())
{
#ifdef NO_ETISS
std::cout << "etiss::fault::Stressor::loadXML(): Failed open file " << file << std::endl;
#else
etiss::log(etiss::ERROR, std::string("etiss::fault::Stressor::loadXML:") +
std::string(" Failed to open Trigger file ") + file);
#endif
return false;
}
if (!etiss::fault::parseXML(faults, in, std::cout))
{
#ifdef NO_ETISS
std::cout << "etiss::fault::Stressor::loadXML: Failed parse file " << file << std::endl;
#else
etiss::log(etiss::ERROR,
std::string("etiss::fault::Stressor::loadXML:") + std::string(" Failed to parse file ") + file);
#endif
return false;
}
// add faults into a map -> access with static std::map<int32_t,Fault> &
// faults()
bool ok = true;
for (size_t i = 0; i < faults.size(); ++i)
{
if (!addFault(faults[i]))
{
#ifdef NO_ETISS
std::cout << "etiss::fault::Stressor::loadXML: Failed to add Fault: " << faults[i].name_ << std::endl;
#else
etiss::log(etiss::ERROR,
std::string("etiss::fault::Stressor::loadXML:") + std::string(" Failed to add Fault "),
faults[i]);
#endif
ok = false;
}
}
return ok;
}
bool Stressor::addFault(const Fault &f)
{
#if CXX0X_UP_SUPPORTED
std::lock_guard<std::mutex> lock(faults_sync());
#endif
#ifdef NO_ETISS
std::cout << "etiss::fault::Stressor::addFault called." << std::endl;
#else
etiss::log(etiss::INFO, std::string("etiss::fault::Stressor::addFault called. "));
#endif
// check if fault already exists
std::map<int32_t, Fault>::iterator find = faults().find(f.id_);
if (find != faults().end())
{
#ifdef NO_ETISS
std::cout << "etiss::fault::Stressor::addFault: Trigger already exists:" << f.toString() << std::endl;
#else
etiss::log(etiss::ERROR,
std::string("etiss::fault::Stressor::addFault:") + std::string(" Trigger already exists. "), f);
#endif
return false;
}
// insert fault into map
faults().insert(std::pair<int32_t, Fault>(f.id_, f));
// Iterate through triggers of the fault
for (std::vector<Trigger>::const_iterator iter = f.triggers.begin(); iter != f.triggers.end(); ++iter)
{
Injector::ptr iptr = iter->getInjector();
if (iptr)
{
#ifdef NO_ETISS
std::cout << "etiss::fault::Stressor::addFault: Added trigger: " << iter->toString() << std::endl;
#else
etiss::log(etiss::INFO, std::string("etiss::fault::Stressor::addFault:") + std::string(" Added trigger: "),
*iter);
#endif
iptr->addTrigger(*iter, f.id_);
}
else
{
#ifdef NO_ETISS
std::cout << "etiss::fault::Stressor::addFault: Error: Injector not found for: " << iter->toString()
<< std::endl;
#else
etiss::log(etiss::ERROR,
std::string("etiss::fault::Stressor::addFault:") + std::string(" Injector not found for "),
*iter);
#endif
/// TODO signal error and roll back
}
}
return true;
}
bool Stressor::firedTrigger(const Trigger &triggered, int32_t fault_id, Injector *injector, uint64_t time_ps)
{
etiss::log(etiss::VERBOSE, std::string("etiss::fault::Stressor::firedTrigger() called. "));
#if CXX0X_UP_SUPPORTED
std::lock_guard<std::mutex> lock(faults_sync());
#endif
// find fault in fault-map
std::map<int32_t, Fault>::iterator find = faults().find(fault_id);
if (find != faults().end())
{
// iterate through the actions of the given fault
for (std::vector<etiss::fault::Action>::iterator iter = find->second.actions.begin();
iter != find->second.actions.end(); ++iter)
{
if (iter->getType() == etiss::fault::Action::INJECTION)
{
/// TODO for time relative triggers resolve time must be called!
addFault(iter->getFault());
}
else
{
if (iter->getInjectorAddress().getInjector())
{
#if CXX0X_UP_SUPPORTED
if (iter->getInjectorAddress().getInjector().get() != injector)
#else
if (iter->getInjectorAddress().getInjector() != injector)
#endif
{
#ifndef NO_ETISS
etiss::log(etiss::WARNING,
std::string("etiss::fault::Stressor::firedTrigger: Action") +
std::string(" injector is not the injector that triggered this event.") +
std::string(" threadsafety must be ensured by user."),
find->second, *iter);
#endif
}
std::string err;
if (!iter->getInjectorAddress().getInjector()->applyAction(find->second, *iter, err))
{
#ifdef NO_ETISS
std::cout << "Stressor::firedTrigger: Failed to apply action. Fault: " << fault_id << " ["
<< err << "]" << std::endl;
#else
etiss::log(etiss::ERROR, std::string("Stressor::firedTrigger: Failed to apply action "),
find->second, *iter, err);
#endif
}
return true; /// TODO: when returning true here. the next action will not be applied!
}
else
{
#ifdef NO_ETISS
std::cout << "Stressor::firedTrigger: Failed to find action target. Fault: " << fault_id
<< std::endl;
#else
etiss::log(etiss::ERROR, std::string("Stressor::firedTrigger: Failed to find action target"),
find->second, *iter);
#endif
}
}
}
}
else
{
#ifdef NO_ETISS
std::cout << "Stressor::firedTrigger: Failed to find triggered Fault: " << fault_id << std::endl;
#else
etiss::log(etiss::ERROR, std::string("Stressor::firedTrigger: Failed to find triggered Fault: "), fault_id);
#endif
}
return true;
}
void Stressor::clear()
{
#if CXX0X_UP_SUPPORTED
std::lock_guard<std::mutex> lock(faults_sync());
#endif
faults().clear();
}
} // namespace fault
} // namespace etiss