Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: bfa: use proper time accessor for stats_reset_time

We use the deprecated do_gettimeofday() function to read the current
time when resetting the statistics in both bfa_port and bfa_svc. This
works fine because overflow is handled correctly, but we want to get rid
of do_gettimeofday() and using a non-monotonic time suffers from
concurrent settimeofday calls and other problems.

This uses the ktime_get_seconds() function instead, which does what we
need here.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Anil Gurumurthy <Anil.Gurumurthy@cavium.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Arnd Bergmann and committed by
Martin K. Petersen
8f604a03 7e75f607

+9 -25
+3 -12
drivers/scsi/bfa/bfa_port.c
··· 96 96 port->stats_busy = BFA_FALSE; 97 97 98 98 if (status == BFA_STATUS_OK) { 99 - struct timeval tv; 100 - 101 99 memcpy(port->stats, port->stats_dma.kva, 102 100 sizeof(union bfa_port_stats_u)); 103 101 bfa_port_stats_swap(port, port->stats); 104 102 105 - do_gettimeofday(&tv); 106 - port->stats->fc.secs_reset = tv.tv_sec - port->stats_reset_time; 103 + port->stats->fc.secs_reset = ktime_get_seconds() - port->stats_reset_time; 107 104 } 108 105 109 106 if (port->stats_cbfn) { ··· 121 124 static void 122 125 bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status) 123 126 { 124 - struct timeval tv; 125 - 126 127 port->stats_status = status; 127 128 port->stats_busy = BFA_FALSE; 128 129 129 130 /* 130 131 * re-initialize time stamp for stats reset 131 132 */ 132 - do_gettimeofday(&tv); 133 - port->stats_reset_time = tv.tv_sec; 133 + port->stats_reset_time = ktime_get_seconds(); 134 134 135 135 if (port->stats_cbfn) { 136 136 port->stats_cbfn(port->stats_cbarg, status); ··· 465 471 bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc, 466 472 void *dev, struct bfa_trc_mod_s *trcmod) 467 473 { 468 - struct timeval tv; 469 - 470 474 WARN_ON(!port); 471 475 472 476 port->dev = dev; ··· 486 494 /* 487 495 * initialize time stamp for stats reset 488 496 */ 489 - do_gettimeofday(&tv); 490 - port->stats_reset_time = tv.tv_sec; 497 + port->stats_reset_time = ktime_get_seconds(); 491 498 492 499 bfa_trc(port, 0); 493 500 }
+1 -1
drivers/scsi/bfa/bfa_port.h
··· 36 36 bfa_port_stats_cbfn_t stats_cbfn; 37 37 void *stats_cbarg; 38 38 bfa_status_t stats_status; 39 - u32 stats_reset_time; 39 + time64_t stats_reset_time; 40 40 union bfa_port_stats_u *stats; 41 41 struct bfa_dma_s stats_dma; 42 42 bfa_boolean_t endis_pending;
+4 -11
drivers/scsi/bfa/bfa_svc.c
··· 3047 3047 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); 3048 3048 struct bfa_port_cfg_s *port_cfg = &fcport->cfg; 3049 3049 struct bfa_fcport_ln_s *ln = &fcport->ln; 3050 - struct timeval tv; 3051 3050 3052 3051 fcport->bfa = bfa; 3053 3052 ln->fcport = fcport; ··· 3059 3060 /* 3060 3061 * initialize time stamp for stats reset 3061 3062 */ 3062 - do_gettimeofday(&tv); 3063 - fcport->stats_reset_time = tv.tv_sec; 3063 + fcport->stats_reset_time = ktime_get_seconds(); 3064 3064 fcport->stats_dma_ready = BFA_FALSE; 3065 3065 3066 3066 /* ··· 3293 3295 union bfa_fcport_stats_u *ret; 3294 3296 3295 3297 if (complete) { 3296 - struct timeval tv; 3297 - if (fcport->stats_status == BFA_STATUS_OK) 3298 - do_gettimeofday(&tv); 3298 + time64_t time = ktime_get_seconds(); 3299 3299 3300 3300 list_for_each_safe(qe, qen, &fcport->stats_pending_q) { 3301 3301 bfa_q_deq(&fcport->stats_pending_q, &qe); ··· 3308 3312 bfa_fcport_fcoe_stats_swap(&ret->fcoe, 3309 3313 &fcport->stats->fcoe); 3310 3314 ret->fcoe.secs_reset = 3311 - tv.tv_sec - fcport->stats_reset_time; 3315 + time - fcport->stats_reset_time; 3312 3316 } 3313 3317 } 3314 3318 bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe, ··· 3369 3373 struct list_head *qe, *qen; 3370 3374 3371 3375 if (complete) { 3372 - struct timeval tv; 3373 - 3374 3376 /* 3375 3377 * re-initialize time stamp for stats reset 3376 3378 */ 3377 - do_gettimeofday(&tv); 3378 - fcport->stats_reset_time = tv.tv_sec; 3379 + fcport->stats_reset_time = ktime_get_seconds(); 3379 3380 list_for_each_safe(qe, qen, &fcport->statsclr_pending_q) { 3380 3381 bfa_q_deq(&fcport->statsclr_pending_q, &qe); 3381 3382 cb = (struct bfa_cb_pending_q_s *)qe;
+1 -1
drivers/scsi/bfa/bfa_svc.h
··· 505 505 struct list_head stats_pending_q; 506 506 struct list_head statsclr_pending_q; 507 507 bfa_boolean_t stats_qfull; 508 - u32 stats_reset_time; /* stats reset time stamp */ 508 + time64_t stats_reset_time; /* stats reset time stamp */ 509 509 bfa_boolean_t diag_busy; /* diag busy status */ 510 510 bfa_boolean_t beacon; /* port beacon status */ 511 511 bfa_boolean_t link_e2e_beacon; /* link beacon status */