linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] scsi: ips.c: Use jiffies comparison instead of do_gettimeofday()
@ 2014-10-20 17:06 Ebru Akagunduz
  2014-10-20 17:39 ` James Bottomley
  2014-10-20 17:43 ` [OPW kernel] " Arnd Bergmann
  0 siblings, 2 replies; 3+ messages in thread
From: Ebru Akagunduz @ 2014-10-20 17:06 UTC (permalink / raw)
  To: arnd; +Cc: JBottomley, linux-scsi, linux-kernel, opw-kernel, Ebru Akagunduz

do_gettimeofday() only can get 32-bit time types
but the driver should be able to use dates that are
after January 2038.

Remove do_gettimeofday() and use
jiffies comparison to supply 64-bit time types.

Signed-off-by: Ebru Akagunduz <ebru.akagunduz@gmail.com>
---
 drivers/scsi/ips.c | 25 +++++++++++++------------
 drivers/scsi/ips.h |  2 +-
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index e5afc38..6d27024 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -162,6 +162,7 @@
  */
 
 #include <asm/io.h>
+#include <linux/jiffies.h>
 #include <asm/byteorder.h>
 #include <asm/page.h>
 #include <linux/stddef.h>
@@ -297,7 +298,7 @@ static void ips_freescb(ips_ha_t *, ips_scb_t *);
 static void ips_setup_funclist(ips_ha_t *);
 static void ips_statinit(ips_ha_t *);
 static void ips_statinit_memio(ips_ha_t *);
-static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, time_t);
+static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, unsigned long);
 static void ips_ffdc_reset(ips_ha_t *, int);
 static void ips_ffdc_time(ips_ha_t *);
 static uint32_t ips_statupd_copperhead(ips_ha_t *);
@@ -993,10 +994,10 @@ static int __ips_eh_reset(struct scsi_cmnd *SC)
 
 	/* FFDC */
 	if (le32_to_cpu(ha->subsys->param[3]) & 0x300000) {
-		struct timeval tv;
+		unsigned long now;
 
-		do_gettimeofday(&tv);
-		ha->last_ffdc = tv.tv_sec;
+		now = jiffies;
+		ha->last_ffdc = jiffies;
 		ha->reset_count++;
 		ips_ffdc_reset(ha, IPS_INTR_IORL);
 	}
@@ -2404,7 +2405,7 @@ static int
 ips_hainit(ips_ha_t * ha)
 {
 	int i;
-	struct timeval tv;
+	unsigned long now;
 
 	METHOD_TRACE("ips_hainit", 1);
 
@@ -2419,8 +2420,8 @@ ips_hainit(ips_ha_t * ha)
 
 	/* Send FFDC */
 	ha->reset_count = 1;
-	do_gettimeofday(&tv);
-	ha->last_ffdc = tv.tv_sec;
+	now = jiffies;
+	ha->last_ffdc = jiffies;
 	ips_ffdc_reset(ha, IPS_INTR_IORL);
 
 	if (!ips_read_config(ha, IPS_INTR_IORL)) {
@@ -2560,12 +2561,12 @@ ips_next(ips_ha_t * ha, int intr)
 
 	if ((ha->subsys->param[3] & 0x300000)
 	    && (ha->scb_activelist.count == 0)) {
-		struct timeval tv;
+		unsigned long now;
 
-		do_gettimeofday(&tv);
+		now = jiffies;
 
-		if (tv.tv_sec - ha->last_ffdc > IPS_SECS_8HOURS) {
-			ha->last_ffdc = tv.tv_sec;
+		if (time_after(now, ha->last_ffdc + IPS_SECS_8HOURS * HZ)) {
+			ha->last_ffdc = now;
 			ips_ffdc_time(ha);
 		}
 	}
@@ -6000,7 +6001,7 @@ ips_ffdc_time(ips_ha_t * ha)
 /*                                                                          */
 /****************************************************************************/
 static void
-ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time_t current_time)
+ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, unsigned long current_time)
 {
 	long days;
 	long rem;
diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
index 45b9566..250beea 100644
--- a/drivers/scsi/ips.h
+++ b/drivers/scsi/ips.h
@@ -1054,7 +1054,7 @@ typedef struct ips_ha {
    uint8_t            active;
    int                ioctl_reset;        /* IOCTL Requested Reset Flag */
    uint16_t           reset_count;        /* number of resets           */
-   time_t             last_ffdc;          /* last time we sent ffdc info*/
+   unsigned long      last_ffdc;          /* last time we sent ffdc info*/
    uint8_t            slot_num;           /* PCI Slot Number            */
    int                ioctl_len;          /* size of ioctl buffer       */
    dma_addr_t         ioctl_busaddr;      /* dma address of ioctl buffer*/
-- 
1.9.1


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

* Re: [PATCH v2] scsi: ips.c: Use jiffies comparison instead of do_gettimeofday()
  2014-10-20 17:06 [PATCH v2] scsi: ips.c: Use jiffies comparison instead of do_gettimeofday() Ebru Akagunduz
@ 2014-10-20 17:39 ` James Bottomley
  2014-10-20 17:43 ` [OPW kernel] " Arnd Bergmann
  1 sibling, 0 replies; 3+ messages in thread
From: James Bottomley @ 2014-10-20 17:39 UTC (permalink / raw)
  To: Ebru Akagunduz; +Cc: arnd, linux-scsi, linux-kernel, opw-kernel

On Mon, 2014-10-20 at 20:06 +0300, Ebru Akagunduz wrote:
> do_gettimeofday() only can get 32-bit time types
> but the driver should be able to use dates that are
> after January 2038.
> 
> Remove do_gettimeofday() and use
> jiffies comparison to supply 64-bit time types.
> 
> Signed-off-by: Ebru Akagunduz <ebru.akagunduz@gmail.com>
> ---
>  drivers/scsi/ips.c | 25 +++++++++++++------------
>  drivers/scsi/ips.h |  2 +-
>  2 files changed, 14 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
> index e5afc38..6d27024 100644
> --- a/drivers/scsi/ips.c
> +++ b/drivers/scsi/ips.c
> @@ -162,6 +162,7 @@
>   */
>  
>  #include <asm/io.h>
> +#include <linux/jiffies.h>
>  #include <asm/byteorder.h>
>  #include <asm/page.h>
>  #include <linux/stddef.h>
> @@ -297,7 +298,7 @@ static void ips_freescb(ips_ha_t *, ips_scb_t *);
>  static void ips_setup_funclist(ips_ha_t *);
>  static void ips_statinit(ips_ha_t *);
>  static void ips_statinit_memio(ips_ha_t *);
> -static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, time_t);
> +static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, unsigned long);
>  static void ips_ffdc_reset(ips_ha_t *, int);
>  static void ips_ffdc_time(ips_ha_t *);
>  static uint32_t ips_statupd_copperhead(ips_ha_t *);
> @@ -993,10 +994,10 @@ static int __ips_eh_reset(struct scsi_cmnd *SC)
>  
>  	/* FFDC */
>  	if (le32_to_cpu(ha->subsys->param[3]) & 0x300000) {
> -		struct timeval tv;
> +		unsigned long now;
>  
> -		do_gettimeofday(&tv);
> -		ha->last_ffdc = tv.tv_sec;
> +		now = jiffies;
> +		ha->last_ffdc = jiffies;
>  		ha->reset_count++;
>  		ips_ffdc_reset(ha, IPS_INTR_IORL);
>  	}
> @@ -2404,7 +2405,7 @@ static int
>  ips_hainit(ips_ha_t * ha)
>  {
>  	int i;
> -	struct timeval tv;
> +	unsigned long now;
>  
>  	METHOD_TRACE("ips_hainit", 1);
>  
> @@ -2419,8 +2420,8 @@ ips_hainit(ips_ha_t * ha)
>  
>  	/* Send FFDC */
>  	ha->reset_count = 1;
> -	do_gettimeofday(&tv);
> -	ha->last_ffdc = tv.tv_sec;
> +	now = jiffies;
> +	ha->last_ffdc = jiffies;
>  	ips_ffdc_reset(ha, IPS_INTR_IORL);
>  
>  	if (!ips_read_config(ha, IPS_INTR_IORL)) {
> @@ -2560,12 +2561,12 @@ ips_next(ips_ha_t * ha, int intr)
>  
>  	if ((ha->subsys->param[3] & 0x300000)
>  	    && (ha->scb_activelist.count == 0)) {
> -		struct timeval tv;
> +		unsigned long now;
>  
> -		do_gettimeofday(&tv);
> +		now = jiffies;
>  
> -		if (tv.tv_sec - ha->last_ffdc > IPS_SECS_8HOURS) {
> -			ha->last_ffdc = tv.tv_sec;
> +		if (time_after(now, ha->last_ffdc + IPS_SECS_8HOURS * HZ)) {
> +			ha->last_ffdc = now;
>  			ips_ffdc_time(ha);
>  		}
>  	}
> @@ -6000,7 +6001,7 @@ ips_ffdc_time(ips_ha_t * ha)
>  /*                                                                          */
>  /****************************************************************************/
>  static void
> -ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time_t current_time)
> +ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, unsigned long current_time)
>  {
>  	long days;
>  	long rem;
> diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
> index 45b9566..250beea 100644
> --- a/drivers/scsi/ips.h
> +++ b/drivers/scsi/ips.h
> @@ -1054,7 +1054,7 @@ typedef struct ips_ha {
>     uint8_t            active;
>     int                ioctl_reset;        /* IOCTL Requested Reset Flag */
>     uint16_t           reset_count;        /* number of resets           */
> -   time_t             last_ffdc;          /* last time we sent ffdc info*/
> +   unsigned long      last_ffdc;          /* last time we sent ffdc info*/
>     uint8_t            slot_num;           /* PCI Slot Number            */
>     int                ioctl_len;          /* size of ioctl buffer       */
>     dma_addr_t         ioctl_busaddr;      /* dma address of ioctl buffer*/

Great, looks exactly correct as far as it goes, but without the second
part (converting  ips_fix_ffdc_time() to use 64 bit time) it won't
actually work.  The problem is jiffies is a relative time measurement
and the RAID engine needs its real time clock setting periodically, so
there's no need to pass current_time (which is no longer current_time)
into ips_fix_ffdc_time(); just have that routine get the 64 bit time and
convert it to the format the card wants.

James



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

* Re: [OPW kernel] [PATCH v2] scsi: ips.c: Use jiffies comparison instead of do_gettimeofday()
  2014-10-20 17:06 [PATCH v2] scsi: ips.c: Use jiffies comparison instead of do_gettimeofday() Ebru Akagunduz
  2014-10-20 17:39 ` James Bottomley
@ 2014-10-20 17:43 ` Arnd Bergmann
  1 sibling, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2014-10-20 17:43 UTC (permalink / raw)
  To: opw-kernel; +Cc: Ebru Akagunduz, JBottomley, linux-scsi, linux-kernel

On Monday 20 October 2014 20:06:01 Ebru Akagunduz wrote:
> do_gettimeofday() only can get 32-bit time types
> but the driver should be able to use dates that are
> after January 2038.
> 
> Remove do_gettimeofday() and use
> jiffies comparison to supply 64-bit time types.

The description doesn't seem to match what you are doing:

- the use of 'struct timeval' in this driver is not actually unsafe
- using jiffies does not make it use a 64-bit time type.
- you do not mention that using jiffies makes the driver more
  efficient, which is what James was interested in
- The ips_fix_ffdc_time that needs to be changed for 64-bit time
  does not get changed in this patch. As discussed on IRC, that
  should be a separate patch.

> @@ -6000,7 +6001,7 @@ ips_ffdc_time(ips_ha_t * ha)
>  /*                                                                          */
>  /****************************************************************************/
>  static void
> -ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time_t current_time)
> +ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, unsigned long current_time)
>  {
>  	long days;
>  	long rem;

Using 'unsigned long' for a jiffies value also breaks the function, which
makes calculations based on the assumption that you are dealing with a
time_t. I think the best fix here is to use rtc_ktime_to_tm(ktime_get())
to get a 'struct rtc_time' describing the current time, and then removing
most of the code.

You will have to change Kconfig to 'select RTC_LIB' from the ips driver
in order to do this.

	Arnd

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

end of thread, other threads:[~2014-10-20 17:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-20 17:06 [PATCH v2] scsi: ips.c: Use jiffies comparison instead of do_gettimeofday() Ebru Akagunduz
2014-10-20 17:39 ` James Bottomley
2014-10-20 17:43 ` [OPW kernel] " Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).