summaryrefslogtreecommitdiffstats
path: root/schedsim/shell/shared/main_dump_all_cpus.c
blob: 2e1f108a6912bbea86ab792bc4185cf79a0d2a30 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 *  COPYRIGHT (c) 1989-2013.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 */

#include <newlib/getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "shell.h"
#include "rtems_sched.h"
#include "schedsim_shell.h"

#include <rtems.h>
#include <rtems/score/percpu.h>
#include <rtems/score/smp.h>
#include <rtems/score/schedulerpriority.h>

int main_dump_all_cpus(int argc, char **argv)
{
  uint32_t        cpu;
  Thread_Control *h;
  Thread_Control *i;
  Thread_Control *e;
  rtems_id        id;
  bool            mismatch;

  printf(
    "=== CPU Status\n"
    "          EXECUTING      /   HEIR             / SWITCH NEEDED\n"
  );
  for ( cpu=0 ; cpu < rtems_get_processor_count() ; cpu++ ) {
    e = _Per_CPU_Information[cpu].per_cpu.executing;
    h = _Per_CPU_Information[cpu].per_cpu.heir;
    printf(
      "  CPU %d: 0x%08x @%3ld / 0x%08x @%3ld          %s\n",
      cpu,
      e->Object.id, (long) e->current_priority,
      h->Object.id, (long) h->current_priority,
      ((_Per_CPU_Information[cpu].per_cpu.dispatch_necessary) ?
         "true" : "false")
    );
  }
  printf( "=== End of Ready Set of Threads\n" );

  /*
   * If no arguments, then we were not requested to verify task placement.
   */
  if ( argc == 1 )
    return 0;

  /*
   * Now verify the thread on each processor. 
   */
  mismatch = false;
  for ( cpu=0 ; cpu < rtems_get_processor_count() && cpu < argc ; cpu++ ) {
    e = _Per_CPU_Information[cpu].per_cpu.executing;

    if ( argv[cpu + 1][ 0 ] == '-' )
      continue;

    if ( !strcmp( argv[cpu + 1], "IDLE" )) {
      /* XXX should do something cleaner for the ID mask */
      if ( (e->Object.id & 0xFFFF0000) != 0x09010000 ) {
        mismatch = true;
        printf(
          "*** ERROR on CPU %d Expected an IDLE found 0x%08x executing\n",
          cpu,
          e->Object.id
        );
      }
    } else {
      if ( lookup_task( argv[cpu + 1], &id ) ) {
        printf(
          "*** ERROR in scenario -- unknown task %s\n",
           argv[cpu + 1]
        );
        exit( 1 );
      }

      if ( e->Object.id != id ) {
        mismatch = true;
        printf(
          "*** ERROR on CPU %d Expected 0x%08x found 0x%08x executing\n",
          cpu,
          id,
          e->Object.id
        );
      }
    }
  }
  if ( mismatch ) {
    printf( "Exiting test scenario due to scheduling failure\n" );
    exit( 1 );
  }

  return 0;
}

rtems_shell_cmd_t rtems_shell_CPUS_Command = {
  "cpus",                           /* name */
  "cpus [tasks expected on cores]", /* usage */
  "rtems",                          /* topic */
  main_dump_all_cpus,              /* command */
  NULL,                             /* alias */
  NULL                              /* next */
};