On Friday 28 March 2008 01:15, Matthew Wilcox wrote:Uhm, how do you use this exactly? All other holders of this semaphore must have preempt disabled and not sleep, right? (and so you need a new down() that disables preempt too) So the only difference between this and a spinlock I guess is that waiters can sleep rather than spin on contention (except this down_spin guy, which sleeps). Oh, I see from the context of Tony's message... so this can *only* be used when preempt is off, and *only* against other down_spin lockers. Bad idea to be hack this into the semaphore code, IMO. It would take how many lines to implement it properly? struct { atomic_t cur; int max; } ss_t; void spin_init(ss_t *ss, int max) { &ss->cur = ATOMIC_INIT(0); &ss->max = max; } void spin_take(ss_t *ss) { preempt_disable(); while (unlikely(!atomic_add_unless(&ss->cur, 1, &ss->max))) { while (atomic_read(&ss->cur) == ss->max) cpu_relax(); } } void spin_put(ss_t *ss) { smp_mb(); atomic_dec(&ss->cur); preempt_enable(); } About the same number as down_spin(). And it is much harder to misuse. So LOC isn't such a great argument for this kind of thing. My 2c --
| Linus Torvalds | Linux 2.6.27-rc5 |
| Bart Van Assche | Integration of SCST in the mainstream Linux kernel |
| Greg KH | [GIT PATCH] driver core patches against 2.6.24 |
| Eric Paris | [RFC 0/5] [TALPA] Intro to a linux interface for on access scanning |
git: | |
| Johannes Sixt | [PATCH 02/40] Compile some programs only conditionally. |
| Linus Torvalds | [PATCH 0/6] Initial subproject support (RFC?) |
| Jon Smirl | Figured out how to get Mozilla into git |
| Linus Torvalds | irc usage.. |
| GVG GVG | ssh_exchange_identification: Connection closed by remote host |
| Richard Stallman | Real men don't attack straw men |
| Marcos Laufer | dmesg IBM x3650 OpenBSD 4.3 |
| Tony Bruguier | [newbie] ssh and sftp timing out |
| Jim Winstead Jr. | Re: Root Disk/Book Disk Compatibility |
| Doug Evans | Re: Stabilizing Linux |
| Joseph R. Pannon | Re: Ctrl-Alt-Del |
| Pat Rankin | Re: Nethack + Linux, Please Help! |
| usb mic not detected | 19 minutes ago | Applications and Utilities |
| Treason Uncloaked | 5 hours ago | Linux kernel |
| Shared swap partition | 16 hours ago | Linux general |
| high memory | 2 days ago | Linux kernel |
| semaphore access speed | 2 days ago | Applications and Utilities |
| the kernel how to power off the machine | 2 days ago | Linux kernel |
| Easter Eggs in windows XP | 2 days ago | Windows |
| Root password | 2 days ago | Linux general |
| Where/when DNOTIFY is used? | 2 days ago | Linux kernel |
| How to convert Linux Kernel built-in module into a loadable module | 2 days ago | Linux kernel |
