Subject: Re: ktr from freebsd
To: Andrey Petrov <petrov@netbsd.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-kern
Date: 04/23/2004 12:43:17
Andrey Petrov wrote:

> Folks,
> 
> I needed low-level memory buffer tracing and I took freebsd's kern_ktr.c
> for that. I stripped 'bells and whistls' like sysctl control and saving in
> file,  because I don't think they are really needed and it would take more
> time for porting. Main reason was replace sparc64 traptrace with something
> more generic and flexible, uvm_history seems closest by functionality but too tied to
> uvm and somewhat too heavy for .S codes. So I ended up with freebsd's
> kern_ktr and that's light-weight, simple and convinient interface.
> 
> It has mi and md parts, buffer itself, ktr_traptrace and db_show_ktr in mi (and
> for mi, and C code) and CATR assembler macro for md.
> 
> Now, I use it in sparc64 and did support only for sparc64, and put those
> traces only in sparc64. I'd like to go on with it further and commit it
> eventually (sooner better). The problem is that it's not likely that I will
> add support for other platforms or put traces in common parts in short time frame
> but the feature is optionable so it wouldn't hurt to have it in sys and kern
> directories. It's possible to put everything in sparc64 directory as an
> alternative approach but no,
> 
> I'm attaching main pieces of kern_ktr here for your review. I'd like to
> commit after some clean-up. Opinions? objections?

Looks useful at a glance.  A couple of comments:

 - Maybe the default KTR_TIME should be just the kernel time variable?

 - Adding a sysctl to return the trace buffer would be nice (remember
   64-bit alignment so there's no compat32 issues - sparc64 is a good
   place to test this :-).

 - What did FreeBSD have in terms of "sysctl control"?  A simple
   "enable/disable" tracing button would be nice.

 - I'm a little concerned with uvmhist overlap.  I'd guess we'd want
   one or the other in the kernel, not both.

 - A style nit: there's quite a mix of "#define<space>" and
   "#define<tab>".

I agree that a general tracing mechanism for use anywhere in the kernel
is quite handy.

Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD Support and Service:         http://www.wasabisystems.com/