scsi: libfc: fix seconds_since_last_reset calculation
Subsystems (2)
PATCH 1/1 scsi: libfc: fix seconds_since_last_reset calculation
The fc_get_host_stats() function contains a complex conversion from jiffies to timespec to seconds. As we try to get rid of uses of struct timespec, we can clean this up and replace it with a simpler computation.
Simply dividing the difference in jiffies by HZ is not only much more efficient, it also avoids a problem that causes the seconds_since_last_reset value to be incorrect if jiffies has overrun since the 'boot_time' value was recorded.
--- drivers/scsi/libfc/fc_lport.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/scsi/libfc/fc_lport.c +1 -4
@@ -301,7 +301,6 @@ struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) {struct fc_host_statistics *fc_stats;struct fc_lport *lport =shost_priv (shost); -struct timespec v0, v1;unsigned int cpu;u64 fcp_in_bytes =0 ;u64 fcp_out_bytes =0 ;
@@ -309,9 +308,7 @@ struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) fc_stats = &lport->host_stats;memset (fc_stats,0 ,sizeof (struct fc_host_statistics )); -jiffies_to_timespec (jiffies, &v0); -jiffies_to_timespec (lport->boot_time, &v1); - fc_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec); + fc_stats->seconds_since_last_reset = (lport->boot_time - jiffies) /HZ ;for_each_possible_cpu (cpu) {struct fc_stats *stats;
Signature · 1 line
2.9.0
drivers/scsi/libfc/fc_lport.c struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) · line 311
Quoted 4 lines · Arnd Bergmann
drivers/scsi/libfc/fc_lport.c +1
-3-jiffies_to_timespec (jiffies, &v0); -jiffies_to_timespec (lport->boot_time, &v1); - fc_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec); + fc_stats->seconds_since_last_reset = (lport->boot_time - jiffies) /HZ ;
Does this patch introduce a 64-bit division? There might still be 32-bit users of this code.
Bart.
_______________________________________________
Y2038 mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/y2038
Quoted 8 lines · CEST Bart Van Assche
drivers/scsi/libfc/fc_lport.c struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) · line 311
Quoted 4 lines · Arnd Bergmann
drivers/scsi/libfc/fc_lport.c +1
-3-jiffies_to_timespec (jiffies, &v0); -jiffies_to_timespec (lport->boot_time, &v1); - fc_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec); + fc_stats->seconds_since_last_reset = (lport->boot_time - jiffies) /HZ ;Does this patch introduce a 64-bit division? There might still be 32-bit users of this code.
No, both lport->boot_time and jiffies are 'unsigned long'.
Arnd
Bart Van Assche
Reviewed-byQuoted 11 lines · Arnd Bergmann
Quoted 8 lines · CEST Bart Van Assche
drivers/scsi/libfc/fc_lport.c struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) · line 311
Quoted 4 lines · Arnd Bergmann
drivers/scsi/libfc/fc_lport.c +1
-3-jiffies_to_timespec (jiffies, &v0); -jiffies_to_timespec (lport->boot_time, &v1); - fc_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec); + fc_stats->seconds_since_last_reset = (lport->boot_time - jiffies) /HZ ;Does this patch introduce a 64-bit division? There might still be 32-bit users of this code.
No, both
lport->boot_timeand jiffies are 'unsigned long'.
Ah, you're right. Hence:
_______________________________________________
Y2038 mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/y2038
Martin K. Petersen
AppliedQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Arnd" == Arnd Bergmann <[email protected]> writes:
Arnd> The fc_get_host_stats() function contains a complex conversion Arnd> from jiffies to timespec to seconds. As we try to get rid of uses Arnd> of struct timespec, we can clean this up and replace it with a Arnd> simpler computation.
Arnd> Simply dividing the difference in jiffies by HZ is not only much Arnd> more efficient, it also avoids a problem that causes the Arnd> seconds_since_last_reset value to be incorrect if jiffies has Arnd> overrun since the 'boot_time' value was recorded.
Applied to 4.8/scsi-queue.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering