Received: by 10.213.65.68 with SMTP id h4csp180749imn; Mon, 26 Mar 2018 18:37:01 -0700 (PDT) X-Google-Smtp-Source: AG47ELs2Dbk0NGbJ8bt5FTF4oUkZYdFuFqKhiZznxS2cDg9QcfDG95igDbLFX5sHbJi+HTZceTnD X-Received: by 2002:a17:902:bf43:: with SMTP id u3-v6mr41968511pls.227.1522114621550; Mon, 26 Mar 2018 18:37:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522114621; cv=none; d=google.com; s=arc-20160816; b=rraf5+ZohX09/gTfK9ZaGY6hGGOf98e2pcmC2uZN3Kb/0Zy+ON8az4y+mv5PTSXF4T dcDlokLeNii+Z9YTmZHQvUbxnRSHY3l+EZgDtV8qlY6r7Pqv/82aYZnciQR2Zc6CK74t TEkIsrMj97sbUd+zNtNv/hXr73MXJvbZfeZuo/+OOOKEfamo/f10vvcugDxPwGtxmF/D oI6f25fKhMCgRQFGfwlLCyxpwkiSthqrHEzg8+3CdJaoC4HyvGu3rAQOAkTtKk+1NdXY tgDM3AffNk0zIl0Bz3tOBowqb77PSk3Q/DTuFxmwt15xYCex4etMYzqUg7AGfq6eHLO5 SsWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=QXj4O6qustCq+w4DyQTkWRQlHcr+ycsvgV94tWarQ38=; b=N8rrbBJTrkgC6dFqn+YJvxTjqaQJ9oc2qnnAs2wfyWuM6Hj/mdDj8R1R0rsu5HjL+5 8unuUfrW+nPb722BEhgthp7K+G6eQfqCgbYhfn9kZ4REOOMc4sqkfnNwA6PJ6l2SUZJr Lc7i92BkqKRrP2nTutRu9y98CUR++yMYt2ZEy43/Ico0IyAUZsOGTKY/vz7nXnDGUKhx dZNYZAEpb3w23mxmS2LCSNc0i4p04qW5ic2GhyUKXj9KXr7flKxshV2uwRLovkEb15eh 2YsoO+O5LGjN9a4WuZLR8AeqdydyBm78wxpyByJxP5MC5O0vJPky7VtFmlnub81nJc7D CrQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=p+8o/TZN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si34173pfg.278.2018.03.26.18.36.47; Mon, 26 Mar 2018 18:37:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=p+8o/TZN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752138AbeC0Bfz (ORCPT + 99 others); Mon, 26 Mar 2018 21:35:55 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:55190 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751896AbeC0Bfy (ORCPT ); Mon, 26 Mar 2018 21:35:54 -0400 Received: by mail-wm0-f65.google.com with SMTP id h76so18683051wme.4 for ; Mon, 26 Mar 2018 18:35:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=QXj4O6qustCq+w4DyQTkWRQlHcr+ycsvgV94tWarQ38=; b=p+8o/TZNudLaUGkE5KeYKakeDcZDXmP9djVK2iOreO03aovNJpNaifVGjq2tGIc/qU mW3m2ACBmkXNj6axq+GI0ByNxPM+Y6ibHU9SPe9ivR26y5uXgRfqcox41KTpMJZqi4GJ UuKBrnb83WWoC9aAKMVA1JnXJ/GFcup1BzhOmFKX15bqJeX8vWZyZ422XOG6pch0fzLB 387DGrY5bMB347+jOYioHVZnk27OPMBk82/23DKs3ZTKS8cIE5sKrxLHZMri2HepCPzZ aKfQq/ntUER3J0o3IiEwmJDwknr6d8N5XJSvPATVpWEWXvquwsoV9MlKAvXx6KKMUqNY SdIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=QXj4O6qustCq+w4DyQTkWRQlHcr+ycsvgV94tWarQ38=; b=WAjeF3qp8k5bKBozWRCPYEQcNrkKPPByu/4s7zdKS+Buou3j+8O+RywH2hUWpb43ck 2gMj6GVaIum8/T/snwlZVUH0KxefIu5yl0JZpKB2HkUZ6IMQ+TRgiVZ9Iz2OG04a/7mm aM1cEFHOOq2fDP2QIYupF768qmvBbYKvnExo9l39EDgrSelIqdljoKFqLjgcy1z0V/Q4 RE+/Dfumtc2wduocStyNCU+8BjsExSrDZPKq0hXaXMlQi+MV0Z4wd2KdVNAuzDw87jXB d9PJ5ELLBVxPussZQ1d7Sam/1d7DWcAE8tOyId0OXpl13IgJSJe7XQVwQmuBnePByHMe zAAw== X-Gm-Message-State: AElRT7GB5YTVDmnYDbqXCTQhxg3Ntkl8pjZP4UE8wI6VJaKm54HimXPN e/Jz9s7/iGboNSC22Zbsv9MrPE3utAiJsurHsHyon+k+ X-Received: by 10.80.135.164 with SMTP id a33mr36685370eda.34.1522114553258; Mon, 26 Mar 2018 18:35:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.80.139.137 with HTTP; Mon, 26 Mar 2018 18:35:52 -0700 (PDT) In-Reply-To: <20180326191031.14939-1-mathieu.desnoyers@efficios.com> References: <20180326191031.14939-1-mathieu.desnoyers@efficios.com> From: "Joel Fernandes (Google)" Date: Mon, 26 Mar 2018 18:35:52 -0700 Message-ID: Subject: Re: [RFC PATCH] tracepoint: Provide tracepoint_kernel_find_by_name To: Mathieu Desnoyers Cc: Steven Rostedt , Linux Kernel Mailing List , Alexei Starovoitov , Peter Zijlstra , Ingo Molnar Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mathieu, On Mon, Mar 26, 2018 at 12:10 PM, Mathieu Desnoyers wrote: > Provide an API allowing eBPF to lookup core kernel tracepoints by name. > > Given that a lookup by name explicitly requires tracepoint definitions > to be unique for a given name (no duplicate keys), include a > WARN_ON_ONCE() check that only a single match is encountered at runtime. > This should always be the case, given that a DEFINE_TRACE emits a > __tracepoint_##name symbol, which would cause a link-time error if more > than one instance is found. Nevertheless, check this at runtime with > WARN_ON_ONCE() to stay on the safe side. > > Signed-off-by: Mathieu Desnoyers > CC: Steven Rostedt > CC: Alexei Starovoitov > CC: Peter Zijlstra > CC: Ingo Molnar > --- > include/linux/tracepoint.h | 1 + > kernel/tracepoint.c | 35 +++++++++++++++++++++++++++++++++++ > 2 files changed, 36 insertions(+) > > diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h > index c94f466d57ef..1b4ae64b7c6a 100644 > --- a/include/linux/tracepoint.h > +++ b/include/linux/tracepoint.h > @@ -43,6 +43,7 @@ tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data); > extern void > for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv), > void *priv); > +extern struct tracepoint *tracepoint_kernel_find_by_name(const char *name); > > #ifdef CONFIG_MODULES > struct tp_module { > diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c > index 671b13457387..0a59f988055a 100644 > --- a/kernel/tracepoint.c > +++ b/kernel/tracepoint.c > @@ -60,6 +60,11 @@ struct tp_probes { > struct tracepoint_func probes[0]; > }; > > +struct tp_find_args { > + const char *name; > + struct tracepoint *tp; > +}; > + > static inline void *allocate_probes(int count) > { > struct tp_probes *p = kmalloc(count * sizeof(struct tracepoint_func) > @@ -528,6 +533,36 @@ void for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv), > } > EXPORT_SYMBOL_GPL(for_each_kernel_tracepoint); > > +static void find_tp(struct tracepoint *tp, void *priv) > +{ > + struct tp_find_args *args = priv; > + > + if (!strcmp(tp->name, args->name)) { > + WARN_ON_ONCE(args->tp); > + args->tp = tp; I think this runtime check is not needed if it really can't happen (linker verifies that already as you mentioned) although I'm not opposed if you still want to keep it, because there's no way to break out of the outer loop anyway so I guess your call.. I would just do: if (args->tp) return; if find_tp already found the tracepoint. Tried to also create a duplicate tracepoint and I get: CC init/version.o AR init/built-in.o AR built-in.o LD vmlinux.o block/blk-core.o:(__tracepoints+0x440): multiple definition of `__tracepoint_sched_switch' kernel/sched/core.o:(__tracepoints+0x440): first defined here Makefile:1032: recipe for target 'vmlinux' failed make: *** [vmlinux] Error 1 For this senseless diff: diff --git a/include/trace/events/block.h b/include/trace/events/block.h index 81b43f5bdf23..2b855c05197d 100644 --- a/include/trace/events/block.h +++ b/include/trace/events/block.h @@ -49,6 +49,13 @@ DEFINE_EVENT(block_buffer, block_touch_buffer, TP_ARGS(bh) ); +DEFINE_EVENT(block_buffer, sched_switch, + + TP_PROTO(struct buffer_head *bh), + + TP_ARGS(bh) +); + /** * block_dirty_buffer - mark a buffer dirty * @bh: buffer_head being dirtied thanks, - Joel