Skip to content

Commit 61f24c6

Browse files
Stanislav Fomichevdavem330
authored andcommitted
selftests: ncdevmem: make chunking optional
Add new -z argument to specify max IOV size. By default, use single large IOV. Signed-off-by: Stanislav Fomichev <[email protected]> Reviewed-by: Mina Almasry <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 384492c commit 61f24c6

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

tools/testing/selftests/drivers/net/hw/ncdevmem.c

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
#define MSG_SOCK_DEVMEM 0x2000000
8383
#endif
8484

85+
#define MAX_IOV 1024
86+
87+
static size_t max_chunk;
8588
static char *server_ip;
8689
static char *client_ip;
8790
static char *port;
@@ -834,10 +837,10 @@ static int do_client(struct memory_buffer *mem)
834837
struct sockaddr_in6 server_sin;
835838
struct sockaddr_in6 client_sin;
836839
struct ynl_sock *ys = NULL;
840+
struct iovec iov[MAX_IOV];
837841
struct msghdr msg = {};
838842
ssize_t line_size = 0;
839843
struct cmsghdr *cmsg;
840-
struct iovec iov[2];
841844
char *line = NULL;
842845
unsigned long mid;
843846
size_t len = 0;
@@ -893,27 +896,29 @@ static int do_client(struct memory_buffer *mem)
893896
if (line_size < 0)
894897
break;
895898

896-
mid = (line_size / 2) + 1;
897-
898-
iov[0].iov_base = (void *)1;
899-
iov[0].iov_len = mid;
900-
iov[1].iov_base = (void *)(mid + 2);
901-
iov[1].iov_len = line_size - mid;
899+
if (max_chunk) {
900+
msg.msg_iovlen =
901+
(line_size + max_chunk - 1) / max_chunk;
902+
if (msg.msg_iovlen > MAX_IOV)
903+
error(1, 0,
904+
"can't partition %zd bytes into maximum of %d chunks",
905+
line_size, MAX_IOV);
902906

903-
provider->memcpy_to_device(mem, (size_t)iov[0].iov_base, line,
904-
iov[0].iov_len);
905-
provider->memcpy_to_device(mem, (size_t)iov[1].iov_base,
906-
line + iov[0].iov_len,
907-
iov[1].iov_len);
907+
for (int i = 0; i < msg.msg_iovlen; i++) {
908+
iov[i].iov_base = (void *)(i * max_chunk);
909+
iov[i].iov_len = max_chunk;
910+
}
908911

909-
fprintf(stderr,
910-
"read line_size=%ld iov[0].iov_base=%lu, iov[0].iov_len=%lu, iov[1].iov_base=%lu, iov[1].iov_len=%lu\n",
911-
line_size, (unsigned long)iov[0].iov_base,
912-
iov[0].iov_len, (unsigned long)iov[1].iov_base,
913-
iov[1].iov_len);
912+
iov[msg.msg_iovlen - 1].iov_len =
913+
line_size - (msg.msg_iovlen - 1) * max_chunk;
914+
} else {
915+
iov[0].iov_base = 0;
916+
iov[0].iov_len = line_size;
917+
msg.msg_iovlen = 1;
918+
}
914919

915920
msg.msg_iov = iov;
916-
msg.msg_iovlen = 2;
921+
provider->memcpy_to_device(mem, 0, line, line_size);
917922

918923
msg.msg_control = ctrl_data;
919924
msg.msg_controllen = sizeof(ctrl_data);
@@ -934,7 +939,8 @@ static int do_client(struct memory_buffer *mem)
934939
fprintf(stderr, "sendmsg_ret=%d\n", ret);
935940

936941
if (ret != line_size)
937-
error(1, errno, "Did not send all bytes");
942+
error(1, errno, "Did not send all bytes %d vs %zd", ret,
943+
line_size);
938944

939945
wait_compl(socket_fd);
940946
}
@@ -956,7 +962,7 @@ int main(int argc, char *argv[])
956962
int is_server = 0, opt;
957963
int ret;
958964

959-
while ((opt = getopt(argc, argv, "ls:c:p:v:q:t:f:")) != -1) {
965+
while ((opt = getopt(argc, argv, "ls:c:p:v:q:t:f:z:")) != -1) {
960966
switch (opt) {
961967
case 'l':
962968
is_server = 1;
@@ -982,6 +988,9 @@ int main(int argc, char *argv[])
982988
case 'f':
983989
ifname = optarg;
984990
break;
991+
case 'z':
992+
max_chunk = atoi(optarg);
993+
break;
985994
case '?':
986995
fprintf(stderr, "unknown option: %c\n", optopt);
987996
break;

0 commit comments

Comments
 (0)