Skip to content

Commit 1937f8a

Browse files
KAGA-KOKOmartinkpetersen
authored andcommitted
scsi: bnx2fc: Simplify CPU hotplug code
The CPU hotplug related code of this driver can be simplified by: 1) Consolidating the callbacks into a single state. The CPU thread can be torn down on the CPU which goes offline. There is no point in delaying that to the CPU dead state 2) Let the core code invoke the online/offline callbacks and remove the extra for_each_online_cpu() loops. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 2fa2fa1 commit 1937f8a

File tree

2 files changed

+15
-55
lines changed

2 files changed

+15
-55
lines changed

drivers/scsi/bnx2fc/bnx2fc_fcoe.c

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,12 +2624,11 @@ static struct fcoe_transport bnx2fc_transport = {
26242624
};
26252625

26262626
/**
2627-
* bnx2fc_percpu_thread_create - Create a receive thread for an
2628-
* online CPU
2627+
* bnx2fc_cpu_online - Create a receive thread for an online CPU
26292628
*
26302629
* @cpu: cpu index for the online cpu
26312630
*/
2632-
static void bnx2fc_percpu_thread_create(unsigned int cpu)
2631+
static int bnx2fc_cpu_online(unsigned int cpu)
26332632
{
26342633
struct bnx2fc_percpu_s *p;
26352634
struct task_struct *thread;
@@ -2639,15 +2638,17 @@ static void bnx2fc_percpu_thread_create(unsigned int cpu)
26392638
thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
26402639
(void *)p, cpu_to_node(cpu),
26412640
"bnx2fc_thread/%d", cpu);
2641+
if (IS_ERR(thread))
2642+
return PTR_ERR(thread);
2643+
26422644
/* bind thread to the cpu */
2643-
if (likely(!IS_ERR(thread))) {
2644-
kthread_bind(thread, cpu);
2645-
p->iothread = thread;
2646-
wake_up_process(thread);
2647-
}
2645+
kthread_bind(thread, cpu);
2646+
p->iothread = thread;
2647+
wake_up_process(thread);
2648+
return 0;
26482649
}
26492650

2650-
static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2651+
static int bnx2fc_cpu_offline(unsigned int cpu)
26512652
{
26522653
struct bnx2fc_percpu_s *p;
26532654
struct task_struct *thread;
@@ -2661,7 +2662,6 @@ static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
26612662
thread = p->iothread;
26622663
p->iothread = NULL;
26632664

2664-
26652665
/* Free all work in the list */
26662666
list_for_each_entry_safe(work, tmp, &p->work_list, list) {
26672667
list_del_init(&work->list);
@@ -2673,20 +2673,6 @@ static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
26732673

26742674
if (thread)
26752675
kthread_stop(thread);
2676-
}
2677-
2678-
2679-
static int bnx2fc_cpu_online(unsigned int cpu)
2680-
{
2681-
printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2682-
bnx2fc_percpu_thread_create(cpu);
2683-
return 0;
2684-
}
2685-
2686-
static int bnx2fc_cpu_dead(unsigned int cpu)
2687-
{
2688-
printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2689-
bnx2fc_percpu_thread_destroy(cpu);
26902676
return 0;
26912677
}
26922678

@@ -2761,31 +2747,16 @@ static int __init bnx2fc_mod_init(void)
27612747
spin_lock_init(&p->fp_work_lock);
27622748
}
27632749

2764-
get_online_cpus();
2765-
2766-
for_each_online_cpu(cpu)
2767-
bnx2fc_percpu_thread_create(cpu);
2768-
2769-
rc = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN,
2770-
"scsi/bnx2fc:online",
2771-
bnx2fc_cpu_online, NULL);
2750+
rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/bnx2fc:online",
2751+
bnx2fc_cpu_online, bnx2fc_cpu_offline);
27722752
if (rc < 0)
2773-
goto stop_threads;
2753+
goto stop_thread;
27742754
bnx2fc_online_state = rc;
27752755

2776-
cpuhp_setup_state_nocalls_cpuslocked(CPUHP_SCSI_BNX2FC_DEAD,
2777-
"scsi/bnx2fc:dead",
2778-
NULL, bnx2fc_cpu_dead);
2779-
put_online_cpus();
2780-
27812756
cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2782-
27832757
return 0;
27842758

2785-
stop_threads:
2786-
for_each_online_cpu(cpu)
2787-
bnx2fc_percpu_thread_destroy(cpu);
2788-
put_online_cpus();
2759+
stop_thread:
27892760
kthread_stop(l2_thread);
27902761
free_wq:
27912762
destroy_workqueue(bnx2fc_wq);
@@ -2804,7 +2775,6 @@ static void __exit bnx2fc_mod_exit(void)
28042775
struct fcoe_percpu_s *bg;
28052776
struct task_struct *l2_thread;
28062777
struct sk_buff *skb;
2807-
unsigned int cpu = 0;
28082778

28092779
/*
28102780
* NOTE: Since cnic calls register_driver routine rtnl_lock,
@@ -2845,16 +2815,7 @@ static void __exit bnx2fc_mod_exit(void)
28452815
if (l2_thread)
28462816
kthread_stop(l2_thread);
28472817

2848-
get_online_cpus();
2849-
/* Destroy per cpu threads */
2850-
for_each_online_cpu(cpu) {
2851-
bnx2fc_percpu_thread_destroy(cpu);
2852-
}
2853-
2854-
cpuhp_remove_state_nocalls_cpuslocked(bnx2fc_online_state);
2855-
cpuhp_remove_state_nocalls_cpuslocked(CPUHP_SCSI_BNX2FC_DEAD);
2856-
2857-
put_online_cpus();
2818+
cpuhp_remove_state(bnx2fc_online_state);
28582819

28592820
destroy_workqueue(bnx2fc_wq);
28602821
/*

include/linux/cpuhotplug.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ enum cpuhp_state {
3939
CPUHP_PCI_XGENE_DEAD,
4040
CPUHP_IOMMU_INTEL_DEAD,
4141
CPUHP_LUSTRE_CFS_DEAD,
42-
CPUHP_SCSI_BNX2FC_DEAD,
4342
CPUHP_SCSI_BNX2I_DEAD,
4443
CPUHP_WORKQUEUE_PREP,
4544
CPUHP_POWER_NUMA_PREPARE,

0 commit comments

Comments
 (0)