improve portability by removing rdtsc calls
https://github.com/vysheng/tg/issues/8
This commit is contained in:
parent
4b6870f048
commit
22c1a41109
@ -90,14 +90,13 @@ struct connection_methods auth_methods = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
long long precise_time;
|
long long precise_time;
|
||||||
long long precise_time_rdtsc;
|
|
||||||
double get_utime (int clock_id) {
|
double get_utime (int clock_id) {
|
||||||
struct timespec T;
|
struct timespec T;
|
||||||
my_clock_gettime (clock_id, &T);
|
my_clock_gettime (clock_id, &T);
|
||||||
double res = T.tv_sec + (double) T.tv_nsec * 1e-9;
|
double res = T.tv_sec + (double) T.tv_nsec * 1e-9;
|
||||||
if (clock_id == CLOCK_REALTIME) {
|
if (clock_id == CLOCK_REALTIME) {
|
||||||
precise_time = (long long) (res * (1LL << 32));
|
precise_time = (long long) (res * (1LL << 32));
|
||||||
precise_time_rdtsc = rdtsc ();
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,9 @@ int get_random_bytes (unsigned char *buf, int n) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
close (h);
|
close (h);
|
||||||
|
if (r < 0) {
|
||||||
|
r = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r < n) {
|
if (r < n) {
|
||||||
@ -105,18 +108,15 @@ void my_clock_gettime (int clock_id UU, struct timespec *T) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void prng_seed (const char *password_filename, int password_length) {
|
void prng_seed (const char *password_filename, int password_length) {
|
||||||
unsigned char *a = talloc0 (64 + password_length);
|
unsigned char *a = talloc0 (64 + password_length);
|
||||||
long long r = rdtsc ();
|
|
||||||
struct timespec T;
|
struct timespec T;
|
||||||
my_clock_gettime (CLOCK_REALTIME, &T);
|
my_clock_gettime (CLOCK_REALTIME, &T);
|
||||||
memcpy (a, &T.tv_sec, 4);
|
memcpy (a, &T.tv_sec, 4);
|
||||||
memcpy (a+4, &T.tv_nsec, 4);
|
memcpy (a + 4, &T.tv_nsec, 4);
|
||||||
memcpy (a+8, &r, 8);
|
|
||||||
unsigned short p = getpid ();
|
unsigned short p = getpid ();
|
||||||
memcpy (a + 16, &p, 2);
|
memcpy (a + 8, &p, 2);
|
||||||
int s = get_random_bytes (a + 18, 32) + 18;
|
int s = get_random_bytes (a + 10, 32) + 10;
|
||||||
if (password_filename) {
|
if (password_filename) {
|
||||||
int fd = open (password_filename, O_RDONLY);
|
int fd = open (password_filename, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
@ -375,12 +375,6 @@ static inline void fetch_skip_str (void) {
|
|||||||
fetch_str (l);
|
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) {
|
static inline long have_prefetch_ints (void) {
|
||||||
return in_end - in_ptr;
|
return in_end - in_ptr;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user