Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
inrval.c File Reference
#include "plgetopt.h"
#include "prinit.h"
#include "obsolete/pralarm.h"
#include "prio.h"
#include "prprf.h"
#include "prlock.h"
#include "prlong.h"
#include "prcvar.h"
#include "prinrval.h"
#include "prtime.h"
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

static void TestConversions (void)
static void TestIntervalOverhead (void)
static void TestNowOverhead (void)
static void TestIntervals (void)
static PRIntn PR_CALLBACK RealMain (int argc, char **argv)
PRIntn main (PRIntn argc, char *argv[])

Variables

static PRIntn debug_mode
static PRFileDescoutput

Function Documentation

PRIntn main ( PRIntn  argc,
char *  argv[] 
)

Definition at line 234 of file inrval.c.

{
    PRIntn rv;
    
    PR_STDIO_INIT();
    rv = PR_Initialize(RealMain, argc, argv, 0);
    return rv;
}  /* main */

Here is the call graph for this function:

static PRIntn PR_CALLBACK RealMain ( int  argc,
char **  argv 
) [static]

Definition at line 171 of file inrval.c.

{
    PRUint32 vcpu, cpus = 0, loops = 1000;

       /* The command line argument: -d is used to determine if the test is being run
       in debug mode. The regress tool requires only one line output:PASS or FAIL.
       All of the printfs associated with this test has been handled with a if (debug_mode)
       test.
       Usage: test_name -d
       */

 /* main test */
       
       PLOptStatus os;
       PLOptState *opt = PL_CreateOptState(argc, argv, "dl:c:");
       while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
              if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'd':  /* debug mode */
                     debug_mode = 1;
            break;
        case 'c':  /* concurrency counter */
                     cpus = atoi(opt->value);
            break;
        case 'l':  /* loop counter */
                     loops = atoi(opt->value);
            break;
         default:
            break;
        }
    }
       PL_DestroyOptState(opt);
       
    output = PR_GetSpecialFD(PR_StandardOutput);
    PR_fprintf(output, "inrval: Examine stdout to determine results.\n");

    if (cpus == 0) cpus = 8;
    if (loops == 0) loops = 1000;

    if (debug_mode > 0)
    {
        PR_fprintf(output, "Inrval: Using %d loops\n", loops);
        PR_fprintf(output, "Inrval: Using 1 and %d cpu(s)\n", cpus);
    }

    for (vcpu = 1; vcpu <= cpus; vcpu += cpus - 1)
    {
        if (debug_mode)
            PR_fprintf(output, "\nInrval: Using %d CPU(s)\n\n", vcpu);
        PR_SetConcurrency(vcpu);

        TestNowOverhead();
        TestIntervalOverhead();
        TestConversions();
        TestIntervals();
    }
        
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestConversions ( void  ) [static]

Definition at line 80 of file inrval.c.

{
    PRIntervalTime ticks = PR_TicksPerSecond();

       if (debug_mode) {
    PR_fprintf(output, "PR_TicksPerSecond: %ld\n\n", ticks);
    PR_fprintf(output, "PR_SecondsToInterval(1): %ld\n", PR_SecondsToInterval(1));
    PR_fprintf(output, "PR_MillisecondsToInterval(1000): %ld\n", PR_MillisecondsToInterval(1000));
    PR_fprintf(output, "PR_MicrosecondsToInterval(1000000): %ld\n\n", PR_MicrosecondsToInterval(1000000));

    PR_fprintf(output, "PR_SecondsToInterval(3): %ld\n", PR_SecondsToInterval(3));
    PR_fprintf(output, "PR_MillisecondsToInterval(3000): %ld\n", PR_MillisecondsToInterval(3000));
    PR_fprintf(output, "PR_MicrosecondsToInterval(3000000): %ld\n\n", PR_MicrosecondsToInterval(3000000));

    PR_fprintf(output, "PR_IntervalToSeconds(%ld): %ld\n", ticks, PR_IntervalToSeconds(ticks));
    PR_fprintf(output, "PR_IntervalToMilliseconds(%ld): %ld\n", ticks, PR_IntervalToMilliseconds(ticks));
    PR_fprintf(output, "PR_IntervalToMicroseconds(%ld): %ld\n\n", ticks, PR_IntervalToMicroseconds(ticks));

    ticks *= 3;
    PR_fprintf(output, "PR_IntervalToSeconds(%ld): %ld\n", ticks, PR_IntervalToSeconds(ticks));
    PR_fprintf(output, "PR_IntervalToMilliseconds(%ld): %ld\n", ticks, PR_IntervalToMilliseconds(ticks));
    PR_fprintf(output, "PR_IntervalToMicroseconds(%ld): %ld\n\n", ticks, PR_IntervalToMicroseconds(ticks));
       } /*end debug mode */
}  /* TestConversions */

Here is the caller graph for this function:

static void TestIntervalOverhead ( void  ) [static]

Definition at line 105 of file inrval.c.

{
    /* Hopefully the optimizer won't delete this function */
    PRUint32 elapsed, per_call, loops = 1000000;

    PRIntervalTime timeout, timein = PR_IntervalNow();
    while (--loops > 0)
        timeout = PR_IntervalNow();

    elapsed = 1000U * PR_IntervalToMicroseconds(timeout - timein);
    per_call = elapsed / 1000000U;
    PR_fprintf(
        output, "Overhead of 'PR_IntervalNow()' is %u nsecs\n\n", per_call);
}  /* TestIntervalOverhead */

Here is the caller graph for this function:

static void TestIntervals ( void  ) [static]

Definition at line 141 of file inrval.c.

{
    PRStatus rv;
    PRUint32 delta;
    PRInt32 seconds;
    PRUint64 elapsed, thousand;
    PRTime timein, timeout;
    PRLock *ml = PR_NewLock();
    PRCondVar *cv = PR_NewCondVar(ml);
    for (seconds = 0; seconds < 10; ++seconds)
    {
        PRIntervalTime ticks = PR_SecondsToInterval(seconds);
        PR_Lock(ml);
        timein = PR_Now();
        rv = PR_WaitCondVar(cv, ticks);
        timeout = PR_Now();
        PR_Unlock(ml);
        LL_SUB(elapsed, timeout, timein);
        LL_I2L(thousand, 1000);
        LL_DIV(elapsed, elapsed, thousand);
        LL_L2UI(delta, elapsed);
        if (debug_mode) PR_fprintf(output, 
            "TestIntervals: %swaiting %ld seconds took %ld msecs\n",
            ((rv == PR_SUCCESS) ? "" : "FAILED "), seconds, delta);
    }
    PR_DestroyCondVar(cv);
    PR_DestroyLock(ml);
    if (debug_mode) PR_fprintf(output, "\n");
}  /* TestIntervals */

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestNowOverhead ( void  ) [static]

Definition at line 120 of file inrval.c.

{
    PRTime timeout, timein;
    PRInt32 overhead, loops = 1000000;
    PRInt64 elapsed, per_call, ten23rd, ten26th;

    LL_I2L(ten23rd, 1000);
    LL_I2L(ten26th, 1000000);

    timein = PR_Now();
    while (--loops > 0)
        timeout = PR_Now();

    LL_SUB(elapsed, timeout, timein);
    LL_MUL(elapsed, elapsed, ten23rd);
    LL_DIV(per_call, elapsed, ten26th);
    LL_L2I(overhead, per_call);
    PR_fprintf(
        output, "Overhead of 'PR_Now()' is %u nsecs\n\n", overhead);
}  /* TestNowOverhead */

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

PRIntn debug_mode [static]

Definition at line 76 of file inrval.c.

PRFileDesc* output [static]

Definition at line 77 of file inrval.c.