diff --git a/linux/Makefile b/linux/Makefile index 43395306855..dc7830a3a85 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -13,14 +13,13 @@ OBJS = $(patsubst %.c,%.$(OEXT),$(SRCS)) TARGET = libtokuportability.$(AEXT) build install: $(LIBPORTABILITY) - cd tests;$(MAKE) build $(LIBPORTABILITY): $(TARGET) if ! diff $< $@ 2>/dev/null; then cp $< $@; fi $(TARGET): $(OBJS) -$(OBJS): CFLAGS += -DTOKU_ALLOW_DEPRECATED +$(OBJS): CFLAGS += -DTOKU_ALLOW_DEPRECATED -D_GNU_SOURCE #Blank on purpose check: $(TARGET) diff --git a/linux/linux.c b/linux/linux.c index 51201b42f41..9adedbb2acb 100644 --- a/linux/linux.c +++ b/linux/linux.c @@ -226,3 +226,31 @@ toku_fstat(int fd, toku_struct_stat *buf) { return r; } +int +toku_os_get_processor_frequency(uint64_t *hzret) { + int r; + FILE *fp = fopen("/proc/cpuinfo", "r"); + if (!fp) { + r = errno; + } else { + uint64_t maxhz = 0; + char *buf = NULL; + size_t n = 0; + while (getline(&buf, &n, fp) >= 0) { + unsigned int cpu; + sscanf(buf, "processor : %u", &cpu); + unsigned int ma, mb; + if (sscanf(buf, "cpu MHz : %d.%d", &ma, &mb) == 2) { + uint64_t hz = ma * 1000000ULL + mb * 1000ULL; + if (hz > maxhz) + maxhz = hz; + } + } + if (buf) + free(buf); + fclose(fp); + *hzret = maxhz; + r = maxhz == 0 ? ENOENT : 0;; + } + return r; +} diff --git a/linux/tests/test-cpu-freq.c b/linux/tests/test-cpu-freq.c new file mode 100644 index 00000000000..9c35ec28ef7 --- /dev/null +++ b/linux/tests/test-cpu-freq.c @@ -0,0 +1,12 @@ +#include +#include +#include +#include + +int main(void) { + uint64_t cpuhz; + int r = toku_os_get_processor_frequency(&cpuhz); + assert(r == 0); + printf("%"PRIu64"\n", cpuhz); + return 0; +} diff --git a/linux/toku_pthread.h b/linux/toku_pthread.h index 44c2331ff75..11b547fe64f 100644 --- a/linux/toku_pthread.h +++ b/linux/toku_pthread.h @@ -1,6 +1,6 @@ /* -*- mode: C; c-basic-offset: 4 -*- */ #ident "$Id: brt.c 10921 2009-04-01 16:54:40Z yfogel $" -#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." +#ident "Copyright (c) 2007-2009 Tokutek Inc. All rights reserved." #ifndef _TOKU_PTHREAD_H #define _TOKU_PTHREAD_H @@ -19,6 +19,7 @@ typedef pthread_condattr_t toku_pthread_condattr_t; typedef pthread_cond_t toku_pthread_cond_t; typedef pthread_rwlock_t toku_pthread_rwlock_t; typedef pthread_rwlockattr_t toku_pthread_rwlockattr_t; +typedef pthread_key_t toku_pthread_key_t; typedef struct timespec toku_timespec_t; static inline int @@ -105,7 +106,10 @@ int toku_pthread_mutex_lock(toku_pthread_mutex_t *mutex) { return pthread_mutex_lock(mutex); } -int toku_pthread_mutex_trylock(toku_pthread_mutex_t *mutex); +static inline +int toku_pthread_mutex_trylock(toku_pthread_mutex_t *mutex) { + return pthread_mutex_trylock(mutex); +} static inline int toku_pthread_mutex_unlock(toku_pthread_mutex_t *mutex) { @@ -142,6 +146,26 @@ int toku_pthread_cond_broadcast(toku_pthread_cond_t *cond) { return pthread_cond_broadcast(cond); } +static inline +int toku_pthread_key_create(toku_pthread_key_t *key, void (*destroyf)(void *)) { + return pthread_key_create(key, destroyf); +} + +static inline +int toku_pthread_key_delete(toku_pthread_key_t key) { + return pthread_key_delete(key); +} + +static inline +void *toku_pthread_getspecific(toku_pthread_key_t key) { + return pthread_getspecific(key); +} + +static inline +int toku_pthread_setspecific(toku_pthread_key_t key, void *data) { + return pthread_setspecific(key, data); +} + #if defined(__cplusplus) }; #endif diff --git a/toku_include/toku_os.h b/toku_include/toku_os.h index 55174392067..b54c128aaa4 100644 --- a/toku_include/toku_os.h +++ b/toku_include/toku_os.h @@ -25,6 +25,10 @@ int toku_os_get_pagesize(void); // Returns: the size of physical memory (in bytes) uint64_t toku_os_get_phys_memory_size(void); +// Returns the processor frequency in Hz +// Returns 0 if success +int toku_os_get_processor_frequency(uint64_t *hz); + // Returns: 0 on success // sets fsize to the number of bytes in a file int toku_os_get_file_size(int fildes, int64_t *fsize) __attribute__((__visibility__("default")));