Optimised PLDM daemon to use vectored IO
The pldm daemon currently receives a PLDM response message as a
std::vector<uint8_t> from a command handler which then inserts MCTP
EID and Type (as required by the mctp demux daemon) at the beginning
of the vector which requires O(n) element moves. The code has been
refactored to now use scatter/gather which replaces the vector
inserts resulting in O(1). This is accomplished by using sendmsg()
instead of sendto() syscall.
Change-Id: I47a051ed267eadc3bc9566cca24431b45322205f
Signed-off-by: Zahed Hossain <zahzahed@in.ibm.com>
diff --git a/pldmd.cpp b/pldmd.cpp
index e02bb57..eed1292 100644
--- a/pldmd.cpp
+++ b/pldmd.cpp
@@ -68,8 +68,6 @@
}
response.insert(response.end(), completion_code);
}
- response.insert(response.begin(), type);
- response.insert(response.begin(), eid);
}
return response;
}
@@ -95,6 +93,15 @@
pldm::responder::base::registerHandlers();
pldm::responder::bios::registerHandlers();
+ // Outgoing message.
+ struct iovec iov[2]{};
+
+ // This structure contains the parameter information for the response
+ // message.
+ struct msghdr msg
+ {
+ };
+
#ifdef OEM_IBM
pldm::responder::oem_ibm::registerHandlers();
#endif
@@ -183,8 +190,16 @@
log<level::INFO>("Sending Msg ");
printBuffer(response);
#endif
- result = sendto(socketFd(), response.data(),
- response.size(), 0, nullptr, 0);
+ iov[0].iov_base = &requestMsg;
+ iov[0].iov_len =
+ sizeof(requestMsg[0]) + sizeof(requestMsg[1]);
+ iov[1].iov_base = response.data();
+ iov[1].iov_len = response.size();
+
+ msg.msg_iov = iov;
+ msg.msg_iovlen = sizeof(iov) / sizeof(iov[0]);
+
+ result = sendmsg(socketFd(), &msg, 0);
if (-1 == result)
{
returnCode = -errno;