From 5c64f74795aec93967358d528fc1b2cc5a6ad3c7 Mon Sep 17 00:00:00 2001 From: Rafi Wiener Date: Wed, 16 Jan 2019 17:24:57 +0200 Subject: [PATCH] isuue: 1647751 Use burst info when setting rate limit with VMA Signed-off-by: Rafi Wiener --- src/client.cpp | 3 ++- src/common.cpp | 14 +++++++++++--- src/common.h | 4 +--- src/server.cpp | 3 ++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 13a3a1b7..c2ba7bdf 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -588,7 +588,8 @@ int Client 0 && - sock_set_rate_limit(ifd, s_user_params.rate_limit)) { + sock_set_rate_limit(ifd, s_user_params.rate_limit, (s_user_params.msg_size - 42) * 30, + (uint16_t)s_user_params.msg_size - 42)) { log_err("[fd=%d] failed setting rate limit on address %s\n", ifd, inet_ntoa(g_fds_array[ifd]->server_addr.sin_addr)); rc = SOCKPERF_ERR_SOCKET; diff --git a/src/common.cpp b/src/common.cpp index 37fe998c..a3e4a5c9 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -212,10 +212,18 @@ int read_int_from_sys_file(const char *path) { return retVal; } - -int sock_set_rate_limit(int fd, uint32_t rate_limit) { +int sock_set_rate_limit(int fd, uint32_t rate_limit, uint32_t burst_packet_size, uint16_t pkt_size) { int rc = SOCKPERF_ERR_NONE; - if (setsockopt(fd, SOL_SOCKET, SO_MAX_PACING_RATE, &rate_limit, sizeof(rate_limit)) < 0) { +#ifdef USING_VMA_EXTRA_API + vma_rate_limit_t limit; + limit.rate = rate_limit; + limit.max_burst_sz = burst_packet_size; + limit.typical_pkt_sz = pkt_size; + int ret = setsockopt(fd, SOL_SOCKET, SO_MAX_PACING_RATE, &limit, sizeof(limit)); +#else + int ret = setsockopt(fd, SOL_SOCKET, SO_MAX_PACING_RATE, &rate_limit, sizeof(rate_limit)); +#endif + if (ret < 0) { log_err("setsockopt(SO_MAX_PACING_RATE), set rate-limit failed. " "It could be that this option is not supported in your system"); rc = SOCKPERF_ERR_SOCKET; diff --git a/src/common.h b/src/common.h index a58a7099..1d6b801e 100644 --- a/src/common.h +++ b/src/common.h @@ -325,7 +325,5 @@ static inline int msg_sendto(int fd, uint8_t *buf, int nbytes, return ret; } - -int sock_set_rate_limit(int fd, uint32_t rate_limit); - +int sock_set_rate_limit(int fd, uint32_t rate_limit, uint32_t burst_packet_size, uint16_t pkt_size); #endif /* COMMON_H_ */ diff --git a/src/server.cpp b/src/server.cpp index 7e9541fe..4cfd2670 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -100,7 +100,8 @@ int ServerBase::initBeforeLoop() { * with the rest of the setsockopt */ if (s_user_params.rate_limit > 0 && - sock_set_rate_limit(ifd, s_user_params.rate_limit)) { + sock_set_rate_limit(ifd, s_user_params.rate_limit, s_user_params.msg_size * 10, + (uint16_t)s_user_params.msg_size)) { log_err("[fd=%d] failed setting rate limit, %s\n", ifd, inet_ntoa(p_bind_addr->sin_addr)); rc = SOCKPERF_ERR_SOCKET;