All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: libfc: fix seconds_since_last_reset calculation
@ 2016-06-17 15:47 ` Arnd Bergmann
  0 siblings, 0 replies; 9+ messages in thread
From: Arnd Bergmann @ 2016-06-17 15:47 UTC (permalink / raw)
  To: Vasu Dev, James E.J. Bottomley, Martin K. Petersen
  Cc: y2038, Arnd Bergmann, fcoe-devel, linux-scsi, linux-kernel

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/scsi/libfc/fc_lport.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index e01a29863c38..99c6d9251404 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -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;
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] scsi: libfc: fix seconds_since_last_reset calculation
@ 2016-06-17 15:47 ` Arnd Bergmann
  0 siblings, 0 replies; 9+ messages in thread
From: Arnd Bergmann @ 2016-06-17 15:47 UTC (permalink / raw)
  To: Vasu Dev, James E.J. Bottomley, Martin K. Petersen
  Cc: y2038, fcoe-devel, linux-scsi, Arnd Bergmann, linux-kernel

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/scsi/libfc/fc_lport.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index e01a29863c38..99c6d9251404 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -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;
-- 
2.9.0

_______________________________________________
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: libfc: fix seconds_since_last_reset calculation
  2016-06-17 15:47 ` Arnd Bergmann
@ 2016-06-20 13:54   ` Bart Van Assche
  -1 siblings, 0 replies; 9+ messages in thread
From: Bart Van Assche @ 2016-06-20 13:54 UTC (permalink / raw)
  To: Arnd Bergmann, Vasu Dev, James E.J. Bottomley, Martin K. Petersen
  Cc: y2038, fcoe-devel, linux-scsi, linux-kernel

On 06/17/2016 05:47 PM, Arnd Bergmann wrote:
> -	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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: libfc: fix seconds_since_last_reset calculation
@ 2016-06-20 13:54   ` Bart Van Assche
  0 siblings, 0 replies; 9+ messages in thread
From: Bart Van Assche @ 2016-06-20 13:54 UTC (permalink / raw)
  To: Arnd Bergmann, Vasu Dev, James E.J. Bottomley, Martin K. Petersen
  Cc: y2038, fcoe-devel, linux-kernel, linux-scsi

On 06/17/2016 05:47 PM, Arnd Bergmann wrote:
> -	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
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: libfc: fix seconds_since_last_reset calculation
  2016-06-20 13:54   ` Bart Van Assche
@ 2016-06-20 14:50     ` Arnd Bergmann
  -1 siblings, 0 replies; 9+ messages in thread
From: Arnd Bergmann @ 2016-06-20 14:50 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Vasu Dev, James E.J. Bottomley, Martin K. Petersen, y2038,
	fcoe-devel, linux-scsi, linux-kernel

On Monday, June 20, 2016 3:54:06 PM CEST Bart Van Assche wrote:
> On 06/17/2016 05:47 PM, Arnd Bergmann wrote:
> > -     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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: libfc: fix seconds_since_last_reset calculation
@ 2016-06-20 14:50     ` Arnd Bergmann
  0 siblings, 0 replies; 9+ messages in thread
From: Arnd Bergmann @ 2016-06-20 14:50 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi, Vasu Dev,
	y2038, linux-kernel, fcoe-devel

On Monday, June 20, 2016 3:54:06 PM CEST Bart Van Assche wrote:
> On 06/17/2016 05:47 PM, Arnd Bergmann wrote:
> > -     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
_______________________________________________
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: libfc: fix seconds_since_last_reset calculation
  2016-06-20 14:50     ` Arnd Bergmann
@ 2016-06-20 14:58       ` Bart Van Assche
  -1 siblings, 0 replies; 9+ messages in thread
From: Bart Van Assche @ 2016-06-20 14:58 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Vasu Dev, James E.J. Bottomley, Martin K. Petersen, y2038,
	fcoe-devel, linux-scsi, linux-kernel

On 06/20/2016 04:48 PM, Arnd Bergmann wrote:
> On Monday, June 20, 2016 3:54:06 PM CEST Bart Van Assche wrote:
>> On 06/17/2016 05:47 PM, Arnd Bergmann wrote:
>>> -     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'.

Ah, you're right. Hence:

Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: libfc: fix seconds_since_last_reset calculation
@ 2016-06-20 14:58       ` Bart Van Assche
  0 siblings, 0 replies; 9+ messages in thread
From: Bart Van Assche @ 2016-06-20 14:58 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi, Vasu Dev,
	y2038, linux-kernel, fcoe-devel

On 06/20/2016 04:48 PM, Arnd Bergmann wrote:
> On Monday, June 20, 2016 3:54:06 PM CEST Bart Van Assche wrote:
>> On 06/17/2016 05:47 PM, Arnd Bergmann wrote:
>>> -     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'.

Ah, you're right. Hence:

Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com>
_______________________________________________
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: libfc: fix seconds_since_last_reset calculation
  2016-06-17 15:47 ` Arnd Bergmann
  (?)
  (?)
@ 2016-06-21  2:05 ` Martin K. Petersen
  -1 siblings, 0 replies; 9+ messages in thread
From: Martin K. Petersen @ 2016-06-21  2:05 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Vasu Dev, James E.J. Bottomley, Martin K. Petersen, y2038,
	fcoe-devel, linux-scsi, linux-kernel

>>>>> "Arnd" == Arnd Bergmann <arnd@arndb.de> 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.

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-06-21  2:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-17 15:47 [PATCH] scsi: libfc: fix seconds_since_last_reset calculation Arnd Bergmann
2016-06-17 15:47 ` Arnd Bergmann
2016-06-20 13:54 ` Bart Van Assche
2016-06-20 13:54   ` Bart Van Assche
2016-06-20 14:50   ` Arnd Bergmann
2016-06-20 14:50     ` Arnd Bergmann
2016-06-20 14:58     ` Bart Van Assche
2016-06-20 14:58       ` Bart Van Assche
2016-06-21  2:05 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.