Scheduling in Kernel 2.2

Scheduling in Kernel 2.2

Post by Christoph Pleg » Wed, 01 Sep 1999 04:00:00



Hello,

What has happened with the scheduling under Kernel 2.2?

I had compiled the following program under Kernel 2.0. The program - as intended
- switched the context between two processes:

#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include <sched.h>
#include <stdio.h>

#define DPRINTF(str) { printf(str); fflush(stdout); }
#define LOOPS 10

struct sched_param schedparam;
pid_t Children[2] = {0,0};
int min,max;

void server(void)
{
  schedparam.sched_priority = max - 5;
  sched_setscheduler(0,SCHED_FIFO,&schedparam);
  sched_yield();

  while (1)
    {
      DPRINTF("server\n");
      sched_yield();
    }

Quote:}

void client(void)
{
  int i;

  schedparam.sched_priority = max - 5;
  sched_setscheduler(0,SCHED_FIFO,&schedparam);
  sched_yield();

  for (i = 0;i < LOOPS;i++)
    {
      DPRINTF("client\n");
      sched_yield();
    }

  kill(Children[0],SIGKILL);}

void main(void)
{
  min = sched_get_priority_min(SCHED_FIFO);
  max = sched_get_priority_max(SCHED_FIFO);

  schedparam.sched_priority = max;
  sched_setscheduler(0,SCHED_FIFO,&schedparam);

  if ((Children[0] = fork()) != 0)
    {
      if ((Children[1] = fork()) == 0)
        {
          client();
          _exit(0);
        }
    }

  else
    {
      server();
      _exit(0);
    }

  waitpid(Children[0],NULL,0);
  waitpid(Children[1],NULL,0);

Quote:}

After switching to Kernel 2.2 the program was recompiled. When I let it run
now, the server-process stays in its endless-loop and the client-process is
never reached. What can be the reason for that? Was the scheduling changed in the
kernel?

Then I tested the following:

void main(void)
{
  min = sched_get_priority_min(SCHED_FIFO);
  max = sched_get_priority_max(SCHED_FIFO);

  schedparam.sched_priority = max;
  sched_setscheduler(0,SCHED_FIFO,&schedparam);

  if ((Children[0] = fork()) != 0)
    {
      if ((Children[1] = fork()) == 0)
        {
          switch (sched_getscheduler(0))
            {
              case SCHED_OTHER: printf("client: SCHED_OTHER, "); break;
              case SCHED_FIFO:  printf("client: SCHED_FIFO, "); break;
              case SCHED_RR: printf("client: SCHED_RR, "); break;
              default:                                     break;
            }

  sched_getparam(0,&schedparam);
  printf("%d\n",schedparam.sched_priority);

          // client();
          // _exit(0);
        }
    }

  else
    {
      switch (sched_getscheduler(0))
        {
          case SCHED_OTHER: printf("server: SCHED_OTHER, "); break;
          case SCHED_FIFO:  printf("server: SCHED_FIFO, "); break;
          case SCHED_RR: printf("server: SCHED_RR, "); break;
          default:                                     break;
        }

      sched_getparam(0,&schedparam);
      printf("%d\n",schedparam.sched_priority);

      // server();
      // _exit(0);
    }

  waitpid(Children[0],NULL,0);
  waitpid(Children[1],NULL,0);

Quote:}

This program gave the following output:

client: SCHED_FIFO, 99
server: SCHED_FIFO, 99

How is it possible that - in spite of SCHED_FIFO and equal priority - the
client makes its output before the server, though the server was created
before the client?

In Kernel 2.0 the server was started before the client.

Christoph