source: rtems-schedsim/schedsim/shell/shared/main_tasksetaffinity.c @ 08abc0f

Last change on this file since 08abc0f was 08abc0f, checked in by Jennifer Averett <jennifer.averett@…>, on 05/16/14 at 19:45:58

schedsim: Fix affinity error message.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 *  @file
3 *
4 *  Task Set Affinity Shell Command Implmentation
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2014.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 */
15
16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#define _GNU_SOURCE
21#include <sys/cpuset.h>
22
23#include <stdio.h>
24
25#include <rtems.h>
26#include "shell.h"
27#include <rtems/stringto.h>
28#include <schedsim_shell.h>
29#include <rtems/error.h>
30
31int rtems_shell_main_task_set_affinity(
32  int   argc,
33  char *argv[]
34)
35{
36  rtems_id             id;
37  rtems_status_code    status;
38  unsigned long        tmp;
39  cpu_set_t            cpuset;
40
41  CHECK_RTEMS_IS_UP();
42
43  if (argc != 3) {
44    fprintf( stderr, "%s: Usage [name|id] affinity\n", argv[0] );
45    return -1;
46  }
47
48  if ( lookup_task( argv[1], &id ) )
49    return -1;
50
51  if ( rtems_string_to_unsigned_long( argv[2], &tmp, NULL, 0) ) {
52    fprintf( stderr, "Affinity (%s) is not a number\n", argv[2] );
53    return 1;
54  }
55
56  CPU_ZERO( &cpuset );
57  cpuset.__bits[0] = tmp;
58
59  /*
60   *  Now change the affinity of the task
61   */
62  status = rtems_task_set_affinity( id, sizeof(cpuset), &cpuset );
63  if ( status != RTEMS_SUCCESSFUL ) {
64    fprintf(
65      stderr,
66      "Task Set Affinity(%s) returned %s\n",
67      argv[1],
68      rtems_status_text( status )
69    );
70    return -1;
71  }
72
73  printf("Task (0x%08x) Set affinity=0x%08x\n", id, cpuset.__bits[0] );
74
75  return 0;
76}
77
78rtems_shell_cmd_t rtems_shell_TASK_SET_AFFINITY_Command = {
79  "task_set_affinity",                 /* name */
80  "task_set_affinity name ",           /* usage */
81  "rtems",                             /* topic */
82  rtems_shell_main_task_set_affinity,  /* command */
83  NULL,                                /* alias */
84  NULL                                 /* next */
85};
Note: See TracBrowser for help on using the repository browser.