本文整理汇总了C++中rdtsc函数的典型用法代码示例。如果您正苦于以下问题:C++ rdtsc函数的具体用法?C++ rdtsc怎么用?C++ rdtsc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rdtsc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ti_threadgroup_fork
int ti_threadgroup_fork(ti_threadgroup_t *tg, int16_t ext_tid,
void **bcast_val)
{
if (tg->tid_map[ext_tid] == 0) {
tg->envelope = bcast_val ? *bcast_val : NULL;
cpu_sfence();
tg->forked = 1;
tg->group_sense = tg->thread_sense[0]->sense;
// if it's possible that threads are sleeping, signal them
if (tg->sleep_threshold) {
uv_mutex_lock(&tg->alarm_lock);
uv_cond_broadcast(&tg->alarm);
uv_mutex_unlock(&tg->alarm_lock);
}
}
else {
// spin up to threshold cycles (count sheep), then sleep
uint64_t spin_cycles, spin_start = rdtsc();
while (tg->group_sense !=
tg->thread_sense[tg->tid_map[ext_tid]]->sense) {
if (tg->sleep_threshold) {
spin_cycles = rdtsc() - spin_start;
if (spin_cycles >= tg->sleep_threshold) {
uv_mutex_lock(&tg->alarm_lock);
if (tg->group_sense !=
tg->thread_sense[tg->tid_map[ext_tid]]->sense) {
uv_cond_wait(&tg->alarm, &tg->alarm_lock);
}
uv_mutex_unlock(&tg->alarm_lock);
spin_start = rdtsc();
continue;
}
}
cpu_pause();
}
cpu_lfence();
if (bcast_val)
*bcast_val = tg->envelope;
}
return 0;
}
示例2: main
int main(int argc, char* argv[]) {
char b;
int bits1[48];
char word[100];
//allocate huge pages
long an = 1024*1024*1024;
char* a = (char*)mmap(NULL, an, PROT_READ | PROT_WRITE, FLAGS, 0, 0);
if (a==MAP_FAILED) {
printf("Error: could not allocate huge pages\n");
return 0;
}
int i=0;
for (i=0; i<an; i++) { //fill the array
a[i]=0;
}
for (i=0; i<1000000; i++) {
int ra = rand() % an;
long low; long high;
rdtsc(low, high);
b = a[ra];
long t = low;
rdtsc(low,high);
long tiempo = low-t;
printf("%ld %p\n", tiempo, &a[ra]);
}
}
示例3: getFrequencyInMHz
static double getFrequencyInMHz()
{
struct timeval tvstart, tvstop;
unsigned long long int cycles[2];
gettimeofday(&tvstart, NULL);
cycles[0] = rdtsc();
gettimeofday(&tvstart, NULL);
usleep(250000);
gettimeofday(&tvstop, NULL);
cycles[1] = rdtsc();
gettimeofday(&tvstop, NULL);
const unsigned long microseconds = ((tvstop.tv_sec-tvstart.tv_sec)*1000000) + (tvstop.tv_usec-tvstart.tv_usec);
unsigned long mhz = (unsigned long) (cycles[1]-cycles[0]) / microseconds;
//std::cout << "MIC frequency is " << mhz << " MHz" << std::endl;
return (double)mhz;
}
示例4: timer_get_tsc
uint64_t timer_get_tsc(void)
{
uint64_t time_now;
time_now = rdtsc();
if (!gd->arch.tsc_base)
gd->arch.tsc_base = time_now;
return time_now - gd->arch.tsc_base;
}
示例5: Handler
void Handler ( int sig, siginfo_t * extra, void *cruft )
{
static int last_i=0;
unsigned int i, j;
rdtsc(i,j);
QString strInfo( "time:%1, %2, [%3] %4HZ ");
strInfo.arg( "%1", j ).arg( "%2", i ).arg( "%3", i - last_i ).arg( "%4", ( i - last_i ) * 10 / 1000000 );
qDebug( ) << strInfo;
last_i = i;
}
示例6: PRESENT80bitslice16_cipher_
/* It takes less memory since subkeys are not stored */
void PRESENT80bitslice16_cipher_(const u64 plaintext[BITSLICE16_P], const u16 key[BITSLICE16_P][KEY80], u64 ciphertext[BITSLICE16_P])
{
PRESENT_init();
#ifdef MEASURE_PERF
key_schedule_start = 0;
#endif
#ifdef MEASURE_PERF
key_schedule_start = 0;
#endif
#ifdef MEASURE_PERF
encrypt_start = rdtsc();
#endif
PRESENT_CORE_ENCRYPT_AND_KEY_SCHED(BITSLICE16_P, 80);
#ifdef MEASURE_PERF
encrypt_end = rdtsc();
#endif
return;
}
示例7: IPC_sendToAll
// Send a message to all the cores
// The message id will be msg_id
void IPC_sendToAll(int msg_size, char msg_id)
{
uint64_t cycle_start, cycle_stop;
char *msg;
if (msg_size < MIN_MSG_SIZE)
{
msg_size = MIN_MSG_SIZE;
}
msg = (char*) malloc(GET_MALLOC_SIZE(sizeof(char) * msg_size));
if (!msg)
{
perror("IPC_sendToAll allocation error! ");
exit(errno);
}
// malloc is lazy: the pages may not be really allocated yet.
// We force the allocation and the fetch of the pages with bzero
bzero(msg, msg_size);
msg[0] = msg_id;
#ifdef DEBUG
printf(
"[producer %i] going to send message %i of size %i to %i recipients\n",
core_id, msg_long[0], msg_size, nb_receivers);
#endif
int sent = 0;
while (sent < msg_size)
{
rdtsc(cycle_start);
sent += sendto(sock, msg, msg_size, 0, (struct sockaddr*) &multicast_addr,
sizeof(multicast_addr));
rdtsc(cycle_stop);
nb_cycles_send += cycle_stop - cycle_start;
}
free(msg);
}
示例8: testloop1
uint64_t testloop1()
{
int i, warmup = niters;
uint64_t start, end, result = 0;
for(i = 0; i < niters + warmup; i++) {
if(want_cache_flush) {
flush_cache();
}
start = rdtsc();
/* Perform access multiple times */
runloop(0, narrays, 0, nitems, 1);
end = rdtsc();
if( i >= warmup ) {
result += end - start;
}
}
return result;
}
示例9: wtime
void wtime(double *t)
{
uint64_t tsc;
static uint64_t sec = 0;
// struct timeval tv;
// gettimeofday(&tv, (void *)0);
tsc = rdtsc();
if (sec == 0) sec = tsc;
*t = (tsc - sec);
}
示例10: Calculate
/*! Calculate elapsed time (delta).
\return reference to this object */
const IntervalTimer& Calculate()
{
#if defined USE_RDTSC && defined HAVE_RDTSC
Tickval::ticks now(rdtsc());
#else
Tickval now(true);
#endif
delta_ = now - startTime_;
return *this;
}
示例11: store_initial_timestamp
static void store_initial_timestamp(void)
{
/* On Cougar Point we have two 32bit scratchpad registers available:
* D0:F0 0xdc (SKPAD)
* D31:F2 0xd0 (SATA SP)
*/
tsc_t tsc = rdtsc();
pci_write_config32(PCI_DEV(0, 0x00, 0), 0xdc, tsc.lo);
pci_write_config32(PCI_DEV(0, 0x1f, 2), 0xd0, tsc.hi);
}
示例12: main
int main()
{
u64 t1, t2;
t1 = rdtsc();
t2 = rdtsc();
printf("rdtsc latency %u\n", (unsigned)(t2 - t1));
test_wrtsc(0);
test_wrtsc(100000000000ull);
if (check_cpuid_80000001_edx(CPUID_80000001_EDX_RDTSCP)) {
test_rdtscp(0);
test_rdtscp(10);
test_rdtscp(0x100);
} else
printf("rdtscp not supported\n");
return report_summary();
}
示例13: causePagefaults
static void causePagefaults(const char *path) {
uint64_t start,end;
uint64_t total = 0;
uint64_t min = ULLONG_MAX, max = 0;
int fd = -1;
if(path) {
fd = open(path,O_RDONLY);
if(fd < 0) {
printe("Unable to open '%s'",path);
return;
}
}
for(int j = 0; j < TEST_COUNT; ++j) {
volatile char *addr = mmap(NULL,MAP_SIZE * PAGE_SIZE,path ? MAP_SIZE * PAGE_SIZE : 0,
PROT_READ | PROT_WRITE,MAP_PRIVATE,fd,0);
if(!addr) {
printe("mmap failed");
return;
}
for(size_t i = 0; i < MAP_SIZE; ++i) {
start = rdtsc();
*(addr + i * PAGE_SIZE) = 0;
end = rdtsc();
uint64_t duration = end - start;
if(duration < min)
min = duration;
if(duration > max)
max = duration;
total += duration;
}
if(munmap((void*)addr) != 0)
printe("munmap failed");
}
if(path)
close(fd);
printf("%-30s: %Lu cycles average\n",path ? path : "NULL",total / (TEST_COUNT * MAP_SIZE));
printf("%-30s: %Lu cycles minimum\n",path ? path : "NULL",min);
printf("%-30s: %Lu cycles maximum\n",path ? path : "NULL",max);
}
示例14: omp_get_wtime
double
omp_get_wtime (void)
{
double ret;
ret = (double) (rdtsc() - start_tsc) / ((double) get_cpufreq() * 1000000.0);
//printf("CPU frequency: %d MHz\n", get_cpufreq());
return ret;
}
示例15: timing_sync_timer
errval_t timing_sync_timer(void)
{
#if defined(__x86_64__) || defined(__i386__)
uint64_t tscperms;
errval_t err = sys_debug_get_tsc_per_ms(&tscperms);
assert(err_is_ok(err));
// Exponential backoff loop
for(uint64_t time_offset = MIN_DELAY_MS;
time_offset <= MAX_DELAY_MS;
time_offset *= 2) {
uint64_t synctime = rdtsc() + tscperms * time_offset;
int waitfor = 0;
received = 0;
error = SYS_ERR_OK;
for(int i = 0; i < MAX_CPUS; i++) {
struct intermon_binding *b = NULL;
err = intermon_binding_get(i, &b);
if(err_no(err) == MON_ERR_NO_MONITOR_FOR_CORE) {
continue;
}
assert(err_is_ok(err));
err = b->tx_vtbl.rsrc_timer_sync(b, NOP_CONT, synctime);
assert(err_is_ok(err));
waitfor++;
}
err = invoke_monitor_sync_timer(synctime);
if(err_is_fail(err)) {
error = err;
}
// Collect success/failure replies
while(received < waitfor) {
messages_wait_and_handle_next();
}
if(err_is_fail(error)) {
if(err_no(error) != SYS_ERR_SYNC_MISS) {
return error;
}
} else {
break;
}
}
return error;
#else
printf("Phase-locked local clocks not supported on this platform!\n");
return SYS_ERR_OK;
#endif
}