Sponsored Content
Full Discussion: semaphore access speed
Top Forums Programming semaphore access speed Post 302243588 by otheus on Monday 6th of October 2008 05:11:05 AM
Old 10-06-2008
I checked the kernels. There were major changes in 1995 (before version 2.0), 1998 (before version 2.4), and then again with the introduction of the "O(1) scheduler" (not sure). Here's the code -- unchanged since 2.4 -- that does semctl(GETALL):
Code:
        sma = sem_lock(semid);
/* check condition omitted */
        nsems = sma->sem_nsems;
        err=-EIDRM;
        if (sem_checkid(sma,semid)) goto out_unlock;
        err = -EACCES;
        if (ipcperms (&sma->sem_perm, (cmd==SETVAL||cmd==SETALL)?S_IWUGO:S_IRUGO))
                goto out_unlock;

	case GETALL:	{
		ushort __user *array = arg.array;
		int i;

		if(nsems > SEMMSL_FAST) {
/* omitted code -- relevant only when nsems > 256 */
		}

		for (i = 0; i < sma->sem_nsems; i++)
			sem_io[i] = sma->sem_base[i].semval;
		sem_unlock(sma);
		err = 0;
		if(copy_to_user(array, sem_io, nsems*sizeof(ushort)))
			err = -EFAULT;
		goto out_free;

Here's the code from 2.0:
Code:
        case GETALL:
                if (ipcperms (ipcp, S_IRUGO)) return -EACCES;
                switch (cmd) {
/* ommitted irrelevant code */
                case GETALL:
                        array = arg.array;
                        i = verify_area (VERIFY_WRITE, array, nsems*sizeof(ushort));
                        if (i)
                                return i;
                }
                break;
/* skipping case statements */

        if (semary[id] == IPC_UNUSED || semary[id] == IPC_NOID)
                return -EIDRM;
/* the next line provides the sem_checkid() call from 2.4/2.6 code */
        if (sma->sem_perm.seq != (unsigned int) semid / SEMMNI)
                return -EIDRM;

        switch (cmd) {
        case GETALL:
                if (ipcperms (ipcp, S_IRUGO))
                        return -EACCES;
                for (i = 0; i < sma->sem_nsems; i++)
                        sem_io[i] = sma->sem_base[i].semval;
                memcpy_tofs (array, sem_io, nsems*sizeof(ushort));
                break;

When you break it down, the only difference is in the semlock() call, which is needed on multi-CPU systems. It could be SCO is also similarly limited. Why don't you try a linux 2.0 distribution, like RedHat 5.2, which uses Linux 2.0.36 (and uses the same sem code as above). Install it and benchmark the same code. That would be a great help to all of us, I think.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

semaphore

hi, is there any command where we can monitor semaphores? (1 Reply)
Discussion started by: yls177
1 Replies

2. UNIX for Dummies Questions & Answers

Semaphore

Hi, I'm new to UNIX. I need to know what's a semaphore Do reply. Thanks VJ (3 Replies)
Discussion started by: vjsony
3 Replies

3. Filesystems, Disks and Memory

dmidecode, RAM speed = "Current Speed: Unknown"

Hello, I have a Supermicro server with a P4SCI mother board running Debian Sarge 3.1. This is the "dmidecode" output related to RAM info: RAM speed information is incomplete.. "Current Speed: Unknown", is there anyway/soft to get the speed of installed RAM modules? thanks!! Regards :)... (0 Replies)
Discussion started by: Santi
0 Replies

4. Shell Programming and Scripting

Semaphore

Hi, I am looking to use a semaphore for the first time in one of my scripts. I am just wondering if there are any simple examples or tutorials around? I am a beginner so the simpler the better :) Thanks -Jaken (2 Replies)
Discussion started by: Jaken
2 Replies

5. UNIX for Dummies Questions & Answers

semaphore

what is semaphore? can any body explain it in a more simple way than the manual ?? replies appreciated Regards raguram R (7 Replies)
Discussion started by: raguramtgr
7 Replies

6. Filesystems, Disks and Memory

data from blktrace: read speed V.S. write speed

I analysed disk performance with blktrace and get some data: read: 8,3 4 2141 2.882115217 3342 Q R 195732187 + 32 8,3 4 2142 2.882116411 3342 G R 195732187 + 32 8,3 4 2144 2.882117647 3342 I R 195732187 + 32 8,3 4 2145 ... (1 Reply)
Discussion started by: W.C.C
1 Replies

7. Shell Programming and Scripting

semaphore

Control two exclusively shared resources(semaphore). The two resources are two files. The producer will write even numbers to one file, and odd numbers to another one. The consumer respectively reads from each file until it gets 5 even numbers and 5 odd numbers. Can any one help me with the... (0 Replies)
Discussion started by: gokult
0 Replies

8. Programming

Semaphore

If I create a semaphore and then I fork a number of child processes then all the child process use that same semaphore. Since the process address spaces are different rfom each other then how all the child process are able to access the same semaphore? I understand that semaphore/mutex is at os... (0 Replies)
Discussion started by: rupeshkp728
0 Replies

9. UNIX for Beginners Questions & Answers

Semaphore

I was asked to add this piece of code to a c program which I will execute through the shell: for(long i = 0; i < NITER; i++) { sem_wait( &sema); count++; sem_post( &sema); } I didn't get it, which is the critical section ? if it's "count++" how would a thread wake up in order to enter it... (1 Reply)
Discussion started by: uniran
1 Replies
SEMCTL(2)						      BSD System Calls Manual							 SEMCTL(2)

NAME
semctl -- semaphore control operations LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/sem.h> int semctl(int semid, int semnum, int cmd, ...); DESCRIPTION
The semctl() system call provides a number of control operations on the semaphore specified by semnum and semid. The operation to be per- formed is specified in cmd (see below). The fourth argument is optional and depends upon the operation requested. If required, it is a union of the following fields: int val; /* value for SETVAL */ struct semid_ds *buf; /* buffer for IPC_{STAT,SET} */ u_short *array; /* array for GETALL & SETALL */ The semid_ds structure used in the IPC_SET and IPC_STAT commands is defined in <sys/sem.h> and contains the following members: struct ipc_perm sem_perm; /* operation permissions */ unsigned short sem_nsems; /* number of sems in set */ time_t sem_otime; /* last operation time */ time_t sem_ctime; /* last change time */ The ipc_perm structure used inside the semid_ds structure is defined in <sys/ipc.h> and contains the following members: uid_t cuid; /* creator user id */ gid_t cgid; /* creator group id */ uid_t uid; /* user id */ gid_t gid; /* group id */ mode_t mode; /* permission (lower 9 bits) */ semctl() provides the following operations: GETVAL Return the value of the semaphore. SETVAL Set the value of the semaphore to arg.val, where arg is the fourth argument to semctl(). GETPID Return the pid of the last process that did an operation on this semaphore. GETNCNT Return the number of processes waiting to acquire the semaphore. GETZCNT Return the number of processes waiting for the value of the semaphore to reach 0. GETALL Return the values of all the semaphores associated with semid. SETALL Set the values of all the semaphores that are associated with the semaphore identifier semid to the corresponding values in arg.array, where arg is the fourth argument to semctl(). IPC_STAT Gather information about a semaphore and place the information in the structure pointed to by arg.buf, where arg is the fourth argument to semctl(). IPC_SET Set the value of the sem_perm.uid, sem_perm.gid and sem_perm.mode fields in the structure associated with the semaphore. The val- ues are taken from the corresponding fields in the structure pointed to by arg.buf, there arg is the fourth argument to semctl(). This operation can only be executed by the super-user, or a process that has an effective user id equal to either sem_perm.cuid or sem_perm.uid in the data structure associated with the semaphore. IPC_RMID Remove the semaphores associated with semid from the system and destroy the data structures associated with it. Only the super- user or a process with an effective uid equal to the sem_perm.cuid or sem_perm.uid values in the data structure associated with the semaphore can do this. The permission to read or change a semaphore (see semop(2)) is determined by the sem_perm.mode field in the same way as is done with files (see chmod(2)), but the effective uid can match either the sem_perm.cuid field or the sem_perm.uid field, and the effective gid can match either sem_perm.cgid or sem_perm.gid. RETURN VALUES
For the GETVAL, GETPID, GETNCNT, and GETZCNT operations, semctl() returns one of the values described above if successful. All other opera- tions will make semctl() return 0 if no errors occur. Otherwise -1 is returned and errno set to reflect the error. ERRORS
semctl() will fail if: [EACCES] The caller has no operation permission for this semaphore. [EFAULT] arg.buf or arg.array specifies an invalid address. [EINVAL] semid is not a valid message semaphore identifier. cmd is not a valid command. [EPERM] cmd is equal to IPC_SET or IPC_RMID and the caller is not the super-user, nor does the effective uid match either the sem_perm.uid or sem_perm.cuid fields of the data structure associated with the semaphore. [ERANGE] cmd is equal to SETVAL or SETALL and the value to be set is greater than the system semaphore maximum value. SEE ALSO
semget(2), semop(2) STANDARDS
The semctl system call conforms to X/Open System Interfaces and Headers Issue 5 (``XSH5''). HISTORY
Semaphores appeared in the first release of AT&T System V UNIX. BSD
August 25, 1999 BSD
All times are GMT -4. The time now is 02:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy