Skip to content

Commit f9f22a8

Browse files
KAGA-KOKOmartinkpetersen
authored andcommitted
scsi: bnx2i: 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> Acked-by: Chad Dupuis <chad.dupuis@cavium.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 1937f8a commit f9f22a8

File tree

2 files changed

+15
-51
lines changed

2 files changed

+15
-51
lines changed

drivers/scsi/bnx2i/bnx2i_init.c

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,11 @@ int bnx2i_get_stats(void *handle)
404404

405405

406406
/**
407-
* bnx2i_percpu_thread_create - Create a receive thread for an
408-
* online CPU
407+
* bnx2i_cpu_online - Create a receive thread for an online CPU
409408
*
410409
* @cpu: cpu index for the online cpu
411410
*/
412-
static void bnx2i_percpu_thread_create(unsigned int cpu)
411+
static int bnx2i_cpu_online(unsigned int cpu)
413412
{
414413
struct bnx2i_percpu_s *p;
415414
struct task_struct *thread;
@@ -419,16 +418,17 @@ static void bnx2i_percpu_thread_create(unsigned int cpu)
419418
thread = kthread_create_on_node(bnx2i_percpu_io_thread, (void *)p,
420419
cpu_to_node(cpu),
421420
"bnx2i_thread/%d", cpu);
421+
if (IS_ERR(thread))
422+
return PTR_ERR(thread);
423+
422424
/* bind thread to the cpu */
423-
if (likely(!IS_ERR(thread))) {
424-
kthread_bind(thread, cpu);
425-
p->iothread = thread;
426-
wake_up_process(thread);
427-
}
425+
kthread_bind(thread, cpu);
426+
p->iothread = thread;
427+
wake_up_process(thread);
428+
return 0;
428429
}
429430

430-
431-
static void bnx2i_percpu_thread_destroy(unsigned int cpu)
431+
static int bnx2i_cpu_offline(unsigned int cpu)
432432
{
433433
struct bnx2i_percpu_s *p;
434434
struct task_struct *thread;
@@ -451,19 +451,6 @@ static void bnx2i_percpu_thread_destroy(unsigned int cpu)
451451
spin_unlock_bh(&p->p_work_lock);
452452
if (thread)
453453
kthread_stop(thread);
454-
}
455-
456-
static int bnx2i_cpu_online(unsigned int cpu)
457-
{
458-
pr_info("bnx2i: CPU %x online: Create Rx thread\n", cpu);
459-
bnx2i_percpu_thread_create(cpu);
460-
return 0;
461-
}
462-
463-
static int bnx2i_cpu_dead(unsigned int cpu)
464-
{
465-
pr_info("CPU %x offline: Remove Rx thread\n", cpu);
466-
bnx2i_percpu_thread_destroy(cpu);
467454
return 0;
468455
}
469456

@@ -511,28 +498,14 @@ static int __init bnx2i_mod_init(void)
511498
p->iothread = NULL;
512499
}
513500

514-
get_online_cpus();
515-
516-
for_each_online_cpu(cpu)
517-
bnx2i_percpu_thread_create(cpu);
518-
519-
err = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN,
520-
"scsi/bnx2i:online",
521-
bnx2i_cpu_online, NULL);
501+
err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/bnx2i:online",
502+
bnx2i_cpu_online, bnx2i_cpu_offline);
522503
if (err < 0)
523-
goto remove_threads;
504+
goto unreg_driver;
524505
bnx2i_online_state = err;
525-
526-
cpuhp_setup_state_nocalls_cpuslocked(CPUHP_SCSI_BNX2I_DEAD,
527-
"scsi/bnx2i:dead",
528-
NULL, bnx2i_cpu_dead);
529-
put_online_cpus();
530506
return 0;
531507

532-
remove_threads:
533-
for_each_online_cpu(cpu)
534-
bnx2i_percpu_thread_destroy(cpu);
535-
put_online_cpus();
508+
unreg_driver:
536509
cnic_unregister_driver(CNIC_ULP_ISCSI);
537510
unreg_xport:
538511
iscsi_unregister_transport(&bnx2i_iscsi_transport);
@@ -552,7 +525,6 @@ static int __init bnx2i_mod_init(void)
552525
static void __exit bnx2i_mod_exit(void)
553526
{
554527
struct bnx2i_hba *hba;
555-
unsigned cpu = 0;
556528

557529
mutex_lock(&bnx2i_dev_lock);
558530
while (!list_empty(&adapter_list)) {
@@ -570,14 +542,7 @@ static void __exit bnx2i_mod_exit(void)
570542
}
571543
mutex_unlock(&bnx2i_dev_lock);
572544

573-
get_online_cpus();
574-
575-
for_each_online_cpu(cpu)
576-
bnx2i_percpu_thread_destroy(cpu);
577-
578-
cpuhp_remove_state_nocalls_cpuslocked(bnx2i_online_state);
579-
cpuhp_remove_state_nocalls_cpuslocked(CPUHP_SCSI_BNX2I_DEAD);
580-
put_online_cpus();
545+
cpuhp_remove_state(bnx2i_online_state);
581546

582547
iscsi_unregister_transport(&bnx2i_iscsi_transport);
583548
cnic_unregister_driver(CNIC_ULP_ISCSI);

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_BNX2I_DEAD,
4342
CPUHP_WORKQUEUE_PREP,
4443
CPUHP_POWER_NUMA_PREPARE,
4544
CPUHP_HRTIMERS_PREPARE,

0 commit comments

Comments
 (0)