A small c++ program that does nothing but the following:
struct bat
{
const char* a;
const char* b;
void* v;
};
struct rat
{
rat()
:
isOn(true),
bats(),
batscounter(0) {}
uint64_t
update()
{
uint64_t start = rdtsc();
if (!isOn)
return;
bat& b = bats[batscounter];
batscounter = (++batscounter % 10);
b.v = this;
b.a = "aname";
b.b = "bname";
return (rdtsc() - start);
}
bool isOn;
bat bats[10];
size_t batscounter;
};
Looping over it and inspecting the timestamps from rdtsc I see an average of 20 cycles but a lot of the time I see spikes over 20K cycles (every second). The method is getting called about 70M times per second. I am running this on an empty host using ulimit -r 99
and I even set the affinity mask for the process to 1
to see if that would help but it hasn't. What could be causing this with those settings on and what other methods would I have available to me to prevent this?