Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754160AbbBEXzj (ORCPT ); Thu, 5 Feb 2015 18:55:39 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:40918 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754080AbbBEXzg (ORCPT ); Thu, 5 Feb 2015 18:55:36 -0500 From: Shaohua Li To: CC: Arnaldo Carvalho de Melo , Frederic Weisbecker , Paul Mackerras , Peter Zijlstra , Andy Lutomirski , Ingo Molnar Subject: [PATCH 2/2 --resend] perf: update userspace page info for software event Date: Thu, 5 Feb 2015 15:55:32 -0800 Message-ID: X-Mailer: git-send-email 1.8.1 In-Reply-To: <9cd0276d6a047cb7c2885994f25e3a1f7c8c28af.1423180257.git.shli@fb.com> References: <9cd0276d6a047cb7c2885994f25e3a1f7c8c28af.1423180257.git.shli@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.13.68,1.0.33,0.0.0000 definitions=2015-02-05_06:2015-02-05,2015-02-05,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 spamscore=0 suspectscore=1 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1502050227 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2282 Lines: 82 For hardware event, the userspace page of the event gets updated in context switch, so if we read time in the page, we get updated info. For software event, this is missed currently. This patch makes the behavior consistency. With this patch, we can implement clock_gettime(THREAD_CPUTIME) with PERF_COUNT_SW_DUMMY in userspace as suggested by Andy and Peter. Code likes this: if (pc->cap_user_time) { do { seq = pc->lock; barrier(); running = pc->time_running; cyc = rdtsc(); time_mult = pc->time_mult; time_shift = pc->time_shift; time_offset = pc->time_offset; barrier(); } while (pc->lock != seq); quot = (cyc >> time_shift); rem = cyc & ((1 << time_shift) - 1); delta = time_offset + quot * time_mult + ((rem * time_mult) >> time_shift); running += delta; return running; } I tried in a busy system, the userspace page updating hasn't noticeable overhead. Cc: Arnaldo Carvalho de Melo Cc: Frederic Weisbecker Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Andy Lutomirski Cc: Ingo Molnar Signed-off-by: Shaohua Li --- kernel/events/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index 04d8b48..98105cf 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5950,6 +5950,7 @@ static int perf_swevent_add(struct perf_event *event, int flags) } hlist_add_head_rcu(&event->hlist_entry, head); + perf_event_update_userpage(event); return 0; } @@ -6419,6 +6420,7 @@ static int cpu_clock_event_add(struct perf_event *event, int flags) { if (flags & PERF_EF_START) cpu_clock_event_start(event, flags); + perf_event_update_userpage(event); return 0; } @@ -6493,6 +6495,7 @@ static int task_clock_event_add(struct perf_event *event, int flags) { if (flags & PERF_EF_START) task_clock_event_start(event, flags); + perf_event_update_userpage(event); return 0; } -- 1.8.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/