mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "g-j v dijk" <aka_mr_zapper@hotmail.com>
To: linux-kernel@vger.kernel.org
Subject: Problem with SCHED_RR and kernel 2.4.18-4GB
Date: Mon, 29 Dec 2003 12:08:05 +0100	[thread overview]
Message-ID: <BAY2-F11yKFRJrzdDW6000379f5@hotmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1603 bytes --]

Hi All,

I'm a newbie at Linux, but have been busy developing (with some other 
people) sort of a DVB zapper demo application/stack on top of Hauppauge HW 
and SUSE 8.0 kernel 2.4.18-4GB for the last 2 months.

As the stack wil eventually be ported to one (or more) dedicated HW 
platforms, we defined an OS independant API. Now, we want to be able to set 
priorities, and have sort of a realtime behaviour.

The problem is that if I implement this, and set scheduling to be SCHED_RR, 
or SCHED_FIFO, my linux machine hangs. With SCHED_OTHER, I don't have that 
(note that for testing I used to set all prios to minimum (=1)).

I already read 2 issues/threads on the internet (that's all I could find 
closely related), but they didn't gave me the solution 
(http://www.ussg.iu.edu/hypermail/linux/kernel/0206.1/0946.html and 
http://www.cs.utah.edu/~regehr/hourglass/).

I already tinckered with it for a day now :-(

I checked whether all threads have an OS call (sem_lock, or sleep etc), to 
allow scheduling and not cause starvation of other processes/threads and yes 
that is the case and in IMHO this looks fine.

The questions:
1) Is this the right mailinglist for this question? If not, please direct me 
to the correct one, and I'm sorry for the inconvenience.
2) Attached a snippet of the code I made. Am i missing something obviously?
3) Is there a problem in 2.4.18? And if so, to which kernel should I move?

Thanks a lot,

Gert-Jan van Dijk

_________________________________________________________________
Play online games with your friends with MSN Messenger 
http://messenger.msn.nl/

[-- Attachment #2: gosy_thread_snippet.cpp --]
[-- Type: application/octet-stream, Size: 3460 bytes --]

#include <pthread.h> // include this first
#include <sched.h>
#include <errno.h>
#include <signal.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <unistd.h>
#include <assert.h>
#include "gosy_thread.hpp"
#include "gosy_threadimpl.hpp"
#include "glog_logging.hpp"
#include "gosy_common.hpp"


/***************** cGosyThreadImpl *****************/


cGosyThreadImpl::cGosyThreadImpl(void)
{
    mRunning = false;

    if ( geteuid() != 0) // root
    {
        assert(false); // Must run as root, else we cannot change priority of task
    }
}

cGosyThreadImpl::~cGosyThreadImpl()
{
}

void *cGosyThreadImpl::StartThread(cGosyThread *pThread)
{
    pThread->StartThread();

    return NULL;
}
        

void cGosyThreadImpl::Start(int Priority, cGosyThread* pThread)
{
    int                 RetVal = 0;
                                // SCHED_OTHER (0 @ sched.h) -> Regular, non-realtime
                                // SCHED_RR    (1 @ sched.h) -> Round Robin, Realtime
                                // SCHED_FIFO  (2 @ sched.h) -> First-in First-out, Realtime
#   define              POLICY   (SCHED_FIFO)
    int                 Policy;
    pthread_attr_t      Attr;
    struct sched_param  SchedParam;

    assert( cGosyThread::GetMinPrio() <= Priority 
            && 
            cGosyThread::GetMaxPrio() >= Priority );
#if (POLICY != SCHED_OTHER)
    // SCHED_RR & SCHED_FIFO have prio between 1..99, so add 1 to priority of GOSY
    // as GOSY has prio between 0..15
    Priority = 1;
    assert( sched_get_priority_min(POLICY) <= Priority 
            && 
            sched_get_priority_max(POLICY) >= Priority );
#endif

    if (!mRunning)
    {
        mRunning    = true;

        RetVal = pthread_attr_init(&Attr);        
        assert( RetVal == 0 );

        // Detach state of thread will prevent "zombie processes" as no need
        // to join threads after cancellation.
        RetVal = pthread_attr_setdetachstate(&Attr, PTHREAD_CREATE_DETACHED);
        assert( RetVal == 0 );

#if (POLICY != SCHED_OTHER)
        RetVal = pthread_attr_setschedpolicy( &Attr, POLICY);
        assert( RetVal == 0 );
        SchedParam.sched_priority = Priority;
        RetVal = pthread_attr_setschedparam( &Attr, &SchedParam);  
        assert( RetVal == 0 );
#endif
        RetVal = pthread_create(&mThread, &Attr, (void *(*) (void *))&StartThread, (void *)pThread);
        assert( RetVal == 0 );

        RetVal = pthread_getschedparam(mThread, &Policy, &SchedParam);
        assert( RetVal == 0 );
        assert( Policy == POLICY );
#if (POLICY != SCHED_OTHER)
        assert( SchedParam.sched_priority == Priority );
#endif

        RetVal = pthread_attr_destroy(&Attr);
        assert( RetVal == 0 );
    }
}

int cGosyThreadImpl::SetPriority(int Priority)
{
    struct sched_param  SchedParam;
    int                 RetVal = 0;
    pthread_attr_t      Attr;

    if (Priority < cGosyThread::GetMinPrio()
        ||
        Priority > cGosyThread::GetMaxPrio())
    {
        return GOSY_WRONG_PRIO;
    }

#if (POLICY != SCHED_OTHER)
    assert(mRunning);

    RetVal = pthread_attr_init(&Attr);        
    assert( RetVal == 0 );

    SchedParam.sched_priority = Priority;
    RetVal = pthread_setschedparam(mThread, POLICY, &SchedParam);
    assert( RetVal == 0 );
#endif
}



             reply	other threads:[~2003-12-29 11:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-29 11:08 g-j v dijk [this message]
2003-12-29 23:47 Roger Larsson
2003-12-30  9:42 g-j v dijk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BAY2-F11yKFRJrzdDW6000379f5@hotmail.com \
    --to=aka_mr_zapper@hotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®