From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 11 15:45:51 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3C4E3106564A for ; Sun, 11 Mar 2012 15:45:51 +0000 (UTC) (envelope-from vmagerya@gmail.com) Received: from mail-we0-f182.google.com (mail-we0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id CBAF58FC12 for ; Sun, 11 Mar 2012 15:45:50 +0000 (UTC) Received: by wern13 with SMTP id n13so821827wer.13 for ; Sun, 11 Mar 2012 08:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=hhwTaKf9GjFqKJqRTAdIZdpBVFWdflP3s0ScH/k49K0=; b=GaFWgLrYVVEKvmCCPasdBNe/N1mg9XalsG67QN5XnbqJ0xsBWnL5YGMiFWWbRAFG3m kNksJKuwfACtweOQIVXcS8T+gPkC+IWQ0UfGD3zb8uD0xJi5GccksurRfZh6Z1yEhnfE ecAKa8GlJ88OW8c7o+6pxkBlQ5G9bbKsf0PSnUWjXL2+nTFQexfHwKbO5XZm87LxEWJ+ kmKyCC5cDdrnxUZz7ssLYQ9krCe0pNSLmvB64VQe0oBiSr1cGy/i1wmqzckVbH1sXtc2 5C8NtMQbJA0odUBbzuY6kMsq+PpbzXLCGsQY434wVbz+P5mIKk6BmzT1brdae/6jQyas +XRg== MIME-Version: 1.0 Received: by 10.180.105.194 with SMTP id go2mr20166419wib.22.1331480749856; Sun, 11 Mar 2012 08:45:49 -0700 (PDT) Received: by 10.223.103.8 with HTTP; Sun, 11 Mar 2012 08:45:49 -0700 (PDT) Date: Sun, 11 Mar 2012 17:45:49 +0200 Message-ID: From: Vitaly Magerya To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=UTF-8 Subject: pmc(3): when are the counters updated? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Mar 2012 15:45:51 -0000 Hi, folks. I'm trying to use pmc(3) to analyze code fragments, and I've run into strange behavior: the counter values returned by pmc_read(3) sometimes show no increment between readings, but are updated a second later; even if the PMC in question was stopped before. Here's a test program: #include #include #include #include int main() { pmc_id_t pmcid; pmc_value_t value; int i; pmc_init(); pmc_allocate("instructions", PMC_MODE_TC, 0, PMC_CPU_ANY, &pmcid); pmc_start(pmcid); for (i = 0; i < 5000000; i++); pmc_stop(pmcid); pmc_read(pmcid, &value); printf("first reading: %lu\n", (unsigned long)value); sleep(1); pmc_read(pmcid, &value); printf("second reading: %lu\n", (unsigned long)value); } It's output on my system (FreeBSD 8.2 amd64, an Intel Atom processor) is something like this: first reading: 0 second reading: 15090110 I don't really like both numbers; I expect the first reading not to be zero (there obviously are instructions between pmc_start and pmc_stop), and I expect the second reading not to differ from the first, as the PMC was stopped before both of them, so it's value should not change. So, what's going on here? Is this the intended behavior, or can it be changed? And how do I get accurate readings? (BTW, is this the right list for such questions?)