Commit d61ea075 authored by Mike Marciniszyn's avatar Mike Marciniszyn Committed by Doug Ledford

IB/hfi1: Fix a wrapping test to insure the correct timeout

The "2 * UINT_MAX"  statement:
	if ((u64)(ts - cce->timestamp) > 2 * UINT_MAX) {

is equivalent to:
	if ((u64)(ts - cce->timestamp) > UINT_MAX - 1) {

This results in a premature timeout of the cong log entry.

Fix by using unsigned 64 bit integers, removing casts, and using
an algebraic equivalent test to avoid the "2 * UINT_MAX" issue.

Also make use of kernel API to get nanoseconds instead of
open coding.
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: default avatarMike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent 0e31a2e1
...@@ -3760,7 +3760,7 @@ static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am, ...@@ -3760,7 +3760,7 @@ static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am,
struct hfi1_ibport *ibp = to_iport(ibdev, port); struct hfi1_ibport *ibp = to_iport(ibdev, port);
struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
struct opa_hfi1_cong_log *cong_log = (struct opa_hfi1_cong_log *)data; struct opa_hfi1_cong_log *cong_log = (struct opa_hfi1_cong_log *)data;
s64 ts; u64 ts;
int i; int i;
if (am || smp_length_check(sizeof(*cong_log), max_len)) { if (am || smp_length_check(sizeof(*cong_log), max_len)) {
...@@ -3778,7 +3778,7 @@ static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am, ...@@ -3778,7 +3778,7 @@ static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am,
ppd->threshold_cong_event_map, ppd->threshold_cong_event_map,
sizeof(cong_log->threshold_cong_event_map)); sizeof(cong_log->threshold_cong_event_map));
/* keep timestamp in units of 1.024 usec */ /* keep timestamp in units of 1.024 usec */
ts = ktime_to_ns(ktime_get()) / 1024; ts = ktime_get_ns() / 1024;
cong_log->current_time_stamp = cpu_to_be32(ts); cong_log->current_time_stamp = cpu_to_be32(ts);
for (i = 0; i < OPA_CONG_LOG_ELEMS; i++) { for (i = 0; i < OPA_CONG_LOG_ELEMS; i++) {
struct opa_hfi1_cong_log_event_internal *cce = struct opa_hfi1_cong_log_event_internal *cce =
...@@ -3790,7 +3790,7 @@ static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am, ...@@ -3790,7 +3790,7 @@ static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am,
* required to wrap the counter are supposed to * required to wrap the counter are supposed to
* be zeroed (CA10-49 IBTA, release 1.2.1, V1). * be zeroed (CA10-49 IBTA, release 1.2.1, V1).
*/ */
if ((u64)(ts - cce->timestamp) > (2 * UINT_MAX)) if ((ts - cce->timestamp) / 2 > U32_MAX)
continue; continue;
memcpy(cong_log->events[i].local_qp_cn_entry, &cce->lqpn, 3); memcpy(cong_log->events[i].local_qp_cn_entry, &cce->lqpn, 3);
memcpy(cong_log->events[i].remote_qp_number_cn_entry, memcpy(cong_log->events[i].remote_qp_number_cn_entry,
......
...@@ -239,7 +239,7 @@ struct opa_hfi1_cong_log_event_internal { ...@@ -239,7 +239,7 @@ struct opa_hfi1_cong_log_event_internal {
u8 sl; u8 sl;
u8 svc_type; u8 svc_type;
u32 rlid; u32 rlid;
s64 timestamp; /* wider than 32 bits to detect 32 bit rollover */ u64 timestamp; /* wider than 32 bits to detect 32 bit rollover */
}; };
struct opa_hfi1_cong_log_event { struct opa_hfi1_cong_log_event {
......
...@@ -1965,7 +1965,7 @@ static void log_cca_event(struct hfi1_pportdata *ppd, u8 sl, u32 rlid, ...@@ -1965,7 +1965,7 @@ static void log_cca_event(struct hfi1_pportdata *ppd, u8 sl, u32 rlid,
cc_event->svc_type = svc_type; cc_event->svc_type = svc_type;
cc_event->rlid = rlid; cc_event->rlid = rlid;
/* keep timestamp in units of 1.024 usec */ /* keep timestamp in units of 1.024 usec */
cc_event->timestamp = ktime_to_ns(ktime_get()) / 1024; cc_event->timestamp = ktime_get_ns() / 1024;
spin_unlock_irqrestore(&ppd->cc_log_lock, flags); spin_unlock_irqrestore(&ppd->cc_log_lock, flags);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment