From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andi Kleen Subject: Re: Use of PMU counters inside kernel? Date: Thu, 19 Jun 2014 14:11:59 -0700 Message-ID: <87d2e48uzk.fsf@tassilo.jf.intel.com> References: <20140619125352.768e1ec9@redhat.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from mga02.intel.com ([134.134.136.20]:61448 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934695AbaFSVMJ (ORCPT ); Thu, 19 Jun 2014 17:12:09 -0400 In-Reply-To: <20140619125352.768e1ec9@redhat.com> (Jesper Dangaard Brouer's message of "Thu, 19 Jun 2014 12:53:52 +0200") Sender: linux-perf-users-owner@vger.kernel.org List-ID: To: Jesper Dangaard Brouer Cc: Arnaldo Carvalho de Melo , linux-perf-users@vger.kernel.org, Daniel Borkmann , Florian Westphal , Hannes Frederic Sowa Jesper Dangaard Brouer writes: > I want to use/read the PMU counters for 'instructions' and 'cycles', > from within the kernel, to measure the overhead of different in-kernel > functions (and calc the pipeline efficiency ala perf-stat insns per cycle). > > What is the prefered way/API to read these counters, without > conflicting with the perf tool? > perf_event_create_counter() > I basically just need a in-kernel API to turn in these counters, and > then I can just read them via the rdpcm instruction. For RDPMC you would need extra support actually, as there is no guarantee perf uses the fixed counter. In user space this information is in the perf mmap page. Also please be aware that RDPMC is not synchronizing. -Andi -- ak@linux.intel.com -- Speaking for myself only