Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Oct 2000 10:14:07 -0600
From:      Chuck Paterson <cp@bsdi.com>
To:        Poul-Henning Kamp <phk@FreeBSD.ORG>
Cc:        smp@FreeBSD.ORG
Subject:   Re: ktr.h improvement 
Message-ID:  <200010271614.KAA12094@berserker.bsdi.com>
In-Reply-To: Your message of "Fri, 27 Oct 2000 15:46:41 %2B0200." <10863.972654401@critter> 

next in thread | previous in thread | raw e-mail | index | archive | help
The macros that came from BSD/OS actually can be improved very
little my changing. In the case of Sparc a small section is done
in a function to set up the pointer and then the rest is inline.
In X86 the upfront code is quite small so everything was done
inline. The code in question is
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
        movl    $ KTR_ESIZE,reg;        /* How much to incr */          \
        xaddl   reg,%fs:PCPU_KTR_IDX;   /* get a slot */                \
        rdtsc;                          /* time -> eax/edx */           \
        andl    seg ktr_size_mask,reg;  /* wrap buffer */               \
        addl    %fs:PCPU_KTR_BUF,reg;   /* Point to actual spot in buffer */ \
        movl    %eax,seg KTR_CLKV(reg);/* Time low */                   \
        movl    %edx,seg KTR_CLKV+4(reg); /* Time high */               \
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

The rest of the macros as little or less space as passing the data
to a function so there really isn't anything to be gained, and speed
to be lost.


In the case of FreeBSD there is also the KTR_EXTEND. This should
be pushed into a function as much as possible. It is already so
slow that it really can't be used in any kind of live kernel so
any space to time overhead is a win.



There is another big issue with the KTR macros which really
needs to be addressed. Macros which are defined to not be compiled
in are removed by the optimizer. This removes the code, but doesn't
remove the strings. I have include a sample to show how this
could be done so that the preprocessor rather than the optimizer
leave this stuff out.

Chuck

#include <sys/cdefs.h>

#define KTR_TRACE       2

#define TRACE_KTR_FOO_BIT       2               /* some random bit */


#if KTR_TRACE & TRACE_KTR_FOO_BIT
#define TRACE_KTR_FOO(x) printf ("%s\n", x)
#else
#define TRACE_KTR_FOO(x)
#endif

#define CTR0(x,y)  __CONCAT(TRACE_, x)(y)


int main(int ac, char **av)
{
       CTR0(KTR_FOO, "now is the time");
}



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-smp" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200010271614.KAA12094>