[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-sparc
Subject:    [gentoo-sparc] sparc64 semctl(x,x,SETVAL,x) problem?
From:       Ferris McCormick <fmccor () inforead ! com>
Date:       2003-08-27 16:45:02
[Download RAW message or body]

Appologies for duplicating a forum thread I started, but I
think the readership sets for the forum and for the mailing list
are not identical.

This is not original code; it is extracted from LAM-MPI.

I am seeing incorrect operation for the semctl(id,index,SETVAL,arg)
function call on an Ultra-2 and Ultra-60, but correct on SS20.
All are SMP running kernel "2.4.21-sparc-r1 #1 SMP" (but I see
the same failure on U2 with kernel 2.4.20).

On all systems, gcc=sys-devel/gcc-3.2.3-r1 and
glibc= sys-libs/glibc-2.3.1-r4 (and on the U60, it is the one
supplied on the install ISO image).

OVERVIEW:  The program which follows creates a semaphore,
  sets its value to 43, and reads it back.  If you call it
  with no arguments, it uses SETVAL to set the value; if
  you call with 2 arguments, it uses SETALL.  The 1 argument
  case is special for when you want to follow to copies
  around while they share the semaphore.

  For our purposes here, ignore the arguments, because
  the program as shown below uses SETALL to set the
  semaphore to 66 before anything else happens in the

  Since the program pauses at each step, you can use the
  ipcs command to convince yourself that everything is
  happening correctly EXCEPT that on sparc64, no value
  is ever copied in for SETVAL except for 0.  AND, the program
  does verify that SETVAL changes the value to 0 -- it doesn't
  leave it as it was.

What I am hoping is that someone can try the little test case
(or one like it) on a different sparc64 (SMP) and let me know if
the problem is unique to my site, although for purposes of this
test, the U60 is about as close to an out-of-the-box system
as you can get.

Here is the Code:
=======================================================
#include <stdio.h>
#include <sys/sem.h>
static union {
    int val;
    short* array;
} v;
/*
 * By itself, this program creates a sysv-semaphore,
 * sets its value to something, reads it back, and
 * then destroys it.
 *
 * You can run two copies by starting one, then starting
 * the second with 'shsem 61440' (assuming 'gcc -o shsem ...')
 *
 * On SS20, it gives back the value "43".
 *
 * For me, on U2, U60, kernels 2-4.21,20 it gives back the
 * values 0.
 *
 * Running two copies and interrogating with ipcs, ipcs -s -i ...
 * shows that the semaphore gets created & passed around, and
 * the times are updated correctly.
 *
 * HOWEVER, value=0 is always set in.
 *
 * I cannot see any problem in semctl.c in glibc,
 * nor in the kernel's ipc/sem.c, assuming it gets used for
 * this.  Still, the times and owners get copied in fine,
 * but the value somehow gets misplaced.
 *
 * NB:, Use 2 dummy arguments if you just want to see an
 * alternate form with SETALL.
 *
 * So:
 * a.  0 args = run with SETVAL
 * b.  1 arg  = run a second SETVAL coordinating with 1st
 * c.  2 args = run using SETALL
 *
 * In cases a, c:  Preset the semaphore to -66- with SETALL.
 *
 * */
main(int argc, char * argv[]) {
    int s,sn  ;
    short a[1];
    if( (argc != 2) || ( (sn=(int)atoi(argv[1]) ) <= 0) ) {
      s=semget(61440,1,0777|IPC_CREAT);
      sn = 0;
      v.val = 43;
    } else {
        s=semget(sn, 1, 0777);
        if(s <= 0) {
            fprintf(stderr,"semget for %d gives %d\n", sn, s);
            exit(s);
        }
        v.val= 86;
    }
    /* Make sure to start out with something in the semaphore */
    if(argc != 2) {
      a[0] = 66;
      sn = v.val;
      v.array = a;
      semctl(s, 0, SETALL, v);
      printf("We initialized %d to %d; VERIFY with ipcs & CR\n",
              s, semctl(s,0,GETVAL,v));
      getchar();
      v.val = sn;
      sn = 0;
    }
    if(argc < 3) {
      semctl(s,0,  SETVAL ,v);
    } else {
        a[0] = 43;
        v.array = a;
        semctl(s,0, SETALL, v);
    }
    printf("%d set to %d; CR to read it\n", s,
       (argc < 3) ? v.val : v.array[0]);
    getchar();
    printf("val=%d; CR to end\n",semctl(s,0,GETVAL,v));
    if(sn== 0) {
        getchar();
        semctl(s,0,IPC_RMID,v);
    }
    return(0);
}

========================================================================

Sorry to be so long winded,
Regards,
--
Ferris McCormick (P44646, MI) <fmccor@inforead.com>
Phone: (703) 392-0303
Fax:   (703) 392-0401


--
gentoo-sparc@gentoo.org mailing list

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic