0

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?

Palace Chan
  • 8,845
  • 11
  • 41
  • 93
  • Possible thread related: use real time priority: http://stackoverflow.com/questions/8887531/which-real-time-priority-is-the-highest-priority-in-linux – Gui13 Jul 23 '12 at 15:15
  • I have only a main thread though and ulimit -r 99 sets the real time priority though doesn't it? – Palace Chan Jul 23 '12 at 15:26
  • My `ulimit` has no `-r` switch, so I have no idea at all what that's supposed to do. – cdhowie Jul 23 '12 at 15:50
  • Isn't it the opposite? See the linked question, apparently it's 1 the higher limit. – Gui13 Jul 23 '12 at 16:01
  • No, it's 99...the priority is inverted with ulimit and 99 is higher..if you set ulimit -r 80 and then try to set ulimit r 90 it wont allow you. – Palace Chan Jul 23 '12 at 16:19
  • I noticed no difference in these rare preemptions even when i used set_sched to get priority up to 139 (99 real time priority) There are still a ton of watchdog and migration daemons at that same priority level though. – Palace Chan Jul 23 '12 at 21:33

0 Answers0