/* Initialize the percpu object */
SEC("?fentry/bpf_fentry_test1") int BPF_PROG(test_array_map_1)
{ struct val_t __percpu_kptr *p; struct elem *e; int index = 0;
e = bpf_map_lookup_elem(&array, &index); if (!e) return 0;
p = bpf_percpu_obj_new(struct val_t); if (!p) return 0;
p = bpf_kptr_xchg(&e->pc, p); if (p)
bpf_percpu_obj_drop(p);
return 0;
}
/* Update percpu data */
SEC("?fentry/bpf_fentry_test2") int BPF_PROG(test_array_map_2)
{ struct val_t __percpu_kptr *p; struct val_t *v; struct elem *e; int index = 0;
e = bpf_map_lookup_elem(&array, &index); if (!e) return 0;
p = e->pc; if (!p) return 0;
v = bpf_per_cpu_ptr(p, 0); if (!v) return 0;
v->c = 1;
v->d = 2;
return 0;
}
int cpu0_field_d, sum_field_c; int my_pid;
/* Summarize percpu data */
SEC("?fentry/bpf_fentry_test3") int BPF_PROG(test_array_map_3)
{ struct val_t __percpu_kptr *p; int i, index = 0; struct val_t *v; struct elem *e;
if ((bpf_get_current_pid_tgid() >> 32) != my_pid) return 0;
e = bpf_map_lookup_elem(&array, &index); if (!e) return 0;
p = e->pc; if (!p) return 0;
bpf_for(i, 0, nr_cpus) {
v = bpf_per_cpu_ptr(p, i); if (v) { if (i == 0)
cpu0_field_d = v->d;
sum_field_c += v->c;
}
}
return 0;
}
/* Explicitly free allocated percpu data */
SEC("?fentry/bpf_fentry_test4") int BPF_PROG(test_array_map_4)
{ struct val_t __percpu_kptr *p; struct elem *e; int index = 0;
e = bpf_map_lookup_elem(&array, &index); if (!e) return 0;
/* delete */
p = bpf_kptr_xchg(&e->pc, NULL); if (p) {
bpf_percpu_obj_drop(p);
}
return 0;
}
SEC("?fentry.s/bpf_fentry_test1") int BPF_PROG(test_array_map_10)
{ struct val_t __percpu_kptr *p, *p1; int i, index = 0; struct val_t *v; struct elem *e;
if ((bpf_get_current_pid_tgid() >> 32) != my_pid) return 0;
e = bpf_map_lookup_elem(&array, &index); if (!e) return 0;
bpf_rcu_read_lock();
p = e->pc; if (!p) {
p = bpf_percpu_obj_new(struct val_t); if (!p) goto out;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.