Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753907AbbBRROD (ORCPT ); Wed, 18 Feb 2015 12:14:03 -0500 Received: from terminus.zytor.com ([198.137.202.10]:39329 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752134AbbBRROA (ORCPT ); Wed, 18 Feb 2015 12:14:00 -0500 Date: Wed, 18 Feb 2015 09:13:23 -0800 From: tip-bot for Shaohua Li Message-ID: Cc: acme@kernel.org, peterz@infradead.org, tglx@linutronix.de, torvalds@linux-foundation.org, fweisbec@gmail.com, shli@fb.com, linux-kernel@vger.kernel.org, mingo@kernel.org, hpa@zytor.com, luto@amacapital.net, acme@redhat.com Reply-To: tglx@linutronix.de, fweisbec@gmail.com, torvalds@linux-foundation.org, acme@kernel.org, peterz@infradead.org, hpa@zytor.com, mingo@kernel.org, acme@redhat.com, luto@amacapital.net, linux-kernel@vger.kernel.org, shli@fb.com In-Reply-To: References: To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf: Update userspace page info for software event Git-Commit-ID: 6a694a607a97d58c042fb7fbd60ef1caea26950c X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2861 Lines: 93 Commit-ID: 6a694a607a97d58c042fb7fbd60ef1caea26950c Gitweb: http://git.kernel.org/tip/6a694a607a97d58c042fb7fbd60ef1caea26950c Author: Shaohua Li AuthorDate: Thu, 5 Feb 2015 15:55:32 -0800 Committer: Ingo Molnar CommitDate: Wed, 18 Feb 2015 17:01:45 +0100 perf: Update userspace page info for software event For hardware events, the userspace page of the event gets updated in context switches, so if we read the timestamp in the page, we get fresh info. For software events, this is missing currently. This patch makes the behavior consistent. With this patch, we can implement clock_gettime(THREAD_CPUTIME) with PERF_COUNT_SW_DUMMY in userspace as suggested by Andy and Peter. Code like 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 it on a busy system, the userspace page updating doesn't have noticeable overhead. Signed-off-by: Shaohua Li Signed-off-by: Peter Zijlstra (Intel) Cc: Andy Lutomirski Cc: Arnaldo Carvalho de Melo Cc: Arnaldo Carvalho de Melo Cc: Frederic Weisbecker Cc: Linus Torvalds Link: http://lkml.kernel.org/r/aa2dd2e4f1e9f2225758be5ba00f14d6909a8ce1.1423180257.git.shli@fb.com [ Improved the changelog. ] Signed-off-by: Ingo Molnar --- kernel/events/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index e580e0f..fef45b4 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6123,6 +6123,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; } @@ -6592,6 +6593,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; } @@ -6666,6 +6668,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; } -- 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/