Skip to content

Commit 5e5e92d

Browse files
Robert Lovejejb
authored andcommitted
[SCSI] fcoe: Use percpu kernel funcs for struct fcoe_percpu_s
Convert fcoe_percpu array to use the per-cpu variables that the kernel provides. Use the kernel's functions to access this structure. The cpu member of the fcoe_percpu_s is no longer needed, so this patch removes it too. Signed-off-by: Yi Zou <yi.zou@intel.com> Signed-off-by: Robert Love <robert.w.love@intel.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
1 parent 38eccab commit 5e5e92d

2 files changed

Lines changed: 43 additions & 52 deletions

File tree

‎drivers/scsi/fcoe/libfcoe.c‎

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ MODULE_LICENSE("GPL");
6565
LIST_HEAD(fcoe_hostlist);
6666
DEFINE_RWLOCK(fcoe_hostlist_lock);
6767
DEFINE_TIMER(fcoe_timer, NULL, 0, 0);
68-
struct fcoe_percpu_s *fcoe_percpu[NR_CPUS];
68+
DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
6969

7070

7171
/* Function Prototyes */
@@ -226,6 +226,7 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
226226
fr->fr_dev = lp;
227227
fr->ptype = ptype;
228228
cpu_idx = 0;
229+
229230
#ifdef CONFIG_SMP
230231
/*
231232
* The incoming frame exchange id(oxid) is ANDed with num of online
@@ -235,10 +236,12 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
235236
* initialize to first online cpu index.
236237
*/
237238
cpu_idx = oxid & (num_online_cpus() - 1);
238-
if (!fcoe_percpu[cpu_idx] || !cpu_online(cpu_idx))
239+
if (!cpu_online(cpu_idx))
239240
cpu_idx = first_cpu(cpu_online_map);
241+
240242
#endif
241-
fps = fcoe_percpu[cpu_idx];
243+
244+
fps = &per_cpu(fcoe_percpu, cpu_idx);
242245

243246
spin_lock_bh(&fps->fcoe_rx_list.lock);
244247
__skb_queue_tail(&fps->fcoe_rx_list, skb);
@@ -292,15 +295,13 @@ static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen)
292295
{
293296
struct fcoe_percpu_s *fps;
294297
struct page *page;
295-
unsigned int cpu_idx;
296298

297-
cpu_idx = get_cpu();
298-
fps = fcoe_percpu[cpu_idx];
299+
fps = &get_cpu_var(fcoe_percpu);
299300
page = fps->crc_eof_page;
300301
if (!page) {
301302
page = alloc_page(GFP_ATOMIC);
302303
if (!page) {
303-
put_cpu();
304+
put_cpu_var(fcoe_percpu);
304305
return -ENOMEM;
305306
}
306307
fps->crc_eof_page = page;
@@ -320,7 +321,7 @@ static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen)
320321
fps->crc_eof_offset = 0;
321322
put_page(page);
322323
}
323-
put_cpu();
324+
put_cpu_var(fcoe_percpu);
324325
return 0;
325326
}
326327

@@ -1122,30 +1123,28 @@ EXPORT_SYMBOL_GPL(fcoe_link_ok);
11221123
*/
11231124
void fcoe_percpu_clean(struct fc_lport *lp)
11241125
{
1125-
int idx;
11261126
struct fcoe_percpu_s *pp;
11271127
struct fcoe_rcv_info *fr;
11281128
struct sk_buff_head *list;
11291129
struct sk_buff *skb, *next;
11301130
struct sk_buff *head;
1131+
unsigned int cpu;
11311132

1132-
for (idx = 0; idx < NR_CPUS; idx++) {
1133-
if (fcoe_percpu[idx]) {
1134-
pp = fcoe_percpu[idx];
1135-
spin_lock_bh(&pp->fcoe_rx_list.lock);
1136-
list = &pp->fcoe_rx_list;
1137-
head = list->next;
1138-
for (skb = head; skb != (struct sk_buff *)list;
1139-
skb = next) {
1140-
next = skb->next;
1141-
fr = fcoe_dev_from_skb(skb);
1142-
if (fr->fr_dev == lp) {
1143-
__skb_unlink(skb, list);
1144-
kfree_skb(skb);
1145-
}
1133+
for_each_possible_cpu(cpu) {
1134+
pp = &per_cpu(fcoe_percpu, cpu);
1135+
spin_lock_bh(&pp->fcoe_rx_list.lock);
1136+
list = &pp->fcoe_rx_list;
1137+
head = list->next;
1138+
for (skb = head; skb != (struct sk_buff *)list;
1139+
skb = next) {
1140+
next = skb->next;
1141+
fr = fcoe_dev_from_skb(skb);
1142+
if (fr->fr_dev == lp) {
1143+
__skb_unlink(skb, list);
1144+
kfree_skb(skb);
11461145
}
1147-
spin_unlock_bh(&pp->fcoe_rx_list.lock);
11481146
}
1147+
spin_unlock_bh(&pp->fcoe_rx_list.lock);
11491148
}
11501149
}
11511150
EXPORT_SYMBOL_GPL(fcoe_percpu_clean);
@@ -1377,33 +1376,27 @@ static int __init fcoe_init(void)
13771376
#endif /* CONFIG_HOTPLUG_CPU */
13781377

13791378
for_each_possible_cpu(cpu) {
1380-
p = fcoe_percpu[cpu];
1381-
p->cpu = cpu;
1379+
p = &per_cpu(fcoe_percpu, cpu);
13821380
skb_queue_head_init(&p->fcoe_rx_list);
13831381
}
13841382

13851383
/*
13861384
* initialize per CPU interrupt thread
13871385
*/
13881386
for_each_online_cpu(cpu) {
1389-
p = kzalloc(sizeof(struct fcoe_percpu_s), GFP_KERNEL);
1390-
if (p) {
1391-
p->thread = kthread_create(fcoe_percpu_receive_thread,
1392-
(void *)p,
1393-
"fcoethread/%d", cpu);
1387+
p = &per_cpu(fcoe_percpu, cpu);
1388+
p->thread = kthread_create(fcoe_percpu_receive_thread,
1389+
(void *)p, "fcoethread/%d", cpu);
13941390

1395-
/*
1396-
* if there is no error then bind the thread to the cpu
1397-
* initialize the semaphore and skb queue head
1398-
*/
1399-
if (likely(!IS_ERR(p->thread))) {
1400-
fcoe_percpu[cpu] = p;
1401-
kthread_bind(p->thread, cpu);
1402-
wake_up_process(p->thread);
1403-
} else {
1404-
fcoe_percpu[cpu] = NULL;
1405-
kfree(p);
1406-
}
1391+
/*
1392+
* If there is no error then bind the thread to the CPU
1393+
* and wake it up.
1394+
*/
1395+
if (!IS_ERR(p->thread)) {
1396+
kthread_bind(p->thread, cpu);
1397+
wake_up_process(p->thread);
1398+
} else {
1399+
p->thread = NULL;
14071400
}
14081401
}
14091402

@@ -1432,7 +1425,7 @@ module_init(fcoe_init);
14321425
*/
14331426
static void __exit fcoe_exit(void)
14341427
{
1435-
u32 idx;
1428+
unsigned int cpu;
14361429
struct fcoe_softc *fc, *tmp;
14371430
struct fcoe_percpu_s *p;
14381431
struct sk_buff *skb;
@@ -1454,17 +1447,16 @@ static void __exit fcoe_exit(void)
14541447
list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list)
14551448
fcoe_transport_release(fc->real_dev);
14561449

1457-
for (idx = 0; idx < NR_CPUS; idx++) {
1458-
if (fcoe_percpu[idx]) {
1459-
kthread_stop(fcoe_percpu[idx]->thread);
1460-
p = fcoe_percpu[idx];
1450+
for_each_possible_cpu(cpu) {
1451+
p = &per_cpu(fcoe_percpu, cpu);
1452+
if (p->thread) {
1453+
kthread_stop(p->thread);
14611454
spin_lock_bh(&p->fcoe_rx_list.lock);
14621455
while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
14631456
kfree_skb(skb);
14641457
spin_unlock_bh(&p->fcoe_rx_list.lock);
1465-
if (fcoe_percpu[idx]->crc_eof_page)
1466-
put_page(fcoe_percpu[idx]->crc_eof_page);
1467-
kfree(fcoe_percpu[idx]);
1458+
if (p->crc_eof_page)
1459+
put_page(p->crc_eof_page);
14681460
}
14691461
}
14701462

‎include/scsi/libfcoe.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
* this percpu struct for fcoe
3030
*/
3131
struct fcoe_percpu_s {
32-
unsigned int cpu;
3332
struct task_struct *thread;
3433
struct sk_buff_head fcoe_rx_list;
3534
struct page *crc_eof_page;

0 commit comments

Comments
 (0)