Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Sep 2007 23:05:05 -0400
From:      Kurt Miller <lists@intricatesoftware.com>
To:        freebsd-java@freebsd.org
Cc:        Kris Kennaway <kris@freebsd.org>, performance@freebsd.org
Subject:   Re: Massive performance loss from OS::sleep hack
Message-ID:  <200709152305.06116.lists@intricatesoftware.com>
In-Reply-To: <200709152250.50879.kurt@intricatesoftware.com>
References:  <46EC1B55.4060202@FreeBSD.org> <200709152250.50879.kurt@intricatesoftware.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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();
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200709152305.06116.lists>