Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isuue: 1647751 Use burst info when setting rate limit with VMA #118

Open
wants to merge 1 commit into
base: sockperf_v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@ int Client<IoType, SwitchDataIntegrity, SwitchActivityInfo, SwitchCycleDuration,
* with the rest of the setsockopt
*/
if (s_user_params.rate_limit > 0 &&
sock_set_rate_limit(ifd, s_user_params.rate_limit)) {
log_err("[fd=%d] failed setting rate limit on address %s\n", ifd,
inet_ntoa(g_fds_array[ifd]->server_addr.sin_addr));
sock_set_rate_limit(ifd, s_user_params)) {
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;
break;
}
Expand Down
22 changes: 19 additions & 3 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,26 @@ 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, user_params_t &params) {
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;
uint16_t packet_size_incl_hdr = s_user_params.msg_size + ETH_HEADER_LEN +
IP_HEADER_LEN;
if (s_user_params.sock_type == SOCK_STREAM) {
packet_size_incl_hdr += TCP_HEADER_LEN;
} else {
packet_size_incl_hdr += UDP_HEADER_LEN;
}
limit.rate = params.rate_limit;
limit.max_burst_sz = packet_size_incl_hdr * DEFAULT_RATE_BURST;
limit.typical_pkt_sz = packet_size_incl_hdr;
int ret = setsockopt(fd, SOL_SOCKET, SO_MAX_PACING_RATE, &limit, sizeof(limit));
#else
int ret = setsockopt(fd, SOL_SOCKET, SO_MAX_PACING_RATE,
&params.rate_limit, sizeof(params.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;
Expand Down
4 changes: 1 addition & 3 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, user_params_t &params);
#endif /* COMMON_H_ */
5 changes: 5 additions & 0 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ extern const int MAX_FDS_NUM;
#ifndef SO_MAX_PACING_RATE
#define SO_MAX_PACING_RATE 47
#endif
#define DEFAULT_RATE_BURST (30)
#define ETH_HEADER_LEN (14)
#define IP_HEADER_LEN (20)
#define UDP_HEADER_LEN (8)
#define TCP_HEADER_LEN (20)
/*
Used by offload libraries to do egress path warm-up of caches.
It is not in use by kernel. WARNING: it will actually end this packet on the wire.
Expand Down
2 changes: 1 addition & 1 deletion src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ 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)) {
log_err("[fd=%d] failed setting rate limit, %s\n", ifd,
inet_ntoa(p_bind_addr->sin_addr));
rc = SOCKPERF_ERR_SOCKET;
Expand Down