Skip to content

Commit 89be6b4

Browse files
committed
xdpsock: Reuse immediate exit logic from xdp_sample
Use the immediate exit logic from xdp_sample in xdpsock as well (exporting the function that checks the envvar), so we can use it in tests. Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
1 parent ec50b1a commit 89be6b4

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

lib/util/xdp_sample.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,21 +1559,26 @@ static int sample_timer_cb(int timerfd, struct stats_record **rec,
15591559
return print_stats(rec, prev);
15601560
}
15611561

1562-
int sample_run(unsigned int interval, void (*post_cb)(void *), void *ctx)
1562+
bool sample_immediate_exit(void)
15631563
{
1564-
struct timespec ts = { interval, 0 };
1565-
struct itimerspec its = { ts, ts };
1566-
struct stats_record *rec, *prev;
1567-
struct pollfd pfd[2] = {};
1568-
bool imm_exit = false;
15691564
const char *envval;
1570-
int timerfd, ret;
15711565

15721566
envval = secure_getenv("XDP_SAMPLE_IMMEDIATE_EXIT");
15731567
if (envval && envval[0] == '1' && envval[1] == '\0') {
15741568
pr_debug("XDP_SAMPLE_IMMEDIATE_EXIT envvar set, exiting immediately after setup\n");
1575-
imm_exit = true;
1569+
return true;
15761570
}
1571+
return false;
1572+
}
1573+
1574+
int sample_run(unsigned int interval, void (*post_cb)(void *), void *ctx)
1575+
{
1576+
bool imm_exit = sample_immediate_exit();
1577+
struct timespec ts = { interval, 0 };
1578+
struct itimerspec its = { ts, ts };
1579+
struct stats_record *rec, *prev;
1580+
struct pollfd pfd[2] = {};
1581+
int timerfd, ret;
15771582

15781583
if (!interval) {
15791584
pr_warn("Incorrect interval 0\n");

lib/util/xdp_sample.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ int sample_run(unsigned int interval, void (*post_cb)(void *), void *ctx);
4444
bool sample_is_compat(enum sample_compat compat_value);
4545
bool sample_probe_cpumap_compat(void);
4646
bool sample_probe_xdp_load_bytes(void);
47+
bool sample_immediate_exit(void);
4748
void sample_check_cpumap_compat(struct bpf_program *prog,
4849
struct bpf_program *prog_compat);
4950

lib/util/xdpsock.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <bpf/libbpf.h>
4242
#include <bpf/bpf.h>
4343
#include "xdpsock.h"
44+
#include "xdp_sample.h"
4445
#include "logging.h"
4546
#include "util.h"
4647

@@ -529,6 +530,10 @@ static bool is_benchmark_done(struct xsk_ctx *ctx)
529530
if (dt >= ctx->duration)
530531
ctx->benchmark_done = true;
531532
}
533+
534+
if (sample_immediate_exit())
535+
ctx->benchmark_done = true;
536+
532537
return ctx->benchmark_done;
533538
}
534539

0 commit comments

Comments
 (0)