-
Notifications
You must be signed in to change notification settings - Fork 17
/
traffic_profile_desc.cc
187 lines (160 loc) · 6.23 KB
/
traffic_profile_desc.cc
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
/*
* SPDX-License-Identifier: BSD-3-Clause-Clear
*
* Copyright (c) 2015 ARM Limited
* All rights reserved
* Created on: Oct 2, 2015
* Author: Matteo Andreozzi
*/
#include "traffic_profile_desc.hh"
#include "traffic_profile_manager.hh"
#include "logger.hh"
#include "utilities.hh"
#include <algorithm>
#include <stdexcept>
namespace TrafficProfiles {
constexpr char TrafficProfileDescriptor::Name::Reserved;
const string TrafficProfileDescriptor::Name::CloneSuffix {
Reserved + string("clone")
};
const string TrafficProfileDescriptor::Name::Default {
Reserved + string("profile")
};
uint64_t TrafficProfileDescriptor::Name::AnonymousCount { 0 };
TrafficProfileDescriptor::TrafficProfileDescriptor(
TrafficProfileManager* manager, const uint64_t index, const Profile* p,
const uint64_t clone_num) :
EventManager(index,manager),
config(p),
role(NONE), type(p->type()), tpm(manager), id(index), name(p->name()),
masterName(""), masterId(0),
_masterIommuId(p->has_iommu_id() ?
p->iommu_id() : InvalidId<uint32_t>()),
ot(0), started(false), startTime(0), terminated(false) {
if (clone_num)
name.append(Name::CloneSuffix).append(to_string(clone_num - 1));
LOG("TrafficProfileDescriptor [", this->name, "]");
if (manager->isProfilesAsMasters()){
WARN("TrafficProfileDescriptor [", this->name, "] profile names used as master names");
}
// Initialise waited for events (base class only)
for (int i = 0; i < p->wait_for_size(); ++i) {
string eventStr = p->wait_for(i);
string profile;
Event::Type evType = Event::NONE;
if (Event::parse(evType, profile, eventStr)) {
// register events to the EventManager base class
// NOTE: FIFO events will be registered separately in FIFO init function
if (clone_num)
profile.append(Name::CloneSuffix)
.append(to_string(clone_num - 1));
waitEvent(evType, tpm->getOrGeneratePid(profile), true);
} else {
ERROR("TrafficProfileDescriptor", id, "unable to parse wait event",
eventStr);
}
}
// Initialise packet tagger with protobuf config if required for metadata
if (p->has_flow_id() || p->has_iommu_id() || p->has_pattern()) {
packetTagger = new PacketTagger();
// check for configured flow_id and add it to the Packet Tagger
if (p->has_flow_id()){
packetTagger->flow_id = p->flow_id();
LOG("TrafficProfileDescriptor [", this->name, "] uses ", p->flow_id(), " as flow_id");
}
// check for configured iommu_id and add it to the Packet Tagger
if (p->has_iommu_id()){
packetTagger->iommu_id = p->iommu_id();
LOG("TrafficProfileDescriptor [", this->name, "] uses ", p->iommu_id(), " as iommu_id");
}
}
// configure time scale in stats using the global time resolution
stats.timeScale = tpm->toFrequency(tpm->getTimeResolution());
}
TrafficProfileDescriptor::~TrafficProfileDescriptor() {
if (this->packetTagger != nullptr)
delete this->packetTagger;
}
void TrafficProfileDescriptor::reset() {
// restore waited termination events
EventManager::reset();
LOG("TrafficProfileDescriptor::reset [",
this->name, "] reset requested");
ot=0;
started=false;
if (terminated) tpm->signalReset(id);
terminated=false;
}
void TrafficProfileDescriptor::addToMaster(const uint64_t mId,
const string& name) {
masterId = mId;
masterName=name;
LOG("TrafficProfileDescriptor::addToMaster [", this->name, "] added to", masterName);
}
void TrafficProfileDescriptor::addToStream(const uint64_t stream_id) {
// check stream_id validity
if (isValid(stream_id)){
this->_streamId = stream_id;
// create packetTagger in case not instantiated
if (packetTagger == nullptr)
packetTagger = new PacketTagger();
packetTagger->stream_id = this->_streamId;
LOG("TrafficProfileDescriptor::", __func__, "[", this->name, "] added to", this->_streamId);
}
else {
ERROR("Attempting to add TrafficProfileDescriptor::", __func__, "[",
this->name, "] to invalid stream: ", this->_streamId);
}
}
void
TrafficProfileDescriptor::activate()
{
emitEvent(Event::ACTIVATION);
started = true;
startTime = tpm->getTime();
}
pair<uint64_t, uint64_t>
TrafficProfileDescriptor::parseRate(const string s) {
LOG("TrafficProfileDescriptor::parseRate [", this->name,
"] parsing",s);
uint64_t rate = 0, scale = 0, period = 0, multiplier = 0;
// load global ATP time tick frequency (Hz)
uint64_t atpFrequency = tpm->toFrequency(tpm->getTimeResolution());
// convert rate to B
tie(rate, multiplier) = Utilities::toRate<uint64_t>(s);
// rate was configured by specifying its unit
if (multiplier > 0) {
if (atpFrequency > rate) {
period = atpFrequency/multiplier;
}
else {
scale = multiplier/atpFrequency;
}
} else {
// no time unit configured, query TPM
// for normalized scale
// and period factors, load them
tie(scale, period) = tpm->getTimeScaleFactors(id);
}
// simplify rate with period
auto ret = Utilities::reduce(rate, period);
LOG("TrafficProfileDescriptor::parseRate [", this->name,
"] , configured FIFO rate to", ret.first, "every", ret.second,
" time units");
return ret;
}
uint64_t TrafficProfileDescriptor::parseTime(const string t) {
LOG("TrafficProfileDescriptor::parseTime [", this->name,
"] parsing",t);
double ret = 0;
// load global ATP time tick frequency (Hz)
double atpFrequency = tpm->toFrequency(tpm->getTimeResolution());
// convert passed time to frequency
double frequency = Utilities::timeToHz<double>(t);
// compute amount of time units - the error is +- 1 ATP time unit
ret = frequency > 0 ? atpFrequency/frequency : 0;
LOG("TrafficProfileDescriptor::parseTime [", this->name,
"], frequency",frequency,"computed time", ret,"ATP time units");
return (uint64_t)round(ret);
}
} // end of namespace