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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/timer_mim.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) 2021 Facebook */
  3 #include <linux/bpf.h>
  4 #include <time.h>
  5 #include <errno.h>
  6 #include <bpf/bpf_helpers.h>
  7 #include <bpf/bpf_tracing.h>
  8 
  9 char _license[] SEC("license") = "GPL";
 10 struct hmap_elem {
 11         int pad; /* unused */
 12         struct bpf_timer timer;
 13 };
 14 
 15 struct inner_map {
 16         __uint(type, BPF_MAP_TYPE_HASH);
 17         __uint(max_entries, 1024);
 18         __type(key, int);
 19         __type(value, struct hmap_elem);
 20 } inner_htab SEC(".maps");
 21 
 22 #define ARRAY_KEY 1
 23 #define HASH_KEY 1234
 24 
 25 struct outer_arr {
 26         __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
 27         __uint(max_entries, 2);
 28         __uint(key_size, sizeof(int));
 29         __uint(value_size, sizeof(int));
 30         __array(values, struct inner_map);
 31 } outer_arr SEC(".maps") = {
 32         .values = { [ARRAY_KEY] = &inner_htab },
 33 };
 34 
 35 __u64 err;
 36 __u64 ok;
 37 __u64 cnt;
 38 
 39 static int timer_cb1(void *map, int *key, struct hmap_elem *val);
 40 
 41 static int timer_cb2(void *map, int *key, struct hmap_elem *val)
 42 {
 43         cnt++;
 44         bpf_timer_set_callback(&val->timer, timer_cb1);
 45         if (bpf_timer_start(&val->timer, 1000, 0))
 46                 err |= 1;
 47         ok |= 1;
 48         return 0;
 49 }
 50 
 51 /* callback for inner hash map */
 52 static int timer_cb1(void *map, int *key, struct hmap_elem *val)
 53 {
 54         cnt++;
 55         bpf_timer_set_callback(&val->timer, timer_cb2);
 56         if (bpf_timer_start(&val->timer, 1000, 0))
 57                 err |= 2;
 58         /* Do a lookup to make sure 'map' and 'key' pointers are correct */
 59         bpf_map_lookup_elem(map, key);
 60         ok |= 2;
 61         return 0;
 62 }
 63 
 64 SEC("fentry/bpf_fentry_test1")
 65 int BPF_PROG(test1, int a)
 66 {
 67         struct hmap_elem init = {};
 68         struct bpf_map *inner_map;
 69         struct hmap_elem *val;
 70         int array_key = ARRAY_KEY;
 71         int hash_key = HASH_KEY;
 72 
 73         inner_map = bpf_map_lookup_elem(&outer_arr, &array_key);
 74         if (!inner_map)
 75                 return 0;
 76 
 77         bpf_map_update_elem(inner_map, &hash_key, &init, 0);
 78         val = bpf_map_lookup_elem(inner_map, &hash_key);
 79         if (!val)
 80                 return 0;
 81 
 82         bpf_timer_init(&val->timer, inner_map, CLOCK_MONOTONIC);
 83         if (bpf_timer_set_callback(&val->timer, timer_cb1))
 84                 err |= 4;
 85         if (bpf_timer_start(&val->timer, 0, 0))
 86                 err |= 8;
 87         return 0;
 88 }
 89 

~ [ 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