Loading xlap.c +1 −0 Original line number Diff line number Diff line #define XLAP #include "xlap.h" #include <stdatomic.h> Loading xlap.h +100 −39 Original line number Diff line number Diff line Loading @@ -81,17 +81,25 @@ typedef struct XlapTimestampTableRow { /* * Table that stores timestamp table rows */ #ifdef XLAP typedef struct XlapTimestampTable { XlapTimestampTableRow rows[TS_ROWS]; } XlapTimestampTable; #else /* XLAP */ typedef char XlapTimestampTable; #endif /* * Dummy data structure to store a single timestamp table row. */ #ifdef XLAP typedef struct XlapTimestampPlaceholder { _Atomic(XlapTimestampTable *) tstable[1]; XlapTimestampTableRow rows[1]; } XlapTimestampPlaceholder; #else /* XLAP */ typedef char XlapTimestampPlaceholder; #endif /* * update the clock value of a timestamp Loading @@ -99,9 +107,19 @@ typedef struct XlapTimestampPlaceholder { * This macro will cause a SIGSEGV if the application does not install a * timestamp table to the socket. */ #ifdef XLAP # define XlapTimeStampClock(sck, kind, seqno, id) do { \ clock_gettime(CLOCK_MONOTONIC, &atomic_load_explicit(&(sck)->tstable[kind], memory_order_acquire)->rows[(seqno) % TS_ROWS].time[ts_##id].actual.t); \ } while (0); } while (0) #else /* XLAP */ # define XlapTimeStampClock(sck, kind, seqno, id) do { \ (void) (sck); \ (void) (kind); \ (void) (seqno); \ (void) (ts_##id); \ } while (0) #endif /* * update the cycle value of a timestamp Loading @@ -109,42 +127,76 @@ typedef struct XlapTimestampPlaceholder { * This macro will cause a SIGSEGV if the application does not install a * timestamp table to the socket. */ #ifdef XLAP # define XlapTimeStampCycle(sck, kind, seqno, id) do { \ atomic_load_explicit(&(sck)->tstable[kind], memory_order_acquire)->rows[(seqno) % TS_ROWS].time[ts_##id].actual.c = __builtin_ia32_rdtsc(); \ } while (0); } while (0) #else /* XLAP */ # define XlapTimeStampCycle(sck, kind, seqno, id) do { \ (void) (sck); \ (void) (kind); \ (void) (seqno); \ (void) (ts_##id); \ } while (0) #endif /* * install a time stamp table to a socket */ #ifdef XLAP # define XlapTimestampTableInstall(sck, kind, tstp) do { \ XlapTimestampTable *__tstp = (tstp); \ memset(__tstp, 0, sizeof(XlapTimestampTable)); \ atomic_store_explicit(&(sck)->tstable[kind], __tstp, memory_order_release); \ } while (0) #else /* XLAP */ # define XlapTimestampTableInstall(sck, kind, tstp) do { \ (void) (sck); \ (void) (kind); \ (void) (tstp); \ } while (0) #endif /* * print a timestamp dump header */ #ifdef XLAP extern void XlapTimestampTableDumpHeader(FILE *); #else # define XlapTimestampTableDumpHeader(f) do { \ (void) (f); \ } while (0) #endif /* * dump a timestamp table */ #ifdef XLAP extern void XlapTimestampTableDump(FILE *, XlapTimestampPacketKind, XlapTimestampTable *); /* * use a specific timestamp table */ extern void XlapTimestampTableUse(XlapTimestampTable *); #else # define XlapTimestampTableDump(f, k, t) do { \ (void) (f); \ (void) (k); \ (void) (t); \ } while (0) #endif /* * intialize a timestamp table placeholder */ #ifdef XLAP # define XlapTimestampPlaceholderInitialize(ph) do { \ XlapTimestampPlaceholder *__ph = (ph); \ atomic_store_explicit(&__ph->tstable[0], (XlapTimestampTable *) &__ph->rows, memory_order_release); \ memset(&__ph->rows, 0x0, sizeof(XlapTimestampTableRow)); \ } while (0); } while (0) #else # define XlapTimestampPlaceholderInitialize(ph) do { \ (void) (ph); \ } while (0) #endif /* * copy a timestamp table placeholder into an actual timestamp table Loading @@ -152,6 +204,7 @@ extern void XlapTimestampTableUse(XlapTimestampTable *); * Since every timestamp is taken at most once, either the timestamptable or * the placeholder value must be zero (for each timestamp). */ #ifdef XLAP # define XlapTimestampPlaceholderUse(sck, kind, seqno, ph) do { \ XlapTimestampPlaceholder *__ph = (ph); \ XlapTimestampTable *__ts = atomic_load_explicit(&(sck)->tstable[kind], memory_order_acquire); \ Loading @@ -161,5 +214,13 @@ extern void XlapTimestampTableUse(XlapTimestampTable *); __ts->rows[seqno % TS_ROWS].time[__t].actual.c += __ph->rows[0].time[__t].actual.c; \ } \ } while (0) #else # define XlapTimestampPlaceholderUse(sck, kind, seqno, ph) do { \ (void) (sck); \ (void) (kind); \ (void) (seqno); \ (void) (ph); \ } while (0) #endif #endif // XLAP_H Loading
xlap.c +1 −0 Original line number Diff line number Diff line #define XLAP #include "xlap.h" #include <stdatomic.h> Loading
xlap.h +100 −39 Original line number Diff line number Diff line Loading @@ -81,17 +81,25 @@ typedef struct XlapTimestampTableRow { /* * Table that stores timestamp table rows */ #ifdef XLAP typedef struct XlapTimestampTable { XlapTimestampTableRow rows[TS_ROWS]; } XlapTimestampTable; #else /* XLAP */ typedef char XlapTimestampTable; #endif /* * Dummy data structure to store a single timestamp table row. */ #ifdef XLAP typedef struct XlapTimestampPlaceholder { _Atomic(XlapTimestampTable *) tstable[1]; XlapTimestampTableRow rows[1]; } XlapTimestampPlaceholder; #else /* XLAP */ typedef char XlapTimestampPlaceholder; #endif /* * update the clock value of a timestamp Loading @@ -99,9 +107,19 @@ typedef struct XlapTimestampPlaceholder { * This macro will cause a SIGSEGV if the application does not install a * timestamp table to the socket. */ #ifdef XLAP # define XlapTimeStampClock(sck, kind, seqno, id) do { \ clock_gettime(CLOCK_MONOTONIC, &atomic_load_explicit(&(sck)->tstable[kind], memory_order_acquire)->rows[(seqno) % TS_ROWS].time[ts_##id].actual.t); \ } while (0); } while (0) #else /* XLAP */ # define XlapTimeStampClock(sck, kind, seqno, id) do { \ (void) (sck); \ (void) (kind); \ (void) (seqno); \ (void) (ts_##id); \ } while (0) #endif /* * update the cycle value of a timestamp Loading @@ -109,42 +127,76 @@ typedef struct XlapTimestampPlaceholder { * This macro will cause a SIGSEGV if the application does not install a * timestamp table to the socket. */ #ifdef XLAP # define XlapTimeStampCycle(sck, kind, seqno, id) do { \ atomic_load_explicit(&(sck)->tstable[kind], memory_order_acquire)->rows[(seqno) % TS_ROWS].time[ts_##id].actual.c = __builtin_ia32_rdtsc(); \ } while (0); } while (0) #else /* XLAP */ # define XlapTimeStampCycle(sck, kind, seqno, id) do { \ (void) (sck); \ (void) (kind); \ (void) (seqno); \ (void) (ts_##id); \ } while (0) #endif /* * install a time stamp table to a socket */ #ifdef XLAP # define XlapTimestampTableInstall(sck, kind, tstp) do { \ XlapTimestampTable *__tstp = (tstp); \ memset(__tstp, 0, sizeof(XlapTimestampTable)); \ atomic_store_explicit(&(sck)->tstable[kind], __tstp, memory_order_release); \ } while (0) #else /* XLAP */ # define XlapTimestampTableInstall(sck, kind, tstp) do { \ (void) (sck); \ (void) (kind); \ (void) (tstp); \ } while (0) #endif /* * print a timestamp dump header */ #ifdef XLAP extern void XlapTimestampTableDumpHeader(FILE *); #else # define XlapTimestampTableDumpHeader(f) do { \ (void) (f); \ } while (0) #endif /* * dump a timestamp table */ #ifdef XLAP extern void XlapTimestampTableDump(FILE *, XlapTimestampPacketKind, XlapTimestampTable *); /* * use a specific timestamp table */ extern void XlapTimestampTableUse(XlapTimestampTable *); #else # define XlapTimestampTableDump(f, k, t) do { \ (void) (f); \ (void) (k); \ (void) (t); \ } while (0) #endif /* * intialize a timestamp table placeholder */ #ifdef XLAP # define XlapTimestampPlaceholderInitialize(ph) do { \ XlapTimestampPlaceholder *__ph = (ph); \ atomic_store_explicit(&__ph->tstable[0], (XlapTimestampTable *) &__ph->rows, memory_order_release); \ memset(&__ph->rows, 0x0, sizeof(XlapTimestampTableRow)); \ } while (0); } while (0) #else # define XlapTimestampPlaceholderInitialize(ph) do { \ (void) (ph); \ } while (0) #endif /* * copy a timestamp table placeholder into an actual timestamp table Loading @@ -152,6 +204,7 @@ extern void XlapTimestampTableUse(XlapTimestampTable *); * Since every timestamp is taken at most once, either the timestamptable or * the placeholder value must be zero (for each timestamp). */ #ifdef XLAP # define XlapTimestampPlaceholderUse(sck, kind, seqno, ph) do { \ XlapTimestampPlaceholder *__ph = (ph); \ XlapTimestampTable *__ts = atomic_load_explicit(&(sck)->tstable[kind], memory_order_acquire); \ Loading @@ -161,5 +214,13 @@ extern void XlapTimestampTableUse(XlapTimestampTable *); __ts->rows[seqno % TS_ROWS].time[__t].actual.c += __ph->rows[0].time[__t].actual.c; \ } \ } while (0) #else # define XlapTimestampPlaceholderUse(sck, kind, seqno, ph) do { \ (void) (sck); \ (void) (kind); \ (void) (seqno); \ (void) (ph); \ } while (0) #endif #endif // XLAP_H