Skip to content

Commit

Permalink
path: Use loops in new kernels
Browse files Browse the repository at this point in the history
In "large" kernels we have support for loops. So use them in
prepend_path (a function used in path resolution) to improve loading
time.

Signed-off-by: Anastasios Papagiannis <[email protected]>
  • Loading branch information
tpapagian committed Jan 16, 2024
1 parent 95974f4 commit 57f7b8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions bpf/lib/bpf_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#ifdef __LARGE_BPF_PROG
#define PROBE_CWD_READ_ITERATIONS 128
#define PROBE_CWD_READ_UNROLL 4
#else
#define PROBE_CWD_READ_ITERATIONS 11
#endif
Expand Down
23 changes: 19 additions & 4 deletions bpf/process/bpf_process_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,30 @@ prepend_path(const struct path *path, const struct path *root, char *bf,
probe_read(&data.vfsmnt, sizeof(data.vfsmnt), _(&path->mnt));
data.mnt = real_mount(data.vfsmnt);

#ifndef __V61_BPF_PROG
#if defined(__V61_BPF_PROG)
loop(PROBE_CWD_READ_ITERATIONS, cwd_read_v61, (void *)&data, 0);
#elif defined(__LARGE_BPF_PROG)
// In large kernels we have support for loops so there is no
// neet to unroll here. If we just remove the unroll we get
// verification error (too large program). To overcome this,
// we do "some" loop unrolling.
for (int i = 0; i < PROBE_CWD_READ_ITERATIONS / PROBE_CWD_READ_UNROLL; ++i) {
if (cwd_read(&data))
break;
if (cwd_read(&data))
break;
if (cwd_read(&data))
break;
if (cwd_read(&data))
break;
}
#else
#pragma unroll
for (int i = 0; i < PROBE_CWD_READ_ITERATIONS; ++i) {
if (cwd_read(&data))
break;
}
#else
loop(PROBE_CWD_READ_ITERATIONS, cwd_read_v61, (void *)&data, 0);
#endif /* __V61_BPF_PROG */
#endif

if (data.bptr == *buffer) {
*buflen = 0;
Expand Down

0 comments on commit 57f7b8d

Please sign in to comment.