Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <stfomichev@gmail.com>
Reviewed-by: Mina Almasry <almasrymina@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Stanislav Fomichev and committed by
David S. Miller
61f24c68 384492c4

+29 -20
+29 -20
tools/testing/selftests/drivers/net/hw/ncdevmem.c
··· 82 82 #define MSG_SOCK_DEVMEM 0x2000000 83 83 #endif 84 84 85 + #define MAX_IOV 1024 86 + 87 + static size_t max_chunk; 85 88 static char *server_ip; 86 89 static char *client_ip; 87 90 static char *port; ··· 837 834 struct sockaddr_in6 server_sin; 838 835 struct sockaddr_in6 client_sin; 839 836 struct ynl_sock *ys = NULL; 837 + struct iovec iov[MAX_IOV]; 840 838 struct msghdr msg = {}; 841 839 ssize_t line_size = 0; 842 840 struct cmsghdr *cmsg; 843 - struct iovec iov[2]; 844 841 char *line = NULL; 845 842 unsigned long mid; 846 843 size_t len = 0; ··· 896 893 if (line_size < 0) 897 894 break; 898 895 899 - mid = (line_size / 2) + 1; 896 + if (max_chunk) { 897 + msg.msg_iovlen = 898 + (line_size + max_chunk - 1) / max_chunk; 899 + if (msg.msg_iovlen > MAX_IOV) 900 + error(1, 0, 901 + "can't partition %zd bytes into maximum of %d chunks", 902 + line_size, MAX_IOV); 900 903 901 - iov[0].iov_base = (void *)1; 902 - iov[0].iov_len = mid; 903 - iov[1].iov_base = (void *)(mid + 2); 904 - iov[1].iov_len = line_size - mid; 904 + for (int i = 0; i < msg.msg_iovlen; i++) { 905 + iov[i].iov_base = (void *)(i * max_chunk); 906 + iov[i].iov_len = max_chunk; 907 + } 905 908 906 - provider->memcpy_to_device(mem, (size_t)iov[0].iov_base, line, 907 - iov[0].iov_len); 908 - provider->memcpy_to_device(mem, (size_t)iov[1].iov_base, 909 - line + iov[0].iov_len, 910 - iov[1].iov_len); 911 - 912 - fprintf(stderr, 913 - "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", 914 - line_size, (unsigned long)iov[0].iov_base, 915 - iov[0].iov_len, (unsigned long)iov[1].iov_base, 916 - iov[1].iov_len); 909 + iov[msg.msg_iovlen - 1].iov_len = 910 + line_size - (msg.msg_iovlen - 1) * max_chunk; 911 + } else { 912 + iov[0].iov_base = 0; 913 + iov[0].iov_len = line_size; 914 + msg.msg_iovlen = 1; 915 + } 917 916 918 917 msg.msg_iov = iov; 919 - msg.msg_iovlen = 2; 918 + provider->memcpy_to_device(mem, 0, line, line_size); 920 919 921 920 msg.msg_control = ctrl_data; 922 921 msg.msg_controllen = sizeof(ctrl_data); ··· 939 934 fprintf(stderr, "sendmsg_ret=%d\n", ret); 940 935 941 936 if (ret != line_size) 942 - error(1, errno, "Did not send all bytes"); 937 + error(1, errno, "Did not send all bytes %d vs %zd", ret, 938 + line_size); 943 939 944 940 wait_compl(socket_fd); 945 941 } ··· 962 956 int is_server = 0, opt; 963 957 int ret; 964 958 965 - while ((opt = getopt(argc, argv, "ls:c:p:v:q:t:f:")) != -1) { 959 + while ((opt = getopt(argc, argv, "ls:c:p:v:q:t:f:z:")) != -1) { 966 960 switch (opt) { 967 961 case 'l': 968 962 is_server = 1; ··· 987 981 break; 988 982 case 'f': 989 983 ifname = optarg; 984 + break; 985 + case 'z': 986 + max_chunk = atoi(optarg); 990 987 break; 991 988 case '?': 992 989 fprintf(stderr, "unknown option: %c\n", optopt);