Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755637AbbFOJDo (ORCPT ); Mon, 15 Jun 2015 05:03:44 -0400 Received: from mail.bmw-carit.de ([62.245.222.98]:33526 "EHLO mail.bmw-carit.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754117AbbFOJDc (ORCPT ); Mon, 15 Jun 2015 05:03:32 -0400 X-CTCH-RefID: str=0001.0A0C0205.557E94E0.0140,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 Message-ID: <557E94DA.5000901@bmw-carit.de> Date: Mon, 15 Jun 2015 11:03:22 +0200 From: Daniel Wagner User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Alexei Starovoitov , Daniel Wagner , Steven Rostedt , Tom Zanussi CC: "linux-kernel@vger.kernel.org" , Wang Nan Subject: Re: latency histogram with BPF References: <557937D8.90606@bmw-carit.de> <557A06D7.7030304@plumgrid.com> <557A783C.5080803@bmw-carit.de> <557AEDAD.2060507@bmw-carit.de> <557B141B.3000704@plumgrid.com> In-Reply-To: <557B141B.3000704@plumgrid.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1797 Lines: 48 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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/