forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/bpf: add realistic loop tests
Add a bunch of loop tests. Most of them are created by replacing '#pragma unroll' with '#pragma clang loop unroll(disable)' Several tests are artificially large: /* partial unroll. llvm will unroll loop ~150 times. * C loop count -> 600. * Asm loop count -> 4. * 16k insns in loop body. * Total of 5 such loops. Total program size ~82k insns. */ "./pyperf600.o", /* no unroll at all. * C loop count -> 600. * ASM loop count -> 600. * ~110 insns in loop body. * Total of 5 such loops. Total program size ~1500 insns. */ "./pyperf600_nounroll.o", /* partial unroll. 19k insn in a loop. * Total program size 20.8k insn. * ~350k processed_insns */ "./strobemeta.o", Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
- Loading branch information
Showing
15 changed files
with
1,347 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// Copyright (c) 2019 Facebook | ||
#include <linux/sched.h> | ||
#include <linux/ptrace.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include <linux/bpf.h> | ||
#include "bpf_helpers.h" | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
SEC("raw_tracepoint/kfree_skb") | ||
int nested_loops(volatile struct pt_regs* ctx) | ||
{ | ||
int i, j, sum = 0, m; | ||
|
||
for (j = 0; j < 300; j++) | ||
for (i = 0; i < j; i++) { | ||
if (j & 1) | ||
m = ctx->rax; | ||
else | ||
m = j; | ||
sum += i * m; | ||
} | ||
|
||
return sum; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// Copyright (c) 2019 Facebook | ||
#include <linux/sched.h> | ||
#include <linux/ptrace.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include <linux/bpf.h> | ||
#include "bpf_helpers.h" | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
SEC("raw_tracepoint/consume_skb") | ||
int while_true(volatile struct pt_regs* ctx) | ||
{ | ||
int i = 0; | ||
|
||
while (true) { | ||
if (ctx->rax & 1) | ||
i += 3; | ||
else | ||
i += 7; | ||
if (i > 40) | ||
break; | ||
} | ||
|
||
return i; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// Copyright (c) 2019 Facebook | ||
#include <linux/sched.h> | ||
#include <linux/ptrace.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include <linux/bpf.h> | ||
#include "bpf_helpers.h" | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
SEC("raw_tracepoint/consume_skb") | ||
int while_true(volatile struct pt_regs* ctx) | ||
{ | ||
__u64 i = 0, sum = 0; | ||
do { | ||
i++; | ||
sum += ctx->rax; | ||
} while (i < 0x100000000ULL); | ||
return sum; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// Copyright (c) 2019 Facebook | ||
#define STACK_MAX_LEN 600 | ||
/* clang will not unroll the loop 600 times. | ||
* Instead it will unroll it to the amount it deemed | ||
* appropriate, but the loop will still execute 600 times. | ||
* Total program size is around 90k insns | ||
*/ | ||
#include "pyperf.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// Copyright (c) 2019 Facebook | ||
#define STACK_MAX_LEN 600 | ||
#define NO_UNROLL | ||
/* clang will not unroll at all. | ||
* Total program size is around 2k insns | ||
*/ | ||
#include "pyperf.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) | ||
// Copyright (c) 2019 Facebook | ||
|
||
#define STROBE_MAX_INTS 2 | ||
#define STROBE_MAX_STRS 25 | ||
#define STROBE_MAX_MAPS 100 | ||
#define STROBE_MAX_MAP_ENTRIES 20 | ||
/* full unroll by llvm #undef NO_UNROLL */ | ||
#include "strobemeta.h" | ||
|
Oops, something went wrong.