From owner-freebsd-current@FreeBSD.ORG Sun Mar 16 05:05:55 2008 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6E9B21065673 for ; Sun, 16 Mar 2008 05:05:55 +0000 (UTC) (envelope-from adrian.chadd@gmail.com) Received: from rv-out-0910.google.com (rv-out-0910.google.com [209.85.198.189]) by mx1.freebsd.org (Postfix) with ESMTP id 4F9D88FC1A for ; Sun, 16 Mar 2008 05:05:55 +0000 (UTC) (envelope-from adrian.chadd@gmail.com) Received: by rv-out-0910.google.com with SMTP id g13so3129051rvb.43 for ; Sat, 15 Mar 2008 22:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=iiZ9hvOCZb3lW3dtCufLDpNhHziEgPq+IB+4n4jaLlQ=; b=WvDx3KzUXgifluJgiWNnqMzYkiT0chBGNZMPczHs1HyWIc3tZyxUoBpSF2IKuNByhHXGyWwbc4g63qg9NDdAmI99q5IHvBa6GE4zXajhlyVZDl7IF4MExm87Ddql2c/UCmaNYk3eV6RG4YNKFR1ruOZ40jXZyBPscj61+KXovLE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=gbvT2lQc+XV4k1gH8eEXNHWuvhX4TeUFDSh4tZVy2Hn1VEG4JP9lieZzU/nlQuLoNgjqpb/r8TBf1PljZ9X/UlgrR2VomZKNq3IEyGBoABH9gMMpVR3RevOo3kvRIlu1G33xv3YaN3H4WtcdjqjZT/gDVN6UvnYUsBdtfD3j/14= Received: by 10.141.113.6 with SMTP id q6mr7116640rvm.249.1205643954843; Sat, 15 Mar 2008 22:05:54 -0700 (PDT) Received: by 10.140.143.14 with HTTP; Sat, 15 Mar 2008 22:05:54 -0700 (PDT) Message-ID: Date: Sun, 16 Mar 2008 14:05:54 +0900 From: "Adrian Chadd" Sender: adrian.chadd@gmail.com To: jkoshy@freebsd.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Google-Sender-Auth: 6c86da32d5b43fc8 Cc: current@freebsd.org Subject: Re: issues with hwpmc and athlon XP X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Mar 2008 05:05:55 -0000 On 10/03/2008, Adrian Chadd wrote: > Between my Athlon XP box giving me no useful pmc stats and my new Core > 2 duo box not even working with pmc, I decided to poke at the Athlon > XP support a bit to see if I could figure out what was going on. Here's an updated patch. It seems to be returning the system CPU usage I expect in my profile but I still don't get any useful usermode sampling. I'll dig deeper into that to try and figure out whats going on. It fixes a debugging output issue (which I'm happy to commit seperately) and it "sign-extends" the 48 value read back from the AMD counter to a 64 bit value to preserve the 2s compliment semantics that is used for the "count up to overflow NMI" trick. jkoshy, do you mind if I commit this and then MFC it to RELENG_7? Thanks, Adrian Index: hwpmc_amd.c =================================================================== RCS file: /share/FreeBSD/cvsrepo/src/sys/dev/hwpmc/hwpmc_amd.c,v retrieving revision 1.14 diff -u -r1.14 hwpmc_amd.c --- hwpmc_amd.c 7 Dec 2007 08:20:15 -0000 1.14 +++ hwpmc_amd.c 16 Mar 2008 05:02:38 -0000 @@ -302,12 +302,22 @@ #endif tmp = rdmsr(pd->pm_perfctr); /* RDMSR serializes */ - if (PMC_IS_SAMPLING_MODE(mode)) - *v = AMD_PERFCTR_VALUE_TO_RELOAD_COUNT(tmp); - else - *v = tmp; + PMCDBG(MDP,REA,2,"amd-read (pre-munge) id=%d -> %jd", ri, tmp); + if (PMC_IS_SAMPLING_MODE(mode)) { + /* + * The counters are 48 bit but we expect them to be 64 bit for + * 2s compliment "hack" done to allow the "count up" to overflow + * which triggers the sampling mode NMI. + * This code sign-extends the 48 bit number in case the returned + * value requires it. + */ + if (tmp & 0x0000800000000000) + tmp |= 0xffff000000000000; + tmp = AMD_PERFCTR_VALUE_TO_RELOAD_COUNT(tmp); + } + *v = tmp; - PMCDBG(MDP,REA,2,"amd-read id=%d -> %jd", ri, *v); + PMCDBG(MDP,REA,2,"amd-read (post-munge) id=%d -> %jd", ri, *v); return 0; } @@ -683,7 +693,7 @@ KASSERT(cpu >= 0 && cpu < mp_ncpus, ("[amd,%d] out of range CPU %d", __LINE__, cpu)); - PMCDBG(MDP,INT,1, "cpu=%d tf=0x%p um=%d", cpu, (void *) tf, + PMCDBG(MDP,INT,1, "cpu=%d tf=%p um=%d", cpu, (void *) tf, TRAPF_USERMODE(tf)); retval = 0;