From andreas@klemm.gtn.com  Sun May  4 04:21:19 1997
Received: from news1.gtn.com (news1.gtn.com [194.77.0.15])
          by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id EAA20350
          for <FreeBSD-gnats-submit@freebsd.org>; Sun, 4 May 1997 04:21:18 -0700 (PDT)
Received: (from uucp@localhost) by news1.gtn.com (8.7.2/8.7.2) with UUCP id NAA06052 for FreeBSD-gnats-submit@freebsd.org; Sun, 4 May 1997 13:15:22 +0200 (MET DST)
Received: (from andreas@localhost) by klemm.gtn.com (8.8.5/8.8.2) id NAA19872; Sun, 4 May 1997 13:32:57 +0200 (CEST)
Message-Id: <199705041132.NAA19872@klemm.gtn.com>
Date: Sun, 4 May 1997 13:32:57 +0200 (CEST)
From: Andreas Klemm <andreas@klemm.gtn.com>
Reply-To: andreas@klemm.gtn.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: kernel profiling broken with SMP kernel
X-Send-Pr-Version: 3.2

>Number:         3491
>Category:       kern
>Synopsis:       SMP kernel, profiling broken, prof_machdep.c: i586_ctr_freq undeclared
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun May  4 04:30:01 PDT 1997
>Closed-Date:    Mon Aug 4 14:30:04 PDT 1997
>Last-Modified:  Mon Aug  4 14:35:59 PDT 1997
>Originator:     Andreas Klemm
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
>Environment:

	FreeBSD-current of today

>Description:

Tried to create a kernel with enhanced profiling support.

	config -pp BISDNSMP

Compilation stops with this error:

cc -c -O -pipe -Wreturn-type -Wcomment -Wredundant-decls -Wimplicit  -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes  -Wpointer-arith  -nostdinc -I- -I. -I../.. -I/usr/include -DGPROF -DTELES_HAS_MEMCPYB -DMD5 -DCOMPAT_43 -DNSWAPDEV=3 -DCD9660 -DMSDOSFS -DMFS -DNFS -DFFS -DINET -DSMP_INVLTLB -DGPROF4 -DGUPROF -DKERNEL -include opt_global.h -DMAXUSERS=64 ../../i386/isa/prof_machdep.c
../../i386/isa/prof_machdep.c: In function `startguprof':
../../i386/isa/prof_machdep.c:238: `i586_ctr_freq' undeclared (first use this function)
../../i386/isa/prof_machdep.c:238: (Each undeclared identifier is reported only once
../../i386/isa/prof_machdep.c:238: for each function it appears in.)
*** Error code 1

>How-To-Repeat:

	Simply try to build a kernel with profiling support

>Fix:
	
Browsed through .../isa/clock.c
Seems to be ifdef'ed out for the SMP case ... Why ?

[...snip...]
#if (defined(I586_CPU) || defined(I686_CPU)) && !defined(SMP)
u_int	i586_ctr_bias;
u_int	i586_ctr_comultiplier;
u_int	i586_ctr_freq;
u_int	i586_ctr_multiplier;
#endif
[...snip...]
>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: andreas@klemm.gtn.com, FreeBSD-gnats-submit@FreeBSD.ORG
Cc:  Subject: Re: kern/3491: kernel profiling broken with SMP kernel
Date: Mon, 5 May 1997 05:16:56 +1000

 >Tried to create a kernel with enhanced profiling support.
 
 Don't do that.  Even ordinary profiling doesn't actually work in SMP
 kernels.
 
 For ordinary profiling, I think clock interrupts are taken by only
 one (random) CPU and the other CPUs aren't accounted for.  I think
 they need to all take clock interrupts and all except one handle only
 per-CPU profiling.  A single profiling buffer should work OK unless you
 are interested in per-CPU statistics, but accesses to it would have to
 be locked.
 
 For enhanced profiling, there is a TSC and a set of performance counters
 for each CPU, so the global variables related to these must be arrays in
 the SMP case.  This is not implemented.
 
 >Browsed through .../isa/clock.c
 >Seems to be ifdef'ed out for the SMP case ... Why ?
 >
 >[...snip...]
 >#if (defined(I586_CPU) || defined(I686_CPU)) && !defined(SMP)
 >u_int	i586_ctr_bias;
 >u_int	i586_ctr_comultiplier;
 >u_int	i586_ctr_freq;
 >u_int	i586_ctr_multiplier;
 >#endif
 
 These need to be arrays, except possibly if the CPU frequencies are almost
 the same (e.g., +-1% for profiling and +-0.001% for timekeeping).
 
 Bruce
State-Changed-From-To: open->closed 
State-Changed-By: fsmp 
State-Changed-When: Mon Aug 4 14:30:04 PDT 1997 
State-Changed-Why:  
i586_cnt_freq now available for SMP kernel. 
Note that although "config -pp ..." now creates 
a compilable and runnable kernel, the underlying timer 
issues have NOT yet been addressed in the SMP kernel and the 
results of the profiling code are probably not accurrate. 


>Unformatted:
