summaryrefslogtreecommitdiff
path: root/schedsim/shell/shared/main_taskscheduler.c
blob: 6adc215ce5987023597f39adea32212d54034488 (plain)
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
/*
 *  Task Create Shell Command Implmentation
 *
 *  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.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#if defined(RTEMS_SMP)
#define _GNU_SOURCE
#include <sys/cpuset.h>
#endif

#include <stdio.h>

#define __need_getopt_newlib
#include <newlib/getopt.h>

#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>

int rtems_shell_main_task_set_scheduler(
  int   argc,
  char *argv[]
)
{
  rtems_id           task_id;
  rtems_id           scheduler_id;
  rtems_status_code  status;
  rtems_name         name;
  long               sched;
  bool               ok = true;

  CHECK_RTEMS_IS_UP();

  if (strcmp("", shell_scheduler_list[0]) == 0)
  {
    fprintf(stderr, "Cluster Scheduling not configured\n");
    return -1;
  }

  if (argc != 3)
    ok = false;

  if ( lookup_task( argv[1], &task_id ) )
    ok = false;

  if (!ok)
  {
    fprintf( stderr, "%s: Usage [task name|id]  [sheduler number] \n", argv[0] );
    return -1;
  }

  if ( rtems_string_to_long(argv[2], &sched, NULL, 0) ) {
    fprintf( stderr, "Schedule argument (%s) is not a number\n", argv[2] );
    return -1;
  }

  name = SCHED_NAME(sched);

  status = rtems_scheduler_ident( name, &scheduler_id );
  if ( status != RTEMS_SUCCESSFUL ) {
    fprintf(
      stderr,
      "Task scheduler id (%d) returned %s\n",
      sched,
      rtems_status_text( status )
    );
    return -1;
  }

  printf("Task (0x%08x) on %s\n", task_id, shell_scheduler_list[sched] );

  status = rtems_task_set_scheduler(task_id, scheduler_id );
  if ( status != RTEMS_SUCCESSFUL ) {
    fprintf(
      stderr,
      "Task set scheduler(%s) returned %s\n",
      argv[1],
      rtems_status_text( status )
    );
    return -1;
  }

  return 0;
}

rtems_shell_cmd_t rtems_shell_TASK_SET_SCHEDULER_Command = {
  "task_set_scheduler",                 /* name */
  "task_set_scheduler task_name scheduler_name",   /* usage */
  "rtems",                       /* topic */
  rtems_shell_main_task_set_scheduler,  /* command */
  NULL,                          /* alias */
  NULL                           /* next */
};