Commit c4d6204d authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Martin K. Petersen

scsi: lpfc: use monotonic timestamps for statistics

The get_seconds() function suffers from a possible overflow in 2038 or
2106, as well as jitter due to settimeofday or leap second updates, and is
deprecated.

As we are interested in elapsed time only, using ktime_get_seconds() to
read the CLOCK_MONOTONIC timebase is ideal here. This also lets us remove
the hack that tries to deal with get_seconds() going slightly backwards,
which cannot happen with montonic timestamps.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent fe7f4e5d
...@@ -5891,7 +5891,6 @@ lpfc_get_stats(struct Scsi_Host *shost) ...@@ -5891,7 +5891,6 @@ lpfc_get_stats(struct Scsi_Host *shost)
struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
LPFC_MBOXQ_t *pmboxq; LPFC_MBOXQ_t *pmboxq;
MAILBOX_t *pmb; MAILBOX_t *pmb;
unsigned long seconds;
int rc = 0; int rc = 0;
/* /*
...@@ -5992,12 +5991,7 @@ lpfc_get_stats(struct Scsi_Host *shost) ...@@ -5992,12 +5991,7 @@ lpfc_get_stats(struct Scsi_Host *shost)
hs->dumped_frames = -1; hs->dumped_frames = -1;
seconds = get_seconds(); hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
if (seconds < psli->stats_start)
hs->seconds_since_last_reset = seconds +
((unsigned long)-1 - psli->stats_start);
else
hs->seconds_since_last_reset = seconds - psli->stats_start;
mempool_free(pmboxq, phba->mbox_mem_pool); mempool_free(pmboxq, phba->mbox_mem_pool);
...@@ -6076,7 +6070,7 @@ lpfc_reset_stats(struct Scsi_Host *shost) ...@@ -6076,7 +6070,7 @@ lpfc_reset_stats(struct Scsi_Host *shost)
else else
lso->link_events = (phba->fc_eventTag >> 1); lso->link_events = (phba->fc_eventTag >> 1);
psli->stats_start = get_seconds(); psli->stats_start = ktime_get_seconds();
mempool_free(pmboxq, phba->mbox_mem_pool); mempool_free(pmboxq, phba->mbox_mem_pool);
......
...@@ -4591,7 +4591,7 @@ lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) ...@@ -4591,7 +4591,7 @@ lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
spin_unlock_irq(&phba->hbalock); spin_unlock_irq(&phba->hbalock);
memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
psli->stats_start = get_seconds(); psli->stats_start = ktime_get_seconds();
/* Give the INITFF and Post time to settle. */ /* Give the INITFF and Post time to settle. */
mdelay(100); mdelay(100);
...@@ -4638,7 +4638,7 @@ lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) ...@@ -4638,7 +4638,7 @@ lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
spin_unlock_irq(&phba->hbalock); spin_unlock_irq(&phba->hbalock);
memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
psli->stats_start = get_seconds(); psli->stats_start = ktime_get_seconds();
/* Reset HBA AER if it was enabled, note hba_flag was reset above */ /* Reset HBA AER if it was enabled, note hba_flag was reset above */
if (hba_aer_enabled) if (hba_aer_enabled)
......
...@@ -339,7 +339,7 @@ struct lpfc_sli { ...@@ -339,7 +339,7 @@ struct lpfc_sli {
struct lpfc_iocbq ** iocbq_lookup; /* array to lookup IOCB by IOTAG */ struct lpfc_iocbq ** iocbq_lookup; /* array to lookup IOCB by IOTAG */
size_t iocbq_lookup_len; /* current lengs of the array */ size_t iocbq_lookup_len; /* current lengs of the array */
uint16_t last_iotag; /* last allocated IOTAG */ uint16_t last_iotag; /* last allocated IOTAG */
unsigned long stats_start; /* in seconds */ time64_t stats_start; /* in seconds */
struct lpfc_lnk_stat lnk_stat_offsets; struct lpfc_lnk_stat lnk_stat_offsets;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment