public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* RE: realtime scheduling problems with 2.4 linux kernel >= 2.4.10
@ 2002-06-05 11:53 Ian Collinson
  2002-06-05 12:17 ` Andi Kleen
  0 siblings, 1 reply; 14+ messages in thread
From: Ian Collinson @ 2002-06-05 11:53 UTC (permalink / raw)
  To: 'Andrew Morton', Robert Love, Andi Kleen
  Cc: Mike Kravetz, linux-kernel, andrea

Andi Kleen wrote:
> Fixing it would require boosting keventd's priority either globally 
> or temporarily. E.g. if the original reporter could put this
> (untested/uncompiled) at the beginning of
kernel/context.c:context_thread():
>
>     current->policy = SCHED_RR;
>     current->rt_priority = 99;
>
> it could fix his problem.

OK, I've tried the above fix on 2.4.17, and it seems to work.  Thanks Andi.
We can now get into the box on a high priority console after provoking a
lockup with a lower priority, CPU hogging realtime process.

Are there any potentially negative consequences of this fix, apart from
those already mentioned?

I certainly vote for this feature being preserved, as it is extremely useful
for debugging realtime priority apps.  FYI, we narrowed it down to breaking
in either 2.4.10-pre11 or pre12. 

Cheers
Ian


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
Imerge Limited                          Tel :- +44 (0)1954 783600 
Unit 6 Bar Hill Business Park           Fax :- +44 (0)1954 783601 
Saxon Way                               Web :- http://www.imerge.co.uk 
Bar Hill 
Cambridge 
CB3 8SL 
United Kingdom 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 



^ permalink raw reply	[flat|nested] 14+ messages in thread
* realtime scheduling problems with 2.4 linux kernel >= 2.4.10
@ 2002-05-30 17:54 Ian Collinson
  2002-05-31 18:28 ` Mike Kravetz
  0 siblings, 1 reply; 14+ messages in thread
From: Ian Collinson @ 2002-05-30 17:54 UTC (permalink / raw)
  To: 'linux-kernel@vger.kernel.org'

	

	We're having problems with realtime scheduling (SCHED_RR and
SCHED_FIFO), on 2.4 kernels >= 2.4.10 (built for i386, no SMP).  We have an
app that uses real-time scheduled threads. To aid debugging, in case of
realtime threads spinning and locking the system, we always keep a bash
running on a (text) console, at SCHED_RR, priority 99 (a higher priority
than any threads in our app).  We test that this is a valid approach by
running a lower priority realtime app, on another console, that sits in an
infinite busy loop.  This has always worked, and we've been able to
successfully use the high-priority bash to run gdb, and so on.  This is also
what the man page for sched_setscheduler suggests, to avoid total system
lock up.

	But, it seems to have stopped working with 2.4 kernels >= 2.4.10,
(have tried up to 2.4.19-pre9).  Once the lower priority realtime process is
running, the higher priority shell doesn't pre-empt it, and locks up.

	Details of the test:

	I have a "realtime" app, that sets the scheduling policy and
priority, then forks a specified app, and "eat_cpu", that just sits in an
infinite loop.  Both are attached.
	
	On one console (as root), I do

	> realtime -rr 99 bash
	
	Which gives me a priorty 99, SCHED_RR bash. Then, on another console
(also as root), I do:

	> sleep 10; realtime -rr 50 eat_cpu

	Then I switch back to the first console, with its priority 99 bash.
I am able to type away for 10 seconds, until the priority 50 process starts,
at which point the shell locks up.   I can get the same effect on one
console with:

	> ( sleep 10; realtime -rr 50 eat_cpu ) & realtime -rr 99 bash

	Previously, the high-priority shell would never lock up.  Now it
does.

	Any idea why this doesn't work?

	Cheers,
	Ian

Code:

/* realtime
 * To build:
 *   g++ -o realtime realtime.cxx
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include <unistd.h>
#include <string>


void usage()
{
  printf("usage: realtime -get | {-rr | -fifo} <pri> cmd ...\n");
  exit(1);
}

const char *policyString(int policy)
{
  switch(policy)
  {
  case SCHED_OTHER:   return "SCHED_OTHER";
  case SCHED_FIFO:    return "SCHED_FIFO";
  case SCHED_RR:      return "SCHED_RR";
  }
  return "BAD POLICY";
}

int main(int argc, char *argv[])
{
  seteuid(getuid());

  if (argc < 2)
    usage();

  if (strcmp(argv[1], "-get") == 0)
  {
    int policy = sched_getscheduler(0);
    if (policy < 0)
    {
      perror("sched_getscheduler failed:");
      return 1;
    }

    sched_param param;
    if (sched_getparam(0, &param) < 0)
    {
      perror("sched_getparam failed");
      return 1;
    }

    printf("policy = %d = %s\n", policy, policyString(policy));

    if (policy != SCHED_OTHER)
      printf("priority=%d\n", param.sched_priority);

    int max = sched_get_priority_max(policy);
    if (max < 0) {
      perror("sched_get_priority_max");
      return 1;
    }
    int min = sched_get_priority_min(policy);
    if (min < 0) {
      perror("sched_get_priority_min");
      return 1;
    }                                                        
    printf("prorities: min = %d, max = %d\n", min, max);

    return 0;

  }

  // set

  if (argc < 4)
     usage();

  int policy;

  if (!strcmp(argv[1], "-rr"))
  {
    policy = SCHED_RR;
  }
  else if (!strcmp(argv[1], "-fifo"))
  {
    policy = SCHED_FIFO;
  }
  else {
    printf("bad policy: choose -rr (round robin) or -fifo\n");
    usage();
  }
    
  struct sched_param param;
  param.sched_priority = atoi(argv[2]);

  printf("policy = %d = %s\n", policy, policyString(policy));
  printf("priority=%d\n", param.sched_priority);

  // become root
  seteuid(0);

  if (sched_setscheduler(0, policy, &param) < 0) {
    perror("sched_setscheduler");
    return 1;
  }

  // back down
  seteuid(getuid());

  string cmd;
  for (int i=3; i<argc; i++)
    cmd = cmd + argv[i] + " ";

  printf("cmd = %s\n", cmd.c_str());

  system(cmd.c_str());

  return 0;
}

/* eof */

/* eat_cpu.c */
int main(int argc, char *argv[])
{
  for (;;)
    ;
}    
/* eof */



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
Imerge Limited                          Tel :- +44 (0)1954 783600 
Unit 6 Bar Hill Business Park           Fax :- +44 (0)1954 783601 
Saxon Way                               Web :- http://www.imerge.co.uk 
Bar Hill 
Cambridge 
CB3 8SL 
United Kingdom 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2002-06-05 18:15 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-05 11:53 realtime scheduling problems with 2.4 linux kernel >= 2.4.10 Ian Collinson
2002-06-05 12:17 ` Andi Kleen
2002-06-05 18:05   ` george anzinger
2002-06-05 18:13     ` Robert Love
  -- strict thread matches above, loose matches on Subject: below --
2002-05-30 17:54 Ian Collinson
2002-05-31 18:28 ` Mike Kravetz
2002-05-31 19:41   ` Andrea Arcangeli
2002-06-01 17:05   ` Andi Kleen
2002-06-03 16:03     ` Mike Kravetz
2002-06-03 20:08       ` Andrew Morton
2002-06-03 20:13         ` Robert Love
2002-06-03 21:09           ` Andrew Morton
2002-06-03 21:07         ` Andrea Arcangeli
2002-06-03 20:12       ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox