|
17 | 17 | #include "Framework/DataProcessor.h" |
18 | 18 | #include "Framework/DataSpecUtils.h" |
19 | 19 | #include "Framework/DeviceState.h" |
| 20 | +#include "Framework/DeviceStateEnums.h" |
20 | 21 | #include "Framework/DispatchPolicy.h" |
21 | 22 | #include "Framework/DispatchControl.h" |
22 | 23 | #include "Framework/DanglingContext.h" |
@@ -196,11 +197,10 @@ struct locked_execution { |
196 | 197 | ~locked_execution() { ref.unlock(); } |
197 | 198 | }; |
198 | 199 |
|
199 | | -DataProcessingDevice::DataProcessingDevice(RunningDeviceRef running, ServiceRegistry& registry, ProcessingPolicies& policies) |
| 200 | +DataProcessingDevice::DataProcessingDevice(RunningDeviceRef running, ServiceRegistry& registry) |
200 | 201 | : mRunningDevice{running}, |
201 | 202 | mConfigRegistry{nullptr}, |
202 | | - mServiceRegistry{registry}, |
203 | | - mProcessingPolicies{policies} |
| 203 | + mServiceRegistry{registry} |
204 | 204 | { |
205 | 205 | GetConfig()->Subscribe<std::string>("dpl", [®istry = mServiceRegistry](const std::string& key, std::string value) { |
206 | 206 | if (key == "cleanup") { |
@@ -247,6 +247,7 @@ DataProcessingDevice::DataProcessingDevice(RunningDeviceRef running, ServiceRegi |
247 | 247 | mHandles.resize(1); |
248 | 248 |
|
249 | 249 | ServiceRegistryRef ref{mServiceRegistry}; |
| 250 | + |
250 | 251 | mAwakeHandle = (uv_async_t*)malloc(sizeof(uv_async_t)); |
251 | 252 | auto& state = ref.get<DeviceState>(); |
252 | 253 | assert(state.loop); |
@@ -1330,6 +1331,58 @@ void DataProcessingDevice::Reset() |
1330 | 1331 | ref.get<CallbackService>().call<CallbackService::Id::Reset>(); |
1331 | 1332 | } |
1332 | 1333 |
|
| 1334 | +TransitionHandlingState updateStateTransition(ServiceRegistryRef& ref, ProcessingPolicies const& policies) |
| 1335 | +{ |
| 1336 | + auto& state = ref.get<DeviceState>(); |
| 1337 | + auto& deviceProxy = ref.get<FairMQDeviceProxy>(); |
| 1338 | + if (state.transitionHandling != TransitionHandlingState::NoTransition || deviceProxy.newStateRequested() == false) { |
| 1339 | + return state.transitionHandling; |
| 1340 | + } |
| 1341 | + O2_SIGNPOST_ID_FROM_POINTER(lid, device, state.loop); |
| 1342 | + auto& deviceContext = ref.get<DeviceContext>(); |
| 1343 | + // Check if we only have timers |
| 1344 | + auto& spec = ref.get<DeviceSpec const>(); |
| 1345 | + if (hasOnlyTimers(spec)) { |
| 1346 | + switchState(ref, StreamingState::EndOfStreaming); |
| 1347 | + } |
| 1348 | + |
| 1349 | + // We do not do anything in particular if the data processing timeout would go past the exitTransitionTimeout |
| 1350 | + if (deviceContext.dataProcessingTimeout > 0 && deviceContext.dataProcessingTimeout < deviceContext.exitTransitionTimeout) { |
| 1351 | + uv_update_time(state.loop); |
| 1352 | + O2_SIGNPOST_EVENT_EMIT(calibration, lid, "timer_setup", "Starting %d s timer for dataProcessingTimeout.", deviceContext.dataProcessingTimeout); |
| 1353 | + uv_timer_start(deviceContext.dataProcessingGracePeriodTimer, on_data_processing_expired, deviceContext.dataProcessingTimeout * 1000, 0); |
| 1354 | + } |
| 1355 | + if (deviceContext.exitTransitionTimeout != 0 && state.streaming != StreamingState::Idle) { |
| 1356 | + ref.get<CallbackService>().call<CallbackService::Id::ExitRequested>(ServiceRegistryRef{ref}); |
| 1357 | + uv_update_time(state.loop); |
| 1358 | + O2_SIGNPOST_EVENT_EMIT(calibration, lid, "timer_setup", "Starting %d s timer for exitTransitionTimeout.", |
| 1359 | + deviceContext.exitTransitionTimeout); |
| 1360 | + uv_timer_start(deviceContext.gracePeriodTimer, on_transition_requested_expired, deviceContext.exitTransitionTimeout * 1000, 0); |
| 1361 | + bool onlyGenerated = hasOnlyGenerated(spec); |
| 1362 | + int timeout = onlyGenerated ? deviceContext.dataProcessingTimeout : deviceContext.exitTransitionTimeout; |
| 1363 | + if (policies.termination == TerminationPolicy::QUIT && DefaultsHelpers::onlineDeploymentMode() == false) { |
| 1364 | + O2_SIGNPOST_EVENT_EMIT_INFO(device, lid, "run_loop", "New state requested. Waiting for %d seconds before quitting.", timeout); |
| 1365 | + } else { |
| 1366 | + O2_SIGNPOST_EVENT_EMIT_INFO(device, lid, "run_loop", |
| 1367 | + "New state requested. Waiting for %d seconds before %{public}s", |
| 1368 | + timeout, |
| 1369 | + onlyGenerated ? "dropping remaining input and switching to READY state." : "switching to READY state."); |
| 1370 | + } |
| 1371 | + return TransitionHandlingState::Requested; |
| 1372 | + } else { |
| 1373 | + if (deviceContext.exitTransitionTimeout == 0 && policies.termination == TerminationPolicy::QUIT) { |
| 1374 | + O2_SIGNPOST_EVENT_EMIT_INFO(device, lid, "run_loop", "New state requested. No timeout set, quitting immediately as per --completion-policy"); |
| 1375 | + } else if (deviceContext.exitTransitionTimeout == 0 && policies.termination != TerminationPolicy::QUIT) { |
| 1376 | + O2_SIGNPOST_EVENT_EMIT_INFO(device, lid, "run_loop", "New state requested. No timeout set, switching to READY state immediately"); |
| 1377 | + } else if (policies.termination == TerminationPolicy::QUIT) { |
| 1378 | + O2_SIGNPOST_EVENT_EMIT_INFO(device, lid, "run_loop", "New state pending and we are already idle, quitting immediately as per --completion-policy"); |
| 1379 | + } else { |
| 1380 | + O2_SIGNPOST_EVENT_EMIT_INFO(device, lid, "run_loop", "New state pending and we are already idle, switching to READY immediately."); |
| 1381 | + } |
| 1382 | + return TransitionHandlingState::Expired; |
| 1383 | + } |
| 1384 | +} |
| 1385 | + |
1333 | 1386 | void DataProcessingDevice::Run() |
1334 | 1387 | { |
1335 | 1388 | ServiceRegistryRef ref{mServiceRegistry}; |
@@ -1382,51 +1435,7 @@ void DataProcessingDevice::Run() |
1382 | 1435 | shouldNotWait = true; |
1383 | 1436 | state.loopReason |= DeviceState::LoopReason::NEW_STATE_PENDING; |
1384 | 1437 | } |
1385 | | - if (state.transitionHandling == TransitionHandlingState::NoTransition && NewStatePending()) { |
1386 | | - state.transitionHandling = TransitionHandlingState::Requested; |
1387 | | - auto& deviceContext = ref.get<DeviceContext>(); |
1388 | | - // Check if we only have timers |
1389 | | - auto& spec = ref.get<DeviceSpec const>(); |
1390 | | - if (hasOnlyTimers(spec)) { |
1391 | | - switchState(ref, StreamingState::EndOfStreaming); |
1392 | | - } |
1393 | | - |
1394 | | - // We do not do anything in particular if the data processing timeout would go past the exitTransitionTimeout |
1395 | | - if (deviceContext.dataProcessingTimeout > 0 && deviceContext.dataProcessingTimeout < deviceContext.exitTransitionTimeout) { |
1396 | | - uv_update_time(state.loop); |
1397 | | - O2_SIGNPOST_EVENT_EMIT(calibration, lid, "timer_setup", "Starting %d s timer for dataProcessingTimeout.", deviceContext.dataProcessingTimeout); |
1398 | | - uv_timer_start(deviceContext.dataProcessingGracePeriodTimer, on_data_processing_expired, deviceContext.dataProcessingTimeout * 1000, 0); |
1399 | | - } |
1400 | | - if (deviceContext.exitTransitionTimeout != 0 && state.streaming != StreamingState::Idle) { |
1401 | | - state.transitionHandling = TransitionHandlingState::Requested; |
1402 | | - ref.get<CallbackService>().call<CallbackService::Id::ExitRequested>(ServiceRegistryRef{ref}); |
1403 | | - uv_update_time(state.loop); |
1404 | | - O2_SIGNPOST_EVENT_EMIT(calibration, lid, "timer_setup", "Starting %d s timer for exitTransitionTimeout.", |
1405 | | - deviceContext.exitTransitionTimeout); |
1406 | | - uv_timer_start(deviceContext.gracePeriodTimer, on_transition_requested_expired, deviceContext.exitTransitionTimeout * 1000, 0); |
1407 | | - bool onlyGenerated = hasOnlyGenerated(spec); |
1408 | | - int timeout = onlyGenerated ? deviceContext.dataProcessingTimeout : deviceContext.exitTransitionTimeout; |
1409 | | - if (mProcessingPolicies.termination == TerminationPolicy::QUIT && DefaultsHelpers::onlineDeploymentMode() == false) { |
1410 | | - O2_SIGNPOST_EVENT_EMIT_INFO(device, lid, "run_loop", "New state requested. Waiting for %d seconds before quitting.", timeout); |
1411 | | - } else { |
1412 | | - O2_SIGNPOST_EVENT_EMIT_INFO(device, lid, "run_loop", |
1413 | | - "New state requested. Waiting for %d seconds before %{public}s", |
1414 | | - timeout, |
1415 | | - onlyGenerated ? "dropping remaining input and switching to READY state." : "switching to READY state."); |
1416 | | - } |
1417 | | - } else { |
1418 | | - state.transitionHandling = TransitionHandlingState::Expired; |
1419 | | - if (deviceContext.exitTransitionTimeout == 0 && mProcessingPolicies.termination == TerminationPolicy::QUIT) { |
1420 | | - O2_SIGNPOST_EVENT_EMIT_INFO(device, lid, "run_loop", "New state requested. No timeout set, quitting immediately as per --completion-policy"); |
1421 | | - } else if (deviceContext.exitTransitionTimeout == 0 && mProcessingPolicies.termination != TerminationPolicy::QUIT) { |
1422 | | - O2_SIGNPOST_EVENT_EMIT_INFO(device, lid, "run_loop", "New state requested. No timeout set, switching to READY state immediately"); |
1423 | | - } else if (mProcessingPolicies.termination == TerminationPolicy::QUIT) { |
1424 | | - O2_SIGNPOST_EVENT_EMIT_INFO(device, lid, "run_loop", "New state pending and we are already idle, quitting immediately as per --completion-policy"); |
1425 | | - } else { |
1426 | | - O2_SIGNPOST_EVENT_EMIT_INFO(device, lid, "run_loop", "New state pending and we are already idle, switching to READY immediately."); |
1427 | | - } |
1428 | | - } |
1429 | | - } |
| 1438 | + state.transitionHandling = updateStateTransition(ref, mProcessingPolicies); |
1430 | 1439 | // If we are Idle, we can then consider the transition to be expired. |
1431 | 1440 | if (state.transitionHandling == TransitionHandlingState::Requested && state.streaming == StreamingState::Idle) { |
1432 | 1441 | O2_SIGNPOST_EVENT_EMIT(device, lid, "run_loop", "State transition requested and we are now in Idle. We can consider it to be completed."); |
@@ -1560,7 +1569,7 @@ void DataProcessingDevice::Run() |
1560 | 1569 | } |
1561 | 1570 | } |
1562 | 1571 |
|
1563 | | - O2_SIGNPOST_END(device, lid, "run_loop", "Run loop completed. Transition handling state %d.", state.transitionHandling); |
| 1572 | + O2_SIGNPOST_END(device, lid, "run_loop", "Run loop completed. Transition handling state %d.", (int)state.transitionHandling); |
1564 | 1573 | auto& spec = ref.get<DeviceSpec const>(); |
1565 | 1574 | /// Cleanup messages which are still pending on exit. |
1566 | 1575 | for (size_t ci = 0; ci < spec.inputChannels.size(); ++ci) { |
|
0 commit comments