mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 14:54:20 +01:00
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
This commit is contained in:
parent
07ac9b0dc2
commit
6e3ddb3d14
5 changed files with 71 additions and 4 deletions
|
@ -13,14 +13,13 @@ OBJS = $(patsubst %.c,%.$(OEXT),$(SRCS))
|
||||||
TARGET = libtokuportability.$(AEXT)
|
TARGET = libtokuportability.$(AEXT)
|
||||||
|
|
||||||
build install: $(LIBPORTABILITY)
|
build install: $(LIBPORTABILITY)
|
||||||
cd tests;$(MAKE) build
|
|
||||||
|
|
||||||
$(LIBPORTABILITY): $(TARGET)
|
$(LIBPORTABILITY): $(TARGET)
|
||||||
if ! diff $< $@ 2>/dev/null; then cp $< $@; fi
|
if ! diff $< $@ 2>/dev/null; then cp $< $@; fi
|
||||||
|
|
||||||
$(TARGET): $(OBJS)
|
$(TARGET): $(OBJS)
|
||||||
|
|
||||||
$(OBJS): CFLAGS += -DTOKU_ALLOW_DEPRECATED
|
$(OBJS): CFLAGS += -DTOKU_ALLOW_DEPRECATED -D_GNU_SOURCE
|
||||||
#Blank on purpose
|
#Blank on purpose
|
||||||
|
|
||||||
check: $(TARGET)
|
check: $(TARGET)
|
||||||
|
|
|
@ -226,3 +226,31 @@ toku_fstat(int fd, toku_struct_stat *buf) {
|
||||||
return r;
|
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;
|
||||||
|
}
|
||||||
|
|
12
linux/tests/test-cpu-freq.c
Normal file
12
linux/tests/test-cpu-freq.c
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*- mode: C; c-basic-offset: 4 -*- */
|
/* -*- mode: C; c-basic-offset: 4 -*- */
|
||||||
#ident "$Id: brt.c 10921 2009-04-01 16:54:40Z yfogel $"
|
#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
|
#ifndef _TOKU_PTHREAD_H
|
||||||
#define _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_cond_t toku_pthread_cond_t;
|
||||||
typedef pthread_rwlock_t toku_pthread_rwlock_t;
|
typedef pthread_rwlock_t toku_pthread_rwlock_t;
|
||||||
typedef pthread_rwlockattr_t toku_pthread_rwlockattr_t;
|
typedef pthread_rwlockattr_t toku_pthread_rwlockattr_t;
|
||||||
|
typedef pthread_key_t toku_pthread_key_t;
|
||||||
typedef struct timespec toku_timespec_t;
|
typedef struct timespec toku_timespec_t;
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
@ -105,7 +106,10 @@ int toku_pthread_mutex_lock(toku_pthread_mutex_t *mutex) {
|
||||||
return pthread_mutex_lock(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
|
static inline
|
||||||
int toku_pthread_mutex_unlock(toku_pthread_mutex_t *mutex) {
|
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);
|
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)
|
#if defined(__cplusplus)
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,6 +25,10 @@ int toku_os_get_pagesize(void);
|
||||||
// Returns: the size of physical memory (in bytes)
|
// Returns: the size of physical memory (in bytes)
|
||||||
uint64_t toku_os_get_phys_memory_size(void);
|
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
|
// Returns: 0 on success
|
||||||
// sets fsize to the number of bytes in a file
|
// sets fsize to the number of bytes in a file
|
||||||
int toku_os_get_file_size(int fildes, int64_t *fsize) __attribute__((__visibility__("default")));
|
int toku_os_get_file_size(int fildes, int64_t *fsize) __attribute__((__visibility__("default")));
|
||||||
|
|
Loading…
Add table
Reference in a new issue