Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
semctl(semid,offset,SETVAL,ctl) doesn't on sparc-64?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo on Sparc
View previous topic :: View next topic  
Author Message
Ferris
Retired Dev
Retired Dev


Joined: 13 Jan 2003
Posts: 426
Location: N. Virginia (USA)

PostPosted: Tue Aug 26, 2003 6:56 pm    Post subject: semctl(semid,offset,SETVAL,ctl) doesn't on sparc-64? Reply with quote

Does anyone know the status of the "semctl" call on sparc-64? Or, in
somewhat longer form:

The LAM-MPI (message passing for multiprocessors) package likes to
use shared memory & semaphores in some of its modes of operations. On
my Sparc20-SMP, this works fine, but on U2, U60, the atomic setvalue
calls "semctl(id,offest,SETVAL,..)" don't set values.

I am including a little test case extracted from the LAM-MPI code, and
I'd appreciate it if someone with a similar system could check this so I
can tell if this is a local problem or something more general in the library.

First, here're what the configurations look like:


  • SS20-SMP, kernel=2.4.21-sparc-r1 #1 SMP,
    gcc=sys-devel/gcc-3.2.3-r1, glibc= sys-libs/glibc-2.3.1-r4
  • U2-SMP, kernel=2.4.21-sparc-r1 #1 SMP,
    gcc=sys-devel/gcc-3.2.3-r1, glibc=sys-libs/glibc-2.3.1-r4
  • U60-SMP --- Do you see a pattern here?


Second, you can use the ipcs command (ipcs -s -i <semaphore-id>) to
verify what the program is doing.

Here's the test case:
Code:

/*
 * sysv-semaphore test.
 * This program should allocate three semaphores,
 * set their values to something,
 * read those values back and print them,
 * destroy the semaphores,
 * and exits.
 *
 * On my SS20-2.4.21-SMP, it does just that.
 *
 * On Ultra2, Ultra60-2.4.21-SMP, for me it sets no value
 * into the semaphore.
 *
 * HOWEVER, the SETALL call =does= set in values!
 * */
#include <stdio.h>
#include <sys/sem.h>

/*
 * Documentation says to define this because headers don't
 * */

static union {
    int val;
    struct semid_ds *buf;
    unsigned short *array;
} semctl_arg;

int
main(int argc, char ** argv) {
    int semid;
    char * line;
    int v, i;
    int stat;
    short all_at_once[] = {32, 23, 1};
    line = (char*)  malloc(256);
    /*
     * Grab a semaphore
     * */

    semid = semget(IPC_PRIVATE, 3, 0777 | IPC_CREAT);
    if(semid < 0) {
        fprintf(stderr,"OOPS! Can't get semaphore! <%d>\n", semid);
        return(semid);
    }

    /* See "man semctl" -- we are setting the semaphore values one
     * at a time to 1, 32, 23 respectively */

    printf("Play with id=%d (%x)\n", semid, semid);
    semctl_arg.val = 1;
    stat = semctl(semid, 0, SETVAL, semctl_arg );
    printf("<set 0 to val=%d\n", semctl_arg.val);
    semctl_arg.val = 23;
    stat |= semctl(semid, 2, SETVAL, semctl_arg );
    printf("<set 2 to val=%d\n", semctl_arg.val);
    semctl_arg.val = 32;
    stat |= semctl(semid, 1, SETVAL,  semctl_arg );
    printf("<set 1 to val=%d\n", semctl_arg.val);
    printf("semid=%d has values set, ORed stat=%d; CR to go on\n", semid, stat);
    gets(line);
    for(i=0; i < 3; ++i) {
        v = semctl(semid, i,GETVAL);
        printf("%d(%d) has value = %d\n", semid,i, v);
    }
    printf("Those are what %d has; CR again to batch (SETALL)\n", semid);
    gets(line);
    semctl_arg.array = all_at_once;
    stat = semctl(semid,0, SETALL, semctl_arg);
    printf("For set-all (32,23,1), stat=%d; CR to read them\n", stat);
    gets(line);
    for(i=0; i < 3; ++i) {
        v = semctl(semid, i,GETVAL);
        printf("%d(%d) has value = %d\n", semid,i, v);
    }
    printf("That's values again from %d; CR to end\n", semid);
    semctl(semid,0,IPC_RMID);
    return 0;
}


What should happen looks like this on the SS20:

Play with id=5144577 (4e8001)
<set 0 to val=1
<set 2 to val=23
<set 1 to val=32
semid=5144577 has values set, ORed stat=0; CR to go on

5144577(0) has value = 1
5144577(1) has value = 32
5144577(2) has value = 23
Those are what 5144577 has; CR again to batch (SETALL)

For set-all (32,23,1), stat=0; CR to read them

5144577(0) has value = 32
5144577(1) has value = 23
5144577(2) has value = 1
That's values again from 5144577; CR to end


What happens (and is wrong) on the U2 & U60 is this:


fmccor@antaresia:DASSF/DaSSF-LAM/app [454]% sem
Play with id=917504 (e0000)
<set 0 to val=1
<set 2 to val=23
<set 1 to val=32
semid=917504 has values set, ORed stat=0; CR to go on

917504(0) has value = 0
917504(1) has value = 0
917504(2) has value = 0

Those are what 917504 has; CR again to batch (SETALL)

For set-all (32,23,1), stat=0; CR to read them

917504(0) has value = 32
917504(1) has value = 23
917504(2) has value = 1
That's values again from 917504; CR to end


(Assume here that the program was compiled as "gcc -o sem sem.c"
but optimisation levels don't matter in my tests at least.)

For the impatient, here is a much smaller test:
Code:
#include <sys/sem.h>
main() {
    int s, v=43;
    s=semget(IPC_PRIVATE,1,0777|IPC_CREAT);
    semctl(s,0,SETVAL,&v);
    printf("val=%d\n",semctl(s,0,GETVAL));
    return(0);
}


Sorry for the very long post, but I don't see where the problem is, yet. :?

Regards,
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo on Sparc All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum