improve portability by removing rdtsc calls

https://github.com/vysheng/tg/issues/8
This commit is contained in:
antma 2014-01-15 19:29:26 +04:00
parent 4b6870f048
commit 22c1a41109
3 changed files with 7 additions and 14 deletions

View File

@ -90,14 +90,13 @@ struct connection_methods auth_methods = {
};
long long precise_time;
long long precise_time_rdtsc;
double get_utime (int clock_id) {
struct timespec T;
my_clock_gettime (clock_id, &T);
double res = T.tv_sec + (double) T.tv_nsec * 1e-9;
if (clock_id == CLOCK_REALTIME) {
precise_time = (long long) (res * (1LL << 32));
precise_time_rdtsc = rdtsc ();
}
return res;
}

View File

@ -67,6 +67,9 @@ int get_random_bytes (unsigned char *buf, int n) {
}
}
close (h);
if (r < 0) {
r = 0;
}
}
if (r < n) {
@ -105,18 +108,15 @@ void my_clock_gettime (int clock_id UU, struct timespec *T) {
#endif
}
void prng_seed (const char *password_filename, int password_length) {
unsigned char *a = talloc0 (64 + password_length);
long long r = rdtsc ();
struct timespec T;
my_clock_gettime (CLOCK_REALTIME, &T);
memcpy (a, &T.tv_sec, 4);
memcpy (a+4, &T.tv_nsec, 4);
memcpy (a+8, &r, 8);
memcpy (a + 4, &T.tv_nsec, 4);
unsigned short p = getpid ();
memcpy (a + 16, &p, 2);
int s = get_random_bytes (a + 18, 32) + 18;
memcpy (a + 8, &p, 2);
int s = get_random_bytes (a + 10, 32) + 10;
if (password_filename) {
int fd = open (password_filename, O_RDONLY);
if (fd < 0) {

View File

@ -375,12 +375,6 @@ static inline void fetch_skip_str (void) {
fetch_str (l);
}
static __inline__ unsigned long long rdtsc(void) {
unsigned hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
}
static inline long have_prefetch_ints (void) {
return in_end - in_ptr;
}