[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <32a95c34-9fee-536e-2edf-ec827f2a883b@iogearbox.net>
Date: Wed, 24 Jan 2018 11:04:18 +0100
From: Daniel Borkmann <daniel@...earbox.net>
To: John Fastabend <john.fastabend@...il.com>, borkmann@...earbox.net,
kafai@...com, ast@...nel.org
Cc: netdev@...r.kernel.org, brouer@...hat.com
Subject: Re: [bpf-next PATCH v4 2/7] bpf: add sendmsg option for testing BPF
programs
On 01/22/2018 07:35 PM, John Fastabend wrote:
> When testing BPF programs using sockmap I often want to have more
> control over how sendmsg is exercised. This becomes even more useful
> as new sockmap program types are added.
>
> This adds a test type option to select type of test to run. Currently,
> only "ping" and "sendmsg" are supported, but more can be added as
> needed.
>
> The new help argument gives the following,
>
> Usage: ./sockmap --cgroup <cgroup_path>
> options:
> --help -h
> --cgroup -c
> --rate -r
> --verbose -v
> --iov_count -i
> --length -l
> --test -t
>
> Signed-off-by: John Fastabend <john.fastabend@...il.com>
> ---
> samples/sockmap/sockmap_user.c | 148 +++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 145 insertions(+), 3 deletions(-)
>
> diff --git a/samples/sockmap/sockmap_user.c b/samples/sockmap/sockmap_user.c
> index ffd1d12..ccc7173 100644
> --- a/samples/sockmap/sockmap_user.c
> +++ b/samples/sockmap/sockmap_user.c
> @@ -56,6 +56,9 @@
> {"cgroup", required_argument, NULL, 'c' },
> {"rate", required_argument, NULL, 'r' },
> {"verbose", no_argument, NULL, 'v' },
> + {"iov_count", required_argument, NULL, 'i' },
> + {"length", required_argument, NULL, 'l' },
> + {"test", required_argument, NULL, 't' },
> {0, 0, NULL, 0 }
> };
>
> @@ -182,6 +185,118 @@ static int sockmap_init_sockets(void)
> return 0;
> }
>
> +struct msg_stats {
> + size_t bytes_sent;
> + size_t bytes_recvd;
> +};
> +
> +static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
> + struct msg_stats *s, bool tx)
> +{
> + struct msghdr msg = {0};
> + struct iovec *iov;
> + int i, flags = 0;
> +
> + iov = calloc(iov_count, sizeof(struct iovec));
> + if (!iov)
> + return errno;
> +
> + for (i = 0; i < iov_count; i++) {
> + char *d = calloc(iov_length, sizeof(char));
> +
> + if (!d) {
> + fprintf(stderr, "iov_count %i/%i OOM\n", i, iov_count);
> + goto out_errno;
> + }
> + iov[i].iov_base = d;
> + iov[i].iov_len = iov_length;
> + }
> +
> + msg.msg_iov = iov;
> + msg.msg_iovlen = iov_count;
> +
> + if (tx) {
> + for (i = 0; i < cnt; i++) {
> + int sent = sendmsg(fd, &msg, flags);
> +
> + if (sent < 0) {
> + perror("send loop error:");
> + goto out_errno;
> + }
> + s->bytes_sent += sent;
> + }
> + } else {
> + int slct, recv, max_fd = fd;
> + struct timeval timeout;
> + float total_bytes;
> + fd_set w;
> +
> + total_bytes = (float)iov_count * (float)iov_length * (float)cnt;
> + while (s->bytes_recvd < total_bytes) {
> + timeout.tv_sec = 1;
> + timeout.tv_usec = 0;
> +
> + /* FD sets */
> + FD_ZERO(&w);
> + FD_SET(fd, &w);
> +
> + slct = select(max_fd + 1, &w, NULL, NULL, &timeout);
> + if (slct == -1) {
> + perror("select()");
> + goto out_errno;
> + } else if (!slct) {
> + fprintf(stderr, "unexpected timeout\n");
> + errno = -EIO;
> + goto out_errno;
> + }
> +
> + recv = recvmsg(fd, &msg, flags);
> + if (recv < 0) {
> + if (errno != EWOULDBLOCK) {
> + perror("recv failed()\n");
> + goto out_errno;
> + }
> + }
> +
> + s->bytes_recvd += recv;
> + }
> + }
> +
> + for (i = 0; i < iov_count; i++)
> + free(iov[i].iov_base);
> + free(iov);
> + return 0;
> +out_errno:
> + for (i = 0; i < iov_count; i++)
> + free(iov[i].iov_base);
> + free(iov);
> + return errno;
Nit: when you do a next round of improvements and cleanups to sockmap_user
in future, would be good to consolidate the above two paths as well.
> +}
> +
Powered by blists - more mailing lists