public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
To: Alexei Starovoitov <ast@plumgrid.com>,
	Daniel Wagner <daniel.wagner@bmw-carit.de>,
	Steven Rostedt <rostedt@goodmis.org>,
	Tom Zanussi <tom.zanussi@linux.intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Wang Nan <wangnan0@huawei.com>
Subject: Re: latency histogram with BPF
Date: Mon, 15 Jun 2015 11:03:22 +0200	[thread overview]
Message-ID: <557E94DA.5000901@bmw-carit.de> (raw)
In-Reply-To: <557B141B.3000704@plumgrid.com>

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;
 }

  reply	other threads:[~2015-06-15  9:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-11  7:25 latency histogram with BPF Daniel Wagner
2015-06-11 22:08 ` Alexei Starovoitov
2015-06-12  6:12   ` Daniel Wagner
2015-06-12 14:33     ` Daniel Wagner
2015-06-12 17:17       ` Alexei Starovoitov
2015-06-15  9:03         ` Daniel Wagner [this message]
2015-06-12  6:58 ` Wangnan (F)
2015-06-12 17:21   ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=557E94DA.5000901@bmw-carit.de \
    --to=daniel.wagner@bmw-carit.de \
    --cc=ast@plumgrid.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tom.zanussi@linux.intel.com \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox