int32_t function_exit(int64_t* functionIndex){ int64_t tstop; #ifdef EXCLUDE_TIMER tstop = 1; #else tstop = read_timestamp_counter(); #endif int32_t currentRecord = getRecordIndex(); int32_t popped = funcStack_pop(); if (popped != *functionIndex){ while (popped != *functionIndex){ stackError[popped]++; popped = funcStack_pop(); } funcStack_push(popped); currentRecord = getRecordIndex(); popped = funcStack_pop(); } int64_t tadd = tstop - funcInfos[currentRecord].timer_start; funcInfos[currentRecord].count++; funcInfos[currentRecord].timer_total += tadd; }
int32_t function_entry(){ #ifdef EXCLUDE_TIMER funcInfos[*functionIndexAddr].count++; #else pushIndex(*functionIndexAddr, read_timestamp_counter()); #endif // PRINT_INSTR(stdout, "%s entry %d", functionNames[*functionIndexAddr], *functionIndexAddr); }
int32_t function_exit(){ register uint32_t currentRecord = *functionIndexAddr; #ifndef EXCLUDE_TIMER // PRINT_INSTR(stdout, "%s exit %d", functionNames[currentRecord], currentRecord); uint64_t tadd = popIndex(currentRecord, read_timestamp_counter()); funcInfos[currentRecord].count++; funcInfos[currentRecord].timer_total += tadd; #endif // printFunctionInfo(currentRecord); }
static void perform_reads(struct pci_dev * dev, unsigned long * timestamps, uint64_t iteration_count, uint64_t wait_time_us) { size_t i; for (i = 0; i != iteration_count; ++i) { struct timestamp t; read_timestamp_counter(&t); pci_read_word(dev, PCI_VENDOR_ID); timestamps[i] = cycle_since_timestamp(&t); if (wait_time_us) usleep(wait_time_us); } }
int32_t function_entry(int64_t* functionIndex){ int i, j; funcStack_push(*functionIndex); int32_t currentRecord = getRecordIndex(); if (!funcInfos[currentRecord].hash){ funcInfos[currentRecord].hash = HASH_STACK_HEAD; PRINT_DEBUG("hash[%d](idx %d) = %#llx", currentRecord, *functionIndex, funcInfos[currentRecord].hash); for (i = 0; i < STACK_BACKTRACE_SIZE; i++){ funcInfos[currentRecord].backtrace[i] = funcStack_peep(i); } } #ifdef EXCLUDE_TIMER funcInfos[currentRecord].timer_start = 0; #else funcInfos[currentRecord].timer_start = read_timestamp_counter(); #endif }
static cycle_t mn10300_read(struct clocksource *cs) { return read_timestamp_counter(); }
int main(int argc, char* argv[]) { int err = EXIT_FAILURE; struct cmd_line cmd_line; setlocale(LC_ALL, ""); if (parse_cmd_line(argc, argv, &cmd_line) < 0) goto arg_check_failed; struct pci_access * pci = pci_alloc(); if (! pci) goto pci_alloc_failed; /* This access bypass the kernel and use a memory mapping * to PCI configuration registers */ pci->method = PCI_ACCESS_I386_TYPE1; struct pci_dev * dev = create_pci_dev(pci, cmd_line.slot); if (! dev) goto create_pci_dev_failed; print_device_name(pci, dev); unsigned long * timestamps = malloc(sizeof(*timestamps) * cmd_line.iteration_count); if (! timestamps) { fprintf(stderr, "Can't allocate timestamp storage (%s)\n", strerror(errno)); goto malloc_failed; } struct timestamp t; read_timestamp_counter(&t); perform_reads(dev, timestamps, cmd_line.iteration_count, cmd_line.wait_time_us); unsigned long test_duration_cycles = cycle_since_timestamp(&t); double cpu_mhz = get_cpu_mhz(); if (cpu_mhz < 0) goto get_cpu_mhz_failed; print_results(cpu_mhz, timestamps, cmd_line.iteration_count, test_duration_cycles, cmd_line.limit_ns); err = EXIT_SUCCESS; get_cpu_mhz_failed: free(timestamps); malloc_failed: pci_free_dev(dev); create_pci_dev_failed: pci_cleanup(pci); pci_alloc_failed: arg_check_failed: return err; }
// called at loop exit void inst_lptimer_lpexit() { double t2 = read_timestamp_counter(); loopTimes[*site] += t2 - loopTimers[*site]; exitCalled[*site]++; }
// called at loop entry void inst_lptimer_lpentry() { loopTimers[*site] = read_timestamp_counter(); entryCalled[*site]++; }
int main(int argc, char* argv[]) { int err = EXIT_FAILURE; struct cmd_line cmd_line; setlocale(LC_ALL, ""); if (parse_cmd_line(argc, argv, &cmd_line) < 0) goto arg_check_failed; const double cpu_mhz = get_cpu_mhz(); if (cpu_mhz < 0) goto get_cpu_mhz_failed; const double cycles_per_ns = cpu_mhz / 1e3; const double cycles_limit = cycles_per_ns * cmd_line.limit_ns; size_t spikes_count = 0; struct spike * spikes = calloc(1000, sizeof(struct spike)); if (! spikes) { fprintf(stderr, "Failed to allocate spikes %s\n", strerror(errno)); goto calloc_failed; } struct timestamp initial_timestamp; read_timestamp_counter(&initial_timestamp); struct timestamp t[2]; read_timestamp_counter(&t[0]); size_t i; for (i = 1; i < cmd_line.iteration_count; ++ i) { read_timestamp_counter(&t[i % 2]); uint64_t diff = diff_timestamps(&t[(i - 1) % 2], &t[i % 2]); if (diff > cycles_limit) { spikes[spikes_count].cycles_delta = diff; memcpy(&spikes[spikes_count].timestamp, &t[i % 2], sizeof(struct timestamp)); ++ spikes_count; if (spikes_count == MAX_SPIKES) { print_spikes(spikes, spikes_count, cycles_per_ns, &initial_timestamp); spikes_count = 0; } read_timestamp_counter(&t[ i % 2]); } } print_spikes(spikes, spikes_count, cycles_per_ns, &initial_timestamp); const double cycles_per_ms = cpu_mhz * 1e3; fprintf(stdout, "Iterations count: %'zu\n" "Sampling duration: %'.0lf ms\n" "Detected frequency: %.0lf Mhz\n", cmd_line.iteration_count, cycle_since_timestamp(&initial_timestamp) / cycles_per_ms, cpu_mhz); err = EXIT_SUCCESS; free(spikes); calloc_failed: get_cpu_mhz_failed: arg_check_failed: return err; }