Ignore:
Timestamp:
08/11/95 14:27:23 (28 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
c1403ef1
Parents:
0e4c603
Message:

Initialization of semaphores was incorrect. It did not force
the count to "1" to indicate availability.

Interrupt support was added.

Problem where newlib's errno "overrides" that set by system calls
was addressed.

Fixed bug which resulted in all nodes using the same semaphore although
an array of semaphores was allocated.

Location:
c/src/lib/libbsp/unix/posix/shmsupp
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/unix/posix/shmsupp/getcfg.c

    r0e4c603 raa9f194  
    1212 *    *shmcfg   - pointer to SHM Config Table
    1313 *
    14  *  NOTES:  The MP interrupt used is the Runway bus' ability to directly
    15  *          address the control registers of up to four CPUs and cause
    16  *          interrupts on them.
    17  *
    18  *          The following table illustrates the configuration limitations:
    19  *
    20  *                                   BUS     MAX
    21  *                          MODE    ENDIAN  NODES
    22  *                        ========= ====== =======
    23  *                         POLLED    BIG    2+
    24  *                        INTERRUPT  BIG    2..4
     14 *  NOTES:  This driver is capable of supporting a practically unlimited
     15 *          number of nodes.
    2516 *
    2617 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
     
    4435#include <errno.h>
    4536#include <unistd.h>
     37#include <stdlib.h>
    4638#include <sys/ipc.h>
    4739#include <sys/shm.h>
    4840#include <sys/sem.h>
    49 
    50 #define INTERRUPT 0        /* can be interrupt or polling */
    51 #define POLLING   1
    5241
    5342shm_config_table BSP_shm_cfgtbl;
     
    5948);
    6049
     50void fix_semaphores( void )
     51{
     52    rtems_unsigned32 maximum_nodes;
     53    int          i;
     54
     55    int          shmid;
     56    char        *shm_addr;
     57    key_t        shm_key;
     58    key_t        sem_key;
     59    int          status;
     60    int          shm_size;
     61
     62    if (getenv("RTEMS_SHM_KEY"))
     63        shm_key = strtol(getenv("RTEMS_SHM_KEY"), 0, 0);
     64    else
     65#ifdef RTEMS_SHM_KEY
     66        shm_key = RTEMS_SHM_KEY;
     67#else
     68        shm_key = 0xa000;
     69#endif
     70 
     71    if (getenv("RTEMS_SHM_SIZE"))
     72        shm_size = strtol(getenv("RTEMS_SHM_SIZE"), 0, 0);
     73    else
     74#ifdef RTEMS_SHM_SIZE
     75        shm_size = RTEMS_SHM_SIZE;
     76#else
     77        shm_size = 64 * KILOBYTE;
     78#endif
     79 
     80    if (getenv("RTEMS_SHM_SEMAPHORE_KEY"))
     81        sem_key = strtol(getenv("RTEMS_SHM_SEMAPHORE_KEY"), 0, 0);
     82    else
     83#ifdef RTEMS_SHM_SEMAPHORE_KEY
     84        sem_key = RTEMS_SHM_SEMAPHORE_KEY;
     85#else
     86        sem_key = 0xa001;
     87#endif
     88
     89    shmid = shmget(shm_key, shm_size, IPC_CREAT | 0660);
     90    if ( shmid == -1 ) {
     91       fix_syscall_errno(); /* in case of newlib */
     92       perror( "shmget" );
     93       rtems_fatal_error_occurred(RTEMS_UNSATISFIED);
     94    }
     95
     96    shm_addr = shmat(shmid, (char *)0, SHM_RND);
     97    if ( shm_addr == (void *)-1 ) {
     98       fix_syscall_errno(); /* in case of newlib */
     99       perror( "shmat" );
     100       rtems_fatal_error_occurred(RTEMS_UNSATISFIED);
     101    }
     102
     103    maximum_nodes = Shm_RTEMS_MP_Configuration->maximum_nodes;
     104    semid = semget(sem_key, maximum_nodes + 1, IPC_CREAT | 0660);
     105    if ( semid == -1 ) {
     106       fix_syscall_errno(); /* in case of newlib */
     107       perror( "semget" );
     108       rtems_fatal_error_occurred(RTEMS_UNSATISFIED);
     109    }
     110
     111    if ( Shm_Is_master_node() ) {
     112      for ( i=0 ; i <= maximum_nodes ; i++ ) {
     113
     114#if defined(solaris2)
     115        union semun {
     116          int val;
     117          struct semid_ds *buf;
     118          ushort *array;
     119        } help;
     120 
     121        help.val = 1;
     122        semctl( semid, i, SETVAL, help );
     123#endif
     124#if defined(hpux)
     125        semctl( semid, i, SETVAL, 1 );
     126#endif
     127
     128        fix_syscall_errno(); /* in case of newlib */
     129        if ( status == -1 ) {
     130          fprintf( stderr, "Sem init failed %d\n", errno ); fflush( stderr );
     131          rtems_fatal_error_occurred(RTEMS_UNSATISFIED);
     132        }
     133      }
     134    }
     135
     136    BSP_shm_cfgtbl.base         = (vol_u32 *)shm_addr;
     137    BSP_shm_cfgtbl.length       = shm_size;
     138}
     139
    61140void Shm_Get_configuration(
    62141  rtems_unsigned32   localnode,
     
    64143)
    65144{
    66     rtems_unsigned32 maximum_nodes;
    67     int          i;
    68     int          shmid;
    69     char        *shm_addr;
    70     key_t        shm_key;
    71     key_t        sem_key;
    72     struct sembuf  sb;
    73     int          status;
     145    fix_semaphores();
    74146
    75     shm_key = 0xa000;
    76 
    77     shmid = shmget(shm_key, 16 * KILOBYTE, IPC_CREAT | 0660);
    78     if ( shmid == -1 ) {
    79        perror( "shmget" );
    80        exit( 0 );
    81     }
    82 
    83     shm_addr = shmat(shmid, (char *)0, SHM_RND);
    84     if ( shm_addr == (void *)-1 ) {
    85        perror( "shmat" );
    86        exit( 0 );
    87     }
    88 
    89     sem_key = 0xa001;
    90 
    91     maximum_nodes = Shm_RTEMS_MP_Configuration->maximum_nodes;
    92     semid = semget(sem_key, maximum_nodes + 1, IPC_CREAT | 0660);
    93     if ( semid == -1 ) {
    94        perror( "semget" );
    95        exit( 0 );
    96     }
    97 
    98     if ( Shm_Is_master_node() ) {
    99       for ( i=0 ; i <= maximum_nodes ; i++ ) {
    100         sb.sem_op  = 1;
    101         sb.sem_num = i;
    102         sb.sem_flg = 0;
    103         status = semop( semid, &sb, 1 );
    104         if ( status == -1 ) {
    105           fprintf( stderr, "Sem init failed %d\n", errno ); fflush( stderr );
    106           exit( 0 );
    107         }
    108       }
    109     }
    110 
    111     BSP_shm_cfgtbl.base         = (vol_u32 *)shm_addr;
    112     BSP_shm_cfgtbl.length       = 16 * KILOBYTE;
    113147    BSP_shm_cfgtbl.format       = SHM_BIG;
    114148
     
    121155#endif
    122156
    123 #if ( POLLING == 1 )
     157#ifdef INTERRUPT_EXTERNAL_MPCI
     158    BSP_shm_cfgtbl.poll_intr    = INTR_MODE;
     159    BSP_shm_cfgtbl.Intr.address = (vol_u32 *) getpid();    /* process id */
     160    BSP_shm_cfgtbl.Intr.value   = INTERRUPT_EXTERNAL_MPCI; /* signal to send */
     161    BSP_shm_cfgtbl.Intr.length  = LONG;
     162#else
    124163    BSP_shm_cfgtbl.poll_intr    = POLLED_MODE;
    125164    BSP_shm_cfgtbl.Intr.address = NO_INTERRUPT;
    126165    BSP_shm_cfgtbl.Intr.value   = NO_INTERRUPT;
    127166    BSP_shm_cfgtbl.Intr.length  = NO_INTERRUPT;
    128 #else
    129     BSP_shm_cfgtbl.poll_intr    = INTR_MODE;
    130     BSP_shm_cfgtbl.Intr.address = 0;    /* process id? */
    131     BSP_shm_cfgtbl.Intr.value   = 0;    /* signal to send? */
    132     BSP_shm_cfgtbl.Intr.length  = LONG;
    133167#endif
    134168
  • c/src/lib/libbsp/unix/posix/shmsupp/intr.c

    r0e4c603 raa9f194  
    2424
    2525#include <stdio.h>
    26 
     26#include <signal.h>
     27 
    2728void Shm_Cause_interrupt_unix(
    2829  rtems_unsigned32 node
    2930)
    3031{
     32    Shm_Interrupt_information *intr;
     33    intr = &Shm_Interrupt_table[node];
     34 
     35    kill((pid_t) intr->address, intr->value);
    3136}
  • c/src/lib/libbsp/unix/posix/shmsupp/lock.c

    r0e4c603 raa9f194  
    4242)
    4343{
    44   lq_cb->lock =
    45     ( lq_cb - Shm_Locked_queues ) / sizeof( Shm_Locked_queue_Control );
     44  lq_cb->lock = lq_cb - Shm_Locked_queues;
    4645}
    4746
     
    6160    int                status;
    6261
    63     isr_level = 0;
    64 
    6562    sb.sem_num = lq_cb->lock;
    6663    sb.sem_op  = -1;
    6764    sb.sem_flg = 0;
     65
    6866    rtems_interrupt_disable( isr_level );
    6967
     
    7270    while (1) {
    7371      status = semop(semid, &sb, 1);
    74       if ( status == 0 )
     72      if ( status >= 0 )
    7573        break;
    76       if ( status == -1 && errno == EINTR )
    77         continue;
    78 
    79       fprintf( stderr, "shm lock(%d %d)\n", status, errno );
    80       exit( 0 );
     74      if ( status == -1 ) {
     75         fix_syscall_errno();    /* in case of newlib */
     76          if (errno == EINTR)
     77              continue;
     78          perror("shm lock");
     79          rtems_fatal_error_occurred(RTEMS_UNSATISFIED);
     80      }
    8181    }
    8282}
     
    9696    int                status;
    9797
    98     isr_level = 0;
    99 
    10098    sb.sem_num = lq_cb->lock;
    10199    sb.sem_op  = 1;
     
    104102    while (1) {
    105103      status = semop(semid, &sb, 1);
    106       if ( status == 0 )
     104      if ( status >= 0 )
    107105        break;
    108       if ( status == -1 && errno == EINTR )
    109         continue;
    110106
    111       fprintf( stderr, "shm unlock(%d %d)\n", status, errno );
    112       exit( 0 );
     107      if ( status == -1 ) {
     108          fix_syscall_errno();    /* in case of newlib */
     109          if (errno == EINTR)
     110              continue;
     111          perror("shm unlock");
     112          rtems_fatal_error_occurred(RTEMS_UNSATISFIED);
     113      }
    113114    }
    114115
  • c/src/lib/libbsp/unix/posix/shmsupp/mpisr.c

    r0e4c603 raa9f194  
    2626void Shm_setvec( void )
    2727{
     28#ifdef INTERRUPT_EXTERNAL_MPCI
    2829  set_vector( Shm_isr, INTERRUPT_EXTERNAL_MPCI, 1 );
     30#endif
    2931}
Note: See TracChangeset for help on using the changeset viewer.