mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Jiri Olsa <jolsa@redhat.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@elte.hu>, Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [PATCH 06/21] perf: Add event toggle ioctl interface
Date: Wed, 25 Sep 2013 14:50:32 +0200	[thread overview]
Message-ID: <1380113447-17144-7-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1380113447-17144-1-git-send-email-jolsa@redhat.com>

Adding new ioctl PERF_EVENT_IOC_SET_TOGGLE to interface
the toggle settings for event.

This ioctl has 2 goals:
  - allowing the toggle event being part of the group
  - allowing to define toggle setting after event
    is created

The ioctl interface is:

  u64 args[2] = { toggled_fd, flag };
  err = ioctl(fd, PERF_EVENT_IOC_SET_TOGGLE, args);

Where:
  toggled_fd - is file description of the event we want to toggle
  flag       - is one of PERF_FLAG_TOGGLE_ON|PERF_FLAG_TOGGLE_OFF
  err        -  0 when successful
               -1 otherwise with errno:
                  EBUSY  - event has already toggled event defined
                  EFAULT - could not copy user data
                  EINVAL - wrong data

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 include/uapi/linux/perf_event.h |  1 +
 kernel/events/core.c            | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index ecb0474..b941c21 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -325,6 +325,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_SET_TOGGLE	_IOW('$', 8, u64 *)
 
 enum perf_event_ioc_flags {
 	PERF_IOC_FLAG_GROUP		= 1U << 0,
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 40c792d..b41a0d8 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3575,6 +3575,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_event_set_toggle_fd(struct perf_event *event, u64 __user *arg);
 
 static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
@@ -3629,6 +3630,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_SET_TOGGLE:
+		return perf_event_set_toggle_fd(event, (u64 __user *)arg);
+
 	default:
 		return -ENOTTY;
 	}
@@ -7017,6 +7021,42 @@ perf_event_set_toggle(struct perf_event *event,
 	return 0;
 }
 
+static int perf_event_set_toggle_fd(struct perf_event *event, u64 __user *arg)
+{
+	struct perf_event *toggled_event;
+	struct fd toggled_fd = { NULL, 0 };
+	u64 fd, flag;
+	int err;
+
+	if (event->toggled_event)
+		return -EBUSY;
+
+	if (copy_from_user(&fd, arg, sizeof(fd)))
+		return -EFAULT;
+
+	if (copy_from_user(&flag, arg + 1, sizeof(flag)))
+		return -EFAULT;
+
+	err = perf_fget_light((int) fd, &toggled_fd);
+	if (err)
+		return -EINVAL;
+
+	toggled_event = toggled_fd.file->private_data;
+
+	if (!atomic_long_inc_not_zero(&toggled_event->refcount)) {
+	        fdput(toggled_fd);
+		return -EINVAL;
+	}
+
+	err = perf_event_set_toggle(event, toggled_event, event->ctx, flag);
+	if (err)
+		put_event(toggled_event);
+
+	fdput(toggled_fd);
+	return err;
+}
+
+
 /**
  * sys_perf_event_open - open a performance event, associate it to a task/cpu
  *
-- 
1.7.11.7


  parent reply	other threads:[~2013-09-25 12:51 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-25 12:50 [RFC 00/21] perf tools: Add toggling events support Jiri Olsa
2013-09-25 12:50 ` [PATCH 01/21] perf tools: Introduce perf_evlist__wait_workload function Jiri Olsa
2013-09-25 12:50 ` [PATCH 02/21] perf tools: Separate sys_perf_event_open call into evsel_open Jiri Olsa
2013-09-25 12:50 ` [PATCH 03/21] perf x86: Update event count properly for read syscall Jiri Olsa
2013-09-25 12:50 ` [PATCH 04/21] perf: Move event state initialization before/behind the pmu add/del calls Jiri Olsa
2013-09-25 12:50 ` [PATCH 05/21] perf: Add event toggle sys_perf_event_open interface Jiri Olsa
2013-09-25 22:36   ` Sukadev Bhattiprolu
2013-09-26 12:27     ` Jiri Olsa
2013-09-25 12:50 ` Jiri Olsa [this message]
2013-09-25 19:46   ` [PATCH 06/21] perf: Add event toggle ioctl interface Vince Weaver
2013-09-26 12:30     ` Jiri Olsa
2013-09-26 13:03       ` Vince Weaver
2013-09-25 12:50 ` [PATCH 07/21] perf: Toggle whole group in toggle event overflow Jiri Olsa
2013-09-25 12:50 ` [PATCH 08/21] perf: Add new 'paused' attribute Jiri Olsa
2013-09-25 22:41   ` Sukadev Bhattiprolu
2013-09-26 12:24     ` Jiri Olsa
2013-09-25 12:50 ` [PATCH 09/21] perf: Account toggle masters for toggled event Jiri Olsa
2013-09-25 12:50 ` [PATCH 10/21] perf: Be more specific on pmu related event init naming Jiri Olsa
2013-09-25 12:50 ` [PATCH 11/21] perf: Split allocation and initialization code Jiri Olsa
2013-09-25 12:50 ` [PATCH 12/21] perf: Support event inheritance for toggle feature Jiri Olsa
2013-09-25 12:50 ` [PATCH 13/21] perf tests: Adding event simple toggling test Jiri Olsa
2013-09-25 12:50 ` [PATCH 14/21] perf tests: Adding event group " Jiri Olsa
2013-09-25 12:50 ` [PATCH 15/21] perf tests: Adding event inherit " Jiri Olsa
2013-09-25 12:50 ` [PATCH 16/21] perf tools: Allow numeric event to change name via name term Jiri Olsa
2013-09-25 12:50 ` [PATCH 17/21] perf tools: Add event_config_optional parsing rule Jiri Olsa
2013-09-25 12:50 ` [PATCH 18/21] perf tools: Rename term related parsing function/variable properly Jiri Olsa
2013-09-25 12:50 ` [PATCH 19/21] perf tools: Carry term string value for symbols events Jiri Olsa
2013-09-25 12:50 ` [PATCH 20/21] perf tools: Add support to parse event on/off toggle terms Jiri Olsa
2013-09-25 12:50 ` [PATCH 21/21] perf tools: Add record/stat support for toggling events Jiri Olsa
2013-09-25 19:12 ` [RFC 00/21] perf tools: Add toggling events support Andi Kleen
2013-09-26  7:03   ` Ingo Molnar
2013-09-26 15:45     ` Andi Kleen
2013-09-26 12:11   ` Jiri Olsa
2013-09-26 11:31 ` Stephane Eranian
2013-09-26 12:20   ` Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1380113447-17144-7-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®