Skip to content

Commit bb0f544

Browse files
Kevin Barnettmartinkpetersen
authored andcommitted
scsi: smartpqi: Improve accuracy/performance of raid-bypass-counter
The original implementation of this counter used an atomic variable. However, this implementation negatively impacted performance in some configurations. Switch to using per_cpu variables. Reviewed-by: Scott Benesh <[email protected]> Reviewed-by: Scott Teel <[email protected]> Reviewed-by: Mike McGowen <[email protected]> Co-developed-by: Mahesh Rajashekhara <[email protected]> Signed-off-by: Mahesh Rajashekhara <[email protected]> Signed-off-by: Kevin Barnett <[email protected]> Signed-off-by: Don Brace <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 0e21e73 commit bb0f544

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

drivers/scsi/smartpqi/smartpqi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ struct pqi_scsi_dev {
11581158

11591159
struct pqi_stream_data stream_data[NUM_STREAMS_PER_LUN];
11601160
atomic_t scsi_cmds_outstanding[PQI_MAX_LUNS_PER_DEVICE];
1161-
unsigned int raid_bypass_cnt;
1161+
u64 __percpu *raid_bypass_cnt;
11621162

11631163
struct pqi_tmf_work tmf_work[PQI_MAX_LUNS_PER_DEVICE];
11641164
};

drivers/scsi/smartpqi/smartpqi_init.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,12 @@ static int pqi_get_raid_map(struct pqi_ctrl_info *ctrl_info,
15081508
if (rc)
15091509
goto error;
15101510

1511+
device->raid_bypass_cnt = alloc_percpu(u64);
1512+
if (!device->raid_bypass_cnt) {
1513+
rc = -ENOMEM;
1514+
goto error;
1515+
}
1516+
15111517
device->raid_map = raid_map;
15121518

15131519
return 0;
@@ -2099,6 +2105,10 @@ static void pqi_scsi_update_device(struct pqi_ctrl_info *ctrl_info,
20992105
/* To prevent this from being freed later. */
21002106
new_device->raid_map = NULL;
21012107
}
2108+
if (new_device->raid_bypass_enabled && existing_device->raid_bypass_cnt == NULL) {
2109+
existing_device->raid_bypass_cnt = new_device->raid_bypass_cnt;
2110+
new_device->raid_bypass_cnt = NULL;
2111+
}
21022112
existing_device->raid_bypass_configured = new_device->raid_bypass_configured;
21032113
existing_device->raid_bypass_enabled = new_device->raid_bypass_enabled;
21042114
}
@@ -2121,6 +2131,7 @@ static void pqi_scsi_update_device(struct pqi_ctrl_info *ctrl_info,
21212131
static inline void pqi_free_device(struct pqi_scsi_dev *device)
21222132
{
21232133
if (device) {
2134+
free_percpu(device->raid_bypass_cnt);
21242135
kfree(device->raid_map);
21252136
kfree(device);
21262137
}
@@ -6007,6 +6018,7 @@ static int pqi_scsi_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scm
60076018
u16 hw_queue;
60086019
struct pqi_queue_group *queue_group;
60096020
bool raid_bypassed;
6021+
u64 *raid_bypass_cnt;
60106022
u8 lun;
60116023

60126024
scmd->host_scribble = PQI_NO_COMPLETION;
@@ -6053,7 +6065,8 @@ static int pqi_scsi_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scm
60536065
rc = pqi_raid_bypass_submit_scsi_cmd(ctrl_info, device, scmd, queue_group);
60546066
if (rc == 0 || rc == SCSI_MLQUEUE_HOST_BUSY) {
60556067
raid_bypassed = true;
6056-
device->raid_bypass_cnt++;
6068+
raid_bypass_cnt = per_cpu_ptr(device->raid_bypass_cnt, smp_processor_id());
6069+
(*raid_bypass_cnt)++;
60576070
}
60586071
}
60596072
if (!raid_bypassed)
@@ -7350,7 +7363,9 @@ static ssize_t pqi_raid_bypass_cnt_show(struct device *dev,
73507363
struct scsi_device *sdev;
73517364
struct pqi_scsi_dev *device;
73527365
unsigned long flags;
7353-
unsigned int raid_bypass_cnt;
7366+
u64 raid_bypass_cnt;
7367+
int cpu;
7368+
u64 *per_cpu_bypass_cnt_ptr;
73547369

73557370
sdev = to_scsi_device(dev);
73567371
ctrl_info = shost_to_hba(sdev->host);
@@ -7366,11 +7381,18 @@ static ssize_t pqi_raid_bypass_cnt_show(struct device *dev,
73667381
return -ENODEV;
73677382
}
73687383

7369-
raid_bypass_cnt = device->raid_bypass_cnt;
7384+
raid_bypass_cnt = 0;
7385+
7386+
if (device->raid_bypass_cnt) {
7387+
for_each_online_cpu(cpu) {
7388+
per_cpu_bypass_cnt_ptr = per_cpu_ptr(device->raid_bypass_cnt, cpu);
7389+
raid_bypass_cnt += *per_cpu_bypass_cnt_ptr;
7390+
}
7391+
}
73707392

73717393
spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags);
73727394

7373-
return scnprintf(buffer, PAGE_SIZE, "0x%x\n", raid_bypass_cnt);
7395+
return scnprintf(buffer, PAGE_SIZE, "0x%llx\n", raid_bypass_cnt);
73747396
}
73757397

73767398
static ssize_t pqi_sas_ncq_prio_enable_show(struct device *dev,

0 commit comments

Comments
 (0)