Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751940AbdFSOb4 (ORCPT ); Mon, 19 Jun 2017 10:31:56 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33669 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751317AbdFSObw (ORCPT ); Mon, 19 Jun 2017 10:31:52 -0400 From: "Naveen N. Rao" To: Peter Zijlstra , Arnaldo Carvalho de Melo , Jiri Olsa , Ingo Molnar Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/2] kernel/events: Add option to enable counting sideband events in wakeup_events Date: Mon, 19 Jun 2017 20:01:08 +0530 X-Mailer: git-send-email 2.13.1 In-Reply-To: References: In-Reply-To: References: X-TM-AS-MML: disable x-cbid: 17061914-0052-0000-0000-000002590620 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17061914-0053-0000-0000-00000837974E Message-Id: <3e1d5fea814758906c64b01e1eed186daaf2c9ed.1497881378.git.naveen.n.rao@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-06-19_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706190244 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2652 Lines: 74 Many sideband events are interesting by themselves. When profiling only for sideband events, it is useful to be able to control process wakeup (wakeup_events) based on sideband events alone. Add a new option 'count_sb_events' to do the same. Signed-off-by: Naveen N. Rao --- include/uapi/linux/perf_event.h | 3 ++- kernel/events/core.c | 4 ++-- kernel/events/ring_buffer.c | 13 +++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index e5810b1d74a4..ab4dc9a02151 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -346,7 +346,8 @@ struct perf_event_attr { write_backward : 1, /* Write ring buffer from end to beginning */ namespaces : 1, /* include namespaces data */ signal_on_wakeup : 1, /* send signal on wakeup */ - __reserved_1 : 34; + count_sb_events : 1, /* wakeup_events also counts sideband events */ + __reserved_1 : 33; union { __u32 wakeup_events; /* wakeup every n events */ diff --git a/kernel/events/core.c b/kernel/events/core.c index 812fcfc767f4..9ff9c0e37727 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -2680,7 +2680,7 @@ static int _perf_event_refresh(struct perf_event *event, int refresh) * not supported on inherited events */ if (event->attr.inherit || event->attr.signal_on_wakeup || - !is_sampling_event(event)) + event->attr.count_sb_events || !is_sampling_event(event)) return -EINVAL; atomic_add(refresh, &event->event_limit); @@ -5956,7 +5956,7 @@ void perf_output_sample(struct perf_output_handle *handle, } } - if (!event->attr.watermark) { + if (!event->attr.count_sb_events && !event->attr.watermark) { int wakeup_events = event->attr.wakeup_events; if (wakeup_events) { diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index 4e7c728569a8..f43a6081141f 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -197,6 +197,19 @@ __perf_output_begin(struct perf_output_handle *handle, * none of the data stores below can be lifted up by the compiler. */ + if (event->attr.count_sb_events && !event->attr.watermark) { + int wakeup_events = event->attr.wakeup_events; + + if (wakeup_events) { + int events = local_inc_return(&rb->events); + + if (events >= wakeup_events) { + local_sub(wakeup_events, &rb->events); + local_inc(&rb->wakeup); + } + } + } + if (unlikely(head - local_read(&rb->wakeup) > rb->watermark)) local_add(rb->watermark, &rb->wakeup); -- 2.13.1