lkml.org 
[lkml]   [2012]   [Jun]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRE: [PATCH] sched: Folding nohz load accounting more accurate
    From
    Date
    On Wed, 2012-06-13 at 20:13 -0700, Doug Smythies wrote:
    > ./waiter 2 900 345912 9444

    So we're all simply just trying to burn a particular amount of cpu-time?

    I have a little consume.c thing lying about doing something like that.
    Its independent of clockspeed, but doesn't really like preemption much,
    but it more or less works ;-)

    ---
    #include <sys/time.h>
    #include <unistd.h>
    #include <stdio.h>

    unsigned long long stamp(void)
    {
    struct timeval tv;

    gettimeofday(&tv, NULL);

    return (unsigned long long)tv.tv_sec * 1000000 + tv.tv_usec;
    }

    void consume(int spin, int total)
    {
    unsigned long long begin, now;

    begin = stamp();

    for (;;) {
    now = stamp();
    if ((long long)(now - begin) > spin) {
    usleep(total - spin);
    begin += total;
    }
    }
    }

    int main(int argc, char **argv)
    {
    int period = 100000; /* 100ms */
    int frac;

    if (argc < 2) {
    fprintf(stderr, "%s <frac> [<period>]\n"
    " frac -- [1-100] %% of time to burn\n"
    " period -- [usec] period of burn/sleep cycle\n",
    argv[0]);
    return -1;
    }

    frac = atoi(argv[1]);
    if (argc > 2)
    period = atoi(argv[2]);

    if (frac > 100)
    frac = 100;

    if (frac < 1)
    frac = 1;

    consume((period * frac) / 100, period);

    return 0;
    }



    \
     
     \ /
      Last update: 2012-06-18 13:41    [W:6.602 / U:0.228 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site