Changeset 3200227 in rtems-schedsim


Ignore:
Timestamp:
05/16/14 19:46:36 (10 years ago)
Author:
Jennifer Averett <jennifer.averett@…>
Branches:
master
Children:
9f3c8eb
Parents:
08abc0f
Message:

schedsim: Add affinity support to task create.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • schedsim/shell/shared/main_taskcreate.c

    r08abc0f r3200227  
    1414#endif
    1515
     16#define _GNU_SOURCE
     17#include <sys/cpuset.h>
     18
    1619#include <stdio.h>
    1720
     
    4952)
    5053{
     54  char              *c_p;
    5155  char               name[5];
    5256  rtems_id           id;
     
    5862  char               option;
    5963  int                arg;
     64  unsigned long      affinity;
     65  cpu_set_t          cpuset;
     66  bool               do_affinity;
    6067
    6168  CHECK_RTEMS_IS_UP();
     
    6370  mode = 0;
    6471  mask = 0;
     72  do_affinity = false;
    6573  memset(&getopt_reent, 0, sizeof(getopt_data));
    66   while ( (option = getopt_r( argc, argv, "tTpP", &getopt_reent)) != -1 ) {
     74  while ( (option = getopt_r( argc, argv, "a:tTpP", &getopt_reent)) != -1 ) {
    6775    switch (option) {
     76      case 'a':
     77        c_p = getopt_reent.optarg;
     78        if ( rtems_string_to_unsigned_long( c_p, &affinity, NULL, 0) ) {
     79          fprintf( stderr, "Affinity (%s) is not a number\n", argv[2] );
     80          return 1;
     81        }
     82        do_affinity = true;
     83
     84        CPU_ZERO( &cpuset );
     85        cpuset.__bits[0] = affinity;
     86        break;
     87
    6888      case 't':
    6989        mask |= RTEMS_TIMESLICE_MASK;
     
    94114   */
    95115  arg = getopt_reent.optind;
    96   if ((argc - arg) != 2) {
    97     fprintf( stderr, "%s: Usage [args] name priority\n", argv[0] );
     116  if ( ((argc - arg) != 2) && ((argc - arg) != 4) ){
     117    fprintf( stderr, "%s: Usage [args] name priority -a affinity\n", argv[0] );
    98118    return -1;
    99119  }
    100120
    101121  if ( rtems_string_to_long(argv[arg+1], &priority, NULL, 0) ) {
    102     printf( "Seconds argument (%s) is not a number\n", argv[1] );
     122    printf( "Priority argument (%s) is not a number\n", argv[1] );
    103123    return -1;
    104124  }
     
    135155  );
    136156
     157  /*
     158   * If specified, set the affinity
     159   */
     160  if ( do_affinity ) {
     161    status = rtems_task_set_affinity( id, sizeof(cpuset), &cpuset );
     162    if ( status != RTEMS_SUCCESSFUL ) {
     163      fprintf(
     164        stderr,
     165        "Task Set Affinity(0x%08x) returned %s\n"
     166        "Deleting task 0x%08x\n",
     167        affinity,
     168        rtems_status_text( status ),
     169        id
     170      );
     171      rtems_task_delete( id );
     172      return -1;
     173    }
     174    printf("Task (0x%08x) Set affinity=0x%08x\n", id, cpuset.__bits[0] );
     175  }
     176
     177  /*
     178   * Starting the task
     179   */
    137180  printf(
    138181    "Task (%s) starting: id=0x%08x, priority=%ld\n",
Note: See TracChangeset for help on using the changeset viewer.