From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753296AbbC0OBc (ORCPT ); Fri, 27 Mar 2015 10:01:32 -0400 Received: from casper.infradead.org ([85.118.1.10]:41561 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752293AbbC0OBa (ORCPT ); Fri, 27 Mar 2015 10:01:30 -0400 Date: Fri, 27 Mar 2015 15:01:17 +0100 From: Peter Zijlstra To: Stephane Eranian Cc: linux-kernel@vger.kernel.org, acme@redhat.com, mingo@elte.hu, ak@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, cel@us.ibm.com, sukadev@linux.vnet.ibm.com, sonnyrao@chromium.org, johnmccutchan@google.com, dsahern@gmail.com, adrian.hunter@intel.com, pawel.moll@arm.com Subject: Re: [PATCH v5 4/4] perf tools: add JVMTI agent library Message-ID: <20150327140117.GF23123@twins.programming.kicks-ass.net> References: <1427397429-14808-1-git-send-email-eranian@google.com> <1427397429-14808-5-git-send-email-eranian@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1427397429-14808-5-git-send-email-eranian@google.com> 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 On Thu, Mar 26, 2015 at 08:17:09PM +0100, Stephane Eranian wrote: > This version of the JVMTI agent is using Pawel Moll's CLOCK_MONOTONIC > perf clock patch posted here: > https://lkml.org/lkml/2015/1/21/711 Seeing how we just merged its replacement: http://git.kernel.org/tip/34f439278cef7b1177f8ce24f9fc81dfc6221d3b how about something like this to make it work? Completely not been near a compiler at all. I'll go do the regular perf userspace part now I suppose -- I had somewhat forgotten about that. --- --- a/tools/perf/jvmti/jvmti_agent.c +++ b/tools/perf/jvmti/jvmti_agent.c @@ -36,6 +36,8 @@ #include /* for gettid() */ #include +#include "perf-sys.h" + #include "jvmti_agent.h" #include "../util/jitdump.h" @@ -92,37 +94,44 @@ static int get_e_machine(struct jitheade return ret; } -#define NSEC_PER_SEC 1000000000 -static int perf_clk_id; -static int -perf_get_clock_id(void) -{ - FILE *fp; - int ret; - - fp = fopen("/proc/sys/kernel/perf_sample_time_clk_id", "r"); - if (!fp) - return -1; - ret = fscanf(fp, "%d", &perf_clk_id); +static clockid_t jit_clockid = CLOCK_MONOTONIC_RAW; - fclose(fp); - - return ret == 1 ? 0 : -1; -} +#define NSEC_PER_SEC 1000000000 static int perf_open_timestamp(void) { + struct perf_event_attr perf_attr = { + .type = PERF_TYPE_SOFTWARE, + .config = PERF_COUNT_SW_DUMMY, + .exclude_kernel = 1, + .use_clockid = 1, + }; struct timespec ts; + char *clk; int ret; - if (perf_get_clock_id()) - return -1; + clk = getenv("JITCLOCKID"); + if (clk) { + ret = sscanf(clk, "%d", &jit_clockid); + if (ret != 1) + return -1; + } + /* - * check if clock_id is actually available + * check if jit_clockid is actually available */ - ret = clock_gettime(perf_clk_id, &ts); - return ret ? -1 : 0; + ret = clock_gettime(jit_clockid, &ts); + if (ret) + return ret; + + perf_attr.clockid = jit_clockid; + ret = sys_perf_event_open(&perf_attr, 0, -1, -1, 0); + if (ret < 0) + return ret; + + close(ret); + return 0; } static inline uint64_t @@ -137,7 +146,7 @@ perf_get_timestamp(void) struct timespec ts; int ret; - ret = clock_gettime(perf_clk_id, &ts); + ret = clock_gettime(jit_clockid, &ts); if (ret) return 0; @@ -242,7 +251,7 @@ void *jvmti_open(void) FILE *fp; if (perf_open_timestamp()) - warnx("jvmti: kernel does not support %d clock id", perf_clk_id); + warnx("jvmti: kernel does not support %d clock id", jit_clockid); memset(&header, 0, sizeof(header));