summaryrefslogtreecommitdiffstats
path: root/posix_api/psx_sched_report/psx_sched_report.c
blob: b0381aa50bf2256106a82df609826b740ba2565c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 *  Program to print POSIX Scheduler Characteristics
 */

/*
 * Copyright 2018 Joel Sherrill (joel@rtems.org)
 *
 * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file.
 */

#include <stdlib.h>
#include <stdio.h>
#include <sched.h>
/* FreeBSD 10 needs this for struct timespec which seems wrong */
#include <time.h>

void print_sched_info(
  char *s,
  int policy
)
{
  int min, max, levels;
  struct timespec t;

  printf( "Information on %s\n", s );
  min = sched_get_priority_min( policy );
  max = sched_get_priority_max( policy );
  (void) sched_rr_get_interval( 1, &t );
  levels = abs(max - min + 1);
  printf( "\tSupports %d priority levels (%d - %d)\n", levels, min, max  );
  if ( levels >= 32 )
    printf( "\tImplementation is compliant on priority levels\n");
  else
    printf( "\tImplementation is NOT compliant on priority levels\n" );

  printf( "\tScheduling quantum is %ld seconds and %ld nanoseconds\n",
              (long)t.tv_sec, (long)t.tv_nsec );
  puts( "" );
}

int main()
{
  puts( "*** POSIX Scheduler Characteristics Report ***" );
  print_sched_info( "SCHED_OTHER", SCHED_OTHER );
  print_sched_info( "SCHED_FIFO", SCHED_FIFO );
  print_sched_info( "SCHED_RR", SCHED_RR );
#if defined(SCHED_SPORADIC)
  print_sched_info( "SCHED_SPORADIC", SCHED_SPORADIC );
#else
  printf( "SCHED_SPORADIC is not supported\n" );
#endif
  puts( "*** END OF POSIX Scheduler Characteristics Report ***" );

  exit( 0 );
}