The current totemudp converts the totem ip into a sockaddr on every
mcast and token transmit. It also sets up a msghdr structure for use
with sendmsg. Instead set these only once per configuration.
This reduces the use of these instructions by about 50,000 calls per
second of transmission.
Regards
-steve
Index: exec/totemudp.c
===================================================================
--- exec/totemudp.c (revision 2380)
+++ exec/totemudp.c (working copy)
@@ -205,7 +205,13 @@
struct totem_config *totem_config;
- struct totem_ip_address token_target;
+ struct msghdr token_target_msghdr;
+
+ struct sockaddr_storage token_target_sockaddr;
+
+ struct msghdr mcast_msghdr;
+
+ struct sockaddr_storage mcast_sockaddr;
};
struct work_item {
@@ -880,23 +886,19 @@
}
-static inline void ucast_sendmsg (
+static inline void token_target_sendmsg (
struct totemudp_instance *instance,
- struct totem_ip_address *system_to,
const void *msg,
unsigned int msg_len)
{
- struct msghdr msg_ucast;
int res = 0;
size_t buf_len;
unsigned char sheader[sizeof (struct security_header)];
unsigned char encrypt_data[FRAME_SIZE_MAX];
struct iovec iovec_encrypt[2];
const struct iovec *iovec_sendmsg;
- struct sockaddr_storage sockaddr;
struct iovec iovec;
unsigned int iov_len;
- int addrlen;
if (instance->totem_config->secauth == 1) {
iovec_encrypt[0].iov_base = (void *)sheader;
@@ -932,30 +934,15 @@
iov_len = 1;
}
- /*
- * Build unicast message
- */
- totemip_totemip_to_sockaddr_convert(system_to,
- instance->totem_interface->ip_port, &sockaddr, &addrlen);
- msg_ucast.msg_name = &sockaddr;
- msg_ucast.msg_namelen = addrlen;
- msg_ucast.msg_iov = (void *) iovec_sendmsg;
- msg_ucast.msg_iovlen = iov_len;
-#if !defined(COROSYNC_SOLARIS)
- msg_ucast.msg_control = 0;
- msg_ucast.msg_controllen = 0;
- msg_ucast.msg_flags = 0;
-#else
- msg_ucast.msg_accrights = NULL;
- msg_ucast.msg_accrightslen = 0;
-#endif
+ instance->token_target_msghdr.msg_iov = (void *) iovec_sendmsg;
+ instance->token_target_msghdr.msg_iovlen = iov_len;
-
/*
* Transmit multicast message
* An error here is recovered by totemsrp
*/
- res = sendmsg (instance->totemudp_sockets.mcast_send, &msg_ucast,
+ res = sendmsg (instance->totemudp_sockets.mcast_send,
+ &instance->token_target_msghdr,
MSG_NOSIGNAL);
}
@@ -964,7 +951,6 @@
const void *msg,
unsigned int msg_len)
{
- struct msghdr msg_mcast;
int res = 0;
size_t buf_len;
unsigned char sheader[sizeof (struct security_header)];
@@ -972,9 +958,7 @@
struct iovec iovec_encrypt[2];
struct iovec iovec;
const struct iovec *iovec_sendmsg;
- struct sockaddr_storage sockaddr;
unsigned int iov_len;
- int addrlen;
if (instance->totem_config->secauth == 1) {
@@ -1012,29 +996,15 @@
iov_len = 1;
}
- /*
- * Build multicast message
- */
- totemip_totemip_to_sockaddr_convert(&instance->mcast_address,
- instance->totem_interface->ip_port, &sockaddr, &addrlen);
- msg_mcast.msg_name = &sockaddr;
- msg_mcast.msg_namelen = addrlen;
- msg_mcast.msg_iov = (void *) iovec_sendmsg;
- msg_mcast.msg_iovlen = iov_len;
-#if !defined(COROSYNC_SOLARIS)
- msg_mcast.msg_control = 0;
- msg_mcast.msg_controllen = 0;
- msg_mcast.msg_flags = 0;
-#else
- msg_mcast.msg_accrights = NULL;
- msg_mcast.msg_accrightslen = 0;
-#endif
+ instance->mcast_msghdr.msg_iov = (void *) iovec_sendmsg;
+ instance->mcast_msghdr.msg_iovlen = iov_len;
/*
* Transmit multicast message
* An error here is recovered by totemsrp
*/
- res = sendmsg (instance->totemudp_sockets.mcast_send, &msg_mcast,
+ res = sendmsg (instance->totemudp_sockets.mcast_send,
+ &instance->mcast_msghdr,
MSG_NOSIGNAL);
}
@@ -1259,6 +1229,7 @@
int interface_up;
int interface_num;
struct totem_ip_address *bind_address;
+ int addrlen;
/*
* Build sockets for every interface
@@ -1378,6 +1349,23 @@
instance->netif_state_report = NETIF_STATE_REPORT_UP;
}
+
+ /*
+ * Build multicast header
+ */
+ totemip_totemip_to_sockaddr_convert(&instance->mcast_address,
+ instance->totem_interface->ip_port, &instance->mcast_sockaddr,
+ &addrlen);
+ instance->mcast_msghdr.msg_name = &instance->mcast_sockaddr;
+ instance->mcast_msghdr.msg_namelen = addrlen;
+#if !defined(COROSYNC_SOLARIS)
+ instance->mcast_msghdr.msg_control = 0;
+ instance->mcast_msghdr.msg_controllen = 0;
+ instance->mcast_msghdr.msg_flags = 0;
+#else
+ instance->mcast_msghdr.msg_accrights = NULL;
+ instance->mcast_msghdr.msg_accrightslen = 0;
+#endif
}
/* Set the socket priority to INTERACTIVE to ensure
@@ -1855,7 +1843,7 @@
struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
int res = 0;
- ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
+ token_target_sendmsg (instance, msg, msg_len);
return (res);
}
@@ -1942,10 +1930,27 @@
const struct totem_ip_address *token_target)
{
struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
+ int addrlen;
int res = 0;
- memcpy (&instance->token_target, token_target,
- sizeof (struct totem_ip_address));
+ /*
+ * Build unicast message
+ */
+ totemip_totemip_to_sockaddr_convert (
+ (struct totem_ip_address *)token_target,
+ instance->totem_interface->ip_port,
+ &instance->token_target_sockaddr,
+ &addrlen);
+ instance->token_target_msghdr.msg_name = &instance->token_target_sockaddr;
+ instance->token_target_msghdr.msg_namelen = addrlen;
+#if !defined(COROSYNC_SOLARIS)
+ instance->token_target_msghdr.msg_control = 0;
+ instance->token_target_msghdr.msg_controllen = 0;
+ instance->token_target_msghdr.msg_flags = 0;
+#else
+ instance->token_target_msghdr.msg_accrights = NULL;
+ instance->token_target_msghdr.msg_accrightslen = 0;
+#endif
instance->totemudp_target_set_completed (instance->context);
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais