unsignedlonglong calibrate(void)
{ struct timespec start, finish; unsignedlonglong i, samples, step = 9973;
pid_t pid, ret; int seconds = 15;
ksft_print_msg("Calibrating sample size for %d seconds worth of syscalls ...\n", seconds);
samples = 0;
pid = getpid();
assert(clock_gettime(CLOCK_MONOTONIC, &start) == 0); do { for (i = 0; i < step; i++) {
ret = syscall(__NR_getpid);
assert(pid == ret);
}
assert(clock_gettime(CLOCK_MONOTONIC, &finish) == 0);
samples += step;
i = finish.tv_sec - start.tv_sec;
i *= 1000000000ULL;
i += finish.tv_nsec - start.tv_nsec;
} while (i < 1000000000ULL);
return samples * seconds;
}
bool approx(int i_one, int i_two)
{ /* *Thiscontinuestobeanoisytest.Insteadofa1%comparison *gowith10%.
*/ double one = i_one, one_bump = one * 0.1; double two = i_two, two_bump = two * 0.1;
one_bump = one + MAX(one_bump, 2.0);
two_bump = two + MAX(two_bump, 2.0);
/* Equal to, or within 1% or 2 digits */ if (one == two ||
(one > two && one <= two_bump) ||
(two > one && two <= one_bump)) returntrue; returnfalse;
}
bool le(int i_one, int i_two)
{ if (i_one <= i_two) returntrue; returnfalse;
}
/* Pin to a single CPU so the benchmark won't bounce around the system. */ void affinity(void)
{ long cpu;
ulong ncores = sysconf(_SC_NPROCESSORS_CONF);
cpu_set_t *setp = CPU_ALLOC(ncores);
ulong setsz = CPU_ALLOC_SIZE(ncores);
/* *TotallyunscientificwaytoavoidCPUsthatmightbebusier: *choosethehighestCPUinsteadofthelowest.
*/ for (cpu = ncores - 1; cpu >= 0; cpu--) {
CPU_ZERO_S(setsz, setp);
CPU_SET_S(cpu, setsz, setp); if (sched_setaffinity(getpid(), setsz, setp) == -1) continue;
printf("Pinned to CPU %lu of %lu\n", cpu + 1, ncores); goto out;
}
fprintf(stderr, "Could not set CPU affinity -- calibration may not work well");
/* Fourth filter, can not be converted to bitmap because of filter 3 */
ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &bitmap_prog);
assert(ret == 0);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.