From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 12 12:40:03 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 524A61065670 for ; Mon, 12 Mar 2012 12:40:03 +0000 (UTC) (envelope-from vmagerya@gmail.com) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) by mx1.freebsd.org (Postfix) with ESMTP id B87318FC08 for ; Mon, 12 Mar 2012 12:40:02 +0000 (UTC) Received: by lboi15 with SMTP id i15so1312855lbo.13 for ; Mon, 12 Mar 2012 05:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=HGEU955jAAA5xI1sRgB1H3S3mSIRI4RdOLTWjR2ESnk=; b=q6hMx6KFl8Lxhf1K7CJq1vDk+1k4UajX5LcE3rsssaSMtaZt+AFAxR4lnLxYRF9hvw Kd7lH7CIjTfg4anKXF1sQG7KHgZRRF8hYsf4OppmEyPfVlGg2Jgn6Ad28bTfyzyYyX4c AXhdZFOWCgJgdi9+ChRVKzi0fiUabj4h/0Ax1Bob5d8JJzMw4VqBt0NwGNnCy4M6LLEp E3mBnFtWvi+2xx8Co6wsucA1tnKGVGkIMjiY+CFfYY+vGfT5CjEld/CzIVww3xM0GZhx hS1RoHmChV2UBzae/ojQuVWgQiKTJFYkagnlNrsjpw796nfc08GFTgwHcwTgu6fjlz5E W1Tg== Received: by 10.152.103.239 with SMTP id fz15mr9079481lab.42.1331556001409; Mon, 12 Mar 2012 05:40:01 -0700 (PDT) Received: from [172.29.1.142] (altimet-gw.cs2.dp.wnet.ua. [217.20.178.249]) by mx.google.com with ESMTPS id v4sm18208569lbx.13.2012.03.12.05.39.59 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 12 Mar 2012 05:40:00 -0700 (PDT) Message-ID: <4F5DEE7E.5030008@gmail.com> Date: Mon, 12 Mar 2012 14:39:26 +0200 From: Vitaly Magerya User-Agent: Thunderbird MIME-Version: 1.0 To: Fabien Thomas References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 12:40:03 -0000 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.