Netdev List
 help / color / mirror / Atom feed
From: Taeung Song <treeze.taeung@gmail.com>
To: David Laight <David.Laight@ACULAB.COM>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>
Cc: Teng Qin <qinteng@fb.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/4] samples/bpf: Check the error of write() and read()
Date: Mon, 2 Jul 2018 18:47:35 +0900	[thread overview]
Message-ID: <a80014c4-e74e-179d-3a6e-352704af0b7d@gmail.com> (raw)
In-Reply-To: <c8fd15978e6642158c7e64190e4dee13@AcuMS.aculab.com>

Hi David Laight,

On 07/02/2018 06:25 PM, David Laight wrote:
> From: Taeung Song
>> Sent: 02 July 2018 10:15
>> test_task_rename() and test_urandom_read()
>> can be failed during write() and read(),
>> So check the result of them.
>>
>> Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
>> ---
>>   samples/bpf/test_overhead_user.c | 20 +++++++++++++++-----
>>   1 file changed, 15 insertions(+), 5 deletions(-)
>>
>> diff --git a/samples/bpf/test_overhead_user.c b/samples/bpf/test_overhead_user.c
>> index 6caf47a..8a88d9c 100644
>> --- a/samples/bpf/test_overhead_user.c
>> +++ b/samples/bpf/test_overhead_user.c
>> @@ -6,6 +6,7 @@
>>    */
>>   #define _GNU_SOURCE
>>   #include <sched.h>
>> +#include <errno.h>
>>   #include <stdio.h>
>>   #include <sys/types.h>
>>   #include <asm/unistd.h>
>> @@ -44,8 +45,12 @@ static void test_task_rename(int cpu)
>>   		exit(1);
>>   	}
>>   	start_time = time_get_ns();
>> -	for (i = 0; i < MAX_CNT; i++)
>> -		write(fd, buf, sizeof(buf));
>> +	for (i = 0; i < MAX_CNT; i++) {
>> +		if (write(fd, buf, sizeof(buf)) < 0) {
>> +			printf("task rename failed: %s\n", strerror(errno));
>> +			break;
> 
> I'm not sure 'break' generates sensible output.
> 

OK,
it seems to be better to off on the above error case instead of break;

>> +		}
>> +	}
> 
> What about partial writes??
> 
Hum..
do you mean just skipping several errors of the above write() ?

>>   	printf("task_rename:%d: %lld events per sec\n",
>>   	       cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time));
>>   	close(fd);
>> @@ -55,7 +60,7 @@ static void test_urandom_read(int cpu)
>>   {
>>   	__u64 start_time;
>>   	char buf[4];
>> -	int i, fd;
>> +	int i, fd, err = 0;
>>
>>   	fd = open("/dev/urandom", O_RDONLY);
>>   	if (fd < 0) {
>> @@ -63,8 +68,13 @@ static void test_urandom_read(int cpu)
>>   		exit(1);
>>   	}
>>   	start_time = time_get_ns();
>> -	for (i = 0; i < MAX_CNT; i++)
>> -		read(fd, buf, sizeof(buf));
>> +	for (i = 0; i < MAX_CNT; i++) {
>> +		err = read(fd, buf, sizeof(buf));
>> +		if (err < 0 || err >= sizeof(buf)) {
> 
> Overlong reads indicate that something is seriously awry.
> Short reads are valid - but maybe not expected.
>> +			printf("failed to read from /dev/urandom: %s\n", strerror(errno));
> 
> 
> strerror() won't give anything sensible unless err == -1;
> You probably want to include the loop count.
> 
>> +			break;
> 
> The summary print will be gibberish after break.
> 

Ditto, will change the code to do exit(1);
on the err == -1 case.
What do you think about it ?

Thanks,
Taeung

>> +		}
>> +	}
>>   	printf("urandom_read:%d: %lld events per sec\n",
>>   	       cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time));
>>   	close(fd);
>> --
>> 2.7.4
> 

  reply	other threads:[~2018-07-02  9:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-02  9:14 [PATCH 0/4] samples/bpf: simple fixes Taeung Song
2018-07-02  9:14 ` [PATCH 1/4] samples/bpf: add missing <linux/if_vlan.h> Taeung Song
2018-07-02  9:14 ` [PATCH 2/4] samples/bpf: Check the result of system() Taeung Song
2018-07-02  9:14 ` [PATCH 3/4] samples/bpf: Check the error of write() and read() Taeung Song
2018-07-02  9:25   ` David Laight
2018-07-02  9:47     ` Taeung Song [this message]
2018-07-02  9:14 ` [PATCH 4/4] samples/bpf: add .gitignore file Taeung Song

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=a80014c4-e74e-179d-3a6e-352704af0b7d@gmail.com \
    --to=treeze.taeung@gmail.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=qinteng@fb.com \
    /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