From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 12 13:04:09 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 D9168106566B for ; Mon, 12 Mar 2012 13:04:09 +0000 (UTC) (envelope-from redcrash@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 6C55A8FC0A for ; Mon, 12 Mar 2012 13:04:09 +0000 (UTC) Received: by wern13 with SMTP id n13so1751705wer.13 for ; Mon, 12 Mar 2012 06:04:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Qa9HMWRLuVyuyWrAOiOTeFVtfjjsSqJyDZbvzvutAIE=; b=HKJPESZbl1cdn1dRcEFy6q/zgui9ap0MMqtD6cCGwa5ulBRV3TNcly3DeUq7WOeaZT lx/IqFJwwpBLYrDCVE8AsYIx8rN1fFaaKtuNIIFqOg4i28wjdq+Tt+OJvM6UPgSryR7b MVOXBROvfpzBPwUnj5dNVgml6SI0A9oyRhJHMNXMUAQtlbBrSYr7kPK62J0XlUcrP5rF sMKebtIiL4aRJ4xcWdDwv16ItZuLpgfHR/KF+/zIFku6DcB2j7B0ziMezfx5lozoE6Ow Zj/cJCl7KnOwxAHtwKscI+DUsuhPRjI59xRDaX6liF44yRZA2BndbTNrqrd5bpyoIDgZ 0oOg== MIME-Version: 1.0 Received: by 10.216.131.2 with SMTP id l2mr7162996wei.3.1331557448303; Mon, 12 Mar 2012 06:04:08 -0700 (PDT) Received: by 10.216.48.5 with HTTP; Mon, 12 Mar 2012 06:04:08 -0700 (PDT) In-Reply-To: <4F5DEE7E.5030008@gmail.com> References: <4F5DEE7E.5030008@gmail.com> Date: Mon, 12 Mar 2012 14:04:08 +0100 Message-ID: From: Harald Servat To: Vitaly Magerya Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-hackers@freebsd.org, Fabien Thomas Subject: Re: 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: Mon, 12 Mar 2012 13:04:09 -0000 2012/3/12 Vitaly Magerya > Fabien Thomas wrote: > >> So, what's going on here? Is this the intended behavior, or can it > >> be changed? And how do I get accurate readings? > > > > If i remember well: > > The current code will get real HW PMC if the PMC is running and attached > to owner. > > The first case is not true in your code so you get the saved value which > is updated at > > process switch out time. > > > > I think you can do: > > pmc_read > > pmc_stop. > > Changing the code to this: > > [...] > pmc_read(pmcid, &value); > pmc_stop(pmcid); > printf("reading #1: %lu\n", (unsigned long)value); > pmc_read(pmcid, &value); > printf("reading #2: %lu\n", (unsigned long)value); > sleep(1); > pmc_read(pmcid, &value); > printf("reading #3: %lu\n", (unsigned long)value); > [...] > > Gives me this output: > > reading #1: 15039441 > reading #2: 0 > reading #3: 15084037 > > So, it seems that you are correct; pmc_read reports current values if > the PMC is not stopped, after which it's updated on context switches. > > Hello, I've used the PMC library in the past, and I think that you can't stop the counters if you want to read them. By having them started, you can read their value anywhere in the code, not only in context switches. I suggest you changing the code to something like pmc_read(..); do_some_calculation(..); pmc_read(..); /* difference between reads is devoted to do_some_calculation */ and when you're about to finalize the application, issue pmc_stop. Please, also note, sleep(1) yields the process, so counting it (even if it's 1 second or more) will probably result in very low counter values. Regards -- Fry: You can see how I lived before I met you. Bender: You lived before you met me?! Fry: Yeah, lots of people did. Bender: Really?!