Skip to content

Commit f9814bb

Browse files
committed
prov/udp: detect and use MTU to set max_msg_size and inject_size
For each interface detected by the udp provider, determine the MTU of the interface, and use that value to set the max_msg_size field of the fi_ep_attr and fi_tx_attr values of the fi_info element. When the MTU cannot be determined, the MTU value assumed by previous code versions (1500) is used. Signed-off-by: Martin Pokorny <[email protected]>
1 parent f236201 commit f9814bb

File tree

13 files changed

+147
-25
lines changed

13 files changed

+147
-25
lines changed

include/freebsd/osd.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ static inline size_t ofi_ifaddr_get_speed(struct ifaddrs *ifa)
7676
return 0;
7777
}
7878

79+
static inline int ofi_ifaddr_get_mtu(const struct ifaddrs *ifa)
80+
{
81+
return -1;
82+
}
83+
7984
static inline ssize_t ofi_process_vm_readv(pid_t pid,
8085
const struct iovec *local_iov,
8186
unsigned long liovcnt,
@@ -185,5 +190,3 @@ ofi_recvv_socket(SOCKET fd, const struct iovec *iov, size_t cnt, int flags)
185190
}
186191

187192
#endif /* _FREEBSD_OSD_H_ */
188-
189-

include/linux/osd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ static inline int ofi_hugepage_enabled(void)
9292

9393
size_t ofi_ifaddr_get_speed(struct ifaddrs *ifa);
9494

95+
int ofi_ifaddr_get_mtu(const struct ifaddrs *ifa);
96+
9597
#ifndef __NR_process_vm_readv
9698
# define __NR_process_vm_readv 310
9799
#endif

include/ofi_net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ struct ofi_addr_list_entry {
655655
char ipstr[INET6_ADDRSTRLEN];
656656
union ofi_sock_ip ipaddr;
657657
size_t speed;
658+
int mtu;
658659
char net_name[OFI_ADDRSTRLEN];
659660
char ifa_name[OFI_ADDRSTRLEN];
660661
uint64_t comm_caps;

include/osx/osd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ static inline size_t ofi_ifaddr_get_speed(struct ifaddrs *ifa)
9999
return 0;
100100
}
101101

102+
static inline int ofi_ifaddr_get_mtu(const struct ifaddrs *ifa)
103+
{
104+
return -1;
105+
}
106+
102107
static inline int ofi_hugepage_enabled(void)
103108
{
104109
return 0;

include/windows/ifaddrs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ struct ifaddrs {
3434

3535
char ad_name[16];
3636
size_t speed;
37+
int mtu;
3738
};
3839

3940
int getifaddrs(struct ifaddrs **ifap);
4041
void freeifaddrs(struct ifaddrs *ifa);
41-

include/windows/osd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,8 @@ static inline int ofi_is_loopback_addr(struct sockaddr *addr) {
10061006

10071007
size_t ofi_ifaddr_get_speed(struct ifaddrs *ifa);
10081008

1009+
int ofi_ifaddr_get_mtu(const struct ifaddrs *ifa);
1010+
10091011
#define file2unix_time 10000000i64
10101012
#define win2unix_epoch 116444736000000000i64
10111013
#define CLOCK_REALTIME 0

man/fi_udp.7.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ receiving datagram messages over an unreliable endpoint.
4141

4242
# LIMITATIONS
4343

44-
The UDP provider has hard-coded maximums for supported queue sizes and data
45-
transfers. These values are reflected in the related fabric attribute
46-
structures
44+
The UDP provider has a hard-coded maximum for supported queue sizes.
45+
This value is reflected in the related fabric attribute structures.
4746

4847
EPs must be bound to both RX and TX CQs.
4948

@@ -53,7 +52,10 @@ No support for counters.
5352

5453
# RUNTIME PARAMETERS
5554

56-
No runtime parameters are currently defined.
55+
The UDP provider checks for the following environment variables -
56+
57+
*FI_UDP_IFACE*
58+
: An string value that specifies the name of the interface.
5759

5860
# SEE ALSO
5961

prov/udp/src/udpx.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,21 @@
6363
#ifndef _UDPX_H_
6464
#define _UDPX_H_
6565

66-
6766
extern struct fi_provider udpx_prov;
6867
extern struct util_prov udpx_util_prov;
6968
extern struct fi_info udpx_info;
7069

71-
7270
int udpx_fabric(struct fi_fabric_attr *attr, struct fid_fabric **fabric,
7371
void *context);
7472
int udpx_domain_open(struct fid_fabric *fabric, struct fi_info *info,
7573
struct fid_domain **dom, void *context);
7674
int udpx_eq_open(struct fid_fabric *fabric, struct fi_eq_attr *attr,
7775
struct fid_eq **eq, void *context);
78-
76+
void udpx_util_prov_init(uint32_t version);
7977

8078
#define UDPX_FLAG_MULTI_RECV 1
8179
#define UDPX_IOV_LIMIT 4
80+
#define UDPX_MTU 1500
8281

8382
struct udpx_ep_entry {
8483
void *context;
@@ -88,6 +87,8 @@ struct udpx_ep_entry {
8887
uint8_t resv[sizeof(size_t) - 2];
8988
};
9089

90+
#define UDPX_MAX_MSG_SIZE(mtu) ((mtu) - 28)
91+
9192
OFI_DECLARE_CIRQUE(struct udpx_ep_entry, udpx_rx_cirq);
9293

9394
struct udpx_ep;

prov/udp/src/udpx_attr.c

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
*/
3232

3333
#include "udpx.h"
34+
#include "ofi_osd.h"
3435

3536
#define UDPX_TX_CAPS (OFI_TX_MSG_CAPS | FI_MULTICAST)
3637
#define UDPX_RX_CAPS (FI_SOURCE | OFI_RX_MSG_CAPS)
3738
#define UDPX_DOMAIN_CAPS (FI_LOCAL_COMM | FI_REMOTE_COMM)
3839

3940
struct fi_tx_attr udpx_tx_attr = {
4041
.caps = UDPX_TX_CAPS,
41-
.inject_size = 1472,
42+
.inject_size = UDPX_MAX_MSG_SIZE(UDPX_MTU),
4243
.size = 1024,
4344
.iov_limit = UDPX_IOV_LIMIT
4445
};
@@ -53,7 +54,7 @@ struct fi_ep_attr udpx_ep_attr = {
5354
.type = FI_EP_DGRAM,
5455
.protocol = FI_PROTO_UDP,
5556
.protocol_version = 0,
56-
.max_msg_size = 1472,
57+
.max_msg_size = UDPX_MAX_MSG_SIZE(UDPX_MTU),
5758
.tx_ctx_cnt = 1,
5859
.rx_ctx_cnt = 1
5960
};
@@ -93,6 +94,62 @@ struct fi_info udpx_info = {
9394

9495
struct util_prov udpx_util_prov = {
9596
.prov = &udpx_prov,
96-
.info = &udpx_info,
97-
.flags = 0,
97+
.info = NULL,
98+
.flags = 0,
9899
};
100+
101+
102+
static int match_interface(struct slist_entry *entry, const void *infop)
103+
{
104+
struct ofi_addr_list_entry *addr_entry;
105+
const struct fi_info* info = infop;
106+
addr_entry = container_of(entry, struct ofi_addr_list_entry, entry);
107+
return strcmp(addr_entry->net_name, info->fabric_attr->name) == 0 &&
108+
strcmp(addr_entry->ifa_name, info->domain_attr->name) == 0;
109+
}
110+
111+
static void set_mtu_from_addr_list(struct fi_info* info,
112+
struct slist *addr_list)
113+
{
114+
struct ofi_addr_list_entry *addr_entry;
115+
struct slist_entry *entry;
116+
int max_msg_size;
117+
118+
entry = slist_find_first_match(addr_list, match_interface, info);
119+
assert(entry);
120+
if (entry) {
121+
addr_entry = container_of(entry,
122+
struct ofi_addr_list_entry,
123+
entry);
124+
max_msg_size = UDPX_MAX_MSG_SIZE(addr_entry->mtu);
125+
if (max_msg_size > 0) {
126+
info->tx_attr->inject_size = max_msg_size;
127+
info->ep_attr->max_msg_size = max_msg_size;
128+
}
129+
} else {
130+
FI_DBG(&udpx_prov, FI_LOG_CORE,
131+
"Failed to match interface (%s, %s) to "
132+
"address for MTU size\n",
133+
info->fabric_attr->name, info->domain_attr->name);
134+
}
135+
}
136+
137+
void udpx_util_prov_init(uint32_t version) {
138+
139+
struct slist addr_list;
140+
struct fi_info* cur;
141+
struct fi_info* info;
142+
143+
if (udpx_util_prov.info == NULL) {
144+
udpx_util_prov.info = &udpx_info;
145+
info = fi_allocinfo();
146+
ofi_ip_getinfo(&udpx_util_prov, version, NULL, NULL, 0, NULL,
147+
&info);
148+
slist_init(&addr_list);
149+
ofi_get_list_of_addr(&udpx_prov, "iface", &addr_list);
150+
for (cur = info; cur; cur = cur->next)
151+
set_mtu_from_addr_list(cur, &addr_list);
152+
udpx_util_prov.info = info;
153+
ofi_free_list_of_addr(&addr_list);
154+
}
155+
}

prov/udp/src/udpx_init.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,26 @@
3737

3838
#include <sys/types.h>
3939

40+
static ofi_mutex_t init_lock;
4041

4142
static int udpx_getinfo(uint32_t version, const char *node, const char *service,
4243
uint64_t flags, const struct fi_info *hints,
4344
struct fi_info **info)
4445
{
45-
return ofi_ip_getinfo(&udpx_util_prov, version, node, service, flags,
46-
hints, info);
46+
ofi_mutex_lock(&init_lock);
47+
udpx_util_prov_init(version);
48+
ofi_mutex_unlock(&init_lock);
49+
return util_getinfo(&udpx_util_prov, version, node, service, flags,
50+
hints, info);
4751
}
4852

4953
static void udpx_fini(void)
5054
{
51-
/* yawn */
55+
if (udpx_util_prov.info != NULL)
56+
fi_freeinfo(udpx_util_prov.info);
5257
}
5358

59+
5460
struct fi_provider udpx_prov = {
5561
.name = "udp",
5662
.version = OFI_VERSION_DEF_PROV,
@@ -65,5 +71,6 @@ UDP_INI
6571
fi_param_define(&udpx_prov, "iface", FI_PARAM_STRING,
6672
"Specify interface name");
6773

74+
ofi_mutex_init(&init_lock);
6875
return &udpx_prov;
6976
}

0 commit comments

Comments
 (0)