Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2095819imm; Wed, 16 May 2018 07:50:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrQN1lIEjWDON2O1i4adhpyocUljATu38rNSl8ZZCkfKKs9Rj/DL7/bHnPjbAAZCa5I3oPp X-Received: by 2002:a63:7c0b:: with SMTP id x11-v6mr980715pgc.384.1526482232627; Wed, 16 May 2018 07:50:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526482232; cv=none; d=google.com; s=arc-20160816; b=fJtvvZ3mfNlngdaRmwpwHFhy5RIji4wibMZPubuDGeGDER1b9BYB24tWA4d94DNnvc dvYwuyGQKsseXYGZcVGiFDQyAExfB82yoP0VafC27tBkJi+6CIuI1YS5pywp7cIONZhT hdNt09jdUbyK7IDwaXOJSspePRG8yWSUyRWsahAkPa2cBk0228kW5UTOsKSnZStTpvm7 LV4XLprLIab8kYXqxIh21KRQAkQnj98XcgoYFykspsroK8mHqzlNJ7HfLNx2C6zqXh4e BjOVdBj3+Ad8b0rQrc6f+Etk1ULjmfGlLtxe3yRlQr3AVQT/zs8+H8sQeKI51MM0X1hy KEJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=eOGzVirNlqe54on6PFdYgoZcHXzAKxV9kfwCX8h362c=; b=DhexrElogswKFdcKMu7qFdU7UCAuWYVOe2FrQfHBiZsE+Id8qChm+DxxBOj4B+gHaf DEPTFC56UQjHs2eZYzcCWm6tOQkp2EojI0D5anaPg58kx7zAx42mDk4+LQ6xppmpmrkJ ACas1VMMFPWoBoANd7l/La558ft6lLGEX0dgjfbutJJsY0gLIyAnwOIYeQNQhhZwgppa xh8L/PT2WMbdak89+wmo7f3yAewFw07yoCXS2swuoJ55h28dAEOICL+OXd7rjmAU5N2T tdkTrzftwnpzY8Mskb1oTE6iSYyzgHiZ1PeDWU1ieZKdbg/Duh6BA0nWy9QJmGP9HGdJ KfCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y6PaqD0v; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u3-v6si2804233plj.338.2018.05.16.07.50.17; Wed, 16 May 2018 07:50:32 -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=@kernel.org header.s=default header.b=y6PaqD0v; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752133AbeEPOts (ORCPT + 99 others); Wed, 16 May 2018 10:49:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:46154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751880AbeEPOtr (ORCPT ); Wed, 16 May 2018 10:49:47 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0CBC42075A; Wed, 16 May 2018 14:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526482186; bh=YQpccmH9CI7YQcwjQBJmxgryMMnrPr2t/x9Xf0K79Jo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y6PaqD0vorflmoAkI7+eN76AQ6OzLYcSpfaJt9N2WBC20WzRKiMF4s6lxr9VtfwJG VspoOi2cVtgEhtEwSY96w4UVVh0v0JeXQqNakAQfAjOqXtA20h3gw5ONbxoqqnkw8c gO01uwzMkZL5xj+J6cIwvuuMBQLwtQ3XClxNTN6I= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Adrian Hunter , David Ahern , Jiri Olsa , Namhyung Kim , Wang Nan Subject: [PATCH 08/11] perf bpf: Add probe() helper to reduce kprobes boilerplate Date: Wed, 16 May 2018 11:49:05 -0300 Message-Id: <20180516144908.22212-9-acme@kernel.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180516144908.22212-1-acme@kernel.org> References: <20180516144908.22212-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo So that kprobe definitions become: int probe(function, variables)(void *ctx, int err, var1, var2, ...) The existing 5sec.c, got converted and goes from: SEC("func=hrtimer_nanosleep rqtp->tv_sec") int func(void *ctx, int err, long sec) { } To: int probe(hrtimer_nanosleep, rqtp->tv_sec)(void *ctx, int err, long sec) { } If we decide to add tv_nsec as well, then it becomes: $ cat tools/perf/examples/bpf/5sec.c #include int probe(hrtimer_nanosleep, rqtp->tv_sec rqtp->tv_nsec)(void *ctx, int err, long sec, long nsec) { return sec == 5; } license(GPL); $ And if we run it, system wide as before and run some 'sleep' with values for the tv_nsec field, we get: # perf trace --no-syscalls -e tools/perf/examples/bpf/5sec.c 0.000 perf_bpf_probe:hrtimer_nanosleep:(ffffffff9811b5f0) tv_sec=5 tv_nsec=100000000 9641.650 perf_bpf_probe:hrtimer_nanosleep:(ffffffff9811b5f0) tv_sec=5 tv_nsec=123450001 ^C# Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: https://lkml.kernel.org/n/tip-1v9r8f6ds5av0w9pcwpeknyl@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/examples/bpf/5sec.c | 10 ++++++++-- tools/perf/include/bpf/bpf.h | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/perf/examples/bpf/5sec.c b/tools/perf/examples/bpf/5sec.c index 6fc3697ac749..b9c203219691 100644 --- a/tools/perf/examples/bpf/5sec.c +++ b/tools/perf/examples/bpf/5sec.c @@ -15,6 +15,13 @@ . While this is running, run something like "sleep 5s". + . If we decide to add tv_nsec as well, then it becomes: + + int probe(hrtimer_nanosleep, rqtp->tv_sec rqtp->tv_nsec)(void *ctx, int err, long sec, long nsec) + + I.e. add where it comes from (rqtp->tv_nsec) and where it will be + accessible in the function body (nsec) + # perf trace --no-syscalls -e tools/perf/examples/bpf/5sec.c/call-graph=dwarf/ 0.000 perf_bpf_probe:func:(ffffffff9811b5f0) tv_sec=5 hrtimer_nanosleep ([kernel.kallsyms]) @@ -34,8 +41,7 @@ #include -SEC("func=hrtimer_nanosleep rqtp->tv_sec") -int func(void *ctx, int err, long sec) +int probe(hrtimer_nanosleep, rqtp->tv_sec)(void *ctx, int err, long sec) { return sec == 5; } diff --git a/tools/perf/include/bpf/bpf.h b/tools/perf/include/bpf/bpf.h index cdfd18b9c318..dd764ad5efdf 100644 --- a/tools/perf/include/bpf/bpf.h +++ b/tools/perf/include/bpf/bpf.h @@ -3,6 +3,9 @@ #define _PERF_BPF_H #define SEC(NAME) __attribute__((section(NAME), used)) +#define probe(function, vars) \ + SEC(#function "=" #function " " #vars) function + #define license(name) \ char _license[] SEC("license") = #name; \ int _version SEC("version") = LINUX_VERSION_CODE; -- 2.14.3