Massive performance loss from OS::sleep hack

Kurt Miller lists at intricatesoftware.com
Sat Sep 15 20:05:09 PDT 2007


On Saturday 15 September 2007 10:50:50 pm Kurt Miller wrote:
> The following are programs I wrote when I isolated the problem.
> If the c program runs ok on 7.0 for both single cpu and mp then
> remove the os_sleep() and try the java program. If that works too
> then you're clear to make the os_sleep() hack only apply to <
> 7.0 and still be able to pass the certification tests.

Sorry copy/paste glitch. He is the c program again:

#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <inttypes.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

volatile int init=0;
volatile int interrupt=0;

static void *
yielder(void *arg)
{
    init = 1;
    while (1) {
        pthread_yield();
    }
}

static void
sighandler(int sig)
{
    interrupt = 1;
    printf("sighandler\n");
}

static void
waitForInit() {
    struct timespec t, rt;

    while (init == 0) {
        t.tv_sec = 0;
        t.tv_nsec = 100000;
        nanosleep(&t, &rt);
    }
}

static void
waitForInterrupt() {
    struct timespec t, rt;

    while (interrupt == 0) {
        t.tv_sec = 0;
        t.tv_nsec = 100000;
        nanosleep(&t, &rt);
    }
}

int
main(int argc, char *argv[])
{
    pthread_t        yldr;
    pthread_attr_t   attr;
    struct sigaction act;

    /* Install a signal handler for SIGUSR1 */
    sigemptyset (&act.sa_mask);
    sigaddset (&act.sa_mask, SIGUSR1);
    act.sa_handler = sighandler;
    act.sa_flags = 0;
    sigaction (SIGUSR1, &act, NULL);

    pthread_attr_init(&attr);
    pthread_attr_setschedpolicy(&attr, SCHED_FIFO);

    pthread_create(&yldr, &attr, yielder, NULL);
    pthread_setprio(yldr, 16);
    waitForInit();
    if(pthread_kill(yldr, SIGUSR1) != 0)
        printf("pthread_kill failed with errno = %d\n", errno);
    waitForInterrupt();
}


More information about the freebsd-performance mailing list