Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ foreach(w
Forwarding
ParallelPipeline
ParallelProducer
PipelinedSourceEndOfStream
SlowConsumer
SlowProducerWithWildCard
SimpleDataProcessingDevice01
Expand Down Expand Up @@ -431,6 +432,15 @@ if (BUILD_TESTING)
# TODO: DanglingInput test not working for the moment [ERROR] Unable to relay
# part. [WARN] Incoming data is already obsolete, not relaying.
set_property(TEST test_Framework_test_DanglingInputs PROPERTY DISABLED TRUE)
# The ended lane never produces its timeslices, so the ordered consumers must not report them as dropped,
# but they must report a timeframe really missing on the live lane, or dropped by a device upstream.
set_property(TEST test_Framework_test_PipelinedSourceEndOfStream PROPERTY FAIL_REGULAR_EXPRESSION "CRITICAL\\] Some Lifetime::Timeframe data got dropped")
foreach(missing direct relayed)
add_test(NAME test_Framework_test_PipelinedSourceEndOfStream_${missing}
COMMAND O2test-framework-PipelinedSourceEndOfStream ${DPL_WORKFLOW_TESTS_EXTRA_OPTIONS} --run --shm-segment-size 20000000 --missing ${missing})
set_tests_properties(test_Framework_test_PipelinedSourceEndOfStream_${missing} PROPERTIES LABELS "framework;workflow" TIMEOUT 30
PASS_REGULAR_EXPRESSION "ordered-${missing}\\]: [^ ]*CRITICAL\\] Some Lifetime::Timeframe data got dropped starting at 20[^0-9]")
endforeach()

endif()

Expand Down
3 changes: 2 additions & 1 deletion Framework/Core/include/Framework/DataProcessingDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class DataProcessingDevice : public fair::mq::Device
static void doRun(ServiceRegistryRef);
static void doPrepare(ServiceRegistryRef);
static void handleData(ServiceRegistryRef, InputChannelInfo&);
static bool tryDispatchComputation(ServiceRegistryRef ref, std::vector<DataRelayer::RecordAction>& completed);
/// @a drainingAtEndOfStream: the caller sends the end of stream itself, once all is processed.
static bool tryDispatchComputation(ServiceRegistryRef ref, std::vector<DataRelayer::RecordAction>& completed, bool drainingAtEndOfStream = false);

protected:
void error(const char* msg);
Expand Down
4 changes: 4 additions & 0 deletions Framework/Core/include/Framework/DataProcessingHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ struct DataProcessingHelpers {
static bool sendOldestPossibleTimeframe(ServiceRegistryRef const& ref, OutputChannelInfo const& info, OutputChannelState& state, size_t timeslice);
/// Broadcast the oldest possible timeslice to all channels in output
static void broadcastOldestPossibleTimeslice(ServiceRegistryRef const& ref, size_t timeslice);
/// An ordered consumer skips the timeslices from @a from to @a to, excluded: report them as dropped.
static void skipTimeslices(ServiceRegistryRef const& ref, int64_t from, int64_t to);
/// An ordered consumer consumes @a timeslice: report what was skipped before in the same source lane.
static void consumeTimeslice(ServiceRegistryRef const& ref, int64_t timeslice);
/// change the device StreamingState to newState
static void switchState(ServiceRegistryRef const& ref, StreamingState newState);
/// check if spec is a source devide
Expand Down
3 changes: 3 additions & 0 deletions Framework/Core/include/Framework/DeviceSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ struct DeviceSpec {
size_t inputTimesliceId;
/// The maximum number of time pipelining for this device.
size_t maxInputTimeslices;
/// The lcm of the lane counts of the time pipelined, enumeration driven sources upstream: their
/// lane l gets the timeslices t with t % lanes == l, and a lane can end before the others.
size_t upstreamSourceLanes = 1;
/// The completion policy to use for this device.
CompletionPolicy completionPolicy;
DispatchPolicy dispatchPolicy;
Expand Down
10 changes: 3 additions & 7 deletions Framework/Core/src/CommonServices.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -597,17 +597,11 @@ auto decongestionCallbackOrdered = [](AsyncTask& task, size_t id) -> void {
auto& ref = task.user<DecongestionContext>().ref;

auto& decongestion = ref.get<DecongestionService>();
auto& state = ref.get<DeviceState>();
auto& timesliceIndex = ref.get<TimesliceIndex>();
O2_SIGNPOST_ID_GENERATE(cid, async_queue);
int64_t oldNextTimeslice = decongestion.nextTimeslice;
decongestion.nextTimeslice = std::max(decongestion.nextTimeslice, (int64_t)oldestPossibleOutput.timeslice.value);
if (oldNextTimeslice != decongestion.nextTimeslice) {
if (state.transitionHandling != TransitionHandlingState::NoTransition && DefaultsHelpers::onlineDeploymentMode()) {
O2_SIGNPOST_EVENT_EMIT_WARN(async_queue, cid, "oldest_possible_timeslice", "Stop transition requested. Some Lifetime::Timeframe data got dropped starting at %" PRIi64, oldNextTimeslice);
} else {
O2_SIGNPOST_EVENT_EMIT_CRITICAL(async_queue, cid, "oldest_possible_timeslice", "Some Lifetime::Timeframe data got dropped starting at %" PRIi64, oldNextTimeslice);
}
DataProcessingHelpers::skipTimeslices(ref, oldNextTimeslice, decongestion.nextTimeslice);
timesliceIndex.rescan();
}
};
Expand Down Expand Up @@ -676,6 +670,7 @@ o2::framework::ServiceSpec
break;
}
}
decongestion->pendingGaps.assign(services.get<DeviceSpec const>().upstreamSourceLanes, -1);
auto& queue = services.get<AsyncQueue>();
decongestion->oldestPossibleTimesliceTask = AsyncQueueHelpers::create(queue, {.name = "oldest-possible-timeslice", .score = 100});
return ServiceHandle{TypeIdHelpers::uniqueId<DecongestionService>(), decongestion, ServiceKind::Serial};
Expand Down Expand Up @@ -752,6 +747,7 @@ o2::framework::ServiceSpec
decongestion->nextEnumerationTimesliceRewinded = false;
decongestion->lastTimeslice = 0;
decongestion->nextTimeslice = 0;
std::ranges::fill(decongestion->pendingGaps, -1);
decongestion->oldestPossibleTimesliceTask = {0};
auto &state = services.get<DeviceState>();
for (auto &channel : state.inputChannelInfos) {
Expand Down
3 changes: 2 additions & 1 deletion Framework/Core/src/CompletionPolicyHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "Framework/CompletionPolicyHelpers.h"
#include "Framework/CompletionPolicy.h"
#include "Framework/DataProcessingHelpers.h"
#include "Framework/DataProcessingHeader.h"
#include "Framework/InputSpan.h"
#include "Framework/DeviceSpec.h"
Expand Down Expand Up @@ -191,7 +192,7 @@ CompletionPolicy CompletionPolicyHelpers::consumeWhenAllOrdered(const char* name
return CompletionPolicy::CompletionOp::Retry;
}
}
decongestionService.nextTimeslice++;
DataProcessingHelpers::consumeTimeslice(ref, decongestionService.nextTimeslice++);
return CompletionPolicy::CompletionOp::ConsumeAndRescan;
};
return CompletionPolicy{name, matcher, callbackFull};
Expand Down
36 changes: 31 additions & 5 deletions Framework/Core/src/DataProcessingDevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,9 @@ void DataProcessingDevice::doPrepare(ServiceRegistryRef ref)
O2_SIGNPOST_END(device, dpid, "do_prepare", "Nothing to poll. Waiting for next iteration.");
return;
}
auto currentOldest = state.inputChannelInfos[pollOrder.front()].oldestForChannel;
// A completed channel with nothing left to relay will not send anything anymore, so it must not hold back the others.
auto oldestRunning = std::ranges::find_if(pollOrder, [&infos = state.inputChannelInfos](int a) { return infos[a].state != InputChannelState::Completed || infos[a].parts.Size(); });
auto currentOldest = state.inputChannelInfos[oldestRunning != pollOrder.end() ? *oldestRunning : pollOrder.front()].oldestForChannel;
auto currentNewest = state.inputChannelInfos[pollOrder.back()].oldestForChannel;
auto delta = currentNewest.value - currentOldest.value;
O2_SIGNPOST_EVENT_EMIT(device, dpid, "do_prepare", "Oldest possible timeframe range %" PRIu64 " => %" PRIu64 " delta %" PRIu64,
Expand Down Expand Up @@ -1729,8 +1731,27 @@ void DataProcessingDevice::doRun(ServiceRegistryRef ref)

bool shouldProcess = DataProcessingHelpers::hasOnlyGenerated(spec) == false;

while (DataProcessingDevice::tryDispatchComputation(ref, streamContext.completed) && shouldProcess) {
relayer.processDanglingInputs(context.expirationHandlers, *context.registry, false);
auto& decongestion = ref.get<DecongestionService>();
while (true) {
while (DataProcessingDevice::tryDispatchComputation(ref, streamContext.completed, true) && shouldProcess) {
relayer.processDanglingInputs(context.expirationHandlers, *context.registry, false);
}
// No input can arrive anymore, so an ordered consumer must not wait for the timeslices it misses.
if (!shouldProcess || !decongestion.orderedCompletionPolicyActive) {
break;
}
auto& index = ref.get<TimesliceIndex>();
auto oldest = std::numeric_limits<int64_t>::max();
for (size_t si = 0; si < index.size(); si++) {
if (index.isValid(TimesliceSlot{si})) {
oldest = std::min(oldest, (int64_t)VariableContextHelpers::getTimeslice(index.getVariablesForSlot(TimesliceSlot{si})).value);
}
}
if (oldest == std::numeric_limits<int64_t>::max() || oldest <= decongestion.nextTimeslice) {
break;
}
DataProcessingHelpers::skipTimeslices(ref, std::exchange(decongestion.nextTimeslice, oldest), oldest);
index.rescan();
}

auto& timingInfo = ref.get<TimingInfo>();
Expand Down Expand Up @@ -2115,6 +2136,11 @@ void DataProcessingDevice::handleData(ServiceRegistryRef ref, InputChannelInfo&
}
auto it = std::remove_if(parts.fParts.begin(), parts.fParts.end(), [](auto& msg) -> bool { return msg.get() == nullptr; });
parts.fParts.erase(it, parts.end());
// Once completed with nothing left to relay, the channel no longer holds back the oldest possible input.
if (info.channelType == ChannelAccountingType::DPL && info.state == InputChannelState::Completed && parts.Size() == 0) {
auto& context = ref.get<DataProcessorContext>();
context.domainInfoUpdatedCallback(*context.registry, info.oldestForChannel.value, info.id);
}
if (parts.fParts.size()) {
LOG(debug) << parts.fParts.size() << " messages backpressured";
}
Expand Down Expand Up @@ -2186,7 +2212,7 @@ void update_maximum(std::atomic<T>& maximum_value, T const& value) noexcept
}
} // namespace

bool DataProcessingDevice::tryDispatchComputation(ServiceRegistryRef ref, std::vector<DataRelayer::RecordAction>& completed)
bool DataProcessingDevice::tryDispatchComputation(ServiceRegistryRef ref, std::vector<DataRelayer::RecordAction>& completed, bool drainingAtEndOfStream)
{
auto& context = ref.get<DataProcessorContext>();
LOGP(debug, "DataProcessingDevice::tryDispatchComputation");
Expand Down Expand Up @@ -2620,7 +2646,7 @@ bool DataProcessingDevice::tryDispatchComputation(ServiceRegistryRef ref, std::v
O2_SIGNPOST_END(device, sid, "device", "Start processing ready actions");

// We now broadcast the end of stream if it was requested
if (state.streaming == StreamingState::EndOfStreaming) {
if (state.streaming == StreamingState::EndOfStreaming && !drainingAtEndOfStream) {
LOGP(detail, "Broadcasting end of stream");
for (auto& channel : spec.outputChannels) {
DataProcessingHelpers::sendEndOfStream(ref, channel);
Expand Down
38 changes: 38 additions & 0 deletions Framework/Core/src/DataProcessingHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,44 @@ void DataProcessingHelpers::broadcastOldestPossibleTimeslice(ServiceRegistryRef
}
}

namespace
{
void reportDroppedTimeslices(ServiceRegistryRef const& ref, int64_t timeslice)
{
O2_SIGNPOST_ID_GENERATE(sid, device);
if (ref.get<DeviceState>().transitionHandling != TransitionHandlingState::NoTransition && DefaultsHelpers::onlineDeploymentMode()) {
O2_SIGNPOST_EVENT_EMIT_WARN(device, sid, "oldest_possible_timeslice", "Stop transition requested. Some Lifetime::Timeframe data got dropped starting at %" PRIi64, timeslice);
} else {
O2_SIGNPOST_EVENT_EMIT_CRITICAL(device, sid, "oldest_possible_timeslice", "Some Lifetime::Timeframe data got dropped starting at %" PRIi64, timeslice);
}
}
} // namespace

void DataProcessingHelpers::skipTimeslices(ServiceRegistryRef const& ref, int64_t from, int64_t to)
{
// Behind time pipelined sources (DeviceSpec::upstreamSourceLanes) the timeslices of a lane which ended are
// skipped too, without any loss: report a gap only once a later timeslice of the same lane is consumed.
auto& gaps = ref.get<DecongestionService>().pendingGaps;
auto lanes = (int64_t)gaps.size();
if (lanes <= 1) {
reportDroppedTimeslices(ref, from);
return;
}
O2_SIGNPOST_ID_GENERATE(sid, device);
O2_SIGNPOST_EVENT_EMIT(device, sid, "oldest_possible_timeslice", "Skipping timeslices from %" PRIi64 " to %" PRIi64 ", dropped if their lane goes on", from, to);
for (auto t = from; t < std::min(to, from + lanes); t++) {
gaps[t % lanes] = gaps[t % lanes] < 0 ? t : gaps[t % lanes];
}
}

void DataProcessingHelpers::consumeTimeslice(ServiceRegistryRef const& ref, int64_t timeslice)
{
auto& gaps = ref.get<DecongestionService>().pendingGaps;
if (gaps.size() > 1 && gaps[timeslice % gaps.size()] >= 0) {
reportDroppedTimeslices(ref, std::exchange(gaps[timeslice % gaps.size()], -1));
}
}

void DataProcessingHelpers::switchState(ServiceRegistryRef const& ref, StreamingState newState)
{
auto& state = ref.get<DeviceState>();
Expand Down
4 changes: 4 additions & 0 deletions Framework/Core/src/DecongestionService.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#ifndef O2_FRAMEWORK_DECONGESTIONSERVICE_H_
#define O2_FRAMEWORK_DECONGESTIONSERVICE_H_
#include "Framework/AsyncQueue.h"
#include <vector>

namespace o2::framework
{
Expand All @@ -31,6 +32,9 @@ struct DecongestionService {
/// The next timeslice we should consume, when running in order,
/// using an ordered completion policy.
int64_t nextTimeslice = 0;
/// The oldest timeslice skipped by an ordered consumer and not reported yet, per source lane, -1 if none
/// (see DataProcessingHelpers::skipTimeslices).
std::vector<int64_t> pendingGaps;
/// Ordered completion policy is active.
bool orderedCompletionPolicyActive = false;
/// consumeWhenPastOldestPossibleTimeframe completion policy is active.
Expand Down
12 changes: 12 additions & 0 deletions Framework/Core/src/DeviceSpecHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
Expand Down Expand Up @@ -1231,8 +1232,19 @@ void DeviceSpecHelpers::dataProcessorSpecs2DeviceSpecs(const WorkflowSpec& workf

WorkflowHelpers::validateEdges(workflow, policiesVector, logicalEdges, outputs);

std::vector<size_t> upstreamSourceLanes(workflow.size(), 1);
for (bool changed = true; changed;) {
changed = false;
for (auto& edge : logicalEdges) {
auto& producer = workflow[edge.producer];
bool enumeratedSource = std::ranges::all_of(producer.inputs, [](InputSpec const& input) { return input.lifetime == Lifetime::Enumeration; });
auto lanes = std::lcm(upstreamSourceLanes[edge.consumer], std::lcm(upstreamSourceLanes[edge.producer], enumeratedSource ? producer.maxInputTimeslices : 1));
changed |= std::exchange(upstreamSourceLanes[edge.consumer], lanes) != lanes;
}
}
for (auto& device : devices) {
device.resourceMonitoringInterval = resourcesMonitoringInterval;
device.upstreamSourceLanes = upstreamSourceLanes[std::ranges::find(workflow, device.name, &DataProcessorSpec::name) - workflow.begin()];
}

auto findDeviceIndex = [&deviceIndex](size_t processorIndex, size_t timeslice) {
Expand Down
12 changes: 9 additions & 3 deletions Framework/Core/src/TimesliceIndex.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ TimesliceIndex::OldestInputInfo TimesliceIndex::setOldestPossibleInput(Timeslice
timestamp.value, channel.value, mChannels[channel.value].oldestForChannel.value);
}
mChannels[channel.value].oldestForChannel = timestamp;
OldestInputInfo result{timestamp, channel};
// A completed channel with nothing left to relay will not send anything anymore.
auto done = [](InputChannelInfo const& info) { return info.state == InputChannelState::Completed && info.parts.Size() == 0; };
OldestInputInfo result{done(mChannels[channel.value]) ? TimesliceId{TimesliceId::INVALID} : timestamp, channel};
bool changed = false;
for (int ci = 0; ci < mChannels.size(); ci++) {
// Check if this is a real channel. Skip otherwise.
// Check if this is a real channel which can still send data. Skip otherwise.
auto& channelRef = mChannels[ci];
if (channelRef.channelType != ChannelAccountingType::DPL) {
if (channelRef.channelType != ChannelAccountingType::DPL || done(channelRef)) {
continue;
}
auto& a = channelRef.oldestForChannel;
Expand All @@ -162,6 +164,10 @@ TimesliceIndex::OldestInputInfo TimesliceIndex::setOldestPossibleInput(Timeslice
result = {a, ChannelIndex{ci}};
}
}
if (TimesliceId::isValid(result.timeslice) == false) {
// Every channel completed: nothing can arrive anymore.
result = mOldestPossibleInput;
}
if (changed && mOldestPossibleInput.timeslice.value != result.timeslice.value) {
O2_SIGNPOST_EVENT_EMIT(timeslice_index, tid, "setOldestPossibleInput", "Success (channel %d): Oldest possible input is %zu due to channel %d",
channel.value, result.timeslice.value, result.channel.value);
Expand Down
Loading