Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1685689 > unrolled thread
| Started by | Jiri Olsa <jolsa@redhat.com> |
|---|---|
| First post | 2017-07-12 12:50 +0200 |
| Last post | 2017-07-13 17:40 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH 0/2] Notifications for perf sideband events Jiri Olsa <jolsa@redhat.com> - 2017-07-12 12:50 +0200
Re: [PATCH 0/2] Notifications for perf sideband events "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-07-13 16:30 +0200
Re: [PATCH 0/2] Notifications for perf sideband events Vince Weaver <vincent.weaver@maine.edu> - 2017-07-13 17:40 +0200
| From | Jiri Olsa <jolsa@redhat.com> |
|---|---|
| Date | 2017-07-12 12:50 +0200 |
| Subject | Re: [PATCH 0/2] Notifications for perf sideband events |
| Message-ID | <u2nns-76E-5@gated-at.bofh.it> |
On Mon, Jun 19, 2017 at 08:01:06PM +0530, Naveen N. Rao wrote:
> Currently, there is no way to ask for signals to be delivered when a
> certain number of sideband events have been logged into the ring buffer.
> This is problematic if we are only interested in, say, context switch
> events. Furthermore, signals are more useful (rather than polling) for
> self-profiling. This series provides for a way to achieve this.
>
> We ride on top of the existing support for ring buffer wakeup to
> generate signals as desired. Counting sideband events still requires
> some changes in the output path, but in normal cases, it ends up being
> just a comparison.
>
> The test program below demonstrates how a process can profile itself for
> context switch events and how it can control notification through
> signals. The key changes include the below perf_event_attr settings as
> well as use of IOC_ENABLE:
> pe.signal_on_wakeup = 1;
> pe.count_sb_events = 1;
> pe.wakeup_events = 2;
Vince,
could you please check on this? thanks
Naveen,
have you run Vince's test suite on this?
http://github.com/deater/perf_event_tests.git
jirka
>
> To keep things simple, PERF_EVENT_IOC_REFRESH cannot be used if any of
> the new attributes are set.
>
> RFC v2:
> https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1420363.html
> Changes:
> - Send HUP on perf_event_exit_event() (suggested by Jiri)
> - Disable use of IOC_REFRESH if signal_on_wakeup/count_sb_events is
> set.
>
>
> - Naveen
>
> ---
> Here is a sample program demonstrating the same:
>
> #define _GNU_SOURCE
>
> #include <stdlib.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <fcntl.h>
> #include <string.h>
> #include <signal.h>
> #include <sys/ioctl.h>
> #include <sys/mman.h>
> #include <linux/perf_event.h>
> #include <asm/unistd.h>
>
> static long
> perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
> int cpu, int group_fd, unsigned long flags)
> {
> return syscall(__NR_perf_event_open, hw_event, pid, cpu,
> group_fd, flags);
> }
>
> static void sigio_handler(int n, siginfo_t *info, void *uc)
> {
> fprintf (stderr, "Caught %s\n", info->si_code == POLL_HUP ? "POLL_HUP" :
> (info->si_code == POLL_IN ? "POLL_IN" : "other signal"));
> }
>
> int main(int argc, char **argv)
> {
> struct perf_event_attr pe;
> struct sigaction act;
> int fd;
> void *buf;
>
> memset(&act, 0, sizeof(act));
> act.sa_sigaction = sigio_handler;
> act.sa_flags = SA_SIGINFO;
> sigaction(SIGIO, &act, 0);
>
> memset(&pe, 0, sizeof(struct perf_event_attr));
> pe.size = sizeof(struct perf_event_attr);
> pe.type = PERF_TYPE_SOFTWARE;
> pe.config = PERF_COUNT_SW_DUMMY;
> pe.disabled = 1;
> pe.sample_period = 1;
> pe.context_switch = 1;
> pe.signal_on_wakeup = 1;
> pe.count_sb_events = 1;
> pe.wakeup_events = 2;
>
> fd = perf_event_open(&pe, 0, -1, -1, 0);
> if (fd == -1) {
> fprintf(stderr, "Error opening leader %lx\n", (unsigned long)pe.config);
> exit(EXIT_FAILURE);
> }
>
> buf = mmap(NULL, sysconf(_SC_PAGESIZE) * 2, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
> if (buf == MAP_FAILED) {
> fprintf(stderr, "Can't mmap buffer\n");
> return -1;
> }
>
> if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_ASYNC) == -1)
> return -2;
>
> if (fcntl(fd, F_SETSIG, SIGIO) == -1)
> return -3;
>
> if (fcntl(fd, F_SETOWN, getpid()) == -1)
> return -4;
>
> if (ioctl(fd, PERF_EVENT_IOC_ENABLE, 0) == -1)
> return -5;
>
> fprintf (stderr, "Sleep 1\n");
> sleep(1);
> fprintf (stderr, "Sleep 2\n");
> sleep(1);
> fprintf (stderr, "Sleep 3\n");
> sleep(1);
>
> /* Disable the event counter */
> ioctl(fd, PERF_EVENT_IOC_DISABLE, 1);
>
> close(fd);
>
> return 0;
> }
>
>
> A sample output:
> $ time ./cs
> Sleep 1
> Caught POLL_IN
> Sleep 2
> Caught POLL_IN
> Sleep 3
> Caught POLL_IN
>
> real 0m3.040s
> user 0m0.001s
> sys 0m0.003s
>
>
> Naveen N. Rao (2):
> kernel/events: Add option to notify through signals on wakeup
> kernel/events: Add option to enable counting sideband events in
> wakeup_events
>
> include/uapi/linux/perf_event.h | 4 +++-
> kernel/events/core.c | 20 ++++++++++++--------
> kernel/events/ring_buffer.c | 16 ++++++++++++++++
> 3 files changed, 31 insertions(+), 9 deletions(-)
>
> --
> 2.13.1
>
[toc] | [next] | [standalone]
| From | "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> |
|---|---|
| Date | 2017-07-13 16:30 +0200 |
| Message-ID | <u2NhT-6IB-3@gated-at.bofh.it> |
| In reply to | #1685689 |
[ Adding Vince...] On 2017/07/12 12:48PM, Jiri Olsa wrote: > On Mon, Jun 19, 2017 at 08:01:06PM +0530, Naveen N. Rao wrote: > > Currently, there is no way to ask for signals to be delivered when a > > certain number of sideband events have been logged into the ring buffer. > > This is problematic if we are only interested in, say, context switch > > events. Furthermore, signals are more useful (rather than polling) for > > self-profiling. This series provides for a way to achieve this. > > > > We ride on top of the existing support for ring buffer wakeup to > > generate signals as desired. Counting sideband events still requires > > some changes in the output path, but in normal cases, it ends up being > > just a comparison. > > > > The test program below demonstrates how a process can profile itself for > > context switch events and how it can control notification through > > signals. The key changes include the below perf_event_attr settings as > > well as use of IOC_ENABLE: > > pe.signal_on_wakeup = 1; > > pe.count_sb_events = 1; > > pe.wakeup_events = 2; > > Vince, > could you please check on this? thanks > > Naveen, > have you run Vince's test suite on this? > http://github.com/deater/perf_event_tests.git I just tried this and I see quite a few failures even without these patches. The behavior is similar with/without these patches and all the ioctl tests pass, but I see some failures with the overflow tests. I'll look into those tests in detail tomorrow. I may be missing something. Thanks, Naveen
[toc] | [prev] | [next] | [standalone]
| From | Vince Weaver <vincent.weaver@maine.edu> |
|---|---|
| Date | 2017-07-13 17:40 +0200 |
| Message-ID | <u2OnD-7nP-1@gated-at.bofh.it> |
| In reply to | #1686580 |
On Thu, 13 Jul 2017, Naveen N. Rao wrote: > > could you please check on this? thanks > > > > Naveen, > > have you run Vince's test suite on this? > > http://github.com/deater/perf_event_tests.git > > I just tried this and I see quite a few failures even without these > patches. > > The behavior is similar with/without these patches and all the ioctl > tests pass, but I see some failures with the overflow tests. I'll look > into those tests in detail tomorrow. I may be missing something. the signal/overflow interface has always been a troublesome one :( It's part of why I haven't had much to say about the whole kernel addresses leaking into samples mess. I had noticed some of the related overflow tests have been failing recently (both in perf_event_tests and in PAPI), but I haven't had a chance to see if it was an actual regression or just due to the way the tests are designed. I'll see if I can figure out what's going on. Vince
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web