| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include <stdio.h> |
| 22 |
#include <stdlib.h> |
| 23 |
#include <dlfcn.h> |
| 24 |
#include <errno.h> |
| 25 |
#include <string.h> |
| 26 |
#include "stopwatch.h" |
| 27 |
|
| 28 |
|
| 29 |
#define DYNSOROUTINE "sx_cputime" |
| 30 |
#define DYNSONAME "./so_syx.so" |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#ifndef NONSHARED |
| 35 |
|
| 36 |
static void *sx_object = NULL; |
| 37 |
static void closesx (void); |
| 38 |
|
| 39 |
int |
| 40 |
callsx (int k) |
| 41 |
{ |
| 42 |
int i; |
| 43 |
char buf[1024]; |
| 44 |
char *p; |
| 45 |
char *q = DYNSONAME; |
| 46 |
int errnum; |
| 47 |
|
| 48 |
hrtime_t start = gethrtime (); |
| 49 |
hrtime_t vstart = gethrvtime (); |
| 50 |
|
| 51 |
|
| 52 |
wlog ("start of callsx", NULL); |
| 53 |
|
| 54 |
|
| 55 |
if (sx_object != NULL) |
| 56 |
{ |
| 57 |
fprintf (stderr, "Execution error -- callsx: sx_object already linked\n"); |
| 58 |
return 0; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
sx_object = NULL; |
| 64 |
while (sx_object == NULL) |
| 65 |
{ |
| 66 |
sx_object = dlopen (DYNSONAME, RTLD_NOW); |
| 67 |
if (sx_object != NULL) |
| 68 |
break; |
| 69 |
p = dlerror (); |
| 70 |
if (q == NULL) q = "DYNSONAME"; |
| 71 |
if (p == NULL) p = "dlerror() returns NULL"; |
| 72 |
errnum = errno; |
| 73 |
if (errnum == EINTR) |
| 74 |
continue; |
| 75 |
else |
| 76 |
{ |
| 77 |
fprintf (stderr, "Execution error -- callso: dlopen of %s failed--%s, errno=%d (%s)\n", |
| 78 |
q, p, errnum, strerror (errnum)); |
| 79 |
return (0); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
int (*sx_routine)() = (int (*)())dlsym (sx_object, DYNSOROUTINE); |
| 85 |
if (sx_routine == NULL) |
| 86 |
{ |
| 87 |
fprintf (stderr, "Execution error -- callsx: dlsym %s not found\n", |
| 88 |
DYNSOROUTINE); |
| 89 |
return (0); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
long long count = 0; |
| 94 |
do |
| 95 |
{ |
| 96 |
i = (*sx_routine)(); |
| 97 |
count++; |
| 98 |
} |
| 99 |
while (start + testtime * 1e9 > gethrtime ()); |
| 100 |
|
| 101 |
closesx (); |
| 102 |
sprintf (buf, "end of callsx, %s returned %d", DYNSOROUTINE, i); |
| 103 |
wlog (buf, NULL); |
| 104 |
fprintf (stderr, " Performed %lld while-loop iterations\n", count); |
| 105 |
whrvlog ((gethrtime () - start), (gethrvtime () - vstart), "callsx", NULL); |
| 106 |
return 0; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
void |
| 111 |
closesx (void) |
| 112 |
{ |
| 113 |
|
| 114 |
wlog ("start of closesx", NULL); |
| 115 |
|
| 116 |
|
| 117 |
if (sx_object == NULL) |
| 118 |
{ |
| 119 |
fprintf (stderr, "Execution error -- closesx: sx_object not linked\n"); |
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
#if 0 |
| 124 |
|
| 125 |
rc = dlclose (sx_object); |
| 126 |
if (rc != 0) |
| 127 |
{ |
| 128 |
fprintf (stderr, "Execution error -- closesx: dlclose() failed--%s\n", |
| 129 |
dlerror ()); |
| 130 |
return; |
| 131 |
} |
| 132 |
|
| 133 |
sx_object = NULL; |
| 134 |
#endif |
| 135 |
wlog ("end of closesx", NULL); |
| 136 |
return; |
| 137 |
} |
| 138 |
|
| 139 |
#else |
| 140 |
|
| 141 |
int |
| 142 |
callsx (int i) |
| 143 |
{ |
| 144 |
return 0; |
| 145 |
} |
| 146 |
|
| 147 |
void |
| 148 |
closesx (void) |
| 149 |
{ |
| 150 |
return; |
| 151 |
} |
| 152 |
#endif |