SCSI smpboot thread conversion
Subsystems (4)
cover SCSI smpboot thread conversion
This series converts fcoe, bnx2i and bnx2fc to smpboot thread instead of their own magic. The fcoe driver ended in more patches than I wanted but that way it is easier to find the individual code blocks which were used in the final patch.
The overall diffstat:
8 files changed, 253 insertions(+), 478 deletions(-)
Sebastian
PATCH 1/11 scsi/fcoe: lock online CPUs in fcoe_percpu_clean()
for_each_possible_cpu() with a cpu_online() + `thread' check possibly does the job. But there is a tiny race: Say CPU5 is reported online but is going down. And after fcoe_percpu_clean() saw that CPU5 is online it decided to enqueue a packet. After dev_alloc_skb() returned a skb that CPU is offline (or say the notifier destroyed the kthread). So we would OOps because `thread' is NULL.
An alternative would be to lock the CPUs during our loop (so no CPU is going away) and then we iterate over the online mask.
--- drivers/scsi/fcoe/fcoe.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/scsi/fcoe/fcoe.c +3 -4
@@ -2461,12 +2461,10 @@ static void fcoe_percpu_clean(struct fc_lport *lport)struct sk_buff *skb;unsigned int cpu; -for_each_possible_cpu (cpu) { +get_online_cpus (); +for_each_online_cpu (cpu) { pp = &per_cpu (fcoe_percpu, cpu); -if (!pp->thread || !cpu_online (cpu)) -continue ; - skb =dev_alloc_skb (0 );if (!skb)continue ;
@@ -2481,6 +2479,7 @@ static void fcoe_percpu_clean(struct fc_lport *lport)wait_for_completion (&fcoe_flush_completion); } +put_online_cpus (); }/**
Signature · 1 line
2.7.0
Re: [PATCH 01/11] scsi/fcoe: lock online CPUs in fcoe_percpu_clean()
Quoted 8 lines · Sebastian Andrzej Siewior
for_each_possible_cpu()with acpu_online()+ `thread' check possibly does the job. But there is a tiny race: Say CPU5 is reported online but is going down. And afterfcoe_percpu_clean()saw that CPU5 is online it decided to enqueue a packet. Afterdev_alloc_skb()returned a skb that CPU is offline (or say the notifier destroyed the kthread). So we would OOps because `thread' is NULL.
An alternative would be to lock the CPUs during our loop (so no CPU is going away) and then we iterate over the online mask.
I've looked over this and the following patches, and I suspect the right thing to do for fcoe and bnx2 is to convert them to use the generic workqueue code instead of reinventing it poorly.
Re: [PATCH 01/11] scsi/fcoe: lock online CPUs in fcoe_percpu_clean()
Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Sebastian Andrzej Siewior
for_each_possible_cpu()with acpu_online()+ `thread' check possibly does the job. But there is a tiny race: Say CPU5 is reported online but is going down. And afterfcoe_percpu_clean()saw that CPU5 is online it decided to enqueue a packet. Afterdev_alloc_skb()returned a skb that CPU is offline (or say the notifier destroyed the kthread). So we would OOps because `thread' is NULL.
An alternative would be to lock the CPUs during our loop (so no CPU is going away) and then we iterate over the online mask.
Quoted 3 lines
I've looked over this and the following patches, and I suspect the right thing to do for fcoe and bnx2 is to convert them to use the generic workqueue code instead of reinventing it poorly.
alloc_workqueue() in setup and then queue_work_on(cpu, , item)? item should be struct work_struct but all I have is a skb. Is there an easy way to get this attached?
Sebastian
Re: [PATCH 01/11] scsi/fcoe: lock online CPUs in fcoe_percpu_clean()
Quoted 3 lines · Sebastian Andrzej Siewior
alloc_workqueue()in setup and thenqueue_work_on(cpu, , item)? item should be structwork_structbut all I have is a skb. Is there an easy way to get this attached?
Good question. There is skb->cb, but it looks like it doesn't have space for an additional work_item in the fcoe case. Maybe have a per-cpu work_struct and keep all the list handling as-is for now?
Re: [PATCH 01/11] scsi/fcoe: lock online CPUs in fcoe_percpu_clean()
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Sebastian Andrzej Siewior
alloc_workqueue()in setup and thenqueue_work_on(cpu, , item)? item should be structwork_structbut all I have is a skb. Is there an easy way to get this attached?Good question. There is
skb->cb, but it looks like it doesn't have space for an additionalwork_itemin the fcoe case. Maybe have a per-cpuwork_structand keep all the list handling as-is for now?
Okay. Let me try this. What about the few fixes from the series (which apply before the rework to smbboot theads)?
Sebastian
Re: [PATCH 01/11] scsi/fcoe: lock online CPUs in fcoe_percpu_clean()
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Sebastian Andrzej Siewior
alloc_workqueue()in setup and thenqueue_work_on(cpu, , item)? item should be structwork_structbut all I have is a skb. Is there an easy way to get this attached?
Quoted 6 lines
Quoted 3 lines
Good question. There is
skb->cb, but it looks like it doesn't have space for an additionalwork_itemin the fcoe case. Maybe have a per-cpuwork_structand keep all the list handling as-is for now?Okay. Let me try this. What about the few fixes from the series (which apply before the rework to smbboot theads)?
okay kworker. This does not look good. I have it converted what I miss flushing work when CPU goes down and ensuring not to queue work while the CPU is down.
- cpu_online(x) is racy. In DOWN_PREPARE the worker is deactivated / stopped. However slightly later the bit from the CPU mask is removed.
- Whatever is queued and did not make it before the CPU went down seems to be delayed until the CPU comes back online.
- if the worker keeps running while the CPU is going down the worker continues running on a different CPU.
So I don't see how the former two points can be solved without keeping track of CPUs in a CPU notifier. Getting pushed to a different CPU be probably less of an issue if we would have a work-item and would not need to rely on the per-CPU list.
Sebastian
PATCH v2 1/1 scsi/fcoe: convert to kworker
In reply to Christoph HellwigThe driver creates its own per-CPU threads which are updated based on CPU hotplug events. It is also possible to use kworkers and remove some of the kthread infrastrucure.
The code checked ->thread to decide if there is an active per-CPU thread. By using the kworker infrastructure this is no longer possible (or required). The thread pointer is saved in kthread' instead of thread' so anything trying to use thread is caught by the compiler. Currently only the bnx2fc driver is using struct fcoe_percpu_s and the kthread member.
After a CPU went offline, we may still enqueue items on the "offline" CPU. This isn't much of a problem. The work will be done on a random CPU. The allocated crc_eof_page page won't be cleaned up. It is probably expected that the CPU comes up at some point so it should not be a problem. The crc_eof_page memory is released of course once the module is removed.
This patch was only compile-tested due to -ENODEV.
---
v1…v2: use kworker instead of smbthread as per hch
If you want this I would the same for the two bnx drivers.
drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 8 +- drivers/scsi/fcoe/fcoe.c | 276 ++++---------------------------------- include/scsi/libfcoe.h | 6 +- 3 files changed, 34 insertions(+), 256 deletions(-)
drivers/scsi/bnx2fc/bnx2fc_fcoe.c +4 -4
@@ -466,7 +466,7 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,__skb_queue_tail (&bg->fcoe_rx_list, skb);if (bg->fcoe_rx_list.qlen ==1 ) -wake_up_process (bg->thread); +wake_up_process (bg->kthread);spin_unlock (&bg->fcoe_rx_list.lock);
@@ -2663,7 +2663,7 @@ static int __init bnx2fc_mod_init(void) }wake_up_process (l2_thread);spin_lock_bh (&bg->fcoe_rx_list.lock); - bg->thread = l2_thread; + bg->kthread = l2_thread;spin_unlock_bh (&bg->fcoe_rx_list.lock);for_each_possible_cpu (cpu) {
@@ -2736,8 +2736,8 @@ static void __exit bnx2fc_mod_exit(void)/* Destroy global thread */ bg = &bnx2fc_global;spin_lock_bh (&bg->fcoe_rx_list.lock); - l2_thread = bg->thread; - bg->thread =NULL ; + l2_thread = bg->kthread; + bg->kthread =NULL ;while ((skb =__skb_dequeue (&bg->fcoe_rx_list)) !=NULL )kfree_skb (skb);
drivers/scsi/fcoe/fcoe.c +26 -250
393 lines not on this page · raw message
include/scsi/libfcoe.h +4 -2
@@ -319,14 +319,16 @@ struct fcoe_transport {/** * struct fcoe_percpu_s - The context for FCoE receive thread(s) -* @thread: The thread context +* @kthread: The thread context (used by bnx2fc) +* @work: The work item (used by fcoe) * @fcoe_rx_list: The queue of pending packets to process * @page: The memory page for calculating frame trailer CRCs * @crc_eof_offset: The offset into the CRC page pointing to available * memory for a new trailer */ struct fcoe_percpu_s { -struct task_struct *thread; +struct task_struct *kthread; +struct work_struct work;struct sk_buff_head fcoe_rx_list;struct page *crc_eof_page;int crc_eof_offset;
Signature · 6 lines
2.8.0.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PREEMPT-RT] [PATCH v2] scsi/fcoe: convert to kworker
Quoted 26 lines · Sebastian Andrzej Siewior
The driver creates its own per-CPU threads which are updated based on CPU hotplug events. It is also possible to use kworkers and remove some of the kthread infrastrucure.
The code checked ->thread to decide if there is an active per-CPU thread. By using the kworker infrastructure this is no longer possible (or required). The thread pointer is saved in
kthread' instead ofthread' so anything trying to use thread is caught by the compiler. Currently only the bnx2fc driver is using structfcoe_percpu_sand the kthread member.After a CPU went offline, we may still enqueue items on the "offline" CPU. This isn't much of a problem. The work will be done on a random CPU. The allocated
crc_eof_pagepage won't be cleaned up. It is probably expected that the CPU comes up at some point so it should not be a problem. Thecrc_eof_pagememory is released of course once the module is removed.This patch was only compile-tested due to
-ENODEV.Cc Vasu Dev <[email protected]>Cc "James E.J. Bottomley" <[email protected]>Cc "Martin K. Petersen" <[email protected]>Cc Christoph Hellwig <[email protected]>Signed-off-by Sebastian Andrzej Siewior <[email protected]>
Quoted 4 lines
---
v1…v2: use kworker instead of smbthread as per hchIf you want this I would the same for the two bnx drivers.
*ping*
Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PREEMPT-RT] [PATCH v2] scsi/fcoe: convert to kworker
Quoted 39 lines · Sebastian Andrzej Siewior
Quoted 38 lines · Sebastian Andrzej Siewior
The driver creates its own per-CPU threads which are updated based on
CPU hotplug events. It is also possible to use kworkers and remove some
of the kthread infrastrucure.The code checked ->thread to decide if there is an active per-CPU thread. By using the kworker infrastructure this is no longer possible (or
required). The thread pointer is saved inkthread' instead ofthread' so
anything trying to use thread is caught by the compiler. Currently only the
bnx2fc driver is using structfcoe_percpu_sand the kthread member.After a CPU went offline, we may still enqueue items on the "offline"
CPU. This isn't much of a problem. The work will be done on a random
CPU. The allocatedcrc_eof_pagepage won't be cleaned up. It is probably
expected that the CPU comes up at some point so it should not be a problem. Thecrc_eof_pagememory is released of course once the module is
removed.This patch was only compile-tested due to
-ENODEV.Cc Vasu Dev <[email protected]>Cc "James E.J. Bottomley" <[email protected]>Cc "Martin K. Petersen" <[email protected]>Cc Christoph Hellwig <[email protected]>Signed-off-by Sebastian Andrzej Siewior <[email protected]>---
v1…v2: use kworker instead of smbthread as per hch
Quoted 3 lines
Quoted 1 line
If you want this I would the same for the two bnx drivers.
*ping*
Ping what? You've sent in an untested patch that looks to be a big change. It's definitely not going in until it's tested. Why don't you see if you can recruit an FCoE person to your cause and get them to test it.
It looks like you're looking for testing on bnx2fc, correct? In which case cc'ing a bnx2fc person might have been helpful (cc added).
James
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PREEMPT-RT] [PATCH v2] scsi/fcoe: convert to kworker
I have fcoe for testing.
I will pull this in next week and test it.
Laurence Oberman
Principal Software Maintenance Engineer
Red Hat Global Support Services
----- Original Message -----
From: "James Bottomley" <[email protected]>
To: "Sebastian Andrzej Siewior" <[email protected]>, "Christoph Hellwig" <[email protected]>
Cc: [email protected], "Martin K. Petersen" <[email protected]>, "Vasu Dev" <[email protected]>, [email protected], [email protected], "Chad Dupuis" <[email protected]>
Sent: Friday, April 22, 2016 11:49:45 AM
Subject: Re: [PREEMPT-RT] [PATCH v2] scsi/fcoe: convert to kworker
Quoted 39 lines · Sebastian Andrzej Siewior
Quoted 38 lines · Sebastian Andrzej Siewior
The driver creates its own per-CPU threads which are updated based on
CPU hotplug events. It is also possible to use kworkers and remove some
of the kthread infrastrucure.The code checked ->thread to decide if there is an active per-CPU thread. By using the kworker infrastructure this is no longer possible (or
required). The thread pointer is saved inkthread' instead ofthread' so
anything trying to use thread is caught by the compiler. Currently only the
bnx2fc driver is using structfcoe_percpu_sand the kthread member.After a CPU went offline, we may still enqueue items on the "offline"
CPU. This isn't much of a problem. The work will be done on a random
CPU. The allocatedcrc_eof_pagepage won't be cleaned up. It is probably
expected that the CPU comes up at some point so it should not be a problem. Thecrc_eof_pagememory is released of course once the module is
removed.This patch was only compile-tested due to
-ENODEV.Cc Vasu Dev <[email protected]>Cc "James E.J. Bottomley" <[email protected]>Cc "Martin K. Petersen" <[email protected]>Cc Christoph Hellwig <[email protected]>Signed-off-by Sebastian Andrzej Siewior <[email protected]>---
v1…v2: use kworker instead of smbthread as per hch
Quoted 3 lines
Quoted 1 line
If you want this I would the same for the two bnx drivers.
*ping*
Ping what? You've sent in an untested patch that looks to be a big change. It's definitely not going in until it's tested. Why don't you see if you can recruit an FCoE person to your cause and get them to test it.
It looks like you're looking for testing on bnx2fc, correct? In which case cc'ing a bnx2fc person might have been helpful (cc added).
James
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 186981952.31194082.1461343179889.JavaMail.zimbra-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Re: [PREEMPT-RT] [PATCH v2] scsi/fcoe: convert to kworker
Quoted 2 lines · Laurence Oberman
I have fcoe for testing.
I will pull this in next week and test it.
any update?
Quoted 4 lines
Laurence Oberman
Principal Software Maintenance Engineer
Red Hat Global Support Services
Sebastian
Re: [PREEMPT-RT] [PATCH v2] scsi/fcoe: convert to kworker
----- Original Message -----
Quoted 12 lines
From: "Sebastian Andrzej Siewior" <[email protected]>
To: "Laurence Oberman" <[email protected]>, "James Bottomley" <[email protected]>
Cc: "Christoph Hellwig" <[email protected]>, [email protected], "Martin K. Petersen" <[email protected]>, "Vasu Dev" <[email protected]>, [email protected], [email protected], "Chad Dupuis" <[email protected]>
Sent: Thursday, June 9, 2016 9:09:37 AM
Subject: Re: [PREEMPT-RT] [PATCH v2] scsi/fcoe: convert to kworkerQuoted 2 lines · Laurence Oberman
I have fcoe for testing.
I will pull this in next week and test it.
Quoted 10 lines
any update?
Quoted 4 lines
Laurence Oberman
Principal Software Maintenance Engineer
Red Hat Global Support ServicesSebastian
Hello
Apologies, somehow this fell off my radar.
I will get the FCOE test bed up and get it done ASAP.
Regards
Laurence
Re: [PREEMPT-RT] [PATCH v2] scsi/fcoe: convert to kworker
Quoted 1 line · Laurence Oberman
Hello
Hi,
Quoted 2 lines
Apologies, somehow this fell off my radar.
I will get the FCOE test bed up and get it done ASAP.
Thanks
Quoted 3 lines
Regards
Laurence
Sebastian
Re: [PATCH v2] scsi/fcoe: convert to kworker
In reply to Sebastian Andrzej SiewiorQuoted 19 lines · Sebastian Andrzej Siewior
The driver creates its own per-CPU threads which are updated based on CPU hotplug events. It is also possible to use kworkers and remove some of the kthread infrastrucure.
The code checked ->thread to decide if there is an active per-CPU thread. By using the kworker infrastructure this is no longer possible (or required). The thread pointer is saved in
kthread' instead ofthread' so anything trying to use thread is caught by the compiler. Currently only the bnx2fc driver is using structfcoe_percpu_sand the kthread member.After a CPU went offline, we may still enqueue items on the "offline" CPU. This isn't much of a problem. The work will be done on a random CPU. The allocated
crc_eof_pagepage won't be cleaned up. It is probably expected that the CPU comes up at some point so it should not be a problem. Thecrc_eof_pagememory is released of course once the module is removed.This patch was only compile-tested due to
-ENODEV.
Quoted 7 lines
Cc Vasu Dev <[email protected]>Cc "James E.J. Bottomley" <[email protected]>Cc "Martin K. Petersen" <[email protected]>Cc Christoph Hellwig <[email protected]>Signed-off-by Sebastian Andrzej Siewior <[email protected]>
Tested in a Boot from FCoE scenario using a BCM57840.
Quoted 484 lines
---
v1…v2: use kworker instead of smbthread as per hchIf you want this I would the same for the two bnx drivers.
drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 8 +- drivers/scsi/fcoe/fcoe.c | 276 ++++---------------------------------- include/scsi/libfcoe.h | 6 +- 3 files changed, 34 insertions(+), 256 deletions(-)drivers/scsi/bnx2fc/bnx2fc_fcoe.c +4
-4@@ -466,7 +466,7 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,__skb_queue_tail (&bg->fcoe_rx_list, skb);if (bg->fcoe_rx_list.qlen ==1 ) -wake_up_process (bg->thread); +wake_up_process (bg->kthread);spin_unlock (&bg->fcoe_rx_list.lock);@@ -2663,7 +2663,7 @@ static int __init bnx2fc_mod_init(void) }wake_up_process (l2_thread);spin_lock_bh (&bg->fcoe_rx_list.lock); - bg->thread = l2_thread; + bg->kthread = l2_thread;spin_unlock_bh (&bg->fcoe_rx_list.lock);for_each_possible_cpu (cpu) {@@ -2736,8 +2736,8 @@ static void __exit bnx2fc_mod_exit(void)/* Destroy global thread */ bg = &bnx2fc_global;spin_lock_bh (&bg->fcoe_rx_list.lock); - l2_thread = bg->thread; - bg->thread =NULL ; + l2_thread = bg->kthread; + bg->kthread =NULL ;while ((skb =__skb_dequeue (&bg->fcoe_rx_list)) !=NULL )kfree_skb (skb);drivers/scsi/fcoe/fcoe.c +26
-250@@ -67,9 +67,6 @@ static DEFINE_MUTEX(fcoe_config_mutex);static struct workqueue_struct *fcoe_wq; -/* fcoe_percpu_clean completion. Waiter protected by fcoe_create_mutex */ -static DECLARE_COMPLETION (fcoe_flush_completion); -/* fcoe host list */ /* must only by accessed under the RTNL mutex */ static LIST_HEAD (fcoe_hostlist);@@ -80,7 +77,6 @@ static int fcoe_reset(struct Scsi_Host *);static int fcoe_xmit (struct fc_lport *,struct fc_frame *);static int fcoe_rcv (struct sk_buff *,struct net_device *,struct packet_type *,struct net_device *); -static int fcoe_percpu_receive_thread (void *);static void fcoe_percpu_clean (struct fc_lport *);static int fcoe_link_ok (struct fc_lport *);@@ -107,7 +103,6 @@ static int fcoe_ddp_setup(struct fc_lport *, u16, struct scatterlist *,static int fcoe_ddp_done (struct fc_lport *,u16 );static int fcoe_ddp_target (struct fc_lport *,u16 ,struct scatterlist *,unsigned int ); -static int fcoe_cpu_callback (struct notifier_block *,unsigned long ,void *);static int fcoe_dcb_app_notification (struct notifier_block *notifier,ulong event,void *ptr);@@ -136,11 +131,6 @@ static struct notifier_block fcoe_notifier = { .notifier_call = fcoe_device_notification, }; -/* notification function for CPU hotplug events */ -static struct notifier_block fcoe_cpu_notifier = { - .notifier_call = fcoe_cpu_callback, -}; -/* notification function for DCB events */ static struct notifier_block dcb_notifier = { .notifier_call = fcoe_dcb_app_notification,@@ -1245,152 +1235,21 @@ static int __exit fcoe_if_exit(void)return 0 ; } -/** -* fcoe_percpu_thread_create() - Create a receive thread for an online CPU -* @cpu: The CPU index of the CPU to create a receive thread for -*/ -static void fcoe_percpu_thread_create (unsigned int cpu) +static void fcoe_thread_cleanup_local (unsigned int cpu) { -struct fcoe_percpu_s *p; -struct task_struct *thread; - - p = &per_cpu (fcoe_percpu, cpu); - - thread =kthread_create_on_node (fcoe_percpu_receive_thread, - (void *)p,cpu_to_node (cpu), -"fcoethread/%d" , cpu); - -if (likely (!IS_ERR (thread))) { -kthread_bind (thread, cpu); -wake_up_process (thread); - -spin_lock_bh (&p->fcoe_rx_list.lock); - p->thread = thread; -spin_unlock_bh (&p->fcoe_rx_list.lock); - } -} - -/** -* fcoe_percpu_thread_destroy() - Remove the receive thread of a CPU -* @cpu: The CPU index of the CPU whose receive thread is to be destroyed -* -* Destroys a per-CPU Rx thread. Any pending skbs are moved to the -* current CPU's Rx thread. If the thread being destroyed is bound to -* the CPU processing this context the skbs will be freed. -*/ -static void fcoe_percpu_thread_destroy (unsigned int cpu) -{ -struct fcoe_percpu_s *p; -struct task_struct *thread;struct page *crc_eof; -struct sk_buff *skb; -#ifdef CONFIG_SMP -struct fcoe_percpu_s *p0; -unsigned targ_cpu =get_cpu (); -#endif /* CONFIG_SMP */ +struct fcoe_percpu_s *p; -FCOE_DBG ("Destroying receive thread for CPU %d\n" , cpu); - -/* Prevent any new skbs from being queued for this CPU. */ - p = &per_cpu (fcoe_percpu, cpu); + p =per_cpu_ptr (&fcoe_percpu, cpu);spin_lock_bh (&p->fcoe_rx_list.lock); - thread = p->thread; - p->thread =NULL ; crc_eof = p->crc_eof_page; p->crc_eof_page =NULL ; p->crc_eof_offset =0 ;spin_unlock_bh (&p->fcoe_rx_list.lock); -#ifdef CONFIG_SMP -/* -* Don't bother moving the skb's if this context is running -* on the same CPU that is having its thread destroyed. This -* can easily happen when the module is removed. -*/ -if (cpu != targ_cpu) { - p0 = &per_cpu (fcoe_percpu, targ_cpu); -spin_lock_bh (&p0->fcoe_rx_list.lock); -if (p0->thread) { -FCOE_DBG ("Moving frames from CPU %d to CPU %d\n" , - cpu, targ_cpu); - -while ((skb =__skb_dequeue (&p->fcoe_rx_list)) !=NULL ) -__skb_queue_tail (&p0->fcoe_rx_list, skb); -spin_unlock_bh (&p0->fcoe_rx_list.lock); - }else { -/* -* The targeted CPU is not initialized and cannot accept -* new skbs. Unlock the targeted CPU and drop the skbs -* on the CPU that is going offline. -*/ -while ((skb =__skb_dequeue (&p->fcoe_rx_list)) !=NULL ) -kfree_skb (skb); -spin_unlock_bh (&p0->fcoe_rx_list.lock); - } - }else { -/* -* This scenario occurs when the module is being removed -* and all threads are being destroyed. skbs will continue -* to be shifted from the CPU thread that is being removed -* to the CPU thread associated with the CPU that is processing -* the module removal. Once there is only one CPU Rx thread it -* will reach this case and we will drop all skbs and later -* stop the thread. -*/ -spin_lock_bh (&p->fcoe_rx_list.lock); -while ((skb =__skb_dequeue (&p->fcoe_rx_list)) !=NULL ) -kfree_skb (skb); -spin_unlock_bh (&p->fcoe_rx_list.lock); - } -put_cpu (); -#else -/* -* This a non-SMP scenario where the singular Rx thread is -* being removed. Free all skbs and stop the thread. -*/ -spin_lock_bh (&p->fcoe_rx_list.lock); -while ((skb =__skb_dequeue (&p->fcoe_rx_list)) !=NULL ) -kfree_skb (skb); -spin_unlock_bh (&p->fcoe_rx_list.lock); -#endif - -if (thread) -kthread_stop (thread); -if (crc_eof)put_page (crc_eof); -} - -/** -* fcoe_cpu_callback() - Handler for CPU hotplug events -* @nfb: The callback data block -* @action: The event triggering the callback -* @hcpu: The index of the CPU that the event is for -* -* This creates or destroys per-CPU data for fcoe -* -* Returns NOTIFY_OK always. -*/ -static int fcoe_cpu_callback (struct notifier_block *nfb, -unsigned long action,void *hcpu) -{ -unsigned cpu = (unsigned long )hcpu; - -switch (action) { -case CPU_ONLINE : -case CPU_ONLINE_FROZEN : -FCOE_DBG ("CPU %x online: Create Rx thread\n" , cpu); -fcoe_percpu_thread_create (cpu); -break ; -case CPU_DEAD : -case CPU_DEAD_FROZEN : -FCOE_DBG ("CPU %x offline: Remove Rx thread\n" , cpu); -fcoe_percpu_thread_destroy (cpu); -break ; -default : -break ; - } -return NOTIFY_OK ; +flush_work (&p->work); }/** @@ -1509,26 +1368,6 @@ static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, fps = &per_cpu (fcoe_percpu, cpu);spin_lock (&fps->fcoe_rx_list.lock); -if (unlikely (!fps->thread)) { -/* -* The targeted CPU is not ready, let's target -* the first CPU now. For non-SMP systems this -* will check the same CPU twice. -*/ -FCOE_NETDEV_DBG (netdev,"CPU is online, but no receive thread " -"ready for incoming skb- using first online " -"CPU.\n" ); - -spin_unlock (&fps->fcoe_rx_list.lock); - cpu =cpumask_first (cpu_online_mask); - fps = &per_cpu (fcoe_percpu, cpu); -spin_lock (&fps->fcoe_rx_list.lock); -if (!fps->thread) { -spin_unlock (&fps->fcoe_rx_list.lock); - goto err; - } - } -/* * We now have a valid CPU that we're targeting for * this skb. We also have this receive thread locked, @@ -1543,8 +1382,7 @@ static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,* in softirq context. */ __skb_queue_tail (&fps->fcoe_rx_list, skb); -if (fps->thread->state ==TASK_INTERRUPTIBLE ) -wake_up_process (fps->thread); +schedule_work_on (cpu, &fps->work);spin_unlock (&fps->fcoe_rx_list.lock);return NET_RX_SUCCESS ;@@ -1713,15 +1551,6 @@ static int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp) }/** -* fcoe_percpu_flush_done() - Indicate per-CPU queue flush completion -* @skb: The completed skb (argument required by destructor) -*/ -static void fcoe_percpu_flush_done (struct sk_buff *skb) -{ -complete (&fcoe_flush_completion); -} - -/** * fcoe_filter_frames() - filter out bad fcoe frames, i.e. bad CRC * @lport: The local port the frame was received on * @fp: The received frame @@ -1792,8 +1621,7 @@ static void fcoe_recv_frame(struct sk_buff *skb) fr =fcoe_dev_from_skb (skb); lport = fr->fr_dev;if (unlikely (!lport)) { -if (skb->destructor != fcoe_percpu_flush_done) -FCOE_NETDEV_DBG (skb->dev,"NULL lport in skb\n" ); +FCOE_NETDEV_DBG (skb->dev,"NULL lport in skb\n" );kfree_skb (skb);return ; }@@ -1857,40 +1685,28 @@ static void fcoe_recv_frame(struct sk_buff *skb) }/** -* fcoe_percpu_receive_thread() - The per-CPU packet receive thread -* @arg: The per-CPU context +* fcoe_receive_work() - The per-CPU worker +* @work: The work struct * -* Return: 0 for success */ -static int fcoe_percpu_receive_thread (void *arg) +static void fcoe_receive_work (struct work_struct *work) { -struct fcoe_percpu_s *p = arg; +struct fcoe_percpu_s *p;struct sk_buff *skb;struct sk_buff_head tmp; + p = container_of(work, struct fcoe_percpu_s, work);skb_queue_head_init (&tmp); -set_user_nice (current,MIN_NICE ); +spin_lock_bh (&p->fcoe_rx_list.lock); +skb_queue_splice_init (&p->fcoe_rx_list, &tmp); +spin_unlock_bh (&p->fcoe_rx_list.lock); -while (!kthread_should_stop ()) { +if (!skb_queue_len (&tmp)) +return ; -spin_lock_bh (&p->fcoe_rx_list.lock); -skb_queue_splice_init (&p->fcoe_rx_list, &tmp); - -if (!skb_queue_len (&tmp)) { -set_current_state (TASK_INTERRUPTIBLE ); -spin_unlock_bh (&p->fcoe_rx_list.lock); -schedule (); -continue ; - } - -spin_unlock_bh (&p->fcoe_rx_list.lock); - -while ((skb =__skb_dequeue (&tmp)) !=NULL ) -fcoe_recv_frame (skb); - - } -return 0 ; +while ((skb =__skb_dequeue (&tmp))) +fcoe_recv_frame (skb); }/** @@ -2450,36 +2266,19 @@ static int fcoe_link_ok(struct fc_lport *lport)* * Must be called with fcoe_create_mutex held to single-thread completion. * -* This flushes the pending skbs by adding a new skb to each queue and -* waiting until they are all freed. This assures us that not only are -* there no packets that will be handled by the lport, but also that any -* threads already handling packet have returned. +* This flushes the pending skbs by flush the work item for each CPU. The work +* item on each possible CPU is flushed because we may have used the per-CPU +* struct of an offline CPU. */ static void fcoe_percpu_clean (struct fc_lport *lport) {struct fcoe_percpu_s *pp; -struct sk_buff *skb;unsigned int cpu;for_each_possible_cpu (cpu) { pp = &per_cpu (fcoe_percpu, cpu); -if (!pp->thread || !cpu_online (cpu)) -continue ; - - skb =dev_alloc_skb (0 ); -if (!skb) -continue ; - - skb->destructor = fcoe_percpu_flush_done; - -spin_lock_bh (&pp->fcoe_rx_list.lock); -__skb_queue_tail (&pp->fcoe_rx_list, skb); -if (pp->fcoe_rx_list.qlen ==1 ) -wake_up_process (pp->thread); -spin_unlock_bh (&pp->fcoe_rx_list.lock); - -wait_for_completion (&fcoe_flush_completion); +flush_work (&pp->work); } }@@ -2625,22 +2424,11 @@ static int __init fcoe_init(void)mutex_lock (&fcoe_config_mutex);for_each_possible_cpu (cpu) { - p = &per_cpu (fcoe_percpu, cpu); + p =per_cpu_ptr (&fcoe_percpu, cpu); +INIT_WORK (&p->work, fcoe_receive_work);skb_queue_head_init (&p->fcoe_rx_list); } -cpu_notifier_register_begin (); - -for_each_online_cpu (cpu) -fcoe_percpu_thread_create (cpu); - -/* Initialize per CPU interrupt thread */ - rc =__register_hotcpu_notifier (&fcoe_cpu_notifier); -if (rc) - goto out_free; - -cpu_notifier_register_done (); -/* Setup link change notification */ fcoe_dev_setup ();@@ -2652,12 +2440,6 @@ static int __init fcoe_init(void)return 0 ; out_free: -for_each_online_cpu (cpu) { -fcoe_percpu_thread_destroy (cpu); - } - -cpu_notifier_register_done (); -mutex_unlock (&fcoe_config_mutex);destroy_workqueue (fcoe_wq);return rc;@@ -2690,14 +2472,8 @@ static void __exit fcoe_exit(void) }rtnl_unlock (); -cpu_notifier_register_begin (); - -for_each_online_cpu (cpu) -fcoe_percpu_thread_destroy (cpu); - -__unregister_hotcpu_notifier (&fcoe_cpu_notifier); - -cpu_notifier_register_done (); +for_each_possible_cpu (cpu) +fcoe_thread_cleanup_local (cpu);mutex_unlock (&fcoe_config_mutex);include/scsi/libfcoe.h +4
-2@@ -319,14 +319,16 @@ struct fcoe_transport {/** * struct fcoe_percpu_s - The context for FCoE receive thread(s) -* @thread: The thread context +* @kthread: The thread context (used by bnx2fc) +* @work: The work item (used by fcoe) * @fcoe_rx_list: The queue of pending packets to process * @page: The memory page for calculating frame trailer CRCs * @crc_eof_offset: The offset into the CRC page pointing to available * memory for a new trailer */ struct fcoe_percpu_s { -struct task_struct *thread; +struct task_struct *kthread; +struct work_struct work;struct sk_buff_head fcoe_rx_list;struct page *crc_eof_page;int crc_eof_offset;Signature · 6 lines
2.8.0.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 10 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20160610103812.ojgzop6qdv3mos5d-3LAbnSA0sDC4fIQPS+WK3rNAH6kLmebB@public.gmane.org
Re: [PATCH v2] scsi/fcoe: convert to kworker
On Fri, 2016-06-10 at 12:38 +0200, Johannes Thumshirn wrote:
On Tue, Apr 12, 2016 at 05:16:54PM +0200, Sebastian Andrzej Siewior wrote:
The driver creates its own per-CPU threads which are updated based on CPU hotplug events. It is also possible to use kworkers and remove some of the kthread infrastrucure.
The code checked ->thread to decide if there is an active per-CPU thread. By using the kworker infrastructure this is no longer possible (or required). The thread pointer is saved in kthread' instead of thread' so anything trying to use thread is caught by the compiler. Currently only the bnx2fc driver is using struct fcoe_percpu_s and the kthread member.
After a CPU went offline, we may still enqueue items on the "offline" CPU. This isn't much of a problem. The work will be done on a random CPU. The allocated crc_eof_page page won't be cleaned up. It is probably expected that the CPU comes up at some point so it should not be a problem. The crc_eof_page memory is released of course once the module is removed.
This patch was only compile-tested due to -ENODEV.
Tested in a Boot from FCoE scenario using a BCM57840.
---
v1…v2: use kworker instead of smbthread as per hch
If you want this I would the same for the two bnx drivers.
drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 8 +- drivers/scsi/fcoe/fcoe.c | 276 ++++---------------------------------- include/scsi/libfcoe.h | 6 +- 3 files changed, 34 insertions(+), 256 deletions(-)
drivers/scsi/bnx2fc/bnx2fc_fcoe.c +4 -4
@@ -466,7 +466,7 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,__skb_queue_tail (&bg->fcoe_rx_list, skb);if (bg->fcoe_rx_list.qlen ==1 ) -wake_up_process (bg->thread); +wake_up_process (bg->kthread);spin_unlock (&bg->fcoe_rx_list.lock);
@@ -2663,7 +2663,7 @@ static int __init bnx2fc_mod_init(void) }wake_up_process (l2_thread);spin_lock_bh (&bg->fcoe_rx_list.lock); - bg->thread = l2_thread; + bg->kthread = l2_thread;spin_unlock_bh (&bg->fcoe_rx_list.lock);for_each_possible_cpu (cpu) {
@@ -2736,8 +2736,8 @@ static void __exit bnx2fc_mod_exit(void)/* Destroy global thread */ bg = &bnx2fc_global;spin_lock_bh (&bg->fcoe_rx_list.lock); - l2_thread = bg->thread; - bg->thread =NULL ; + l2_thread = bg->kthread; + bg->kthread =NULL ;while ((skb =__skb_dequeue (&bg->fcoe_rx_list)) !=NULL )kfree_skb (skb);
drivers/scsi/fcoe/fcoe.c +26 -250
393 lines not on this page · raw message
include/scsi/libfcoe.h +4 -2
@@ -319,14 +319,16 @@ struct fcoe_transport {/** * struct fcoe_percpu_s - The context for FCoE receive thread(s) -* @thread: The thread context +* @kthread: The thread context (used by bnx2fc) +* @work: The work item (used by fcoe) * @fcoe_rx_list: The queue of pending packets to process * @page: The memory page for calculating frame trailer CRCs * @crc_eof_offset: The offset into the CRC page pointing to available * memory for a new trailer */ struct fcoe_percpu_s { -struct task_struct *thread; +struct task_struct *kthread; +struct work_struct work;struct sk_buff_head fcoe_rx_list;struct page *crc_eof_page;int crc_eof_offset;
--
2.8.0.rc3
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]<mailto:[email protected]> More majordomo info at http://vger.kernel.org/majordomo-info.html
_______________________________________________
fcoe-devel mailing list
[email protected]
http://lists.open-fcoe.org/mailman/listinfo/fcoe-devel
Re: [PATCH v2] scsi/fcoe: convert to kworker
In reply to Johannes ThumshirnOn 06/10/2016 12:38 PM, Johannes Thumshirn wrote:
…
Quoted 2 lines
Tested in a Boot from FCoE scenario using a BCM57840.
This got merged over the weekend. Thanks for that. I will try to look into the other two (bnx2i, bnx2fc) and convert them as well within this week.
Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/11 scsi/fcoe: remove CONFIG_SMP in fcoe_percpu_thread_destroy()
In reply to Sebastian Andrzej SiewiorThere is only a marginal win in code size if the !SMP code is ifdeffed out. The compiler should be able to optimize almost everything out.
Remove the ifdeffery for readability sake.
--- drivers/scsi/fcoe/fcoe.c | 13 ------------- 1 file changed, 13 deletions(-)
drivers/scsi/fcoe/fcoe.c +0 -13
@@ -1284,10 +1284,8 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)struct task_struct *thread;struct page *crc_eof;struct sk_buff *skb; -#ifdef CONFIG_SMP struct fcoe_percpu_s *p0;unsigned targ_cpu =get_cpu (); -#endif /* CONFIG_SMP */ FCOE_DBG ("Destroying receive thread for CPU %d\n" , cpu);
@@ -1301,7 +1299,6 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu) p->crc_eof_offset =0 ;spin_unlock_bh (&p->fcoe_rx_list.lock); -#ifdef CONFIG_SMP /* * Don't bother moving the skb's if this context is running * on the same CPU that is having its thread destroyed. This
@@ -1343,16 +1340,6 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)spin_unlock_bh (&p->fcoe_rx_list.lock); }put_cpu (); -#else -/* -* This a non-SMP scenario where the singular Rx thread is -* being removed. Free all skbs and stop the thread. -*/ -spin_lock_bh (&p->fcoe_rx_list.lock); -while ((skb =__skb_dequeue (&p->fcoe_rx_list)) !=NULL ) -kfree_skb (skb); -spin_unlock_bh (&p->fcoe_rx_list.lock); -#endif if (thread)kthread_stop (thread);
Signature · 1 line
2.7.0
PATCH 3/11 scsi/fcoe: drop locking in fcoe_percpu_thread_destroy() if cpu == targ_cpu
In reply to Sebastian Andrzej SiewiorThe locking here is not required. At the begin of the function we hold the lock and assign NULL to p->thread. This is used in other places to ensure that nobody adds new items to the list.
Also, in the cpu != targ_cpu case we don't hold the lock of p-> as well. This makes is consistent.
--- drivers/scsi/fcoe/fcoe.c | 2 -- 1 file changed, 2 deletions(-)
drivers/scsi/fcoe/fcoe.c +0 -2
@@ -1334,10 +1334,8 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)* will reach this case and we will drop all skbs and later * stop the thread. */ -spin_lock_bh (&p->fcoe_rx_list.lock);while ((skb =__skb_dequeue (&p->fcoe_rx_list)) !=NULL )kfree_skb (skb); -spin_unlock_bh (&p->fcoe_rx_list.lock); }put_cpu ();
Signature · 1 line
2.7.0
PATCH 4/11 scsi/fcoe: rename p0 to p_target in fcoe_percpu_thread_destroy()
In reply to Sebastian Andrzej SiewiorThe p' and p0' variables have very small names on can get mixed up easily. Thus I rename p0' to p_target' so it sounds more like the target pointer than `p0' does.
--- drivers/scsi/fcoe/fcoe.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/scsi/fcoe/fcoe.c +7 -7
@@ -1284,7 +1284,7 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)struct task_struct *thread;struct page *crc_eof;struct sk_buff *skb; -struct fcoe_percpu_s *p0; +struct fcoe_percpu_s *p_target;unsigned targ_cpu =get_cpu ();FCOE_DBG ("Destroying receive thread for CPU %d\n" , cpu);
@@ -1305,15 +1305,15 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)* can easily happen when the module is removed. */ if (cpu != targ_cpu) { - p0 = &per_cpu (fcoe_percpu, targ_cpu); -spin_lock_bh (&p0->fcoe_rx_list.lock); -if (p0->thread) { + p_target = &per_cpu (fcoe_percpu, targ_cpu); +spin_lock_bh (&p_target->fcoe_rx_list.lock); +if (p_target->thread) {FCOE_DBG ("Moving frames from CPU %d to CPU %d\n" , cpu, targ_cpu);while ((skb =__skb_dequeue (&p->fcoe_rx_list)) !=NULL ) -__skb_queue_tail (&p0->fcoe_rx_list, skb); -spin_unlock_bh (&p0->fcoe_rx_list.lock); +__skb_queue_tail (&p_target->fcoe_rx_list, skb); +spin_unlock_bh (&p_target->fcoe_rx_list.lock); }else {/* * The targeted CPU is not initialized and cannot accept
@@ -1322,7 +1322,7 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)*/ while ((skb =__skb_dequeue (&p->fcoe_rx_list)) !=NULL )kfree_skb (skb); -spin_unlock_bh (&p0->fcoe_rx_list.lock); +spin_unlock_bh (&p_target->fcoe_rx_list.lock); } }else {/*
Signature · 1 line
2.7.0
PATCH 5/11 scsi/fcoe: drop the p_target lock earlier if there is no thread online
In reply to Sebastian Andrzej SiewiorIf the thread on the target CPU is not online then all skbs are freed. There is no need to hold p_target's lock during that period.
--- drivers/scsi/fcoe/fcoe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/fcoe/fcoe.c +2 -1
@@ -1320,9 +1320,10 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)* new skbs. Unlock the targeted CPU and drop the skbs * on the CPU that is going offline. */ +spin_unlock_bh (&p_target->fcoe_rx_list.lock); +while ((skb =__skb_dequeue (&p->fcoe_rx_list)) !=NULL )kfree_skb (skb); -spin_unlock_bh (&p_target->fcoe_rx_list.lock); } }else {/*
Signature · 1 line
2.7.0
PATCH 6/11 scsi/fcoe: use skb_queue_splice_tail() intead of manual job
In reply to Sebastian Andrzej Siewiorskb_queue_splice_tail() is able to do the same thing as a loop with __skb_dequeue() and __skb_queue_tail() like we have it now.
--- drivers/scsi/fcoe/fcoe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/fcoe/fcoe.c +2 -2
@@ -1311,8 +1311,8 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)FCOE_DBG ("Moving frames from CPU %d to CPU %d\n" , cpu, targ_cpu); -while ((skb =__skb_dequeue (&p->fcoe_rx_list)) !=NULL ) -__skb_queue_tail (&p_target->fcoe_rx_list, skb); +skb_queue_splice_tail (&p->fcoe_rx_list, + &p_target->fcoe_rx_list);spin_unlock_bh (&p_target->fcoe_rx_list.lock); }else {/*
Signature · 1 line
2.7.0
PATCH 7/11 scsi/fcoe: drop the crc_eof page early
In reply to Sebastian Andrzej SiewiorOn cleanup we free the crc_eof_page after all skbs are freed. There is no reason why it can't be done earlier. We hold a reference to that page and each skb does.
--- drivers/scsi/fcoe/fcoe.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/scsi/fcoe/fcoe.c +2 -3
@@ -1299,6 +1299,8 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu) p->crc_eof_offset =0 ;spin_unlock_bh (&p->fcoe_rx_list.lock); +if (crc_eof) +put_page (crc_eof);/* * Don't bother moving the skb's if this context is running * on the same CPU that is having its thread destroyed. This
@@ -1342,9 +1344,6 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)if (thread)kthread_stop (thread); - -if (crc_eof) -put_page (crc_eof); }/**
Signature · 1 line
2.7.0
PATCH 8/11 scsi/fcoe: convert to smpboot thread
In reply to Sebastian Andrzej SiewiorThe driver creates its own per-CPU threads which are updated based on CPU hotplug events. It is also possible to delegate this task to the smpboot-thread infrastructure and get the same job done while saving a few lines of code.
The code checked ->thread to decide if there is an active per-CPU thread. With the smpboot infrastructure this is no longer possible and I replaced its logic with the ->active member. The thread pointer is saved in kthread' instead of thread' so anything trying to use thread is caught by the compiler.
The ->park() callback cleans up the resources if a CPU is going down. At least one CPU has to be online (and not parked) and the skbs are moved to this CPU. On module removal the ->cleanup() is invoked instead and all skbs are purged.
The remaining part of the conversion is mostly straightforward. This patch was only compile-tested due to -ENODEV.
--- drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 8 +- drivers/scsi/fcoe/fcoe.c | 281 ++++++++++++++------------------------ include/scsi/libfcoe.h | 6 +- 3 files changed, 112 insertions(+), 183 deletions(-)
drivers/scsi/bnx2fc/bnx2fc_fcoe.c +4 -4
@@ -457,7 +457,7 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,__skb_queue_tail (&bg->fcoe_rx_list, skb);if (bg->fcoe_rx_list.qlen ==1 ) -wake_up_process (bg->thread); +wake_up_process (bg->kthread);spin_unlock (&bg->fcoe_rx_list.lock);
@@ -2654,7 +2654,7 @@ static int __init bnx2fc_mod_init(void) }wake_up_process (l2_thread);spin_lock_bh (&bg->fcoe_rx_list.lock); - bg->thread = l2_thread; + bg->kthread = l2_thread;spin_unlock_bh (&bg->fcoe_rx_list.lock);for_each_possible_cpu (cpu) {
@@ -2727,8 +2727,8 @@ static void __exit bnx2fc_mod_exit(void)/* Destroy global thread */ bg = &bnx2fc_global;spin_lock_bh (&bg->fcoe_rx_list.lock); - l2_thread = bg->thread; - bg->thread =NULL ; + l2_thread = bg->kthread; + bg->kthread =NULL ;while ((skb =__skb_dequeue (&bg->fcoe_rx_list)) !=NULL )kfree_skb (skb);
drivers/scsi/fcoe/fcoe.c +104 -177
408 lines not on this page · raw message
include/scsi/libfcoe.h +4 -2
@@ -319,17 +319,19 @@ struct fcoe_transport {/** * struct fcoe_percpu_s - The context for FCoE receive thread(s) -* @thread: The thread context +* @kthread: The thread context of the smp_hotplug_thread * @fcoe_rx_list: The queue of pending packets to process * @page: The memory page for calculating frame trailer CRCs * @crc_eof_offset: The offset into the CRC page pointing to available * memory for a new trailer +* @active: true if the queue is active and not being removed */ struct fcoe_percpu_s { -struct task_struct *thread; +struct task_struct *kthread;struct sk_buff_head fcoe_rx_list;struct page *crc_eof_page;int crc_eof_offset; +bool active; };/**
Signature · 1 line
2.7.0
PATCH 9/11 scsi: bnx2i: convert to smpboot thread
In reply to Sebastian Andrzej SiewiorThe driver creates its own per-CPU threads which are updated based on CPU hotplug events. It is also possible to delegate this task to the smpboot-thread infrastructure and get the same job done while saving a few lines of code.
The code checked ->iothread to decide if there is an active per-CPU thread. With the smpboot infrastructure this is no longer possible and I replaced its logic with the ->active member. The thread pointer is saved in kthread' instead of iothread' so anything trying to use `thread' is caught by the compiler.
The remaining part of the conversion is mostly straightforward. This patch was only compile-tested due to -ENODEV.
--- drivers/scsi/bnx2i/bnx2i.h | 4 +- drivers/scsi/bnx2i/bnx2i_hwi.c | 45 +---------- drivers/scsi/bnx2i/bnx2i_init.c | 162 ++++++++++++++++------------------------ 3 files changed, 69 insertions(+), 142 deletions(-)
drivers/scsi/bnx2i/bnx2i.h +2 -2
@@ -775,9 +775,10 @@ struct bnx2i_work { };struct bnx2i_percpu_s { -struct task_struct *iothread; +struct task_struct *kthread;struct list_head work_list;spinlock_t p_work_lock; +bool active; };
@@ -875,7 +876,6 @@ extern void bnx2i_print_active_cmd_queue(struct bnx2i_conn *conn);extern void bnx2i_print_xmit_pdu_queue (struct bnx2i_conn *conn);extern void bnx2i_print_recv_state (struct bnx2i_conn *conn); -extern int bnx2i_percpu_io_thread (void *arg);extern int bnx2i_process_scsi_cmd_resp (struct iscsi_session *session,struct bnx2i_conn *bnx2i_conn,struct cqe *cqe);
drivers/scsi/bnx2i/bnx2i_hwi.c +2 -43
63 lines not on this page · raw message
drivers/scsi/bnx2i/bnx2i_init.c +65 -97
232 lines not on this page · raw message
Signature · 1 line
2.7.0
PATCH 10/11 scsi: bnx2fc: fix hotplug race in bnx2fc_process_new_cqes()
In reply to Sebastian Andrzej SiewiorThe ->iothread is accessed without holding the lock. Take this:
CPU A CPU B
------- -------bnx2fc_process_new_cqes() bnx2fc_percpu_thread_destroy()
spin_lock_bh(fp_work_lock);
fps->iothread != NULL
list_add_tail(work)
spin_unlock_bh(&fps->fp_work_lock); spin_lock_bh(&fps->fp_work_lock);
fps->iothread = NULL
if (fps->iothread && work)
... else
bnx2fc_process_cq_compl(work) bnx2fc_process_cq_compl(work);
CPU A will process wqe despite having it added to the work list of CPU B which will at the same time clean up the queued wqe.
The fix is to add the item to the list and wakeup the thread while still holding the lock. If the item was not added to the list then the `process' variable is still true in which case we have to do manually.
--- drivers/scsi/bnx2fc/bnx2fc_hwi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/scsi/bnx2fc/bnx2fc_hwi.c +6 -5
@@ -1045,6 +1045,7 @@ int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt)struct bnx2fc_work *work =NULL ;struct bnx2fc_percpu_s *fps =NULL ;unsigned int cpu = wqe %num_possible_cpus (); +bool process = true; fps = &per_cpu (bnx2fc_percpu, cpu);spin_lock_bh (&fps->fp_work_lock);
@@ -1052,16 +1053,16 @@ int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt) goto unlock; work =bnx2fc_alloc_work (tgt, wqe); -if (work) +if (work) {list_add_tail (&work->list, &fps->work_list); +wake_up_process (fps->iothread); + process = false; + } unlock:spin_unlock_bh (&fps->fp_work_lock); -/* Pending work request completion */ -if (fps->iothread && work) -wake_up_process (fps->iothread); -else +if (process)bnx2fc_process_cq_compl (tgt, wqe); num_free_sqes++; }
Signature · 1 line
2.7.0
PATCH 11/11 scsi: bnx2fc: convert to smpboot thread
In reply to Sebastian Andrzej SiewiorThe driver creates its own per-CPU threads which are updated based on CPU hotplug events. It is also possible to delegate this task to the smpboot-thread infrastructure and get the same job done while saving a few lines of code.
The code checked ->iothread to decide if there is an active per-CPU thread. With the smpboot infrastructure this is no longer possible and I replaced its logic with the ->active member. The thread pointer is saved in kthread' instead of iothread' so anything trying to use thread is caught by the compiler.
The remaining part of the conversion is mostly straightforward. This patch was only compile-tested due to -ENODEV.
--- drivers/scsi/bnx2fc/bnx2fc.h | 3 +- drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 187 ++++++++++++-------------------------- drivers/scsi/bnx2fc/bnx2fc_hwi.c | 4 +- 3 files changed, 64 insertions(+), 130 deletions(-)
drivers/scsi/bnx2fc/bnx2fc.h +2 -1
@@ -168,9 +168,10 @@ extern struct fcoe_percpu_s bnx2fc_global;extern struct workqueue_struct *bnx2fc_wq;struct bnx2fc_percpu_s { -struct task_struct *iothread; +struct task_struct *kthread;struct list_head work_list;spinlock_t fp_work_lock; +bool active; };struct bnx2fc_fw_stats {
drivers/scsi/bnx2fc/bnx2fc_fcoe.c +60 -127
260 lines not on this page · raw message
drivers/scsi/bnx2fc/bnx2fc_hwi.c +2 -2
@@ -1049,14 +1049,14 @@ int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt) fps = &per_cpu (bnx2fc_percpu, cpu);spin_lock_bh (&fps->fp_work_lock); -if (unlikely (!fps->iothread)) +if (unlikely (!fps->active)) goto unlock; work =bnx2fc_alloc_work (tgt, wqe);if (work) {list_add_tail (&work->list, &fps->work_list); -wake_up_process (fps->iothread); +wake_up_process (fps->kthread); process = false; } unlock:
Signature · 1 line
2.7.0