Merge branch 'for-4.2/sg' of git://git.kernel.dk/linux-block
[deliverable/linux.git] / samples / bpf / tracex2_kern.c
index 19ec1cfc45dbb7b4f856b4cba8594467736e3d2e..dc50f4f2943f937d5c389e5384d39a0153d3f273 100644 (file)
@@ -62,11 +62,18 @@ static unsigned int log2l(unsigned long v)
                return log2(v);
 }
 
+struct hist_key {
+       char comm[16];
+       u64 pid_tgid;
+       u64 uid_gid;
+       u32 index;
+};
+
 struct bpf_map_def SEC("maps") my_hist_map = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .key_size = sizeof(u32),
+       .type = BPF_MAP_TYPE_HASH,
+       .key_size = sizeof(struct hist_key),
        .value_size = sizeof(long),
-       .max_entries = 64,
+       .max_entries = 1024,
 };
 
 SEC("kprobe/sys_write")
@@ -75,11 +82,18 @@ int bpf_prog3(struct pt_regs *ctx)
        long write_size = ctx->dx; /* arg3 */
        long init_val = 1;
        long *value;
-       u32 index = log2l(write_size);
+       struct hist_key key = {};
+
+       key.index = log2l(write_size);
+       key.pid_tgid = bpf_get_current_pid_tgid();
+       key.uid_gid = bpf_get_current_uid_gid();
+       bpf_get_current_comm(&key.comm, sizeof(key.comm));
 
-       value = bpf_map_lookup_elem(&my_hist_map, &index);
+       value = bpf_map_lookup_elem(&my_hist_map, &key);
        if (value)
                __sync_fetch_and_add(value, 1);
+       else
+               bpf_map_update_elem(&my_hist_map, &key, &init_val, BPF_ANY);
        return 0;
 }
 char _license[] SEC("license") = "GPL";
This page took 0.026549 seconds and 5 git commands to generate.