Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1728764 > unrolled thread

[PATCH] selftests/bpf: Make bpf_util work on uniprocessor systems

Started byThomas Meyer <thomas@m3y3r.de>
First post2017-09-08 13:20 +0200
Last post2017-09-09 01:10 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] selftests/bpf: Make bpf_util work on uniprocessor systems Thomas Meyer <thomas@m3y3r.de> - 2017-09-08 13:20 +0200
    Re: [PATCH] selftests/bpf: Make bpf_util work on uniprocessor systems Daniel Borkmann <daniel@iogearbox.net> - 2017-09-09 01:10 +0200
    Re: [PATCH] selftests/bpf: Make bpf_util work on uniprocessor systems Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2017-09-09 01:10 +0200

#1728764 — [PATCH] selftests/bpf: Make bpf_util work on uniprocessor systems

FromThomas Meyer <thomas@m3y3r.de>
Date2017-09-08 13:20 +0200
Subject[PATCH] selftests/bpf: Make bpf_util work on uniprocessor systems
Message-ID<unpuh-6iJ-9@gated-at.bofh.it>
The current implementation fails to work on uniprocessor systems.
Fix the parser to also handle the uniprocessor case.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
---
 tools/testing/selftests/bpf/bpf_util.h | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h
index 20ecbaa0d85d..6c53a8906eff 100644
--- a/tools/testing/selftests/bpf/bpf_util.h
+++ b/tools/testing/selftests/bpf/bpf_util.h
@@ -12,6 +12,7 @@ static inline unsigned int bpf_num_possible_cpus(void)
 	unsigned int start, end, possible_cpus = 0;
 	char buff[128];
 	FILE *fp;
+	int n;
 
 	fp = fopen(fcpu, "r");
 	if (!fp) {
@@ -20,17 +21,17 @@ static inline unsigned int bpf_num_possible_cpus(void)
 	}
 
 	while (fgets(buff, sizeof(buff), fp)) {
-		if (sscanf(buff, "%u-%u", &start, &end) == 2) {
-			possible_cpus = start == 0 ? end + 1 : 0;
-			break;
+		n = sscanf(buff, "%u-%u", &start, &end);
+		if (n == 0) {
+			printf("Failed to retrieve # possible CPUs!\n");
+			exit(1);
+		} else if (n == 1) {
+			end = start;
 		}
+		possible_cpus = start == 0 ? end + 1 : 0;
+		break;
 	}
-
 	fclose(fp);
-	if (!possible_cpus) {
-		printf("Failed to retrieve # possible CPUs!\n");
-		exit(1);
-	}
 
 	return possible_cpus;
 }
-- 
2.11.0

[toc] | [next] | [standalone]


#1729338

FromDaniel Borkmann <daniel@iogearbox.net>
Date2017-09-09 01:10 +0200
Message-ID<unAzn-5dI-1@gated-at.bofh.it>
In reply to#1728764
On 09/09/2017 01:01 AM, Alexei Starovoitov wrote:
> On Fri, Sep 08, 2017 at 01:19:23PM +0200, Thomas Meyer wrote:
>> The current implementation fails to work on uniprocessor systems.
>> Fix the parser to also handle the uniprocessor case.
>>
>> Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
>
> Thanks for the fix. lgtm
> Acked-by: Alexei Starovoitov <ast@kernel.org>

Looks good from here as well:

Acked-by: Daniel Borkmann <daniel@iogearbox.net>

> This time it's ok to go via selftest tree, but next time please use net-next/net
> to avoid conflicts.

+1

> Thanks
>
>> ---
>>   tools/testing/selftests/bpf/bpf_util.h | 17 +++++++++--------
>>   1 file changed, 9 insertions(+), 8 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h
>> index 20ecbaa0d85d..6c53a8906eff 100644
>> --- a/tools/testing/selftests/bpf/bpf_util.h
>> +++ b/tools/testing/selftests/bpf/bpf_util.h
>> @@ -12,6 +12,7 @@ static inline unsigned int bpf_num_possible_cpus(void)
>>   	unsigned int start, end, possible_cpus = 0;
>>   	char buff[128];
>>   	FILE *fp;
>> +	int n;
>>
>>   	fp = fopen(fcpu, "r");
>>   	if (!fp) {
>> @@ -20,17 +21,17 @@ static inline unsigned int bpf_num_possible_cpus(void)
>>   	}
>>
>>   	while (fgets(buff, sizeof(buff), fp)) {
>> -		if (sscanf(buff, "%u-%u", &start, &end) == 2) {
>> -			possible_cpus = start == 0 ? end + 1 : 0;
>> -			break;
>> +		n = sscanf(buff, "%u-%u", &start, &end);
>> +		if (n == 0) {
>> +			printf("Failed to retrieve # possible CPUs!\n");
>> +			exit(1);
>> +		} else if (n == 1) {
>> +			end = start;
>>   		}
>> +		possible_cpus = start == 0 ? end + 1 : 0;
>> +		break;
>>   	}
>> -
>>   	fclose(fp);
>> -	if (!possible_cpus) {
>> -		printf("Failed to retrieve # possible CPUs!\n");
>> -		exit(1);
>> -	}
>>
>>   	return possible_cpus;
>>   }
>> --
>> 2.11.0
>>

[toc] | [prev] | [next] | [standalone]


#1729339

FromAlexei Starovoitov <alexei.starovoitov@gmail.com>
Date2017-09-09 01:10 +0200
Message-ID<unAzn-5dI-3@gated-at.bofh.it>
In reply to#1728764
On Fri, Sep 08, 2017 at 01:19:23PM +0200, Thomas Meyer wrote:
> The current implementation fails to work on uniprocessor systems.
> Fix the parser to also handle the uniprocessor case.
> 
> Signed-off-by: Thomas Meyer <thomas@m3y3r.de>

Thanks for the fix. lgtm
Acked-by: Alexei Starovoitov <ast@kernel.org>

This time it's ok to go via selftest tree, but next time please use net-next/net
to avoid conflicts.
Thanks

> ---
>  tools/testing/selftests/bpf/bpf_util.h | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h
> index 20ecbaa0d85d..6c53a8906eff 100644
> --- a/tools/testing/selftests/bpf/bpf_util.h
> +++ b/tools/testing/selftests/bpf/bpf_util.h
> @@ -12,6 +12,7 @@ static inline unsigned int bpf_num_possible_cpus(void)
>  	unsigned int start, end, possible_cpus = 0;
>  	char buff[128];
>  	FILE *fp;
> +	int n;
>  
>  	fp = fopen(fcpu, "r");
>  	if (!fp) {
> @@ -20,17 +21,17 @@ static inline unsigned int bpf_num_possible_cpus(void)
>  	}
>  
>  	while (fgets(buff, sizeof(buff), fp)) {
> -		if (sscanf(buff, "%u-%u", &start, &end) == 2) {
> -			possible_cpus = start == 0 ? end + 1 : 0;
> -			break;
> +		n = sscanf(buff, "%u-%u", &start, &end);
> +		if (n == 0) {
> +			printf("Failed to retrieve # possible CPUs!\n");
> +			exit(1);
> +		} else if (n == 1) {
> +			end = start;
>  		}
> +		possible_cpus = start == 0 ? end + 1 : 0;
> +		break;
>  	}
> -
>  	fclose(fp);
> -	if (!possible_cpus) {
> -		printf("Failed to retrieve # possible CPUs!\n");
> -		exit(1);
> -	}
>  
>  	return possible_cpus;
>  }
> -- 
> 2.11.0
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web