Skip to content

Commit 63f0733

Browse files
Yihang Limartinkpetersen
Yihang Li
authored andcommitted
scsi: hisi_sas: Allocate DFX memory during dump trigger
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]>
1 parent 2ff07b5 commit 63f0733

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
{
@@ -3858,47 +3858,13 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38583858
&debugfs_ras_v3_hw_fops);
38593859
}
38603860

3861-
static void debugfs_snapshot_regs_v3_hw(struct hisi_hba *hisi_hba)
3862-
{
3863-
int debugfs_dump_index = hisi_hba->debugfs_dump_index;
3864-
struct device *dev = hisi_hba->dev;
3865-
u64 timestamp = local_clock();
3866-
3867-
if (debugfs_dump_index >= hisi_sas_debugfs_dump_count) {
3868-
dev_warn(dev, "dump count exceeded!\n");
3869-
return;
3870-
}
3871-
3872-
do_div(timestamp, NSEC_PER_MSEC);
3873-
hisi_hba->debugfs_timestamp[debugfs_dump_index] = timestamp;
3874-
3875-
debugfs_snapshot_prepare_v3_hw(hisi_hba);
3876-
3877-
debugfs_snapshot_global_reg_v3_hw(hisi_hba);
3878-
debugfs_snapshot_port_reg_v3_hw(hisi_hba);
3879-
debugfs_snapshot_axi_reg_v3_hw(hisi_hba);
3880-
debugfs_snapshot_ras_reg_v3_hw(hisi_hba);
3881-
debugfs_snapshot_cq_reg_v3_hw(hisi_hba);
3882-
debugfs_snapshot_dq_reg_v3_hw(hisi_hba);
3883-
debugfs_snapshot_itct_reg_v3_hw(hisi_hba);
3884-
debugfs_snapshot_iost_reg_v3_hw(hisi_hba);
3885-
3886-
debugfs_create_files_v3_hw(hisi_hba);
3887-
3888-
debugfs_snapshot_restore_v3_hw(hisi_hba);
3889-
hisi_hba->debugfs_dump_index++;
3890-
}
3891-
38923861
static ssize_t debugfs_trigger_dump_v3_hw_write(struct file *file,
38933862
const char __user *user_buf,
38943863
size_t count, loff_t *ppos)
38953864
{
38963865
struct hisi_hba *hisi_hba = file->f_inode->i_private;
38973866
char buf[8];
38983867

3899-
if (hisi_hba->debugfs_dump_index >= hisi_sas_debugfs_dump_count)
3900-
return -EFAULT;
3901-
39023868
if (count > 8)
39033869
return -EFAULT;
39043870

@@ -3909,7 +3875,10 @@ static ssize_t debugfs_trigger_dump_v3_hw_write(struct file *file,
39093875
return -EFAULT;
39103876

39113877
down(&hisi_hba->sem);
3912-
debugfs_snapshot_regs_v3_hw(hisi_hba);
3878+
if (debugfs_snapshot_regs_v3_hw(hisi_hba)) {
3879+
up(&hisi_hba->sem);
3880+
return -EFAULT;
3881+
}
39133882
up(&hisi_hba->sem);
39143883

39153884
return count;
@@ -4695,7 +4664,7 @@ static int debugfs_alloc_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
46954664
{
46964665
const struct hisi_sas_hw *hw = hisi_hba->hw;
46974666
struct device *dev = hisi_hba->dev;
4698-
int p, c, d, r, i;
4667+
int p, c, d, r;
46994668
size_t sz;
47004669

47014670
for (r = 0; r < DEBUGFS_REGS_NUM; r++) {
@@ -4775,11 +4744,48 @@ static int debugfs_alloc_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
47754744

47764745
return 0;
47774746
fail:
4778-
for (i = 0; i < hisi_sas_debugfs_dump_count; i++)
4779-
debugfs_release_v3_hw(hisi_hba, i);
4747+
debugfs_release_v3_hw(hisi_hba, dump_index);
47804748
return -ENOMEM;
47814749
}
47824750

4751+
static int debugfs_snapshot_regs_v3_hw(struct hisi_hba *hisi_hba)
4752+
{
4753+
int debugfs_dump_index = hisi_hba->debugfs_dump_index;
4754+
struct device *dev = hisi_hba->dev;
4755+
u64 timestamp = local_clock();
4756+
4757+
if (debugfs_dump_index >= hisi_sas_debugfs_dump_count) {
4758+
dev_warn(dev, "dump count exceeded!\n");
4759+
return -EINVAL;
4760+
}
4761+
4762+
if (debugfs_alloc_v3_hw(hisi_hba, debugfs_dump_index)) {
4763+
dev_warn(dev, "failed to alloc memory\n");
4764+
return -ENOMEM;
4765+
}
4766+
4767+
do_div(timestamp, NSEC_PER_MSEC);
4768+
hisi_hba->debugfs_timestamp[debugfs_dump_index] = timestamp;
4769+
4770+
debugfs_snapshot_prepare_v3_hw(hisi_hba);
4771+
4772+
debugfs_snapshot_global_reg_v3_hw(hisi_hba);
4773+
debugfs_snapshot_port_reg_v3_hw(hisi_hba);
4774+
debugfs_snapshot_axi_reg_v3_hw(hisi_hba);
4775+
debugfs_snapshot_ras_reg_v3_hw(hisi_hba);
4776+
debugfs_snapshot_cq_reg_v3_hw(hisi_hba);
4777+
debugfs_snapshot_dq_reg_v3_hw(hisi_hba);
4778+
debugfs_snapshot_itct_reg_v3_hw(hisi_hba);
4779+
debugfs_snapshot_iost_reg_v3_hw(hisi_hba);
4780+
4781+
debugfs_create_files_v3_hw(hisi_hba);
4782+
4783+
debugfs_snapshot_restore_v3_hw(hisi_hba);
4784+
hisi_hba->debugfs_dump_index++;
4785+
4786+
return 0;
4787+
}
4788+
47834789
static void debugfs_phy_down_cnt_init_v3_hw(struct hisi_hba *hisi_hba)
47844790
{
47854791
struct dentry *dir = debugfs_create_dir("phy_down_cnt",
@@ -4866,7 +4872,6 @@ static void debugfs_exit_v3_hw(struct hisi_hba *hisi_hba)
48664872
static void debugfs_init_v3_hw(struct hisi_hba *hisi_hba)
48674873
{
48684874
struct device *dev = hisi_hba->dev;
4869-
int i;
48704875

48714876
hisi_hba->debugfs_dir = debugfs_create_dir(dev_name(dev),
48724877
hisi_sas_debugfs_dir);
@@ -4883,14 +4888,6 @@ static void debugfs_init_v3_hw(struct hisi_hba *hisi_hba)
48834888

48844889
debugfs_phy_down_cnt_init_v3_hw(hisi_hba);
48854890
debugfs_fifo_init_v3_hw(hisi_hba);
4886-
4887-
for (i = 0; i < hisi_sas_debugfs_dump_count; i++) {
4888-
if (debugfs_alloc_v3_hw(hisi_hba, i)) {
4889-
debugfs_exit_v3_hw(hisi_hba);
4890-
dev_dbg(dev, "failed to init debugfs!\n");
4891-
break;
4892-
}
4893-
}
48944891
}
48954892

48964893
static int

0 commit comments

Comments
 (0)