Commit b77ce225 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

port get_processor_frequency from 2.2.0 to main refs[t:2083]

git-svn-id: file:///svn/toku/tokudb@15130 c7de825b-a66e-492c-adef-691d508d4ae1
parent cda602c7
......@@ -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)
......
......@@ -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;
}
#include <stdio.h>
#include <assert.h>
#include <toku_stdint.h>
#include <toku_os.h>
int main(void) {
uint64_t cpuhz;
int r = toku_os_get_processor_frequency(&cpuhz);
assert(r == 0);
printf("%"PRIu64"\n", cpuhz);
return 0;
}
/* -*- 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
......
......@@ -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")));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment