SLJ Test  1.0
System Latency Jitter Test
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Typedefs | Functions | Variables
sljtest.c File Reference

System Latency Jitter Test. More...

#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>
#include "replgetopt.h"

Go to the source code of this file.

Classes

struct  args_stct
struct  bin_stct
struct  outlier_stct

Macros

#define _GNU_SOURCE
#define SLEEP_SEC(x)   sleep(x)
#define SLEEP_MSEC(x)
#define DEF_BINS   20
#define DEF_CPU   NULL
#define DEF_OUTFILE   NULL
#define DEF_KNEE   50
#define DEF_MIN   10
#define DEF_OUTBUF   10000
#define DEF_PAUSE   0
#define DEF_RUNTIME   1
#define DEF_SUM   0
#define DEF_LINEWID   79
#define rdtsc(x)
 Read value of TSC into a uint64_t.
#define ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define RET_MAX_LEN   10 /* Maximum length of return string */
 sprintf() to a malloc()'d string

Typedefs

typedef struct args_stct args_t
typedef struct bin_stct bin_t
typedef struct outlier_stct outlier_t

Functions

 asprintf (char **ret, const char *format,...)
char * t2ts (uint64_t ticks, double tpns)
 Convert a number of TSC ticks to a time string easily human readable.
int args_parse (int argc, char *argv[])
void outliers_setup ()
 Allocate memory and open file for outliers logging.
void histo_setup ()
int main (int argc, char *argv[])
 Measure and visualize system latency jitter.

Variables

args_t args
struct option OptTable []
const char * OptString = "b:f:hk:m:o:p:r:sw:"
const char * usage = "[-b bins] [-f file] [-h] [-k knee] [-m min] [-o outbuf] [-p pause] [-r runtime] [-s] [-w width]"
const char * version = "SLJ Test 1.0"
bin_thisto
outlier_toutbuf = NULL
FILE * outfile = NULL

Detailed Description

System Latency Jitter Test.

Author
Robert A. Van Valzah - Informatica Corporation

System Latency Jitter Test - Measure and visualize system latency jitter

See accompanying PDF or HTML renderings of doc, or see doc input at end of this file

Termnology used in the source: Ticks: One tick is the time taken for the Time Stamp Counter (TSC) on x86 processors to advance one count. The inverse of the CPU clock frequency is the time taken for one TSC tick in seconds.

Timestamp: One reading of TSC.

Block of timestamps: Timestamps taken in sequence to keep control flow uninterupted by branches. Statistics and logging are done after the block. This maximizes cache hit rates and keeps the CPU executing at full speed.

Delta: The difference between the TSC on two sequential readings.

Bin: One entry in the histogram table

Knee: The midpoint in the number of histogram bins: 1/2 the bins below the knee, 1/2 the bins above the knee. Bins spacing steps linearaly below the knee and exponentially above it.

ToDo Taskset CPU affiinity Maybe option to run many threads at once? Better comments on data structures and algoriths Break up main() so it's not so long

(c) Copyright 2011, 2012 Informatica Corp. Robert A. Van Valzah, October 2011, February 2012, October 2012

Acknowledgements Inspired by David Riddoch of Solarflare Idea for -s flag to sum deltas into histogram bins instead of just counting them from Erez Strauss

License Redistribution and use in source and binary forms, with or without modification, are permitted without restriction. The author will be disappointed if you use this software for making war, mulching babies, or improving systems running competing messaging software.

Disclaimers

THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF THE LIKELIHOOD OF SUCH DAMAGES.

Definition in file sljtest.c.

Macro Definition Documentation

#define _GNU_SOURCE

Has side effect of declaring asprintf()

Definition at line 75 of file sljtest.c.

#define ARRAY_SIZE (   a)    (sizeof(a)/sizeof(a[0]))

Size of array a in elements

Definition at line 160 of file sljtest.c.

#define DEF_BINS   20

DEFault number of histogram BINS

Definition at line 129 of file sljtest.c.

#define DEF_CPU   NULL

DEFault CPU affinity

Definition at line 131 of file sljtest.c.

#define DEF_KNEE   50

DEFault KNEE value (ticks)

Definition at line 135 of file sljtest.c.

#define DEF_LINEWID   79

DEFault maximum output LINE WIDth

Definition at line 147 of file sljtest.c.

#define DEF_MIN   10

DEFault MINimum delta (ticks)

Definition at line 137 of file sljtest.c.

#define DEF_OUTBUF   10000

DEFault OUTlier BUFfer

Definition at line 139 of file sljtest.c.

#define DEF_OUTFILE   NULL

DEFault OUTput FILEname

Definition at line 133 of file sljtest.c.

#define DEF_PAUSE   0

DEFault PAUSE time before each block in microseconds

Definition at line 141 of file sljtest.c.

#define DEF_RUNTIME   1

DEFault RUN TIME in seconds

Definition at line 143 of file sljtest.c.

#define DEF_SUM   0

DEFault SUM mode

Definition at line 145 of file sljtest.c.

#define rdtsc (   x)
Value:
do { \
uint32_t hi, lo; \
asm volatile ("rdtsc" : "=a" (lo), "=d" (hi)); \
x = (uint64_t)hi << 32 | lo; \
} while (0)

Read value of TSC into a uint64_t.

Parameters
xA uint64_t to receive the TSC value

Definition at line 152 of file sljtest.c.

#define RET_MAX_LEN   10 /* Maximum length of return string */

sprintf() to a malloc()'d string

Parameters
retPointer to char * where output string will be returned
formatprintf()-style format string
...Optional arguments a la printf()
Returns
0

Our own hack version of asprintf() for platforms that don't have it. I'm looking at you Solaris.

Definition at line 295 of file sljtest.c.

#define SLEEP_MSEC (   x)
Value:
do{ \
if ((x) >= 1000){ \
sleep((x) / 1000); \
usleep((x) % 1000 * 1000); \
} \
else{ \
usleep((x)*1000); \
} \
}while (0)

Waste time for x microseconds

Definition at line 115 of file sljtest.c.

#define SLEEP_SEC (   x)    sleep(x)

Waste time for x seconds

Definition at line 113 of file sljtest.c.

Typedef Documentation

typedef struct args_stct args_t

Command line argument values

typedef struct bin_stct bin_t

Type for histogram table

typedef struct outlier_stct outlier_t

Type for outlier buffer entry

Function Documentation

int args_parse ( int  argc,
char *  argv[] 
)

Definition at line 339 of file sljtest.c.

asprintf ( char **  ret,
const char *  format,
  ... 
)

Definition at line 296 of file sljtest.c.

void histo_setup ( )

Definition at line 408 of file sljtest.c.

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

Measure and visualize system latency jitter.

Parameters
argcCount of arguments
argvArgument vector

Definition at line 449 of file sljtest.c.

void outliers_setup ( )

Allocate memory and open file for outliers logging.

Definition at line 394 of file sljtest.c.

char* t2ts ( uint64_t  ticks,
double  tpns 
)

Convert a number of TSC ticks to a time string easily human readable.

Parameters
ticksTicks to be converted.
tpnsTicks per nanosecond as measured for this system.

Value is scaled to nanoseconds, microseconds, milliseconds, or seconds. Returns a malloc()'d string, so caller must free() or leak.

Definition at line 319 of file sljtest.c.

Variable Documentation

args_t args
Initial value:

Command line argument values

Definition at line 207 of file sljtest.c.

bin_t* histo

Histogram table of timestamp deltas

Definition at line 252 of file sljtest.c.

const char* OptString = "b:f:hk:m:o:p:r:sw:"

Definition at line 244 of file sljtest.c.

struct option OptTable[]
Initial value:
{
{"bins", required_argument, NULL, 'b'},
{"outfile", required_argument, NULL, 'f'},
{"help", no_argument, NULL, 'h'},
{"knee", required_argument, NULL, 'k'},
{"min", required_argument, NULL, 'm'},
{"outbuf", required_argument, NULL, 'o'},
{"pause", required_argument, NULL, 'p'},
{"runtime", required_argument, NULL, 'r'},
{"sum", no_argument, NULL, 's'},
{"width", required_argument, NULL, 'w'},
}

Command line options for getopt()

Definition at line 223 of file sljtest.c.

outlier_t* outbuf = NULL

Ring BUFfer of recent OUTliers

Definition at line 255 of file sljtest.c.

FILE* outfile = NULL

FILE where we write OUTliers

Definition at line 257 of file sljtest.c.

const char* usage = "[-b bins] [-f file] [-h] [-k knee] [-m min] [-o outbuf] [-p pause] [-r runtime] [-s] [-w width]"

Definition at line 245 of file sljtest.c.

const char* version = "SLJ Test 1.0"

Note that Makefile parses the following line to extract version number

Definition at line 249 of file sljtest.c.