Re: latency histogram with BPF

From: Daniel Wagner
Date: Mon Jun 15 2015 - 05:03:47 EST


On 06/12/2015 07:17 PM, Alexei Starovoitov wrote:
> On 6/12/15 7:33 AM, Daniel Wagner wrote:
>> On 06/12/2015 08:12 AM, Daniel Wagner wrote:
>> Attaching kprobes to trace_preempt_[on|off] works fine. Empty BPF
>> programs connected to the probes is no problem as well. So I changed the
>> BPF program to use only arrays instead of hash tables. No crash anymore.
>
> yes. I've tried that too. arrays work fine indeed.
>
>> I suspect the hash table code will call trace_preempt_[off|on]
>> eventually and that is not going to fly.
>
> The recursive calls into bpf programs are detected and prevented.
> That's ok. I've tested attaching kprobes to kmalloc/kfree and
> from the program do hash_map->update_elem->kmalloc which triggers
> recursive call into the same program. All works fine.
> There is something else here.

If the first map is an array all is fine too. So it seems it need two
hash tables to trigger it.

@@ -11,7 +11,7 @@
#include "bpf_helpers.h"

struct bpf_map_def SEC("maps") my_map = {
- .type = BPF_MAP_TYPE_HASH,
+ .type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(unsigned int),
.value_size = sizeof(u64),
.max_entries = 1024,
@@ -45,9 +45,10 @@ SEC("kprobe/trace_preempt_off")
int bpf_prog1(struct pt_regs *ctx)
{
int cpu = bpf_get_smp_processor_id();
- u64 ts = bpf_ktime_get_ns();
+ u64 *ts = bpf_map_lookup_elem(&my_map, &cpu);

- bpf_map_update_elem(&my_map, &cpu, &ts, BPF_ANY);
+ if (ts)
+ *ts = bpf_ktime_get_ns();

return 0;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/