Skip to content

Commit 4cfc7e4

Browse files
authored
DPL: make sure devices with Sporadic inputs get sorted last, if possible (#14459)
1 parent fdc30b1 commit 4cfc7e4

File tree

1 file changed

+77
-4
lines changed

1 file changed

+77
-4
lines changed

Framework/Core/src/TopologyPolicy.cxx

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,40 @@ bool dataDeps(DataProcessorSpec const& a, DataProcessorSpec const& b)
6969
return false;
7070
}
7171

72+
// This is to make sure that if a device has sporadic / timer inputs
73+
// it gets sorted after one which does not, in case there is no other
74+
// dependencies between the two.
75+
bool sporadicDataDeps(DataProcessorSpec const& a, DataProcessorSpec const& b)
76+
{
77+
auto checkSporadic = [](InputSpec const& input) {
78+
return input.lifetime == Lifetime::Sporadic;
79+
};
80+
bool isBWithSporadicInput = std::find_if(b.inputs.begin(), b.inputs.end(), checkSporadic) != b.inputs.end();
81+
bool isAWithSporadicInput = std::find_if(a.inputs.begin(), a.inputs.end(), checkSporadic) != a.inputs.end();
82+
// If neither has sporadic inputs, we return false and sort as usual
83+
if (!isAWithSporadicInput && !isBWithSporadicInput) {
84+
return false;
85+
}
86+
// If both have sporadic inputs, we return false and sort as usual.
87+
if (isAWithSporadicInput && isBWithSporadicInput) {
88+
return false;
89+
}
90+
// If a has sporadic inputs
91+
if (isAWithSporadicInput && isBWithSporadicInput) {
92+
return false;
93+
}
94+
95+
// We have a with sporadic inputs. We sort it later, unless there was already some actual
96+
// dependency between A and B.
97+
if (isAWithSporadicInput) {
98+
bool hasDependency = dataDeps(b, a);
99+
return !hasDependency;
100+
}
101+
102+
// b is has sporadic inputs and a does not. We are fine as it is.
103+
return false;
104+
}
105+
72106
bool expendableDataDeps(DataProcessorSpec const& a, DataProcessorSpec const& b)
73107
{
74108
O2_SIGNPOST_ID_GENERATE(sid, topology);
@@ -93,7 +127,7 @@ bool expendableDataDeps(DataProcessorSpec const& a, DataProcessorSpec const& b)
93127
return true;
94128
}
95129
// If we are here we do not have any data dependency,
96-
// however we strill consider a dependent on b if
130+
// however we still consider a dependent on b if
97131
// a has the "expendable" label and b does not.
98132
auto checkExpendable = [](DataProcessorLabel const& label) {
99133
if (label.value == "expendable") {
@@ -108,26 +142,45 @@ bool expendableDataDeps(DataProcessorSpec const& a, DataProcessorSpec const& b)
108142
}
109143
return false;
110144
};
145+
111146
bool isBExpendable = std::find_if(b.labels.begin(), b.labels.end(), checkExpendable) != b.labels.end();
112147
bool isAExpendable = std::find_if(a.labels.begin(), a.labels.end(), checkExpendable) != a.labels.end();
113148
bool bResilient = std::find_if(b.labels.begin(), b.labels.end(), checkResilient) != b.labels.end();
114149

115150
// If none is expendable. We simply return false and sort as usual.
116151
if (!isAExpendable && !isBExpendable) {
152+
bool sporadic = sporadicDataDeps(a, b);
153+
if (sporadic) {
154+
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "false. Neither %s nor %s are expendable. However the former has sporadic inputs so we sort it after.",
155+
a.name.c_str(), b.name.c_str());
156+
return true;
157+
}
117158
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "false. Neither %s nor %s are expendable. No dependency beyond data deps.",
118159
a.name.c_str(), b.name.c_str());
119160
return false;
120161
}
121162
// If both are expendable. We return false and sort as usual.
122163
if (isAExpendable && isBExpendable) {
164+
bool sporadic = sporadicDataDeps(a, b);
165+
if (sporadic) {
166+
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "false. Both %s and %s are expendable. However the former has sporadic inputs, so we sort it after.",
167+
a.name.c_str(), b.name.c_str());
168+
return true;
169+
}
123170
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "false. Both %s and %s are expendable. No dependency.",
124171
a.name.c_str(), b.name.c_str());
125172
return false;
126173
}
127174

128-
// If b is expendable but b is resilient, we can keep the same order.
175+
// If a is expendable but b is resilient, we can keep the same order.
129176
if (isAExpendable && bResilient) {
130-
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "false. %s is expendable but %s is resilient, no need to add an unneeded dependency",
177+
bool sporadic = sporadicDataDeps(a, b);
178+
if (sporadic) {
179+
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "false. %s is expendable but %s is resilient, however the former also has sporadic inputs, so we sort it after.",
180+
a.name.c_str(), b.name.c_str());
181+
return true;
182+
}
183+
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "false. %s is expendable but %s is resilient. No need to do do anything.",
131184
a.name.c_str(), b.name.c_str());
132185
return false;
133186
}
@@ -138,11 +191,31 @@ bool expendableDataDeps(DataProcessorSpec const& a, DataProcessorSpec const& b)
138191
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "%s is expendable. %s from %s to %s => %s.",
139192
a.name.c_str(), hasDependency ? "There is however an inverse dependency" : "No inverse dependency", b.name.c_str(), a.name.c_str(),
140193
!hasDependency ? "true" : "false");
141-
return !hasDependency;
194+
if (!hasDependency) {
195+
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "%s is expendable. There is however an inverse dependecy from %s to %s => true.",
196+
a.name.c_str(), b.name.c_str(), a.name.c_str());
197+
return true;
198+
}
199+
bool sporadic = sporadicDataDeps(a, b);
200+
if (sporadic) {
201+
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "%s is expendable. No inverse dependency from %s to %s. However the former has an occasioanl input => true.",
202+
a.name.c_str(), b.name.c_str(), a.name.c_str());
203+
}
204+
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "%s is expendable. No inverse dependency from %s to %s => false.",
205+
a.name.c_str(), b.name.c_str(), a.name.c_str());
206+
return false;
207+
}
208+
// b is expendable and a is not. We are fine with no dependency.
209+
bool sporadic = sporadicDataDeps(a, b);
210+
if (sporadic) {
211+
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "false. %s is expendable but %s is not. However the former has an sporadic input => true.",
212+
b.name.c_str(), a.name.c_str());
213+
return true;
142214
}
143215
// b is expendable and a is not. We are fine with no dependency.
144216
O2_SIGNPOST_END(topology, sid, "expendableDataDeps", "false. %s is expendable but %s is not. No need to add an unneeded dependency.",
145217
b.name.c_str(), a.name.c_str());
218+
146219
return false;
147220
};
148221

0 commit comments

Comments
 (0)