ck_pring
Samy Al Bahra 12 years ago
commit 7de2d45d1a

19
configure vendored

@ -419,10 +419,6 @@ else
VMA_BITS_VALUE_R="${VMA_BITS}ULL" VMA_BITS_VALUE_R="${VMA_BITS}ULL"
fi fi
# Platform will be used as a macro.
PROFILE="${PROFILE:-$PLATFORM}"
PLATFORM="__${PLATFORM}__"
# `which` on Solaris sucks # `which` on Solaris sucks
pathsearch() pathsearch()
{ {
@ -488,7 +484,10 @@ cat << EOF > .1.c
#include <stdio.h> #include <stdio.h>
int main(void) { int main(void) {
#if defined(_WIN32) #if defined(_WIN32)
#if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION >= 3) #if defined(__MINGW64__)
puts("mingw64");
return (0);
#elif defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION >= 3)
puts("mingw32"); puts("mingw32");
return (0); return (0);
#else #else
@ -525,7 +524,7 @@ if test "$COMPILER" = "suncc"; then
LDFLAGS="-G -z text -h libck.so.$VERSION_MAJOR $LDFLAGS" LDFLAGS="-G -z text -h libck.so.$VERSION_MAJOR $LDFLAGS"
CFLAGS="-xO5 $CFLAGS" CFLAGS="-xO5 $CFLAGS"
PTHREAD_CFLAGS="-mt -lpthread" PTHREAD_CFLAGS="-mt -lpthread"
elif test "$COMPILER" = "gcc" || test "$COMPILER" = "clang" || test "$COMPILER" = "mingw32"; then elif test "$COMPILER" = "gcc" || test "$COMPILER" = "clang" || test "$COMPILER" = "mingw32" || test "$COMPILER" = "mingw64"; then
LD=$CC LD=$CC
if test "$SYSTEM" = "darwin"; then if test "$SYSTEM" = "darwin"; then
CC_WL_OPT="-install_name" CC_WL_OPT="-install_name"
@ -535,6 +534,10 @@ elif test "$COMPILER" = "gcc" || test "$COMPILER" = "clang" || test "$COMPILER"
LDFLAGS="-shared -fPIC -Wl,$CC_WL_OPT,libck.so.$VERSION_MAJOR $LDFLAGS" LDFLAGS="-shared -fPIC -Wl,$CC_WL_OPT,libck.so.$VERSION_MAJOR $LDFLAGS"
CFLAGS="-D_XOPEN_SOURCE=600 -D_BSD_SOURCE -std=gnu99 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -fstrict-aliasing -O2 -pipe -Wno-parentheses $CFLAGS" CFLAGS="-D_XOPEN_SOURCE=600 -D_BSD_SOURCE -std=gnu99 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -fstrict-aliasing -O2 -pipe -Wno-parentheses $CFLAGS"
PTHREAD_CFLAGS="-pthread" PTHREAD_CFLAGS="-pthread"
if test "$COMPILER" = "mingw64"; then
ENVIRONMENT=64
PLATFORM=x86_64
fi
else else
assert "" "unknown compiler" assert "" "unknown compiler"
fi fi
@ -558,6 +561,10 @@ EOF
fi fi
done done
# Platform will be used as a macro.
PROFILE="${PROFILE:-$PLATFORM}"
PLATFORM="__${PLATFORM}__"
printf "Generating header files.........." printf "Generating header files.........."
generate include/ck_md.h.in include/ck_md.h generate include/ck_md.h.in include/ck_md.h
echo "success" echo "success"

@ -70,7 +70,7 @@ struct hs_epoch {
ck_epoch_entry_t epoch_entry; ck_epoch_entry_t epoch_entry;
}; };
COMMON_ALARM_DECLARE_GLOBAL(alarm_event, next_stage) COMMON_ALARM_DECLARE_GLOBAL(hs_alarm, alarm_event, next_stage)
static void static void
alarm_handler(int s) alarm_handler(int s)
@ -287,7 +287,7 @@ main(int argc, char *argv[])
pthread_t *readers; pthread_t *readers;
double p_r, p_d; double p_r, p_d;
COMMON_ALARM_DECLARE_LOCAL(alarm_event) COMMON_ALARM_DECLARE_LOCAL(hs_alarm, alarm_event)
r = 20; r = 20;
s = 8; s = 8;
@ -327,7 +327,7 @@ main(int argc, char *argv[])
} }
} }
COMMON_ALARM_INIT(alarm_event, r) COMMON_ALARM_INIT(hs_alarm, alarm_event, r)
affinerator.delta = 1; affinerator.delta = 1;
readers = malloc(sizeof(pthread_t) * n_threads); readers = malloc(sizeof(pthread_t) * n_threads);

@ -71,7 +71,7 @@ struct ht_epoch {
ck_epoch_entry_t epoch_entry; ck_epoch_entry_t epoch_entry;
}; };
COMMON_ALARM_DECLARE_GLOBAL(alarm_event, next_stage) COMMON_ALARM_DECLARE_GLOBAL(ht_alarm, alarm_event, next_stage)
static void static void
alarm_handler(int s) alarm_handler(int s)
@ -265,7 +265,7 @@ main(int argc, char *argv[])
pthread_t *readers; pthread_t *readers;
double p_r, p_d; double p_r, p_d;
COMMON_ALARM_DECLARE_LOCAL(alarm_event) COMMON_ALARM_DECLARE_LOCAL(ht_alarm, alarm_event)
r = 20; r = 20;
s = 8; s = 8;
@ -305,7 +305,7 @@ main(int argc, char *argv[])
} }
} }
COMMON_ALARM_INIT(alarm_event, r) COMMON_ALARM_INIT(ht_alarm, alarm_event, r)
affinerator.delta = 1; affinerator.delta = 1;
readers = malloc(sizeof(pthread_t) * n_threads); readers = malloc(sizeof(pthread_t) * n_threads);

@ -70,7 +70,7 @@ struct ht_epoch {
ck_epoch_entry_t epoch_entry; ck_epoch_entry_t epoch_entry;
}; };
COMMON_ALARM_DECLARE_GLOBAL(alarm_event, next_stage) COMMON_ALARM_DECLARE_GLOBAL(ht_alarm, alarm_event, next_stage)
static void static void
alarm_handler(int s) alarm_handler(int s)
@ -269,7 +269,7 @@ main(int argc, char *argv[])
pthread_t *readers; pthread_t *readers;
double p_r, p_d; double p_r, p_d;
COMMON_ALARM_DECLARE_LOCAL(alarm_event) COMMON_ALARM_DECLARE_LOCAL(ht_alarm, alarm_event)
r = 20; r = 20;
s = 8; s = 8;
@ -309,7 +309,7 @@ main(int argc, char *argv[])
} }
} }
COMMON_ALARM_INIT(alarm_event, r) COMMON_ALARM_INIT(ht_alarm, alarm_event, r)
affinerator.delta = 1; affinerator.delta = 1;
readers = malloc(sizeof(pthread_t) * n_threads); readers = malloc(sizeof(pthread_t) * n_threads);

@ -1,2 +1,6 @@
#include "../ck_ticket_pb.h" #include "../ck_ticket_pb.h"
#ifdef _WIN32
#undef ITERATE
#define ITERATE 1000
#endif
#include "validate.h" #include "validate.h"

@ -233,13 +233,17 @@ main(int argc, char *argv[])
for (i = 0; i < nthr; i++) for (i = 0; i < nthr; i++)
pthread_create(&thread[i], NULL, stack_thread, bucket + i); pthread_create(&thread[i], NULL, stack_thread, bucket + i);
gettimeofday(&stv, NULL); common_gettimeofday(&stv, NULL);
barrier = 1; barrier = 1;
for (i = 0; i < nthr; i++) for (i = 0; i < nthr; i++)
pthread_join(thread[i], NULL); pthread_join(thread[i], NULL);
gettimeofday(&etv, NULL); common_gettimeofday(&etv, NULL);
stack_assert(); stack_assert();
#ifdef _WIN32
printf("%3llu %.6f\n", nthr, TVTOD(etv) - TVTOD(stv));
#else
printf("%3llu %.6lf\n", nthr, TVTOD(etv) - TVTOD(stv)); printf("%3llu %.6lf\n", nthr, TVTOD(etv) - TVTOD(stv));
#endif
return 0; return 0;
} }

@ -253,13 +253,17 @@ main(int argc, char *argv[])
for (i = 0; i < nthr; i++) for (i = 0; i < nthr; i++)
pthread_create(&thread[i], NULL, stack_thread, NULL); pthread_create(&thread[i], NULL, stack_thread, NULL);
gettimeofday(&stv, NULL); common_gettimeofday(&stv, NULL);
barrier = 1; barrier = 1;
for (i = 0; i < nthr; i++) for (i = 0; i < nthr; i++)
pthread_join(thread[i], NULL); pthread_join(thread[i], NULL);
gettimeofday(&etv, NULL); common_gettimeofday(&etv, NULL);
stack_assert(); stack_assert();
#ifdef _WIN32
printf("%3llu %.6f\n", nthr, TVTOD(etv) - TVTOD(stv));
#else
printf("%3llu %.6lf\n", nthr, TVTOD(etv) - TVTOD(stv)); printf("%3llu %.6lf\n", nthr, TVTOD(etv) - TVTOD(stv));
#endif
return 0; return 0;
} }

@ -232,13 +232,17 @@ main(int argc, char *argv[])
for (i = 0; i < nthr; i++) for (i = 0; i < nthr; i++)
pthread_create(&thread[i], NULL, stack_thread, bucket + i * n); pthread_create(&thread[i], NULL, stack_thread, bucket + i * n);
gettimeofday(&stv, NULL); common_gettimeofday(&stv, NULL);
barrier = 1; barrier = 1;
for (i = 0; i < nthr; i++) for (i = 0; i < nthr; i++)
pthread_join(thread[i], NULL); pthread_join(thread[i], NULL);
gettimeofday(&etv, NULL); common_gettimeofday(&etv, NULL);
stack_assert(); stack_assert();
#ifdef _WIN32
printf("%3llu %.6f\n", nthr, TVTOD(etv) - TVTOD(stv));
#else
printf("%3llu %.6lf\n", nthr, TVTOD(etv) - TVTOD(stv)); printf("%3llu %.6lf\n", nthr, TVTOD(etv) - TVTOD(stv));
#endif
return 0; return 0;
} }

@ -37,14 +37,16 @@
#elif defined(__MACH__) #elif defined(__MACH__)
#include <mach/mach.h> #include <mach/mach.h>
#include <mach/thread_policy.h> #include <mach/thread_policy.h>
#include <unistd.h>
#endif #endif
#if defined(_WIN32) #if defined(_WIN32)
#include <assert.h> #include <assert.h>
#include <time.h>
#include <windows.h> #include <windows.h>
#define DELTA_EPOCH 11644473600000000ULL
#else #else
#include <signal.h> #include <signal.h>
#include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -128,6 +130,49 @@ common_sleep(unsigned int n)
#endif #endif
} }
CK_CC_INLINE static int
common_gettimeofday(struct timeval *tv, void *tz)
{
#ifdef _WIN32
FILETIME ft;
uint64_t tmp_time = 0;
static bool tzflag = false;
if (tv != NULL) {
GetSystemTimeAsFileTime(&ft);
tmp_time |= ft.dwHighDateTime;
tmp_time <<= 32;
tmp_time |= ft.dwLowDateTime;
/* GetSystemTimeAsFileTime returns 100 nanosecond intervals. */
tmp_time /= 10;
/* Windows' epoch starts on 01/01/1601, while Unix' starts on 01/01/1970. */
tmp_time -= DELTA_EPOCH;
tv->tv_sec = (long)(tmp_time / 1000000UL);
tv->tv_usec = (long)(tmp_time % 1000000UL);
}
if (tz != NULL) {
if (tzflag == false) {
_tzset();
tzflag = true;
}
struct timezone *tzp = (struct timezone *)tz;
tzp->tz_minuteswest = _timezone / 60;
tzp->tz_dsttime = _daylight;
}
return 0;
#else
return gettimeofday(tv, tz);
#endif
}
CK_CC_UNUSED static unsigned int CK_CC_UNUSED static unsigned int
common_alarm(void (*sig_handler)(int), void *alarm_event, unsigned int duration) common_alarm(void (*sig_handler)(int), void *alarm_event, unsigned int duration)
{ {
@ -150,55 +195,63 @@ common_alarm(void (*sig_handler)(int), void *alarm_event, unsigned int duration)
#ifndef SECOND_TIMER #ifndef SECOND_TIMER
#define SECOND_TIMER 10000000 #define SECOND_TIMER 10000000
#endif #endif
#define COMMON_ALARM_DECLARE_GLOBAL(alarm_event_name, flag_name) \ #define COMMON_ALARM_DECLARE_GLOBAL(prefix, alarm_event_name, flag_name) \
static HANDLE common_win_alarm_timer; \ static HANDLE prefix##_common_win_alarm_timer; \
static HANDLE alarm_event_name; \ static HANDLE alarm_event_name; \
static LARGE_INTEGER timer_length; \ static LARGE_INTEGER prefix##_common_alarm_timer_length; \
\ \
static void CALLBACK \ static void CALLBACK \
common_win_alarm_handler(LPVOID arg, DWORD timer_low_value, DWORD timer_high_value) \ prefix##_common_win_alarm_handler(LPVOID arg, DWORD timer_low_value, DWORD timer_high_value) \
{ \ { \
(void)arg; \ (void)arg; \
(void)timer_low_value; \ (void)timer_low_value; \
(void)timer_high_value; \ (void)timer_high_value; \
flag_name = true; \ flag_name = true; \
return; \ return; \
} \ } \
\ \
static void * \ static void * \
common_win_alarm(void *unused) \ prefix##_common_win_alarm(void *unused) \
{ \ { \
(void)unused; \ (void)unused; \
bool timer_success = false; \ bool timer_success = false; \
for (;;) { \ for (;;) { \
WaitForSingleObjectEx(alarm_event_name, INFINITE, true); \ WaitForSingleObjectEx(alarm_event_name, INFINITE, true); \
timer_success = SetWaitableTimer(common_win_alarm_timer, &timer_length, 0, common_win_alarm_handler, NULL, false); \ timer_success = SetWaitableTimer(prefix##_common_win_alarm_timer, \
assert(timer_success != false); \ &prefix##_common_alarm_timer_length, \
WaitForSingleObjectEx(common_win_alarm_timer, INFINITE, true); \ 0, \
} \ prefix##_common_win_alarm_handler, NULL, false); \
\ assert(timer_success != false); \
return NULL; \ WaitForSingleObjectEx(prefix##_common_win_alarm_timer, INFINITE, true); \
} \
\
return NULL; \
} }
#define COMMON_ALARM_DECLARE_LOCAL(alarm_event_name) \ #define COMMON_ALARM_DECLARE_LOCAL(prefix, alarm_event_name) \
__int64 tl; \ int64_t prefix##_common_alarm_tl; \
pthread_t common_win_alarm_thread; pthread_t prefix##_common_win_alarm_thread;
#define COMMON_ALARM_INIT(alarm_event_name, duration) \ #define COMMON_ALARM_INIT(prefix, alarm_event_name, duration) \
tl = -1 * duration * SECOND_TIMER; \ prefix##_common_alarm_tl = -1 * (duration) * SECOND_TIMER; \
timer_length.LowPart = (DWORD) (tl & 0xFFFFFFFF); \ prefix##_common_alarm_timer_length.LowPart = \
timer_length.HighPart = (LONG) (tl >> 32); \ (DWORD) (prefix##_common_alarm_tl & 0xFFFFFFFF); \
alarm_event_name = CreateEvent(NULL, false, false, NULL); \ prefix##_common_alarm_timer_length.HighPart = \
assert(alarm_event_name != NULL); \ (LONG) (prefix##_common_alarm_tl >> 32); \
common_win_alarm_timer = CreateWaitableTimer(NULL, true, NULL); \ alarm_event_name = CreateEvent(NULL, false, false, NULL); \
assert(common_win_alarm_timer != NULL); \ assert(alarm_event_name != NULL); \
if (pthread_create(&common_win_alarm_thread, NULL, common_win_alarm, NULL) != 0) \ prefix##_common_win_alarm_timer = CreateWaitableTimer(NULL, true, NULL); \
assert(prefix##_common_win_alarm_timer != NULL); \
if (pthread_create(&prefix##_common_win_alarm_thread, \
NULL, \
prefix##_common_win_alarm, \
NULL) != 0) \
ck_error("ERROR: Failed to create common_win_alarm thread.\n"); ck_error("ERROR: Failed to create common_win_alarm thread.\n");
#else #else
#define COMMON_ALARM_DECLARE_GLOBAL(alarm_event_name, flag_name) #define COMMON_ALARM_DECLARE_GLOBAL(prefix, alarm_event_name, flag_name)
#define COMMON_ALARM_DECLARE_LOCAL(alarm_event_name) \ #define COMMON_ALARM_DECLARE_LOCAL(prefix, alarm_event_name) \
int alarm_event_name = 0; int alarm_event_name = 0;
#define COMMON_ALARM_INIT(alarm_event_name, duration) #define COMMON_ALARM_INIT(prefix, alarm_event_name, duration)
#endif #endif
struct affinity { struct affinity {

Loading…
Cancel
Save