mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
To: Paolo Abeni <pabeni@redhat.com>,
	Stefano Garzarella <sgarzare@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	"edumazet@google.com" <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"virtualization@lists.linux-foundation.org" 
	<virtualization@lists.linux-foundation.org>,
	kernel <kernel@sberdevices.ru>,
	Krasnov Arseniy <oxffffaa@gmail.com>,
	Bobby Eshleman <bobby.eshleman@bytedance.com>
Subject: Re: [PATCH net-next v6 4/4] test/vsock: vsock_perf utility
Date: Tue, 10 Jan 2023 10:20:22 +0000	[thread overview]
Message-ID: <6a82d5c7-7718-a488-1827-feac5770fd1d@sberdevices.ru> (raw)
In-Reply-To: <5c8b538bcc9ac75027f41c21e810d3707a2e1ec7.camel@redhat.com>

On 10.01.2023 12:36, Paolo Abeni wrote:
> Hi,
> 
> sorry for the late feedback, a couple of notes below...

Hello! Thanks for review! just fixed it in v7

Thanks, Arseniy

> 
> On Sun, 2023-01-08 at 20:43 +0000, Arseniy Krasnov wrote:
>> This adds utility to check vsock rx/tx performance.
>>
>> Usage as sender:
>> ./vsock_perf --sender <cid> --port <port> --bytes <bytes to send>
>> Usage as receiver:
>> ./vsock_perf --port <port> --rcvlowat <SO_RCVLOWAT>
>>
>> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
>> ---
>>  tools/testing/vsock/Makefile     |   3 +-
>>  tools/testing/vsock/README       |  34 +++
>>  tools/testing/vsock/vsock_perf.c | 441 +++++++++++++++++++++++++++++++
>>  3 files changed, 477 insertions(+), 1 deletion(-)
>>  create mode 100644 tools/testing/vsock/vsock_perf.c
>>
>> diff --git a/tools/testing/vsock/Makefile b/tools/testing/vsock/Makefile
>> index f8293c6910c9..43a254f0e14d 100644
>> --- a/tools/testing/vsock/Makefile
>> +++ b/tools/testing/vsock/Makefile
>> @@ -1,8 +1,9 @@
>>  # SPDX-License-Identifier: GPL-2.0-only
>> -all: test
>> +all: test vsock_perf
>>  test: vsock_test vsock_diag_test
>>  vsock_test: vsock_test.o timeout.o control.o util.o
>>  vsock_diag_test: vsock_diag_test.o timeout.o control.o util.o
>> +vsock_perf: vsock_perf.o
>>  
>>  CFLAGS += -g -O2 -Werror -Wall -I. -I../../include -I../../../usr/include -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -D_GNU_SOURCE
>>  .PHONY: all test clean
>> diff --git a/tools/testing/vsock/README b/tools/testing/vsock/README
>> index 4d5045e7d2c3..84ee217ba8ee 100644
>> --- a/tools/testing/vsock/README
>> +++ b/tools/testing/vsock/README
>> @@ -35,3 +35,37 @@ Invoke test binaries in both directions as follows:
>>                         --control-port=$GUEST_IP \
>>                         --control-port=1234 \
>>                         --peer-cid=3
>> +
>> +vsock_perf utility
>> +-------------------
>> +'vsock_perf' is a simple tool to measure vsock performance. It works in
>> +sender/receiver modes: sender connect to peer at the specified port and
>> +starts data transmission to the receiver. After data processing is done,
>> +it prints several metrics(see below).
>> +
>> +Usage:
>> +# run as sender
>> +# connect to CID 2, port 1234, send 1G of data, tx buf size is 1M
>> +./vsock_perf --sender 2 --port 1234 --bytes 1G --buf-size 1M
>> +
>> +Output:
>> +tx performance: A Gbits/s
>> +
>> +Output explanation:
>> +A is calculated as "number of bits to send" / "time in tx loop"
>> +
>> +# run as receiver
>> +# listen port 1234, rx buf size is 1M, socket buf size is 1G, SO_RCVLOWAT is 64K
>> +./vsock_perf --port 1234 --buf-size 1M --vsk-size 1G --rcvlowat 64K
>> +
>> +Output:
>> +rx performance: A Gbits/s
>> +total in 'read()': B sec
>> +POLLIN wakeups: C
>> +average in 'read()': D ns
>> +
>> +Output explanation:
>> +A is calculated as "number of received bits" / "time in rx loop".
>> +B is time, spent in 'read()' system call(excluding 'poll()')
>> +C is number of 'poll()' wake ups with POLLIN bit set.
>> +D is B / C, e.g. average amount of time, spent in single 'read()'.
>> diff --git a/tools/testing/vsock/vsock_perf.c b/tools/testing/vsock/vsock_perf.c
>> new file mode 100644
>> index 000000000000..ccd595462b40
>> --- /dev/null
>> +++ b/tools/testing/vsock/vsock_perf.c
>> @@ -0,0 +1,441 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * vsock_perf - benchmark utility for vsock.
>> + *
>> + * Copyright (C) 2022 SberDevices.
>> + *
>> + * Author: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>> + */
>> +#include <getopt.h>
>> +#include <stdio.h>
>> +#include <stdlib.h>
>> +#include <stdbool.h>
>> +#include <string.h>
>> +#include <errno.h>
>> +#include <unistd.h>
>> +#include <time.h>
>> +#include <stdint.h>
>> +#include <poll.h>
>> +#include <sys/socket.h>
>> +#include <linux/vm_sockets.h>
>> +
>> +#define DEFAULT_BUF_SIZE_BYTES	(128 * 1024)
>> +#define DEFAULT_TO_SEND_BYTES	(64 * 1024)
>> +#define DEFAULT_VSOCK_BUF_BYTES (256 * 1024)
>> +#define DEFAULT_RCVLOWAT_BYTES	1
>> +#define DEFAULT_PORT		1234
>> +
>> +#define BYTES_PER_GB		(1024 * 1024 * 1024ULL)
>> +#define NSEC_PER_SEC		(1000000000ULL)
>> +
>> +static unsigned int port = DEFAULT_PORT;
>> +static unsigned long buf_size_bytes = DEFAULT_BUF_SIZE_BYTES;
>> +static unsigned long vsock_buf_bytes = DEFAULT_VSOCK_BUF_BYTES;
>> +
>> +static inline time_t current_nsec(void)
> 
> Minor nit: you should avoid 'static inline' functions in c files,
> 'static' would suffice and will allow the compiler to do a better job.
> 
>> +{
>> +	struct timespec ts;
>> +
>> +	if (clock_gettime(CLOCK_REALTIME, &ts)) {
>> +		perror("clock_gettime");
>> +		exit(EXIT_FAILURE);
>> +	}
>> +
>> +	return (ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec;
>> +}
>> +
>> +/* From lib/cmdline.c. */
>> +static unsigned long memparse(const char *ptr)
>> +{
>> +	char *endptr;
>> +
>> +	unsigned long long ret = strtoull(ptr, &endptr, 0);
>> +
>> +	switch (*endptr) {
>> +	case 'E':
>> +	case 'e':
>> +		ret <<= 10;
>> +	case 'P':
>> +	case 'p':
>> +		ret <<= 10;
>> +	case 'T':
>> +	case 't':
>> +		ret <<= 10;
>> +	case 'G':
>> +	case 'g':
>> +		ret <<= 10;
>> +	case 'M':
>> +	case 'm':
>> +		ret <<= 10;
>> +	case 'K':
>> +	case 'k':
>> +		ret <<= 10;
>> +		endptr++;
>> +	default:
>> +		break;
>> +	}
>> +
>> +	return ret;
>> +}
>> +
>> +static void vsock_increase_buf_size(int fd)
>> +{
>> +	if (setsockopt(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_MAX_SIZE,
>> +		       &vsock_buf_bytes, sizeof(vsock_buf_bytes))) {
>> +		perror("setsockopt(SO_VM_SOCKETS_BUFFER_MAX_SIZE)");
>> +		exit(EXIT_FAILURE);
>> +	}
>> +
>> +	if (setsockopt(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_SIZE,
>> +		       &vsock_buf_bytes, sizeof(vsock_buf_bytes))) {
>> +		perror("setsockopt(SO_VM_SOCKETS_BUFFER_SIZE)");
>> +		exit(EXIT_FAILURE);
> 
> You use the above pattern frequently, but you could replace both
> libcall with a single error() call.
> 
> Thanks,
> 
> Paolo
> 


      reply	other threads:[~2023-01-10 10:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-08 20:35 [PATCH net-next v6 0/4] vsock: update tools and error handling Arseniy Krasnov
2023-01-08 20:39 ` [PATCH net-next v6 1/4] vsock: return errors other than -ENOMEM to socket Arseniy Krasnov
2023-01-08 20:40 ` [PATCH net-next v6 2/4] test/vsock: rework message bounds test Arseniy Krasnov
2023-01-08 20:42 ` [PATCH net-next v6 3/4] test/vsock: add big message test Arseniy Krasnov
2023-01-08 20:43 ` [PATCH net-next v6 4/4] test/vsock: vsock_perf utility Arseniy Krasnov
2023-01-10  9:36   ` Paolo Abeni
2023-01-10 10:20     ` Arseniy Krasnov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a82d5c7-7718-a488-1827-feac5770fd1d@sberdevices.ru \
    --to=avkrasnov@sberdevices.ru \
    --cc=bobby.eshleman@bytedance.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kernel@sberdevices.ru \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oxffffaa@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®