From patchwork Fri Sep 12 11:48:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 37295 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 01AF9203EE for ; Fri, 12 Sep 2014 11:58:44 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id v6sf403490lbi.7 for ; Fri, 12 Sep 2014 04:58:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=XYgPpHBErM545SaoGon9Mp03jA+aRfRMYcr5UnObRL4=; b=gW637qE2nh3dPWbjFbULc5L9FTR9OLPZjuwekHccwzJr6TAw0zxxrH6woyTb2J3Vl6 EtQmc0zb9cLXlEFq0wSGu4VWG93Tu0qIxOPADolRnyDTtT4hCc0JHeG6zA0aSrfpMzW2 Gh/2hjGy7O7kdYNInamGxjxzRcFDvIygrqeilFtopm3iQSm9bxNbiHRQuk3exbqmmzgW t2+imKdOiGnvZpnTwykPMiEZbT9v81oF4WIh511d/SKfVizzYEuuNkFQAHs5ihueF7q+ 0kvnG6Pz+HV+gv01qVE0M5eRuBXLZABnXd5h8tL72hLid5w+V24Q3lUtwFC7y2Okcj4P CT6g== X-Gm-Message-State: ALoCoQkLOvqNImtwcVPtdkUQ/d8b9Msa/hSWWItzziKPsPZkkjFIKBbsiCRPh8O9VOkEdPgGggcr X-Received: by 10.180.160.169 with SMTP id xl9mr363787wib.7.1410523123514; Fri, 12 Sep 2014 04:58:43 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.99 with SMTP id kx3ls165526lac.7.gmail; Fri, 12 Sep 2014 04:58:43 -0700 (PDT) X-Received: by 10.152.8.9 with SMTP id n9mr8591424laa.2.1410523123138; Fri, 12 Sep 2014 04:58:43 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com [209.85.215.51]) by mx.google.com with ESMTPS id mm8si6094681lbb.114.2014.09.12.04.58.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 12 Sep 2014 04:58:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id gi9so785080lab.10 for ; Fri, 12 Sep 2014 04:58:43 -0700 (PDT) X-Received: by 10.152.204.231 with SMTP id lb7mr6717365lac.44.1410523123060; Fri, 12 Sep 2014 04:58:43 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.141.42 with SMTP id rl10csp716829lbb; Fri, 12 Sep 2014 04:58:42 -0700 (PDT) X-Received: by 10.70.49.14 with SMTP id q14mr12402417pdn.5.1410523121490; Fri, 12 Sep 2014 04:58:41 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xn3si7398652pab.146.2014.09.12.04.58.40 for ; Fri, 12 Sep 2014 04:58:41 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754394AbaILL6K (ORCPT + 27 others); Fri, 12 Sep 2014 07:58:10 -0400 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:32873 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752797AbaILL6H (ORCPT ); Fri, 12 Sep 2014 07:58:07 -0400 X-Greylist: delayed 553 seconds by postgrey-1.27 at vger.kernel.org; Fri, 12 Sep 2014 07:58:07 EDT Received: from foss-smtp-na-1.foss.arm.com (unknown [10.80.61.8]) by foss-mx-na.foss.arm.com (Postfix) with ESMTP id 05FE245D; Fri, 12 Sep 2014 06:48:51 -0500 (CDT) Received: from collaborate-mta1.arm.com (highbank-bc01-b06.austin.arm.com [10.112.81.134]) by foss-smtp-na-1.foss.arm.com (Postfix) with ESMTP id A23DB5FACF; Fri, 12 Sep 2014 06:48:48 -0500 (CDT) Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.42]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 336CB13F626; Fri, 12 Sep 2014 06:48:47 -0500 (CDT) From: Pawel Moll To: Richard Cochran , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Paul Mackerras , Arnaldo Carvalho de Melo , John Stultz Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Pawel Moll Subject: [RFC 2/2] perf: Marker software event and ioctl Date: Fri, 12 Sep 2014 12:48:33 +0100 Message-Id: <1410522513-1045-3-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1410522513-1045-1-git-send-email-pawel.moll@arm.com> References: <1410522513-1045-1-git-send-email-pawel.moll@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pawel.moll@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch adds a PERF_COUNT_SW_MARKER event type, which can be requested by user and a PERF_EVENT_IOC_MARKER ioctl command which will inject an event of said type into the perf buffer. The ioctl can take a zero-terminated string argument, similar to tracing_marker in ftrace, which will be kept in the "raw" field of the sample. The main use case for this is synchronisation of performance data generated in user space with the perf stream coming from the kernel. For example, the marker can be inserted by a JIT engine after it generated portion of the code, but before the code is executed for the first time, allowing the post-processor to pick the correct debugging information. Other example is a system profiling tool taking data from other sources than just perf, which generates a marker at the beginning at at the end of the session (also possibly periodically during the session) to synchronise kernel timestamps with clock values obtained in userspace (gtod or raw_monotonic). Signed-off-by: Pawel Moll --- include/uapi/linux/perf_event.h | 2 ++ kernel/events/core.c | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index e5a75c5..83b0f5b 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -110,6 +110,7 @@ enum perf_sw_ids { PERF_COUNT_SW_ALIGNMENT_FAULTS = 7, PERF_COUNT_SW_EMULATION_FAULTS = 8, PERF_COUNT_SW_DUMMY = 9, + PERF_COUNT_SW_MARKER = 10, PERF_COUNT_SW_MAX, /* non-ABI */ }; @@ -350,6 +351,7 @@ struct perf_event_attr { #define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5) #define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *) #define PERF_EVENT_IOC_ID _IOR('$', 7, __u64 *) +#define PERF_EVENT_IOC_MARKER _IOR('$', 8, char *) enum perf_event_ioc_flags { PERF_IOC_FLAG_GROUP = 1U << 0, diff --git a/kernel/events/core.c b/kernel/events/core.c index df093e3..dbce284 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3655,6 +3655,7 @@ static inline int perf_fget_light(int fd, struct fd *p) static int perf_event_set_output(struct perf_event *event, struct perf_event *output_event); static int perf_event_set_filter(struct perf_event *event, void __user *arg); +static int perf_sw_event_marker(struct perf_event *event, char __user *arg); static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -3709,6 +3710,9 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case PERF_EVENT_IOC_SET_FILTER: return perf_event_set_filter(event, (void __user *)arg); + case PERF_EVENT_IOC_MARKER: + return perf_sw_event_marker(event, (char __user *)arg); + default: return -ENOTTY; } @@ -3728,6 +3732,7 @@ static long perf_compat_ioctl(struct file *file, unsigned int cmd, switch (_IOC_NR(cmd)) { case _IOC_NR(PERF_EVENT_IOC_SET_FILTER): case _IOC_NR(PERF_EVENT_IOC_ID): + case _IOC_NR(PERF_EVENT_IOC_MARKER): /* Fix up pointer size (usually 4 -> 8 in 32-on-64-bit case */ if (_IOC_SIZE(cmd) == sizeof(compat_uptr_t)) { cmd &= ~IOCSIZE_MASK; @@ -5960,6 +5965,44 @@ static struct pmu perf_swevent = { .event_idx = perf_swevent_event_idx, }; +static int perf_sw_event_marker(struct perf_event *event, char __user *arg) +{ + struct perf_sample_data data; + struct pt_regs *regs = current_pt_regs(); + struct perf_raw_record raw = { 0, }; + + if (!static_key_false(&perf_swevent_enabled[PERF_COUNT_SW_MARKER])) + return 0; + + perf_sample_data_init(&data, 0, 0); + + if (arg) { + long len = strnlen_user(arg, PAGE_SIZE); + + if (len) { + raw.size = ALIGN(len + sizeof(u32), sizeof(u64)) + - sizeof(u32); + raw.data = kzalloc(raw.size, GFP_KERNEL); + if (!raw.data) + return -ENOMEM; + + if (copy_from_user(raw.data, arg, len)) { + kfree(raw.data); + return -EFAULT; + } + + data.raw = &raw; + } + } + + perf_event_output(event, &data, regs); + + if (raw.size) + kfree(raw.data); + + return 0; +} + #ifdef CONFIG_EVENT_TRACING static int perf_tp_filter_match(struct perf_event *event,