mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Stefan Richter <stefanr@s5r6.in-berlin.de>
Cc: torvalds@osdl.org, scjody@modernduck.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2.6.17-rc5] ieee1394_core: switch to kthread API
Date: Mon, 29 May 2006 15:44:02 -0700	[thread overview]
Message-ID: <20060529154402.cfa5143e.akpm@osdl.org> (raw)
In-Reply-To: <tkrat.cfb023075101da5c@s5r6.in-berlin.de>

On Sun, 28 May 2006 18:43:52 +0200 (CEST)
Stefan Richter <stefanr@s5r6.in-berlin.de> wrote:

We end up with:

:static void queue_packet_complete(struct hpsb_packet *packet)
:{
:	if (packet->no_waiter) {
:		hpsb_free_packet(packet);
:		return;
:	}
:	if (packet->complete_routine != NULL) {
:		skb_queue_tail(&hpsbpkt_queue, packet->skb);
:		wake_up_process(khpsbpkt_thread);
:	}
:	return;
:}
:
:static int hpsbpkt_thread(void *__hi)
:{
:	struct sk_buff *skb;
:	struct hpsb_packet *packet;
:	void (*complete_routine)(void*);
:	void *complete_data;
:
:	current->flags |= PF_NOFREEZE;
:
:	while (!kthread_should_stop()) {
:		while ((skb = skb_dequeue(&hpsbpkt_queue)) != NULL) {
:			packet = (struct hpsb_packet *)skb->data;
:
:			complete_routine = packet->complete_routine;
:			complete_data = packet->complete_data;
:
:			packet->complete_routine = packet->complete_data = NULL;
:
:			complete_routine(complete_data);
:		}

There's a race here.

:		set_current_state(TASK_INTERRUPTIBLE );
:		schedule();
:	}
:
:	return 0;
:}

If queue_packet_complete() is called on another CPU in that window, there
will be a new skb queued and we'll miss the wakeup.

I used skb_peek() in the below fix, but there are other ways, perhaps..


--- devel/drivers/ieee1394/ieee1394_core.c~ieee1394_core-switch-to-kthread-api-fix	2006-05-29 15:42:30.000000000 -0700
+++ devel-akpm/drivers/ieee1394/ieee1394_core.c	2006-05-29 15:42:40.000000000 -0700
@@ -1001,7 +1001,6 @@ void abort_timedouts(unsigned long __opa
 static struct task_struct *khpsbpkt_thread;
 static struct sk_buff_head hpsbpkt_queue;
 
-
 static void queue_packet_complete(struct hpsb_packet *packet)
 {
 	if (packet->no_waiter) {
@@ -1036,10 +1035,11 @@ static int hpsbpkt_thread(void *__hi)
 			complete_routine(complete_data);
 		}
 
-		set_current_state(TASK_INTERRUPTIBLE );
-		schedule();
+		set_current_state(TASK_INTERRUPTIBLE);
+		if (!skb_peek(&hpsbpkt_queue))
+			schedule();
+		__set_current_state(TASK_RUNNING);
 	}
-
 	return 0;
 }
 
_


      reply	other threads:[~2006-05-29 22:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-28 16:43 Stefan Richter
2006-05-29 22:44 ` Andrew Morton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060529154402.cfa5143e.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=scjody@modernduck.com \
    --cc=stefanr@s5r6.in-berlin.de \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome