Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Oct 1998 04:37:41 -0800 (PST)
From:      info@highwind.com
To:        freebsd-gnats-submit@FreeBSD.ORG
Subject:   kern/8500: FreeBSD 3.0 thread scheduler is broken
Message-ID:  <199810301237.EAA00786@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         8500
>Category:       kern
>Synopsis:       FreeBSD 3.0 thread scheduler is broken
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct 30 04:40:00 PST 1998
>Last-Modified:
>Originator:     Robert Fleischman
>Organization:
HighWind Software, Inc.
>Release:        3.0
>Environment:
FreeBSD zonda.highwind.com 3.0-19980831-SNAP FreeBSD 3.0-19980831-SNAP #0: Mon Aug 31 14:03:19 GMT 1998     root@make.ican.net:/usr/src/sys/compile/GENERIC  i386

>Description:
When an application has threads that are I/O intensive, that thread
unfairly steals cycles from all other threads. This makes writing
an MT program that does any real amount of I/O impossible.

>How-To-Repeat:
Just run this test program:

/*****************************************************************************
File:     schedBug.C
Contents: FreeBSD Scheduling Bug Illustrator
Created:  28-Oct-1998

This program SHOULD print "Marking Time : 1", etc. However, the thread
scheduler appears to NOT schedule the markTimeThread because the
ioThread is so busy.

If you uncomment the "::pthread_yield()" it works a little
better. Ideally, you should get a print every second.

g++ -o schedBug -D_REENTRANT -D_THREAD_SAFE -g -Wall schedBug.C -pthread 

*****************************************************************************/

#include <assert.h>
#include <fcntl.h>
#include <memory.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef linux
#include <sys/time.h>
#endif
#include <unistd.h>

unsigned int LENGTH = 1024 * 1024;

void *ioThread(void *)
{
    char *data = new char[LENGTH];
    ::memset(data, 0, LENGTH);

    while (true) {
	int file = ::open("scrap", O_CREAT | O_TRUNC | O_WRONLY, 0666);
	assert(file != -1);
	assert(::write(file, data, LENGTH) == static_cast<ssize_t>(LENGTH));
	// ::pthread_yield();
	assert(!::close(file));
    }
}

void *markTimeThread(void *)
{
    time_t start = ::time(0);
    while (true) {
	timeval timeout;
	timeout.tv_sec = 1;
	timeout.tv_usec = 0;
	::select(0, 0, 0, 0, &timeout); 

	::printf("Marking Time: %lu\n", ::time(0) - start);
    }
}

int main(int, char **)
{
    // Set up Thread Arguments
    pthread_t tid;
    pthread_attr_t attr;
    assert(!::pthread_attr_init(&attr));
    assert(!::pthread_attr_setdetachstate(&attr,
					  PTHREAD_CREATE_DETACHED));

    // Spawn markTimeThread
    assert(!::pthread_create(&tid, &attr, markTimeThread, 0));
    // Spawn ioThread
    assert(!::pthread_create(&tid, &attr, ioThread, 0));

    // main() goes away for a long time
    timeval timeout;
    timeout.tv_sec = 3600;
    timeout.tv_usec = 0;
    ::select(0, 0, 0, 0, &timeout); 

    return EXIT_SUCCESS;
}

>Fix:
I do not know a fix. However, the problem appears to be related to the
use of the VTALARM timer only measuring USER space time and not kernel
space time.

>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



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