From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 12 09:03:38 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 A908C106566B for ; Mon, 12 Mar 2012 09:03:38 +0000 (UTC) (envelope-from fabien.thomas@netasq.com) Received: from work.netasq.com (mars.netasq.com [91.212.116.3]) by mx1.freebsd.org (Postfix) with ESMTP id 2161C8FC0A for ; Mon, 12 Mar 2012 09:03:37 +0000 (UTC) Received: from [10.2.1.103] (unknown [10.2.1.103]) by work.netasq.com (Postfix) with ESMTPSA id D275774004C; Mon, 12 Mar 2012 10:02:06 +0100 (CET) Mime-Version: 1.0 (Apple Message framework v1257) Content-Type: multipart/signed; boundary="Apple-Mail=_D3015E11-0567-4272-83FF-B445D0D19193"; protocol="application/pkcs7-signature"; micalg=sha1 From: Fabien Thomas In-Reply-To: Date: Mon, 12 Mar 2012 10:03:35 +0100 Message-Id: References: To: Vitaly Magerya X-Mailer: Apple Mail (2.1257) X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-hackers@freebsd.org 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 09:03:38 -0000 --Apple-Mail=_D3015E11-0567-4272-83FF-B445D0D19193 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 Le 11 mars 2012 =E0 16:45, Vitaly Magerya a =E9crit : > 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. >=20 > Here's a test program: >=20 > #include > #include > #include > #include >=20 > int main() { > pmc_id_t pmcid; > pmc_value_t value; > int i; >=20 > pmc_init(); > pmc_allocate("instructions", PMC_MODE_TC, 0, PMC_CPU_ANY, = &pmcid); > pmc_start(pmcid); > for (i =3D 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); > } >=20 > It's output on my system (FreeBSD 8.2 amd64, an Intel Atom processor) > is something like this: >=20 > first reading: 0 > second reading: 15090110 >=20 > 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. >=20 > 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. >=20 > (BTW, is this the right list for such questions?) > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to = "freebsd-hackers-unsubscribe@freebsd.org" --Apple-Mail=_D3015E11-0567-4272-83FF-B445D0D19193--