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

TOMOYO Linux Cross Reference
Linux/samples/bpf/tracex6_kern.c

Version: ~ [ linux-5.8-rc4 ] ~ [ linux-5.7.7 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.50 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.131 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.187 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.229 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.229 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <linux/ptrace.h>
  2 #include <linux/version.h>
  3 #include <uapi/linux/bpf.h>
  4 #include "bpf_helpers.h"
  5 
  6 struct bpf_map_def SEC("maps") counters = {
  7         .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
  8         .key_size = sizeof(int),
  9         .value_size = sizeof(u32),
 10         .max_entries = 64,
 11 };
 12 struct bpf_map_def SEC("maps") values = {
 13         .type = BPF_MAP_TYPE_HASH,
 14         .key_size = sizeof(int),
 15         .value_size = sizeof(u64),
 16         .max_entries = 64,
 17 };
 18 struct bpf_map_def SEC("maps") values2 = {
 19         .type = BPF_MAP_TYPE_HASH,
 20         .key_size = sizeof(int),
 21         .value_size = sizeof(struct bpf_perf_event_value),
 22         .max_entries = 64,
 23 };
 24 
 25 SEC("kprobe/htab_map_get_next_key")
 26 int bpf_prog1(struct pt_regs *ctx)
 27 {
 28         u32 key = bpf_get_smp_processor_id();
 29         u64 count, *val;
 30         s64 error;
 31 
 32         count = bpf_perf_event_read(&counters, key);
 33         error = (s64)count;
 34         if (error <= -2 && error >= -22)
 35                 return 0;
 36 
 37         val = bpf_map_lookup_elem(&values, &key);
 38         if (val)
 39                 *val = count;
 40         else
 41                 bpf_map_update_elem(&values, &key, &count, BPF_NOEXIST);
 42 
 43         return 0;
 44 }
 45 
 46 SEC("kprobe/htab_map_lookup_elem")
 47 int bpf_prog2(struct pt_regs *ctx)
 48 {
 49         u32 key = bpf_get_smp_processor_id();
 50         struct bpf_perf_event_value *val, buf;
 51         int error;
 52 
 53         error = bpf_perf_event_read_value(&counters, key, &buf, sizeof(buf));
 54         if (error)
 55                 return 0;
 56 
 57         val = bpf_map_lookup_elem(&values2, &key);
 58         if (val)
 59                 *val = buf;
 60         else
 61                 bpf_map_update_elem(&values2, &key, &buf, BPF_NOEXIST);
 62 
 63         return 0;
 64 }
 65 
 66 char _license[] SEC("license") = "GPL";
 67 u32 _version SEC("version") = LINUX_VERSION_CODE;
 68 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp