From: Y Song <ys114321@gmail.com>
To: Stanislav Fomichev <sdf@google.com>
Cc: netdev <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
David Miller <davem@davemloft.net>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Ilya Leoshkevich <iii@linux.ibm.com>
Subject: Re: [PATCH bpf-next] selftests/bpf: make verifier loop tests arch independent
Date: Wed, 3 Jul 2019 16:39:14 -0700 [thread overview]
Message-ID: <CAH3MdRWePmAZNRfGNcBdjKAJ+D33=4Vgg1STYC3khNps8AmaHQ@mail.gmail.com> (raw)
In-Reply-To: <20190703205100.142904-1-sdf@google.com>
On Wed, Jul 3, 2019 at 1:51 PM Stanislav Fomichev <sdf@google.com> wrote:
>
> Take the first x bytes of pt_regs for scalability tests, there is
> no real reason we need x86 specific rax.
>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---
> tools/testing/selftests/bpf/progs/loop1.c | 3 ++-
> tools/testing/selftests/bpf/progs/loop2.c | 3 ++-
> tools/testing/selftests/bpf/progs/loop3.c | 3 ++-
> 3 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/loop1.c b/tools/testing/selftests/bpf/progs/loop1.c
> index dea395af9ea9..d530c61d2517 100644
> --- a/tools/testing/selftests/bpf/progs/loop1.c
> +++ b/tools/testing/selftests/bpf/progs/loop1.c
> @@ -14,11 +14,12 @@ SEC("raw_tracepoint/kfree_skb")
> int nested_loops(volatile struct pt_regs* ctx)
> {
> int i, j, sum = 0, m;
> + volatile int *any_reg = (volatile int *)ctx;
>
> for (j = 0; j < 300; j++)
> for (i = 0; i < j; i++) {
> if (j & 1)
> - m = ctx->rax;
> + m = *any_reg;
I agree. ctx->rax here is only to generate some operations, which
cannot be optimized away by the compiler. dereferencing a volatile
pointee may just serve that purpose.
Comparing the byte code generated with ctx->rax and *any_reg, they are
slightly different. Using *any_reg is slighly worse, but this should
be still okay for the test.
> else
> m = j;
> sum += i * m;
> diff --git a/tools/testing/selftests/bpf/progs/loop2.c b/tools/testing/selftests/bpf/progs/loop2.c
> index 0637bd8e8bcf..91bb89d901e3 100644
> --- a/tools/testing/selftests/bpf/progs/loop2.c
> +++ b/tools/testing/selftests/bpf/progs/loop2.c
> @@ -14,9 +14,10 @@ SEC("raw_tracepoint/consume_skb")
> int while_true(volatile struct pt_regs* ctx)
> {
> int i = 0;
> + volatile int *any_reg = (volatile int *)ctx;
>
> while (true) {
> - if (ctx->rax & 1)
> + if (*any_reg & 1)
> i += 3;
> else
> i += 7;
> diff --git a/tools/testing/selftests/bpf/progs/loop3.c b/tools/testing/selftests/bpf/progs/loop3.c
> index 30a0f6cba080..3a7f12d7186c 100644
> --- a/tools/testing/selftests/bpf/progs/loop3.c
> +++ b/tools/testing/selftests/bpf/progs/loop3.c
> @@ -14,9 +14,10 @@ SEC("raw_tracepoint/consume_skb")
> int while_true(volatile struct pt_regs* ctx)
> {
> __u64 i = 0, sum = 0;
> + volatile __u64 *any_reg = (volatile __u64 *)ctx;
> do {
> i++;
> - sum += ctx->rax;
> + sum += *any_reg;
> } while (i < 0x100000000ULL);
> return sum;
> }
> --
> 2.22.0.410.gd8fdbe21b5-goog
Ilya Leoshkevich (iii@linux.ibm.com, cc'ed) has another patch set
trying to solve this problem by introducing s360 arch register access
macros. I guess for now that patch set is not needed any more?
next prev parent reply other threads:[~2019-07-03 23:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-03 20:51 [PATCH bpf-next] selftests/bpf: make verifier loop tests arch independent Stanislav Fomichev
2019-07-03 23:39 ` Y Song [this message]
2019-07-08 16:13 ` Stanislav Fomichev
2019-07-08 20:14 ` Ilya Leoshkevich
2019-07-08 21:20 ` Stanislav Fomichev
2019-07-08 21:44 ` Ilya Leoshkevich
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='CAH3MdRWePmAZNRfGNcBdjKAJ+D33=4Vgg1STYC3khNps8AmaHQ@mail.gmail.com' \
--to=ys114321@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=iii@linux.ibm.com \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.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;
as well as URLs for NNTP newsgroup(s).