From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,a3ae14aeae49226 X-Google-Attributes: gidfee84,public From: Aurel Balmosan Subject: Re: mutex between processes? Date: 1998/08/11 Message-ID: #1/1 X-Deja-AN: 379998632 X-Nntp-Posting-Host: 194.122.136.143 Sender: news@orga.com (News Administrator) References: <35C85511.E31EBB9E@brighttiger.com> <35CAC907.497400F4@orga.com> <35CB2911.61856927@brighttiger.com> <35CF6191.3BB020B5@ne.mediaone.net> <35CFAAE2.42E645BA@ne.mediaone.net> Organization: ORGA Kartensysteme GmbH Newsgroups: comp.unix.osf.osf1 Monty Brandenberg wrote: > . Cost of syscall versus cost of spinlock contention. The time to execute > a trivial syscall (trap, prepare return value, dismiss trap) on an EV5-class > alpha can be as low as 500 nS (nano). Obviously, a real syscall is going to > take more time. It's been some time since I've benchmarked it but a heavy- > weight syscall using the ioctl interface, a sleep, an interrupt in an > ISR routine to do a wakeup was under 10 uS and 6 uS comes to mind. A mutex > acquire/release pair could be as fast as 1 uS for no contention, and on > the order of 10 uS (plus sleep time) with contention. The user-mode spinlock > widens the spread. First, with no contention, you still need a correct > implementation of the spinlock and that will eat a few cycles (see algorithm) > but is still faster than a syscall. On a single processor, with, say, > a 10,000 uS scheduling quantum, encountering contention, the losing thread > is in a cpu-spin and will have to exhaust its quantum before the lock-owning > thread can proceed and release the lock. In the best case, the lock-owning > thread is scheduled, clears the lock, and *immediately* sleeps allowing > the first thread to execute and do useful work. In this case, the statistical > expected value for lock acquisition is 5,000 uS. I.e. lower bound is half > the scheduling quantum. There are worse cases: The lock-owning thread > is cpu-bound and continues to consume a full quantum every time it is > scheduled. Expected value for lock acquisition: 15,000 uS or 1.5 times > the scheduling quantum. Worse still: lock-owning thread consumes a quantum > and re-acquires lock just before losing quantum. Expected value for lock > acquisition: >1.5 times the scheduling quantum. Now we have: > ... In case there are many spinlocks and the probability for an already locked is very low (1/n where n>10000000) spinlocks would be the right choice. That would be the case if I spend a spinlock for each item. In case of structures used by every process (lets say admin data area where every one needs to write from time to time) an IPC semaphore is still the best solution. > Representative and provided spinlock code is in the Alpha SRM. If you are > attempting to implement SMP algorithms on Alpha without this book, or the > corresponding book on other architectures, you're not doing your > employers good service. Hmm, Alpha SRM? I wander where one get that book. I didn't saw it with our machine. -- Aurel Balmosan | Department SE-SW ORGA Kartensysteme GmbH | phone: +49 5254 991 824 An der Kapelle 2 | fax : +49 5254 991 749 33104 Paderborn, Germany | mailto:ab@orga.com