2018-08-30 22:37:29

by Igor Stoppa

[permalink] [raw]
Subject: [PATCH 05/23] selftest: vm: add unlikely() to BUG_ON()

BUG_ON() is unlikely() to BUG()

Signed-off-by: Igor Stoppa <[email protected]>
Cc: Dmitry Safonov <[email protected]>
Cc: Shuah Khan <[email protected]>
---
tools/testing/selftests/vm/map_populate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/vm/map_populate.c b/tools/testing/selftests/vm/map_populate.c
index 6b8aeaa0bf7a..ca3f54765897 100644
--- a/tools/testing/selftests/vm/map_populate.c
+++ b/tools/testing/selftests/vm/map_populate.c
@@ -23,7 +23,7 @@

#define BUG_ON(condition, description) \
do { \
- if (condition) { \
+ if (unlikely(condition)) { \
fprintf(stderr, "[FAIL]\t%s:%d\t%s:%s\n", __func__, \
__LINE__, (description), strerror(errno)); \
exit(1); \
--
2.17.1



2018-08-30 22:59:15

by Dmitry Safonov

[permalink] [raw]
Subject: Re: [PATCH 05/23] selftest: vm: add unlikely() to BUG_ON()

Hi Igor,

On Fri, 2018-08-31 at 01:34 +0300, Igor Stoppa wrote:
> BUG_ON() is unlikely() to BUG()

This selftest runs in userspace..
So, we should define the macro somehow, as i.e:
rseq/rseq.h:#define rseq_unlikely(x) __builtin_expect(!!(x), 0)

Otherwise,
[selftests]$ make vm/map_populate
cc vm/map_populate.c -o vm/map_populate
vm/map_populate.c: In function ‘parent_f’:
vm/map_populate.c:26:7: warning: implicit declaration of function
‘unlikely’; did you mean ‘unlinkat’? [-Wimplicit-function-declaration]
if (unlikely(condition)) { \
^
vm/map_populate.c:38:2: note: in expansion of macro ‘BUG_ON’
BUG_ON(ret <= 0, "read(sock)");
^~~~~~
/tmp/cc7evGVG.o: In function `parent_f':
map_populate.c:(.text+0x3d): undefined reference to `unlikely'
map_populate.c:(.text+0xbb): undefined reference to `unlikely'
map_populate.c:(.text+0x135): undefined reference to `unlikely'
map_populate.c:(.text+0x1b0): undefined reference to `unlikely'

Not sure if we care for this at all for userspace test.
I don't mind as it runs each time by kbuild robot and cumulatively may
save something. But it's better be at least compile-tested.

--
Dima

2018-08-30 23:05:47

by Dmitry Safonov

[permalink] [raw]
Subject: Re: [PATCH 05/23] selftest: vm: add unlikely() to BUG_ON()

On Thu, 2018-08-30 at 23:57 +0100, Dmitry Safonov wrote:
> Hi Igor,
>
> On Fri, 2018-08-31 at 01:34 +0300, Igor Stoppa wrote:
> > BUG_ON() is unlikely() to BUG()
>
> This selftest runs in userspace..
> So, we should define the macro somehow, as i.e:
> rseq/rseq.h:#define rseq_unlikely(x) __builtin_expect(!!(x), 0)
>
> Otherwise,
> [selftests]$ make vm/map_populate
> cc vm/map_populate.c -o vm/map_populate
> vm/map_populate.c: In function ‘parent_f’:
> vm/map_populate.c:26:7: warning: implicit declaration of function
> ‘unlikely’; did you mean ‘unlinkat’? [-Wimplicit-function-
> declaration]
> if (unlikely(condition)) { \
> ^
> vm/map_populate.c:38:2: note: in expansion of macro ‘BUG_ON’
> BUG_ON(ret <= 0, "read(sock)");
> ^~~~~~
> /tmp/cc7evGVG.o: In function `parent_f':
> map_populate.c:(.text+0x3d): undefined reference to `unlikely'
> map_populate.c:(.text+0xbb): undefined reference to `unlikely'
> map_populate.c:(.text+0x135): undefined reference to `unlikely'
> map_populate.c:(.text+0x1b0): undefined reference to `unlikely'
>
> Not sure if we care for this at all for userspace test.
> I don't mind as it runs each time by kbuild robot and cumulatively
> may
> save something. But it's better be at least compile-tested.

JFI, there are a plenty of definitions for unlikely():
[linux]$ git grep 'define unlikely' tools
+rseq_unlikely() from tools/testing/selftests/rseq/rseq.h

Probably, the one from "tools/include/linux/compiler.h" can be used in
tools directory.

--
Dima

2018-08-31 21:27:50

by Igor Stoppa

[permalink] [raw]
Subject: Re: [PATCH 05/23] selftest: vm: add unlikely() to BUG_ON()

Hi Dmitry,

On 31/08/18 02:04, Dmitry Safonov wrote:

> Probably, the one from "tools/include/linux/compiler.h" can be used in
> tools directory.

Thank you for the advice. It seems to work now.

--
igor