Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752673AbbBKLPm (ORCPT ); Wed, 11 Feb 2015 06:15:42 -0500 Received: from casper.infradead.org ([85.118.1.10]:37673 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752021AbbBKLPl (ORCPT ); Wed, 11 Feb 2015 06:15:41 -0500 Date: Wed, 11 Feb 2015 12:15:33 +0100 From: Peter Zijlstra To: Shaohua Li Cc: linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Frederic Weisbecker , Paul Mackerras , Andy Lutomirski , Ingo Molnar Subject: Re: [PATCH 2/2 --resend] perf: update userspace page info for software event Message-ID: <20150211111533.GS23123@twins.programming.kicks-ass.net> References: <9cd0276d6a047cb7c2885994f25e3a1f7c8c28af.1423180257.git.shli@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1466 Lines: 50 On Thu, Feb 05, 2015 at 03:55:32PM -0800, Shaohua Li wrote: > 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); You could maybe use: static inline u64 mul_u64_u32_shr(u64 a, u32 mul, unsigned int shift) { return (u64)(((unsigned __int128)a * mul) >> shift); } And save yourself a mult instruction if you have suitable (64bit) hardware and a recent GCC. > running += delta; > return running; > } > Thanks for poking me. Applied. -- 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/