Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2098295imm; Wed, 16 May 2018 07:53:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqWNWp2Jgox8GeNA9k7bJN1Suei8dtJd4Bsu3wm6F16fkSJ/jb4PGmziFHrKnqIgb4E9a7G X-Received: by 2002:a17:902:284b:: with SMTP id e69-v6mr1241932plb.240.1526482382997; Wed, 16 May 2018 07:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526482382; cv=none; d=google.com; s=arc-20160816; b=p5ODmQWIyA5XX8ryxAbXYqCmueIQr4bTMOyRnmudO1Dl1Bv8HqwamSC0YEhWspVvEe fW/qomGAqWbNVvdm86OQ1JI0/t8g657Rj9p1gA865kmVkDw9VDq2FKDd+nDhKENuz9BC nRt4qslST/P/HloAuvHhyFe6yov5LwMTGeW9A/7NCiUQ1Ow7Cc7KP41bAF4NKPbvU1Kf 8MIaEX8ZxhmaTAPoRhXydVCybH1pjTpA7fJzrmLowCK1Du6vygzHZNjgn0aXuQmYdJoE nEaoOcTOywJy3hIw6nLt3gqacw7PGWk1KfkE/UdqteHzJwwugvG+hNUvMBaAYr/cITal 5GmA== 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=FaFbnROvHpklacmPoIX13Q96tj69gRMid7a/WpixWg8=; b=egNL2q+xA7R8XaxV+fnoqhsxiAXuF6JkBJ5zRiZA9lISZt+WHmRT3zIXwU2BJ35Cuy 8OQOU2sClBCDX19QojmIcxky4tjTW2fMc+zxNrNuzZHJWDKZcqen3T1qxL5isHbEpSz5 fIw7JVisLbqhPuRm3bKGENpMUGl6t1pZFPlSp5pcZ6PNKZP1Wz/jvPtrTj7+zkMoZ4Dc ORKYYNq+Te71wqczlJ5SEw4sgnIxP1NgiAIYaY3X7EW7681cStHzgSO6diYSM4FNHHGC wx++bWQIBml3Bw8VkFFpc4klxQ39Wj2Gnu9LCJDRxMxZFsWQzxPvSKhxL68wgMXq+sYe 3QGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Tbn9esX2; 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 w12-v6si2239890pgp.252.2018.05.16.07.52.48; Wed, 16 May 2018 07:53:02 -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=Tbn9esX2; 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 S1751986AbeEPOtq (ORCPT + 99 others); Wed, 16 May 2018 10:49:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:46096 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751880AbeEPOtl (ORCPT ); Wed, 16 May 2018 10:49:41 -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 3239D2083A; Wed, 16 May 2018 14:49:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526482180; bh=1wP2KOs75vTO4D2pAkbEC+i8KuiiyUaJyAiiOgfodXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tbn9esX2I2EwwU+d2n2jrXuOFeTdbmqUAipCBmiULgvUHVET4wyLj0oy5nt37d4mm 2BdzrqjFmxgP22MfsNDTZtkPG0nPpuGXC1vwR+fO8u7ixSgPYy9PRFDE9g07HUZUoH DiAwu0K9RSbAvyDUeBcg2BSo56gLubGwSuz/hn7Q= 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 06/11] perf bpf: Add kprobe example to catch 5s naps Date: Wed, 16 May 2018 11:49:03 -0300 Message-Id: <20180516144908.22212-7-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 Description: . Disable strace like syscall tracing (--no-syscalls), or try tracing just some (-e *sleep). . Attach a filter function to a kernel function, returning when it should be considered, i.e. appear on the output: $ cat tools/perf/examples/bpf/5sec.c #include SEC("func=hrtimer_nanosleep rqtp->tv_sec") int func(void *ctx, int err, long sec) { return sec == 5; } char _license[] SEC("license") = "GPL"; int _version SEC("version") = LINUX_VERSION_CODE; $ . Run it system wide, so that any sleep of >= 5 seconds and < than 6 seconds gets caught. . Ask for callgraphs using DWARF info, so that userspace can be unwound . While this is running, run something like "sleep 5s". # 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]) __x64_sys_nanosleep ([kernel.kallsyms]) do_syscall_64 ([kernel.kallsyms]) entry_SYSCALL_64 ([kernel.kallsyms]) __GI___nanosleep (/usr/lib64/libc-2.26.so) rpl_nanosleep (/usr/bin/sleep) xnanosleep (/usr/bin/sleep) main (/usr/bin/sleep) __libc_start_main (/usr/lib64/libc-2.26.so) _start (/usr/bin/sleep) ^C# Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: https://lkml.kernel.org/n/tip-2nmxth2l2h09f9gy85lyexcq@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/examples/bpf/5sec.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tools/perf/examples/bpf/5sec.c diff --git a/tools/perf/examples/bpf/5sec.c b/tools/perf/examples/bpf/5sec.c new file mode 100644 index 000000000000..3d1ed34aec8b --- /dev/null +++ b/tools/perf/examples/bpf/5sec.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + Description: + + . Disable strace like syscall tracing (--no-syscalls), or try tracing + just some (-e *sleep). + + . Attach a filter function to a kernel function, returning when it should + be considered, i.e. appear on the output. + + . Run it system wide, so that any sleep of >= 5 seconds and < than 6 + seconds gets caught. + + . Ask for callgraphs using DWARF info, so that userspace can be unwound + + . While this is running, run something like "sleep 5s". + + # 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]) + __x64_sys_nanosleep ([kernel.kallsyms]) + do_syscall_64 ([kernel.kallsyms]) + entry_SYSCALL_64 ([kernel.kallsyms]) + __GI___nanosleep (/usr/lib64/libc-2.26.so) + rpl_nanosleep (/usr/bin/sleep) + xnanosleep (/usr/bin/sleep) + main (/usr/bin/sleep) + __libc_start_main (/usr/lib64/libc-2.26.so) + _start (/usr/bin/sleep) + ^C# + + Copyright (C) 2018 Red Hat, Inc., Arnaldo Carvalho de Melo +*/ + +#include + +SEC("func=hrtimer_nanosleep rqtp->tv_sec") +int func(void *ctx, int err, long sec) +{ + return sec == 5; +} + +char _license[] SEC("license") = "GPL"; +int _version SEC("version") = LINUX_VERSION_CODE; -- 2.14.3