Messages in this thread | | | Date | Fri, 03 Mar 2006 15:54:19 +0100 | From | Tilman Schmidt <> | Subject | Re: [PATCH 0/7] isdn4linux: add drivers for Siemens Gigaset ISDN DECT PABX |
| |
On Fri, 03 Mar 2006 07:53:28 +0100, Arjan van de Ven wrote:
> On Fri, 2006-03-03 at 00:03 +0100, Tilman Schmidt wrote:
>> So you are saying that, for example >> >> spin_lock_irqsave(&cs->ev_lock, flags); >> head = cs->ev_head; >> tail = cs->ev_tail; >> spin_unlock_irqrestore(&cs->ev_lock, flags); >> >> is (mutatis mutandis) actually cheaper than >> >> head = atomic_read(&cs->ev_head); >> tail = atomic_read(&cs->ev_tail); > > atomic_read is special since it's not actually an atomic operation ;) > but.. think about it: you do 2 atomic reads, however there is ZERO > guarantee that the reads are atomic with respect to eachother; eg your > head and tail are not an atomic "snapshot" of these 2 variables!
That's not a problem. It's a ringbuffer. It doesn't need an atomic snapshot of the reading and writing pointers together. Nothing breaks if a reader advances the read pointer while a writer is holding a local copy of it, or vice versa. The only thing we have to guard against is the result of an individual read operation being corrupted by a parallel write.
So what's better in that case? Should we change these from atomic to spinlocked or not?
[#define IFNULL*] >> Ok, these were mainly debugging aids. We'll just drop them and let the >> oops mechanism catch the (hopefully non-existent) remaining cases of >> pointers being unexpectedly NULL. > > you can also use WARN_ON() and BUG_ON() for that, you then get a more > readable oops message (with filename and line information)
Actually, we won't. The IFNULL* macros were not only printing a message, but also taking evasive action in order to avoid dereferencing the NULL pointer. To achieve the same with WARN_ON() would require four lines of code for each occurrence, which IMHO is too much code clutter for a class of bugs which should be largely eradicated by now anyway.
>> >> +void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, >> >> + size_t len, const unsigned char *buf, int from_user) >> > >> > such "from_user" parameter is highly evil, and also breaks sparse and >> > friends.. (btw please run sparse on the code and fix all warnings) >> >> Are you referring to anything in particular? We do run sparse regularly, >> and it did not emit any warnings for the submitted version, not even for >> this function. (But heaps of them for other parts of the kernel, if you >> pardon the remark.) > > msg should have the __user atribute here since it can be in userspace... > sometimes. It is the "sometimes" that is the bad idea!
That's understood and will be fixed. I was just wondering whether your remark in parentheses was prompted by any particular sparse warnings you wanted us to fix and which for some reason we hadn't seen?
> (GFP_ATOMIC is like borrowing from the VM, the VM will be in slight > imbalance afterwards. With GFP_KERNEL you allow the kernel to fix this > imbalance. A slight imbalance is fine and not a problem. Especially if > you give it the memory back soon. But if the imbalance can accumulate, > for example because you keep allocating and free the memory much later, > it can become a problem)
Thanks muchly for that very lucid explanation. I see much clearer now in that area! :-)
Regards Tilman
-- Tilman Schmidt E-Mail: tilman@imap.cc Bonn, Germany Diese Nachricht besteht zu 100% aus wiederverwerteten Bits. Ungeoeffnet mindestens haltbar bis: (siehe Rueckseite) [unhandled content-type:application/pgp-signature] | |