Пример #1
0
/**
 * @brief Timer handler procedure
 *
 * This is not a realistic workload and it is a demonstration code only.
 *
 * It runs couple thousand of iterations and each iteration is randomizing
 * memory locations to run a number of arithmetic operations on them.
 *
 * @param sig UNUSED
 * @param si UNUSED
 * @param uc UNUSED
 */
static void timer_handler(int sig, siginfo_t *si, void *uc)
{
        const int num_iterations = 5000;
        int *p = (int *) timer_data_ptr;
        const size_t sz = timer_data_size / sizeof(int);
        int m;

        (void) (sig);
        (void) (si);
        (void) (uc);

        tsc_start(&timer_prof);
        /* START - "latency sensitive" code */
        for (m = 0; m < num_iterations; m++) {
                const size_t stride = 5;
                const int idx0 = timer_rand() % (sz - stride);
                const int idx1 = timer_rand() % (sz - stride);
                size_t n;

                for (n = 0; n < stride; n++)
                        p[idx0 + n] = 2 * p[idx1 + n] + p[idx0 + n];
        }
        /* END - "latency sensitive" code */
        tsc_end(&timer_prof, 1);
}
Пример #2
0
int main(void) {
  const long iterations = 1000000000;
  struct timespec ts;
  uint64_t tsc;
  clock_start (&ts);
  tsc_start(&tsc);
  volatile int asignto = 0;
  for (long i = 0; i < iterations; i++) {
    asignto = function_call(i);
  }
  const long long unsigned delta = clock_end(&ts);
  const long long unsigned delta_tsc = tsc_end(&tsc);
  (void) asignto;
  printf("%ld spins in %lluns (%.1fns/spin, %.1f clocks/spin)\n",
         iterations, delta, (delta / (double) iterations),delta_tsc / (double)iterations);
  return 0;
}