Skip to content

Commit

Permalink
target: Convert se_device statistics to atomic_long_t
Browse files Browse the repository at this point in the history
This patch converts the handful of se_device statistics to type
atomic_long_t, instead of using se_device->stats_lock when
incrementing these values.

More importantly, go ahead and drop the spinlock usage within
transport_lookup_cmd_lun() fast-path code.

Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
  • Loading branch information
Nicholas Bellinger committed Nov 14, 2013
1 parent 29f4c09 commit ee48068
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
10 changes: 3 additions & 7 deletions drivers/target/target_core_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,12 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)
/* Directly associate cmd with se_dev */
se_cmd->se_dev = se_lun->lun_se_dev;

/* TODO: get rid of this and use atomics for stats */
dev = se_lun->lun_se_dev;
spin_lock_irqsave(&dev->stats_lock, flags);
dev->num_cmds++;
atomic_long_inc(&dev->num_cmds);
if (se_cmd->data_direction == DMA_TO_DEVICE)
dev->write_bytes += se_cmd->data_length;
atomic_long_add(se_cmd->data_length, &dev->write_bytes);
else if (se_cmd->data_direction == DMA_FROM_DEVICE)
dev->read_bytes += se_cmd->data_length;
spin_unlock_irqrestore(&dev->stats_lock, flags);
atomic_long_add(se_cmd->data_length, &dev->read_bytes);

return 0;
}
Expand Down Expand Up @@ -1426,7 +1423,6 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
INIT_LIST_HEAD(&dev->state_list);
INIT_LIST_HEAD(&dev->qf_cmd_list);
INIT_LIST_HEAD(&dev->g_dev_node);
spin_lock_init(&dev->stats_lock);
spin_lock_init(&dev->execute_task_lock);
spin_lock_init(&dev->delayed_cmd_lock);
spin_lock_init(&dev->dev_reservation_lock);
Expand Down
15 changes: 9 additions & 6 deletions drivers/target/target_core_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ static ssize_t target_stat_scsi_tgt_dev_show_attr_resets(
struct se_device *dev =
container_of(sgrps, struct se_device, dev_stat_grps);

return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
return snprintf(page, PAGE_SIZE, "%lu\n",
atomic_long_read(&dev->num_resets));
}
DEV_STAT_SCSI_TGT_DEV_ATTR_RO(resets);

Expand Down Expand Up @@ -396,8 +397,8 @@ static ssize_t target_stat_scsi_lu_show_attr_num_cmds(
container_of(sgrps, struct se_device, dev_stat_grps);

/* scsiLuNumCommands */
return snprintf(page, PAGE_SIZE, "%llu\n",
(unsigned long long)dev->num_cmds);
return snprintf(page, PAGE_SIZE, "%lu\n",
atomic_long_read(&dev->num_cmds));
}
DEV_STAT_SCSI_LU_ATTR_RO(num_cmds);

Expand All @@ -408,7 +409,8 @@ static ssize_t target_stat_scsi_lu_show_attr_read_mbytes(
container_of(sgrps, struct se_device, dev_stat_grps);

/* scsiLuReadMegaBytes */
return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->read_bytes >> 20));
return snprintf(page, PAGE_SIZE, "%lu\n",
atomic_long_read(&dev->read_bytes) >> 20);
}
DEV_STAT_SCSI_LU_ATTR_RO(read_mbytes);

Expand All @@ -419,7 +421,8 @@ static ssize_t target_stat_scsi_lu_show_attr_write_mbytes(
container_of(sgrps, struct se_device, dev_stat_grps);

/* scsiLuWrittenMegaBytes */
return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->write_bytes >> 20));
return snprintf(page, PAGE_SIZE, "%lu\n",
atomic_long_read(&dev->write_bytes) >> 20);
}
DEV_STAT_SCSI_LU_ATTR_RO(write_mbytes);

Expand All @@ -430,7 +433,7 @@ static ssize_t target_stat_scsi_lu_show_attr_resets(
container_of(sgrps, struct se_device, dev_stat_grps);

/* scsiLuInResets */
return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
return snprintf(page, PAGE_SIZE, "%lu\n", atomic_long_read(&dev->num_resets));
}
DEV_STAT_SCSI_LU_ATTR_RO(resets);

Expand Down
4 changes: 1 addition & 3 deletions drivers/target/target_core_tmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,7 @@ int core_tmr_lun_reset(
pr_debug("LUN_RESET: SCSI-2 Released reservation\n");
}

spin_lock_irq(&dev->stats_lock);
dev->num_resets++;
spin_unlock_irq(&dev->stats_lock);
atomic_long_inc(&dev->num_resets);

pr_debug("LUN_RESET: %s for [%s] Complete\n",
(preempt_and_abort_list) ? "Preempt" : "TMR",
Expand Down
9 changes: 4 additions & 5 deletions include/target/target_core_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,11 +683,10 @@ struct se_device {
/* Pointer to transport specific device structure */
u32 dev_index;
u64 creation_time;
u32 num_resets;
u64 num_cmds;
u64 read_bytes;
u64 write_bytes;
spinlock_t stats_lock;
atomic_long_t num_resets;
atomic_long_t num_cmds;
atomic_long_t read_bytes;
atomic_long_t write_bytes;
/* Active commands on this virtual SE device */
atomic_t simple_cmds;
atomic_t dev_ordered_id;
Expand Down

0 comments on commit ee48068

Please sign in to comment.