zero-cost SDT probes

Slawa Olhovchenkov slw at zxy.spb.ru
Sun Nov 22 10:50:37 UTC 2015


On Sat, Nov 21, 2015 at 06:45:42PM -0800, Mark Johnston wrote:

> Hi,
> 
> For the past while I've been experimenting with various ways to
> implement "zero-cost" SDT DTrace probes. Basically, at the moment an SDT
> probe site expands to this:
> 
> if (func_ptr != NULL)
> 	func_ptr(<probe args>);
> 
> When the probe is enabled, func_ptr is set to dtrace_probe(); otherwise
> it's NULL. With zero-cost probes, the SDT_PROBE macros expand to
> 
> func(<probe args>);

I am experimenting with overhead DTrace probes in userspace.
Total executing time program w/o any probes 3% less then program with
not enabled probes.
With enabled probes (conditional probes too) -- each probe add about 0.7us.
I am place DTrace probe inside inner loop, worst case.

=====
#include <stdio.h>
#include "probes.h"

long primes[1000000] = { 3 };
long primecount = 1;

int main(int argc, char **argv)
{
        long divisor = 0;
        long currentprime = 5;
        long isprime = 1;

        while (currentprime < 1000000)
        {
                isprime = 1;
                PRIMES_PRIMECALC_START(currentprime);
                for(divisor=0;divisor<primecount;divisor++)
                {
                        PRIMES_PRIMECALC_ITER(divisor);
                        if (currentprime % primes[divisor] == 0)
                        {
                                isprime = 0;
                                break;
                        }
                }
                PRIMES_PRIMECALC_DONE(currentprime,isprime);
                if (isprime)
                {
                        primes[primecount++] = currentprime;
                        PRIMES_PRIMECALC_TABLESIZE(primecount);
                        // printf("%d is a prime\n",currentprime);
                }
                currentprime = currentprime + 2;
        }
        printf("Total %ld primes\n", primecount);

}


More information about the freebsd-arch mailing list