* [PATCH 06/14] USB speedtouch: spin_lock_irqsave -> spin_lock_irq in tasklets
@ 2003-05-20 22:58 Duncan Sands
[not found] ` <20030520193646.C32683@devserv.devel.redhat.com>
0 siblings, 1 reply; 2+ messages in thread
From: Duncan Sands @ 2003-05-20 22:58 UTC (permalink / raw)
To: linux-usb-devel; +Cc: Greg KH, linux-kernel
Replace spin_lock_irqsave/spin_unlock_irqrestore with
spin_lock_irq/spin_unlock_irq in tasklet actions, since
these are always called with local irqs enabled.
speedtch.c | 32 +++++++++++++++-----------------
1 files changed, 15 insertions(+), 17 deletions(-)
diff -Nru a/drivers/usb/misc/speedtch.c b/drivers/usb/misc/speedtch.c
--- a/drivers/usb/misc/speedtch.c Wed May 21 00:40:26 2003
+++ b/drivers/usb/misc/speedtch.c Wed May 21 00:40:26 2003
@@ -526,7 +526,6 @@
{
struct udsl_instance_data *instance = (struct udsl_instance_data *) data;
struct udsl_receiver *rcv;
- unsigned long flags;
unsigned char *data_start;
struct sk_buff *skb;
struct urb *urb;
@@ -536,11 +535,11 @@
dbg ("udsl_process_receive entered");
- spin_lock_irqsave (&instance->completed_receivers_lock, flags);
+ spin_lock_irq (&instance->completed_receivers_lock);
while (!list_empty (&instance->completed_receivers)) {
rcv = list_entry (instance->completed_receivers.next, struct udsl_receiver, list);
list_del (&rcv->list);
- spin_unlock_irqrestore (&instance->completed_receivers_lock, flags);
+ spin_unlock_irq (&instance->completed_receivers_lock);
urb = rcv->urb;
dbg ("udsl_process_receive: got packet %p with length %d and status %d", urb, urb->actual_length, urb->status);
@@ -598,15 +597,15 @@
/* fall through */
default: /* error or urb unlinked */
dbg ("udsl_process_receive: adding to spare_receivers");
- spin_lock_irqsave (&instance->spare_receivers_lock, flags);
+ spin_lock_irq (&instance->spare_receivers_lock);
list_add (&rcv->list, &instance->spare_receivers);
- spin_unlock_irqrestore (&instance->spare_receivers_lock, flags);
+ spin_unlock_irq (&instance->spare_receivers_lock);
break;
} /* switch */
- spin_lock_irqsave (&instance->completed_receivers_lock, flags);
+ spin_lock_irq (&instance->completed_receivers_lock);
} /* while */
- spin_unlock_irqrestore (&instance->completed_receivers_lock, flags);
+ spin_unlock_irq (&instance->completed_receivers_lock);
dbg ("udsl_process_receive successful");
}
@@ -676,7 +675,6 @@
{
struct udsl_send_buffer *buf;
int err;
- unsigned long flags;
struct udsl_instance_data *instance = (struct udsl_instance_data *) data;
unsigned int num_written;
struct sk_buff *skb;
@@ -685,7 +683,7 @@
dbg ("udsl_process_send entered");
made_progress:
- spin_lock_irqsave (&instance->send_lock, flags);
+ spin_lock_irq (&instance->send_lock);
while (!list_empty (&instance->spare_senders)) {
if (!list_empty (&instance->filled_send_buffers)) {
buf = list_entry (instance->filled_send_buffers.next, struct udsl_send_buffer, list);
@@ -699,7 +697,7 @@
snd = list_entry (instance->spare_senders.next, struct udsl_sender, list);
list_del (&snd->list);
- spin_unlock_irqrestore (&instance->send_lock, flags);
+ spin_unlock_irq (&instance->send_lock);
snd->buffer = buf;
usb_fill_bulk_urb (snd->urb,
@@ -714,16 +712,16 @@
if ((err = usb_submit_urb(snd->urb, GFP_ATOMIC)) < 0) {
dbg ("submission failed (%d)!", err);
- spin_lock_irqsave (&instance->send_lock, flags);
+ spin_lock_irq (&instance->send_lock);
list_add (&snd->list, &instance->spare_senders);
- spin_unlock_irqrestore (&instance->send_lock, flags);
+ spin_unlock_irq (&instance->send_lock);
list_add (&buf->list, &instance->filled_send_buffers);
return;
}
- spin_lock_irqsave (&instance->send_lock, flags);
+ spin_lock_irq (&instance->send_lock);
} /* while */
- spin_unlock_irqrestore (&instance->send_lock, flags);
+ spin_unlock_irq (&instance->send_lock);
if (!instance->current_skb && !(instance->current_skb = skb_dequeue (&instance->sndqueue))) {
dbg ("done - no more skbs");
@@ -733,16 +731,16 @@
skb = instance->current_skb;
if (!(buf = instance->current_buffer)) {
- spin_lock_irqsave (&instance->send_lock, flags);
+ spin_lock_irq (&instance->send_lock);
if (list_empty (&instance->spare_send_buffers)) {
instance->current_buffer = NULL;
- spin_unlock_irqrestore (&instance->send_lock, flags);
+ spin_unlock_irq (&instance->send_lock);
dbg ("done - no more buffers");
return;
}
buf = list_entry (instance->spare_send_buffers.next, struct udsl_send_buffer, list);
list_del (&buf->list);
- spin_unlock_irqrestore (&instance->send_lock, flags);
+ spin_unlock_irq (&instance->send_lock);
buf->free_start = buf->base;
buf->free_cells = UDSL_SND_BUF_SIZE;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [linux-usb-devel] [PATCH 06/14] USB speedtouch: spin_lock_irqsave -> spin_lock_irq in tasklets
[not found] ` <20030520193646.C32683@devserv.devel.redhat.com>
@ 2003-05-21 7:25 ` Duncan Sands
0 siblings, 0 replies; 2+ messages in thread
From: Duncan Sands @ 2003-05-21 7:25 UTC (permalink / raw)
To: Pete Zaitcev; +Cc: linux-usb-devel, Greg KH, linux-kernel
On Wednesday 21 May 2003 01:36, Pete Zaitcev wrote:
> > From: Duncan Sands <baldrick@wanadoo.fr>
> > Date: Wed, 21 May 2003 00:58:07 +0200
> >
> > Replace spin_lock_irqsave/spin_unlock_irqrestore with
> > spin_lock_irq/spin_unlock_irq in tasklet actions, since
> > these are always called with local irqs enabled.
> >
> > - spin_lock_irqsave (&instance->completed_receivers_lock, flags);
> > + spin_lock_irq (&instance->completed_receivers_lock);
>
> This is a premature optimization and I oppose it strongly.
> There is no evedince that Duncan's cable modem starts working
> any faster with this, or even that his oggs skip less.
> So, there is NO measurable benefit whatsoever.
>
> However, this will trip subtle breakage as the code changes,
> I guarantee it.
>
> Things like this may be done in common paths in TCP stack
> or block I/O, but doing such tricks in drivers is an utter folly.
> I personally had to fix bugs caused by exactly the same
> trickery, as if I have nothing better to do.
Hi Pete, thanks for your comments. I think your concerns about
maintainability would have been better directed against patch 05,
where the same thing was done for routines called in process
context. In this patch (06), only tasklet actions are changed.
It is very unlikely that, in the future, changes to the driver will
cause them to be called from anywhere else than the tasklet.
That is why I am not worried about future changes causing them
to be called with local irqs disabled. So why not make this change
and save a few cycles? Or maybe I misunderstood your concerns?
As for patch 05, this changed the following routines:
udsl_fire_receivers,
udsl_cancel_send,
udsl_usb_disconnect.
Patch 14 removed udsl_fire_receivers, so we can forget about it.
udsl_usb_disconnect is the USB disconnect routine, which I am
confident will be called in process context for all future time. So
this change, while somewhat pointless, seems harmless enough
to me. That leaves udsl_cancel_send. Needless to say this routine
is called in process context (it is called from udsl_atm_close), but
you can't tell that from local inspection of udsl_cancel_send. (Well,
you can tell now because the spin_lock_irq's document it! :) ). So
this is probably the most dangerous change from the point of view
of maintainability.
I have some sympathy for your viewpoint in this case, especially since
in typical use this routine is called just once!
So I am willing to revert the change to udsl_cancel_send, if you like.
All the best,
Duncan.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-05-21 7:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-20 22:58 [PATCH 06/14] USB speedtouch: spin_lock_irqsave -> spin_lock_irq in tasklets Duncan Sands
[not found] ` <20030520193646.C32683@devserv.devel.redhat.com>
2003-05-21 7:25 ` [linux-usb-devel] " Duncan Sands
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®