blob: 63ca741374700dba4e2cf0e1adab8656fc3da6f5 [file] [log] [blame]
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001//
Jim Flynn6398a982020-05-27 17:05:21 +01002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Sadik Armaganb5f01b22019-09-18 17:29:00 +01003// SPDX-License-Identifier: MIT
4//
5
6#include "ConnectionAcknowledgedCommandHandler.hpp"
Finn Williamscf2ad552020-03-20 15:10:59 +00007#include "TimelineUtilityMethods.hpp"
Sadik Armaganb5f01b22019-09-18 17:29:00 +01008
9#include <armnn/Exceptions.hpp>
10
Jan Eilers156113c2020-09-09 19:11:16 +010011#include <fmt/format.h>
Matteo Martincighd0613b52019-10-09 16:47:04 +010012
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000013namespace arm
Sadik Armaganb5f01b22019-09-18 17:29:00 +010014{
15
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000016namespace pipe
Sadik Armaganb5f01b22019-09-18 17:29:00 +010017{
18
Jim Flynnbbfe6032020-07-20 16:57:44 +010019void ConnectionAcknowledgedCommandHandler::operator()(const arm::pipe::Packet& packet)
Sadik Armaganb5f01b22019-09-18 17:29:00 +010020{
Matteo Martincighd0613b52019-10-09 16:47:04 +010021 ProfilingState currentState = m_StateMachine.GetCurrentState();
22 switch (currentState)
Sadik Armaganb5f01b22019-09-18 17:29:00 +010023 {
Matteo Martincighd0613b52019-10-09 16:47:04 +010024 case ProfilingState::Uninitialised:
25 case ProfilingState::NotConnected:
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000026 throw armnn::RuntimeException(fmt::format("Connection Acknowledged Command Handler invoked while in an "
Jan Eilers156113c2020-09-09 19:11:16 +010027 "wrong state: {}",
28 GetProfilingStateName(currentState)));
Matteo Martincighd0613b52019-10-09 16:47:04 +010029 case ProfilingState::WaitingForAck:
30 // Process the packet
31 if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 1u))
32 {
Jan Eilers156113c2020-09-09 19:11:16 +010033 throw armnn::InvalidArgumentException(fmt::format("Expected Packet family = 0, id = 1 but "
34 "received family = {}, id = {}",
35 packet.GetPacketFamily(),
36 packet.GetPacketId()));
Matteo Martincighd0613b52019-10-09 16:47:04 +010037 }
Matteo Martincighc2728f92019-10-07 12:35:21 +010038
Matteo Martincighd0613b52019-10-09 16:47:04 +010039 // Once a Connection Acknowledged packet has been received, move to the Active state immediately
40 m_StateMachine.TransitionToState(ProfilingState::Active);
Colm Donelan2ba48d22019-11-29 09:10:59 +000041 // Send the counter directory packet.
Keith Davis3201eea2019-10-24 17:30:41 +010042 m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
Finn Williamsd7fcafa2020-04-23 17:55:18 +010043
44 if (m_TimelineEnabled)
45 {
46 m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
47 TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket);
48 }
Finn Williamscf2ad552020-03-20 15:10:59 +000049
Jim Flynn6398a982020-05-27 17:05:21 +010050 if (m_BackendProfilingContext.has_value())
Finn Williamsfe5a24b2020-04-09 16:05:28 +010051 {
52 for (auto backendContext : m_BackendProfilingContext.value())
53 {
54 // Enable profiling on the backend and assert that it returns true
55 if(!backendContext.second->EnableProfiling(true))
56 {
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000057 throw armnn::BackendProfilingException(
Finn Williamsfe5a24b2020-04-09 16:05:28 +010058 "Unable to enable profiling on Backend Id: " + backendContext.first.Get());
59 }
60 }
61 }
62
Jim Flynn6398a982020-05-27 17:05:21 +010063 // At this point signal any external processes waiting on the profiling system
64 // to come up that profiling is fully active
65 m_ProfilingServiceStatus.NotifyProfilingServiceActive();
Matteo Martincighd0613b52019-10-09 16:47:04 +010066 break;
67 case ProfilingState::Active:
68 return; // NOP
69 default:
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000070 throw armnn::RuntimeException(fmt::format("Unknown profiling service state: {}",
Jan Eilers156113c2020-09-09 19:11:16 +010071 static_cast<int>(currentState)));
Matteo Martincighd0613b52019-10-09 16:47:04 +010072 }
Sadik Armaganb5f01b22019-09-18 17:29:00 +010073}
74
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000075} // namespace pipe
Sadik Armaganb5f01b22019-09-18 17:29:00 +010076
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000077} // namespace arm
Sadik Armaganb5f01b22019-09-18 17:29:00 +010078