All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/6] scsi: bfa: bfa_svc: Remove 'struct timeval'
@ 2016-01-09 14:29 ` Amitoj Kaur Chawla
  0 siblings, 0 replies; 2+ messages in thread
From: Amitoj Kaur Chawla @ 2016-01-09 14:29 UTC (permalink / raw)
  To: anil.gurumurthy, sudarsana.kalluru, JBottomley, linux-scsi,
	linux-kernel, y2038

32 bit systems using 'struct timeval' will break in the year 2038, so
we modify the code appropriately.

We only need to find the elapsed seconds rather than absolute time,
and we only care about full seconds, so it's better to use monotonic
times, so using ktime_get_seconds() makes the code more efficient
and more robust against a concurrent settimeofday()

Since we need monotonic time only, stats_reset_time variable
does not need to be changed from u32 to u64 type.

After the conversion we get a harmless compiler warning about the
possible use of an uninitialised warning. gcc is wrong here and the
code is actually ok. Introducing a temporary status_ok variable to
store the condition avoids the warning.

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
 drivers/scsi/bfa/bfa_svc.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_svc.c b/drivers/scsi/bfa/bfa_svc.c
index b3668e9..6521896 100644
--- a/drivers/scsi/bfa/bfa_svc.c
+++ b/drivers/scsi/bfa/bfa_svc.c
@@ -3081,7 +3081,6 @@ bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
 	struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
 	struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
 	struct bfa_fcport_ln_s *ln = &fcport->ln;
-	struct timeval tv;
 
 	fcport->bfa = bfa;
 	ln->fcport = fcport;
@@ -3094,8 +3093,7 @@ bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
 	/*
 	 * initialize time stamp for stats reset
 	 */
-	do_gettimeofday(&tv);
-	fcport->stats_reset_time = tv.tv_sec;
+	fcport->stats_reset_time = ktime_get_seconds();
 	fcport->stats_dma_ready = BFA_FALSE;
 
 	/*
@@ -3345,16 +3343,17 @@ __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
 	struct bfa_cb_pending_q_s *cb;
 	struct list_head *qe, *qen;
 	union bfa_fcport_stats_u *ret;
+	bool status_ok = (fcport->stats_status == BFA_STATUS_OK);
 
 	if (complete) {
-		struct timeval tv;
-		if (fcport->stats_status == BFA_STATUS_OK)
-			do_gettimeofday(&tv);
+		time64_t timestamp;
+		if (status_ok)
+			timestamp = ktime_get_seconds();
 
 		list_for_each_safe(qe, qen, &fcport->stats_pending_q) {
 			bfa_q_deq(&fcport->stats_pending_q, &qe);
 			cb = (struct bfa_cb_pending_q_s *)qe;
-			if (fcport->stats_status == BFA_STATUS_OK) {
+			if (status_ok) {
 				ret = (union bfa_fcport_stats_u *)cb->data;
 				/* Swap FC QoS or FCoE stats */
 				if (bfa_ioc_get_fcmode(&fcport->bfa->ioc))
@@ -3364,7 +3363,7 @@ __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
 					bfa_fcport_fcoe_stats_swap(&ret->fcoe,
 							&fcport->stats->fcoe);
 					ret->fcoe.secs_reset =
-					tv.tv_sec - fcport->stats_reset_time;
+					timestamp - fcport->stats_reset_time;
 				}
 			}
 			bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
-- 
1.9.1

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

* [PATCH 2/6] scsi: bfa: bfa_svc: Remove 'struct timeval'
@ 2016-01-09 14:29 ` Amitoj Kaur Chawla
  0 siblings, 0 replies; 2+ messages in thread
From: Amitoj Kaur Chawla @ 2016-01-09 14:29 UTC (permalink / raw)
  To: anil.gurumurthy, sudarsana.kalluru, JBottomley, linux-scsi,
	linux-kernel, y2038

32 bit systems using 'struct timeval' will break in the year 2038, so
we modify the code appropriately.

We only need to find the elapsed seconds rather than absolute time,
and we only care about full seconds, so it's better to use monotonic
times, so using ktime_get_seconds() makes the code more efficient
and more robust against a concurrent settimeofday()

Since we need monotonic time only, stats_reset_time variable
does not need to be changed from u32 to u64 type.

After the conversion we get a harmless compiler warning about the
possible use of an uninitialised warning. gcc is wrong here and the
code is actually ok. Introducing a temporary status_ok variable to
store the condition avoids the warning.

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
 drivers/scsi/bfa/bfa_svc.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_svc.c b/drivers/scsi/bfa/bfa_svc.c
index b3668e9..6521896 100644
--- a/drivers/scsi/bfa/bfa_svc.c
+++ b/drivers/scsi/bfa/bfa_svc.c
@@ -3081,7 +3081,6 @@ bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
 	struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
 	struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
 	struct bfa_fcport_ln_s *ln = &fcport->ln;
-	struct timeval tv;
 
 	fcport->bfa = bfa;
 	ln->fcport = fcport;
@@ -3094,8 +3093,7 @@ bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
 	/*
 	 * initialize time stamp for stats reset
 	 */
-	do_gettimeofday(&tv);
-	fcport->stats_reset_time = tv.tv_sec;
+	fcport->stats_reset_time = ktime_get_seconds();
 	fcport->stats_dma_ready = BFA_FALSE;
 
 	/*
@@ -3345,16 +3343,17 @@ __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
 	struct bfa_cb_pending_q_s *cb;
 	struct list_head *qe, *qen;
 	union bfa_fcport_stats_u *ret;
+	bool status_ok = (fcport->stats_status == BFA_STATUS_OK);
 
 	if (complete) {
-		struct timeval tv;
-		if (fcport->stats_status == BFA_STATUS_OK)
-			do_gettimeofday(&tv);
+		time64_t timestamp;
+		if (status_ok)
+			timestamp = ktime_get_seconds();
 
 		list_for_each_safe(qe, qen, &fcport->stats_pending_q) {
 			bfa_q_deq(&fcport->stats_pending_q, &qe);
 			cb = (struct bfa_cb_pending_q_s *)qe;
-			if (fcport->stats_status == BFA_STATUS_OK) {
+			if (status_ok) {
 				ret = (union bfa_fcport_stats_u *)cb->data;
 				/* Swap FC QoS or FCoE stats */
 				if (bfa_ioc_get_fcmode(&fcport->bfa->ioc))
@@ -3364,7 +3363,7 @@ __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
 					bfa_fcport_fcoe_stats_swap(&ret->fcoe,
 							&fcport->stats->fcoe);
 					ret->fcoe.secs_reset =
-					tv.tv_sec - fcport->stats_reset_time;
+					timestamp - fcport->stats_reset_time;
 				}
 			}
 			bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
-- 
1.9.1

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

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

end of thread, other threads:[~2016-01-09 14:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-09 14:29 [PATCH 2/6] scsi: bfa: bfa_svc: Remove 'struct timeval' Amitoj Kaur Chawla
2016-01-09 14:29 ` Amitoj Kaur Chawla

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.