diff --git a/qdf/inc/qdf_lock.h b/qdf/inc/qdf_lock.h index 0870141b5e..25c57276c5 100644 --- a/qdf/inc/qdf_lock.h +++ b/qdf/inc/qdf_lock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2020 The Linux Foundation. All rights reserved. + * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the @@ -138,8 +138,15 @@ do { \ /* max_hold_time in US */ #define BEFORE_UNLOCK(lock, max_hold_time) \ do {\ - uint64_t held_time = qdf_get_log_timestamp_lightweight() - \ - lock->stats.last_acquired; \ + uint64_t BEFORE_UNLOCK_time; \ + uint64_t held_time; \ + BEFORE_UNLOCK_time = qdf_get_log_timestamp_lightweight(); \ +\ + if (unlikely(BEFORE_UNLOCK_time < lock->stats.last_acquired)) \ + held_time = 0; \ + else \ + held_time = BEFORE_UNLOCK_time - lock->stats.last_acquired; \ +\ lock->stats.held_time += held_time; \ \ if (held_time > lock->stats.max_held_time) \ diff --git a/qdf/inc/qdf_time.h b/qdf/inc/qdf_time.h index a14f9904f3..0365f62290 100644 --- a/qdf/inc/qdf_time.h +++ b/qdf/inc/qdf_time.h @@ -553,7 +553,15 @@ static inline uint64_t qdf_get_log_timestamp_lightweight(void) { uint64_t timestamp_us; - timestamp_us = __qdf_system_ticks_to_msecs(qdf_system_ticks()) * 1000; + /* explicitly change to uint64_t, otherwise it will assign + * uint32_t to timestamp_us, which lose high 32bits. + * on 64bit platform, it will only use low 32bits jiffies in + * jiffies_to_msecs. + * eg: HZ=250, it will overflow every (0xffff ffff<<2==0x3fff ffff) + * ticks. it is 1193 hours. + */ + timestamp_us = + (uint64_t)__qdf_system_ticks_to_msecs(qdf_system_ticks()) * 1000; return timestamp_us; } #endif /* end of MSM_PLATFORM */