Skip to content

Commit 582b45b

Browse files
Robert Lovejejb
authored andcommitted
[SCSI] fcoe: Use per-CPU kernel function for dev_stats instead of an array
Remove the hotplug creation of dev_stats, we allocate for all possible CPUs now when we allocate the lport. v2: Durring the 2.6.30 merge window, before these patches were comitted, 'percpu_ptr' was renamed 'per_cpu_ptr'. This latest update updates this patch for the name change. 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 5e5e92d commit 582b45b

5 files changed

Lines changed: 53 additions & 145 deletions

File tree

‎drivers/scsi/fcoe/fcoe_sw.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ static struct scsi_host_template fcoe_sw_shost_template = {
113113
*/
114114
static int fcoe_sw_lport_config(struct fc_lport *lp)
115115
{
116-
int i = 0;
117-
118116
lp->link_up = 0;
119117
lp->qfull = 0;
120118
lp->max_retry_count = 3;
@@ -123,12 +121,7 @@ static int fcoe_sw_lport_config(struct fc_lport *lp)
123121
lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
124122
FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
125123

126-
/*
127-
* allocate per cpu stats block
128-
*/
129-
for_each_online_cpu(i)
130-
lp->dev_stats[i] = kzalloc(sizeof(struct fcoe_dev_stats),
131-
GFP_KERNEL);
124+
fc_lport_init_stats(lp);
132125

133126
/* lport fc_lport related configuration */
134127
fc_lport_config(lp);
@@ -311,7 +304,6 @@ static inline int fcoe_sw_em_config(struct fc_lport *lp)
311304
*/
312305
static int fcoe_sw_destroy(struct net_device *netdev)
313306
{
314-
int cpu;
315307
struct fc_lport *lp = NULL;
316308
struct fcoe_softc *fc;
317309
u8 flogi_maddr[ETH_ALEN];
@@ -363,8 +355,7 @@ static int fcoe_sw_destroy(struct net_device *netdev)
363355
fcoe_clean_pending_queue(lp);
364356

365357
/* Free memory used by statistical counters */
366-
for_each_online_cpu(cpu)
367-
kfree(lp->dev_stats[cpu]);
358+
fc_lport_free_stats(lp);
368359

369360
/* Release the net_device and Scsi_Host */
370361
dev_put(fc->real_dev);

‎drivers/scsi/fcoe/libfcoe.c‎

Lines changed: 18 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
7171
/* Function Prototyes */
7272
static int fcoe_check_wait_queue(struct fc_lport *);
7373
static void fcoe_recv_flogi(struct fcoe_softc *, struct fc_frame *, u8 *);
74-
#ifdef CONFIG_HOTPLUG_CPU
75-
static int fcoe_cpu_callback(struct notifier_block *, ulong, void *);
76-
#endif /* CONFIG_HOTPLUG_CPU */
7774
static int fcoe_device_notification(struct notifier_block *, ulong, void *);
7875
static void fcoe_dev_setup(void);
7976
static void fcoe_dev_cleanup(void);
@@ -83,87 +80,6 @@ static struct notifier_block fcoe_notifier = {
8380
.notifier_call = fcoe_device_notification,
8481
};
8582

86-
87-
#ifdef CONFIG_HOTPLUG_CPU
88-
static struct notifier_block fcoe_cpu_notifier = {
89-
.notifier_call = fcoe_cpu_callback,
90-
};
91-
92-
/**
93-
* fcoe_create_percpu_data() - creates the associated cpu data
94-
* @cpu: index for the cpu where fcoe cpu data will be created
95-
*
96-
* create percpu stats block, from cpu add notifier
97-
*
98-
* Returns: none
99-
*/
100-
static void fcoe_create_percpu_data(unsigned int cpu)
101-
{
102-
struct fc_lport *lp;
103-
struct fcoe_softc *fc;
104-
105-
write_lock_bh(&fcoe_hostlist_lock);
106-
list_for_each_entry(fc, &fcoe_hostlist, list) {
107-
lp = fc->lp;
108-
if (lp->dev_stats[cpu] == NULL)
109-
lp->dev_stats[cpu] =
110-
kzalloc(sizeof(struct fcoe_dev_stats),
111-
GFP_KERNEL);
112-
}
113-
write_unlock_bh(&fcoe_hostlist_lock);
114-
}
115-
116-
/**
117-
* fcoe_destroy_percpu_data() - destroys the associated cpu data
118-
* @cpu: index for the cpu where fcoe cpu data will destroyed
119-
*
120-
* destroy percpu stats block called by cpu add/remove notifier
121-
*
122-
* Retuns: none
123-
*/
124-
static void fcoe_destroy_percpu_data(unsigned int cpu)
125-
{
126-
struct fc_lport *lp;
127-
struct fcoe_softc *fc;
128-
129-
write_lock_bh(&fcoe_hostlist_lock);
130-
list_for_each_entry(fc, &fcoe_hostlist, list) {
131-
lp = fc->lp;
132-
kfree(lp->dev_stats[cpu]);
133-
lp->dev_stats[cpu] = NULL;
134-
}
135-
write_unlock_bh(&fcoe_hostlist_lock);
136-
}
137-
138-
/**
139-
* fcoe_cpu_callback() - fcoe cpu hotplug event callback
140-
* @nfb: callback data block
141-
* @action: event triggering the callback
142-
* @hcpu: index for the cpu of this event
143-
*
144-
* this creates or destroys per cpu data for fcoe
145-
*
146-
* Returns NOTIFY_OK always.
147-
*/
148-
static int fcoe_cpu_callback(struct notifier_block *nfb, unsigned long action,
149-
void *hcpu)
150-
{
151-
unsigned int cpu = (unsigned long)hcpu;
152-
153-
switch (action) {
154-
case CPU_ONLINE:
155-
fcoe_create_percpu_data(cpu);
156-
break;
157-
case CPU_DEAD:
158-
fcoe_destroy_percpu_data(cpu);
159-
break;
160-
default:
161-
break;
162-
}
163-
return NOTIFY_OK;
164-
}
165-
#endif /* CONFIG_HOTPLUG_CPU */
166-
16783
/**
16884
* fcoe_rcv() - this is the fcoe receive function called by NET_RX_SOFTIRQ
16985
* @skb: the receive skb
@@ -181,7 +97,6 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
18197
struct fc_lport *lp;
18298
struct fcoe_rcv_info *fr;
18399
struct fcoe_softc *fc;
184-
struct fcoe_dev_stats *stats;
185100
struct fc_frame_header *fh;
186101
struct fcoe_percpu_s *fps;
187102
unsigned short oxid;
@@ -252,13 +167,7 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
252167

253168
return 0;
254169
err:
255-
#ifdef CONFIG_SMP
256-
stats = lp->dev_stats[smp_processor_id()];
257-
#else
258-
stats = lp->dev_stats[0];
259-
#endif
260-
if (stats)
261-
stats->ErrorFrames++;
170+
fc_lport_get_stats(lp)->ErrorFrames++;
262171

263172
err2:
264173
kfree_skb(skb);
@@ -495,11 +404,9 @@ int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
495404
}
496405
#endif
497406
/* update tx stats: regardless if LLD fails */
498-
stats = lp->dev_stats[smp_processor_id()];
499-
if (stats) {
500-
stats->TxFrames++;
501-
stats->TxWords += wlen;
502-
}
407+
stats = fc_lport_get_stats(lp);
408+
stats->TxFrames++;
409+
stats->TxWords += wlen;
503410

504411
/* send down to lld */
505412
fr_dev(fp) = lp;
@@ -565,8 +472,6 @@ int fcoe_percpu_receive_thread(void *arg)
565472
continue;
566473
}
567474

568-
stats = lp->dev_stats[smp_processor_id()];
569-
570475
if (unlikely(debug_fcoe)) {
571476
FC_DBG("skb_info: len:%d data_len:%d head:%p data:%p "
572477
"tail:%p end:%p sum:%d dev:%s",
@@ -593,24 +498,25 @@ int fcoe_percpu_receive_thread(void *arg)
593498
hp = (struct fcoe_hdr *) skb_network_header(skb);
594499
fh = (struct fc_frame_header *) skb_transport_header(skb);
595500

501+
stats = fc_lport_get_stats(lp);
596502
if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
597-
if (stats) {
598-
if (stats->ErrorFrames < 5)
599-
FC_DBG("unknown FCoE version %x",
600-
FC_FCOE_DECAPS_VER(hp));
601-
stats->ErrorFrames++;
602-
}
503+
if (stats->ErrorFrames < 5)
504+
printk(KERN_WARNING "FCoE version "
505+
"mismatch: The frame has "
506+
"version %x, but the "
507+
"initiator supports version "
508+
"%x\n", FC_FCOE_DECAPS_VER(hp),
509+
FC_FCOE_VER);
510+
stats->ErrorFrames++;
603511
kfree_skb(skb);
604512
continue;
605513
}
606514

607515
skb_pull(skb, sizeof(struct fcoe_hdr));
608516
fr_len = skb->len - sizeof(struct fcoe_crc_eof);
609517

610-
if (stats) {
611-
stats->RxFrames++;
612-
stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
613-
}
518+
stats->RxFrames++;
519+
stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
614520

615521
fp = (struct fc_frame *)skb;
616522
fc_frame_init(fp);
@@ -885,9 +791,8 @@ static int fcoe_device_notification(struct notifier_block *notifier,
885791
if (new_link_up)
886792
fc_linkup(lp);
887793
else {
888-
stats = lp->dev_stats[smp_processor_id()];
889-
if (stats)
890-
stats->LinkFailureCount++;
794+
stats = fc_lport_get_stats(lp);
795+
stats->LinkFailureCount++;
891796
fc_linkdown(lp);
892797
fcoe_clean_pending_queue(lp);
893798
}
@@ -1371,10 +1276,6 @@ static int __init fcoe_init(void)
13711276
INIT_LIST_HEAD(&fcoe_hostlist);
13721277
rwlock_init(&fcoe_hostlist_lock);
13731278

1374-
#ifdef CONFIG_HOTPLUG_CPU
1375-
register_cpu_notifier(&fcoe_cpu_notifier);
1376-
#endif /* CONFIG_HOTPLUG_CPU */
1377-
13781279
for_each_possible_cpu(cpu) {
13791280
p = &per_cpu(fcoe_percpu, cpu);
13801281
skb_queue_head_init(&p->fcoe_rx_list);
@@ -1430,17 +1331,9 @@ static void __exit fcoe_exit(void)
14301331
struct fcoe_percpu_s *p;
14311332
struct sk_buff *skb;
14321333

1433-
/*
1434-
* Stop all call back interfaces
1435-
*/
1436-
#ifdef CONFIG_HOTPLUG_CPU
1437-
unregister_cpu_notifier(&fcoe_cpu_notifier);
1438-
#endif /* CONFIG_HOTPLUG_CPU */
14391334
fcoe_dev_cleanup();
14401335

1441-
/*
1442-
* stop timer
1443-
*/
1336+
/* Stop the timer */
14441337
del_timer_sync(&fcoe_timer);
14451338

14461339
/* releases the associated fcoe transport for each lport */

‎drivers/scsi/libfc/fc_fcp.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,12 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
407407

408408
if (~crc != le32_to_cpu(fr_crc(fp))) {
409409
crc_err:
410-
stats = lp->dev_stats[smp_processor_id()];
410+
stats = fc_lport_get_stats(lp);
411411
stats->ErrorFrames++;
412+
/* FIXME - per cpu count, not total count! */
412413
if (stats->InvalidCRCCount++ < 5)
413-
FC_DBG("CRC error on data frame\n");
414+
printk(KERN_WARNING "CRC error on data frame for port (%6x)\n",
415+
fc_host_port_id(lp->host));
414416
/*
415417
* Assume the frame is total garbage.
416418
* We may have copied it over the good part
@@ -1752,7 +1754,7 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *))
17521754
/*
17531755
* setup the data direction
17541756
*/
1755-
stats = lp->dev_stats[smp_processor_id()];
1757+
stats = fc_lport_get_stats(lp);
17561758
if (sc_cmd->sc_data_direction == DMA_FROM_DEVICE) {
17571759
fsp->req_flags = FC_SRB_READ;
17581760
stats->InputRequests++;

‎drivers/scsi/libfc/fc_lport.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ EXPORT_SYMBOL(fc_get_host_speed);
267267

268268
struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost)
269269
{
270-
int i;
271270
struct fc_host_statistics *fcoe_stats;
272271
struct fc_lport *lp = shost_priv(shost);
273272
struct timespec v0, v1;
273+
unsigned int cpu;
274274

275275
fcoe_stats = &lp->host_stats;
276276
memset(fcoe_stats, 0, sizeof(struct fc_host_statistics));
@@ -279,10 +279,11 @@ struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost)
279279
jiffies_to_timespec(lp->boot_time, &v1);
280280
fcoe_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec);
281281

282-
for_each_online_cpu(i) {
283-
struct fcoe_dev_stats *stats = lp->dev_stats[i];
284-
if (stats == NULL)
285-
continue;
282+
for_each_possible_cpu(cpu) {
283+
struct fcoe_dev_stats *stats;
284+
285+
stats = per_cpu_ptr(lp->dev_stats, cpu);
286+
286287
fcoe_stats->tx_frames += stats->TxFrames;
287288
fcoe_stats->tx_words += stats->TxWords;
288289
fcoe_stats->rx_frames += stats->RxFrames;

‎include/scsi/libfc.h‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <linux/timer.h>
2424
#include <linux/if.h>
25+
#include <linux/percpu.h>
2526

2627
#include <scsi/scsi_transport.h>
2728
#include <scsi/scsi_transport_fc.h>
@@ -661,7 +662,8 @@ struct fc_lport {
661662
unsigned long boot_time;
662663

663664
struct fc_host_statistics host_stats;
664-
struct fcoe_dev_stats *dev_stats[NR_CPUS];
665+
struct fcoe_dev_stats *dev_stats;
666+
665667
u64 wwpn;
666668
u64 wwnn;
667669
u8 retry_count;
@@ -722,6 +724,25 @@ static inline void fc_lport_state_enter(struct fc_lport *lp,
722724
lp->state = state;
723725
}
724726

727+
static inline int fc_lport_init_stats(struct fc_lport *lp)
728+
{
729+
/* allocate per cpu stats block */
730+
lp->dev_stats = alloc_percpu(struct fcoe_dev_stats);
731+
if (!lp->dev_stats)
732+
return -ENOMEM;
733+
return 0;
734+
}
735+
736+
static inline void fc_lport_free_stats(struct fc_lport *lp)
737+
{
738+
free_percpu(lp->dev_stats);
739+
}
740+
741+
static inline struct fcoe_dev_stats *fc_lport_get_stats(struct fc_lport *lp)
742+
{
743+
return per_cpu_ptr(lp->dev_stats, smp_processor_id());
744+
}
745+
725746

726747
/*
727748
* LOCAL PORT LAYER

0 commit comments

Comments
 (0)