source: rtems-schedsim/schedsim/shell/shared/main_taskgetaffinity.c @ 156cb91

Last change on this file since 156cb91 was 156cb91, checked in by Joel Sherrill <joel.sherrill@…>, on May 14, 2014 at 2:23:26 PM

shell/shared: Add task get/set affinity

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 *  @file
3 *
4 *  Task Get 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_get_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 != 2) {
44    fprintf( stderr, "%s: Usage [name|id]\n", argv[0] );
45    return -1;
46  }
47
48  if ( lookup_task( argv[1], &id ) )
49    return -1;
50
51  CPU_ZERO( &cpuset );
52  cpuset.__bits[0] = tmp;
53
54  /*
55   *  Now obtain the affinity the task
56   */
57  status = rtems_task_get_affinity( id, sizeof(cpuset), &cpuset );
58  if ( status != RTEMS_SUCCESSFUL ) {
59    fprintf(
60      stderr,
61      "Task Get Affinity(%s) returned %s\n",
62      argv[1],
63      rtems_status_text( status )
64    ); 
65    return -1;
66  }
67
68  printf("Task (0x%08x) Get affinity=0x%08x\n", id, cpuset.__bits[0] );
69 
70  return 0;
71}
72
73rtems_shell_cmd_t rtems_shell_TASK_GET_AFFINITY_Command = {
74  "task_get_affinity",                 /* name */
75  "task_get_affinity name ",           /* usage */
76  "rtems",                             /* topic */
77  rtems_shell_main_task_get_affinity,  /* command */
78  NULL,                                /* alias */
79  NULL                                 /* next */
80};
Note: See TracBrowser for help on using the repository browser.