Skip to content

Commit 0449286

Browse files
Yihang Ligregkh
Yihang Li
authored andcommitted
scsi: hisi_sas: Allocate DFX memory during dump trigger
[ Upstream commit 63f0733 ] Currently, if CONFIG_SCSI_HISI_SAS_DEBUGFS_DEFAULT_ENABLE is enabled, the memory space used by DFX is allocated during device initialization, which occupies a large number of memory resources. The memory usage before and after the driver is loaded is as follows: Memory usage before the driver is loaded: $ free -m total used free shared buff/cache available Mem: 867352 2578 864037 11 735 861681 Swap: 4095 0 4095 Memory usage after the driver which include 4 HBAs is loaded: $ insmod hisi_sas_v3_hw.ko $ free -m total used free shared buff/cache available Mem: 867352 4760 861848 11 743 859495 Swap: 4095 0 4095 The driver with 4 HBAs connected will allocate about 110 MB of memory without enabling debugfs. Therefore, to avoid wasting memory resources, DFX memory is allocated during dump triggering. The dump may fail due to memory allocation failure. After this change, each dump costs about 10 MB of memory, and each dump lasts about 100 ms. Signed-off-by: Yihang Li <[email protected]> Signed-off-by: Xiang Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]> Stable-dep-of: 9f564f1 ("scsi: hisi_sas: Create all dump files during debugfs initialization") Signed-off-by: Sasha Levin <[email protected]>
1 parent 91e035e commit 0449286

File tree

2 files changed

+46
-49
lines changed

2 files changed

+46
-49
lines changed

drivers/scsi/hisi_sas/hisi_sas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ struct hisi_sas_hw {
343343
u8 reg_index, u8 reg_count, u8 *write_data);
344344
void (*wait_cmds_complete_timeout)(struct hisi_hba *hisi_hba,
345345
int delay_ms, int timeout_ms);
346-
void (*debugfs_snapshot_regs)(struct hisi_hba *hisi_hba);
346+
int (*debugfs_snapshot_regs)(struct hisi_hba *hisi_hba);
347347
int complete_hdr_size;
348348
const struct scsi_host_template *sht;
349349
};

drivers/scsi/hisi_sas/hisi_sas_v3_hw.c

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ static int experimental_iopoll_q_cnt;
558558
module_param(experimental_iopoll_q_cnt, int, 0444);
559559
MODULE_PARM_DESC(experimental_iopoll_q_cnt, "number of queues to be used as poll mode, def=0");
560560

561-
static void debugfs_snapshot_regs_v3_hw(struct hisi_hba *hisi_hba);
561+
static int debugfs_snapshot_regs_v3_hw(struct hisi_hba *hisi_hba);
562562

563563
static u32 hisi_sas_read32(struct hisi_hba *hisi_hba, u32 off)
564564
{
@@ -3867,47 +3867,13 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38673867
&debugfs_ras_v3_hw_fops);
38683868
}
38693869

3870-
static void debugfs_snapshot_regs_v3_hw(struct hisi_hba *hisi_hba)
3871-
{
3872-
int debugfs_dump_index = hisi_hba->debugfs_dump_index;
3873-
struct device *dev = hisi_hba->dev;
3874-
u64 timestamp = local_clock();
3875-
3876-
if (debugfs_dump_index >= hisi_sas_debugfs_dump_count) {
3877-
dev_warn(dev, "dump count exceeded!\n");
3878-
return;
3879-
}
3880-
3881-
do_div(timestamp, NSEC_PER_MSEC);
3882-
hisi_hba->debugfs_timestamp[debugfs_dump_index] = timestamp;
3883-
3884-
debugfs_snapshot_prepare_v3_hw(hisi_hba);
3885-
3886-
debugfs_snapshot_global_reg_v3_hw(hisi_hba);
3887-
debugfs_snapshot_port_reg_v3_hw(hisi_hba);
3888-
debugfs_snapshot_axi_reg_v3_hw(hisi_hba);
3889-
debugfs_snapshot_ras_reg_v3_hw(hisi_hba);
3890-
debugfs_snapshot_cq_reg_v3_hw(hisi_hba);
3891-
debugfs_snapshot_dq_reg_v3_hw(hisi_hba);
3892-
debugfs_snapshot_itct_reg_v3_hw(hisi_hba);
3893-
debugfs_snapshot_iost_reg_v3_hw(hisi_hba);
3894-
3895-
debugfs_create_files_v3_hw(hisi_hba);
3896-
3897-
debugfs_snapshot_restore_v3_hw(hisi_hba);
3898-
hisi_hba->debugfs_dump_index++;
3899-
}
3900-
39013870
static ssize_t debugfs_trigger_dump_v3_hw_write(struct file *file,
39023871
const char __user *user_buf,
39033872
size_t count, loff_t *ppos)
39043873
{
39053874
struct hisi_hba *hisi_hba = file->f_inode->i_private;
39063875
char buf[8];
39073876

3908-
if (hisi_hba->debugfs_dump_index >= hisi_sas_debugfs_dump_count)
3909-
return -EFAULT;
3910-
39113877
if (count > 8)
39123878
return -EFAULT;
39133879

@@ -3918,7 +3884,10 @@ static ssize_t debugfs_trigger_dump_v3_hw_write(struct file *file,
39183884
return -EFAULT;
39193885

39203886
down(&hisi_hba->sem);
3921-
debugfs_snapshot_regs_v3_hw(hisi_hba);
3887+
if (debugfs_snapshot_regs_v3_hw(hisi_hba)) {
3888+
up(&hisi_hba->sem);
3889+
return -EFAULT;
3890+
}
39223891
up(&hisi_hba->sem);
39233892

39243893
return count;
@@ -4704,7 +4673,7 @@ static int debugfs_alloc_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
47044673
{
47054674
const struct hisi_sas_hw *hw = hisi_hba->hw;
47064675
struct device *dev = hisi_hba->dev;
4707-
int p, c, d, r, i;
4676+
int p, c, d, r;
47084677
size_t sz;
47094678

47104679
for (r = 0; r < DEBUGFS_REGS_NUM; r++) {
@@ -4784,11 +4753,48 @@ static int debugfs_alloc_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
47844753

47854754
return 0;
47864755
fail:
4787-
for (i = 0; i < hisi_sas_debugfs_dump_count; i++)
4788-
debugfs_release_v3_hw(hisi_hba, i);
4756+
debugfs_release_v3_hw(hisi_hba, dump_index);
47894757
return -ENOMEM;
47904758
}
47914759

4760+
static int debugfs_snapshot_regs_v3_hw(struct hisi_hba *hisi_hba)
4761+
{
4762+
int debugfs_dump_index = hisi_hba->debugfs_dump_index;
4763+
struct device *dev = hisi_hba->dev;
4764+
u64 timestamp = local_clock();
4765+
4766+
if (debugfs_dump_index >= hisi_sas_debugfs_dump_count) {
4767+
dev_warn(dev, "dump count exceeded!\n");
4768+
return -EINVAL;
4769+
}
4770+
4771+
if (debugfs_alloc_v3_hw(hisi_hba, debugfs_dump_index)) {
4772+
dev_warn(dev, "failed to alloc memory\n");
4773+
return -ENOMEM;
4774+
}
4775+
4776+
do_div(timestamp, NSEC_PER_MSEC);
4777+
hisi_hba->debugfs_timestamp[debugfs_dump_index] = timestamp;
4778+
4779+
debugfs_snapshot_prepare_v3_hw(hisi_hba);
4780+
4781+
debugfs_snapshot_global_reg_v3_hw(hisi_hba);
4782+
debugfs_snapshot_port_reg_v3_hw(hisi_hba);
4783+
debugfs_snapshot_axi_reg_v3_hw(hisi_hba);
4784+
debugfs_snapshot_ras_reg_v3_hw(hisi_hba);
4785+
debugfs_snapshot_cq_reg_v3_hw(hisi_hba);
4786+
debugfs_snapshot_dq_reg_v3_hw(hisi_hba);
4787+
debugfs_snapshot_itct_reg_v3_hw(hisi_hba);
4788+
debugfs_snapshot_iost_reg_v3_hw(hisi_hba);
4789+
4790+
debugfs_create_files_v3_hw(hisi_hba);
4791+
4792+
debugfs_snapshot_restore_v3_hw(hisi_hba);
4793+
hisi_hba->debugfs_dump_index++;
4794+
4795+
return 0;
4796+
}
4797+
47924798
static void debugfs_phy_down_cnt_init_v3_hw(struct hisi_hba *hisi_hba)
47934799
{
47944800
struct dentry *dir = debugfs_create_dir("phy_down_cnt",
@@ -4875,7 +4881,6 @@ static void debugfs_exit_v3_hw(struct hisi_hba *hisi_hba)
48754881
static void debugfs_init_v3_hw(struct hisi_hba *hisi_hba)
48764882
{
48774883
struct device *dev = hisi_hba->dev;
4878-
int i;
48794884

48804885
hisi_hba->debugfs_dir = debugfs_create_dir(dev_name(dev),
48814886
hisi_sas_debugfs_dir);
@@ -4892,14 +4897,6 @@ static void debugfs_init_v3_hw(struct hisi_hba *hisi_hba)
48924897

48934898
debugfs_phy_down_cnt_init_v3_hw(hisi_hba);
48944899
debugfs_fifo_init_v3_hw(hisi_hba);
4895-
4896-
for (i = 0; i < hisi_sas_debugfs_dump_count; i++) {
4897-
if (debugfs_alloc_v3_hw(hisi_hba, i)) {
4898-
debugfs_exit_v3_hw(hisi_hba);
4899-
dev_dbg(dev, "failed to init debugfs!\n");
4900-
break;
4901-
}
4902-
}
49034900
}
49044901

49054902
static int

0 commit comments

Comments
 (0)