Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2021 Facebook */
0003 #include "vmlinux.h"
0004 #include <bpf/bpf_helpers.h>
0005 #include <bpf/bpf_tracing.h>
0006 
0007 char _license[] SEC("license") = "GPL";
0008 
0009 __u64 test1_hits = 0;
0010 __u64 address_low = 0;
0011 __u64 address_high = 0;
0012 int wasted_entries = 0;
0013 long total_entries = 0;
0014 
0015 #define ENTRY_CNT 32
0016 struct perf_branch_entry entries[ENTRY_CNT] = {};
0017 
0018 static inline bool in_range(__u64 val)
0019 {
0020     return (val >= address_low) && (val < address_high);
0021 }
0022 
0023 SEC("fexit/bpf_testmod_loop_test")
0024 int BPF_PROG(test1, int n, int ret)
0025 {
0026     long i;
0027 
0028     total_entries = bpf_get_branch_snapshot(entries, sizeof(entries), 0);
0029     total_entries /= sizeof(struct perf_branch_entry);
0030 
0031     for (i = 0; i < ENTRY_CNT; i++) {
0032         if (i >= total_entries)
0033             break;
0034         if (in_range(entries[i].from) && in_range(entries[i].to))
0035             test1_hits++;
0036         else if (!test1_hits)
0037             wasted_entries++;
0038     }
0039     return 0;
0040 }