~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/benchs/bench_rename.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /* Copyright (c) 2020 Facebook */
  3 #include <fcntl.h>
  4 #include "bench.h"
  5 #include "test_overhead.skel.h"
  6 
  7 /* BPF triggering benchmarks */
  8 static struct ctx {
  9         struct test_overhead *skel;
 10         struct counter hits;
 11         int fd;
 12 } ctx;
 13 
 14 static void validate(void)
 15 {
 16         if (env.producer_cnt != 1) {
 17                 fprintf(stderr, "benchmark doesn't support multi-producer!\n");
 18                 exit(1);
 19         }
 20         if (env.consumer_cnt != 0) {
 21                 fprintf(stderr, "benchmark doesn't support consumer!\n");
 22                 exit(1);
 23         }
 24 }
 25 
 26 static void *producer(void *input)
 27 {
 28         char buf[] = "test_overhead";
 29         int err;
 30 
 31         while (true) {
 32                 err = write(ctx.fd, buf, sizeof(buf));
 33                 if (err < 0) {
 34                         fprintf(stderr, "write failed\n");
 35                         exit(1);
 36                 }
 37                 atomic_inc(&ctx.hits.value);
 38         }
 39 }
 40 
 41 static void measure(struct bench_res *res)
 42 {
 43         res->hits = atomic_swap(&ctx.hits.value, 0);
 44 }
 45 
 46 static void setup_ctx(void)
 47 {
 48         setup_libbpf();
 49 
 50         ctx.skel = test_overhead__open_and_load();
 51         if (!ctx.skel) {
 52                 fprintf(stderr, "failed to open skeleton\n");
 53                 exit(1);
 54         }
 55 
 56         ctx.fd = open("/proc/self/comm", O_WRONLY|O_TRUNC);
 57         if (ctx.fd < 0) {
 58                 fprintf(stderr, "failed to open /proc/self/comm: %d\n", -errno);
 59                 exit(1);
 60         }
 61 }
 62 
 63 static void attach_bpf(struct bpf_program *prog)
 64 {
 65         struct bpf_link *link;
 66 
 67         link = bpf_program__attach(prog);
 68         if (!link) {
 69                 fprintf(stderr, "failed to attach program!\n");
 70                 exit(1);
 71         }
 72 }
 73 
 74 static void setup_base(void)
 75 {
 76         setup_ctx();
 77 }
 78 
 79 static void setup_kprobe(void)
 80 {
 81         setup_ctx();
 82         attach_bpf(ctx.skel->progs.prog1);
 83 }
 84 
 85 static void setup_kretprobe(void)
 86 {
 87         setup_ctx();
 88         attach_bpf(ctx.skel->progs.prog2);
 89 }
 90 
 91 static void setup_rawtp(void)
 92 {
 93         setup_ctx();
 94         attach_bpf(ctx.skel->progs.prog3);
 95 }
 96 
 97 static void setup_fentry(void)
 98 {
 99         setup_ctx();
100         attach_bpf(ctx.skel->progs.prog4);
101 }
102 
103 static void setup_fexit(void)
104 {
105         setup_ctx();
106         attach_bpf(ctx.skel->progs.prog5);
107 }
108 
109 const struct bench bench_rename_base = {
110         .name = "rename-base",
111         .validate = validate,
112         .setup = setup_base,
113         .producer_thread = producer,
114         .measure = measure,
115         .report_progress = hits_drops_report_progress,
116         .report_final = hits_drops_report_final,
117 };
118 
119 const struct bench bench_rename_kprobe = {
120         .name = "rename-kprobe",
121         .validate = validate,
122         .setup = setup_kprobe,
123         .producer_thread = producer,
124         .measure = measure,
125         .report_progress = hits_drops_report_progress,
126         .report_final = hits_drops_report_final,
127 };
128 
129 const struct bench bench_rename_kretprobe = {
130         .name = "rename-kretprobe",
131         .validate = validate,
132         .setup = setup_kretprobe,
133         .producer_thread = producer,
134         .measure = measure,
135         .report_progress = hits_drops_report_progress,
136         .report_final = hits_drops_report_final,
137 };
138 
139 const struct bench bench_rename_rawtp = {
140         .name = "rename-rawtp",
141         .validate = validate,
142         .setup = setup_rawtp,
143         .producer_thread = producer,
144         .measure = measure,
145         .report_progress = hits_drops_report_progress,
146         .report_final = hits_drops_report_final,
147 };
148 
149 const struct bench bench_rename_fentry = {
150         .name = "rename-fentry",
151         .validate = validate,
152         .setup = setup_fentry,
153         .producer_thread = producer,
154         .measure = measure,
155         .report_progress = hits_drops_report_progress,
156         .report_final = hits_drops_report_final,
157 };
158 
159 const struct bench bench_rename_fexit = {
160         .name = "rename-fexit",
161         .validate = validate,
162         .setup = setup_fexit,
163         .producer_thread = producer,
164         .measure = measure,
165         .report_progress = hits_drops_report_progress,
166         .report_final = hits_drops_report_final,
167 };
168 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php