解决ktime部分函数计算时unsigned long溢出 (#9008)

* 解决ktime部分函数计算时unsigned long溢出

* 恢复部分不需要ktime中部分rt_uint64_t类型的为unsigned long
This commit is contained in:
LaterComer 2024-05-30 12:04:33 +08:00 committed by GitHub
parent 2fcf151a8e
commit 2cbe8bdae0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 74 additions and 74 deletions

View File

@ -23,7 +23,7 @@ AlignConsecutiveBitFields:
AlignCompound: true
PadOperators: true
AlignConsecutiveDeclarations:
Enabled: false
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false

View File

@ -18,7 +18,7 @@
#include "rtthread.h"
#define RT_KTIME_RESMUL (1000000UL)
#define RT_KTIME_RESMUL (1000000ULL)
struct rt_ktime_hrtimer
{
@ -62,7 +62,7 @@ rt_err_t rt_ktime_boottime_get_ns(struct timespec *ts);
*
* @return (resolution * RT_KTIME_RESMUL)
*/
unsigned long rt_ktime_cputimer_getres(void);
rt_uint64_t rt_ktime_cputimer_getres(void);
/**
* @brief Get cputimer frequency
@ -96,7 +96,7 @@ void rt_ktime_cputimer_init(void);
*
* @return (resolution * RT_KTIME_RESMUL)
*/
unsigned long rt_ktime_hrtimer_getres(void);
rt_uint64_t rt_ktime_hrtimer_getres(void);
/**
* @brief Get hrtimer frequency

View File

@ -13,9 +13,9 @@
static volatile unsigned long _init_cnt = 0;
unsigned long rt_ktime_cputimer_getres(void)
rt_uint64_t rt_ktime_cputimer_getres(void)
{
return ((1000UL * 1000 * 1000) * RT_KTIME_RESMUL) / rt_hw_get_gtimer_frq();
return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / rt_hw_get_gtimer_frq();
}
unsigned long rt_ktime_cputimer_getfrq(void)

View File

@ -10,16 +10,16 @@
#include "ktime.h"
#define __KTIME_MUL ((1000UL * 1000 * 1000) / RT_TICK_PER_SECOND)
#define __KTIME_MUL ((1000ULL * 1000 * 1000) / RT_TICK_PER_SECOND)
rt_weak rt_err_t rt_ktime_boottime_get_us(struct timeval *tv)
{
RT_ASSERT(tv != RT_NULL);
unsigned long ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL;
rt_uint64_t ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL;
tv->tv_sec = ns / (1000UL * 1000 * 1000);
tv->tv_usec = (ns % (1000UL * 1000 * 1000)) / 1000;
tv->tv_sec = ns / (1000ULL * 1000 * 1000);
tv->tv_usec = (ns % (1000ULL * 1000 * 1000)) / 1000;
return RT_EOK;
}
@ -28,9 +28,9 @@ rt_weak rt_err_t rt_ktime_boottime_get_s(time_t *t)
{
RT_ASSERT(t != RT_NULL);
unsigned long ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL;
rt_uint64_t ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL;
*t = ns / (1000UL * 1000 * 1000);
*t = ns / (1000ULL * 1000 * 1000);
return RT_EOK;
}
@ -39,10 +39,10 @@ rt_weak rt_err_t rt_ktime_boottime_get_ns(struct timespec *ts)
{
RT_ASSERT(ts != RT_NULL);
unsigned long ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL;
rt_uint64_t ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL;
ts->tv_sec = ns / (1000UL * 1000 * 1000);
ts->tv_nsec = ns % (1000UL * 1000 * 1000);
ts->tv_sec = ns / (1000ULL * 1000 * 1000);
ts->tv_nsec = ns % (1000ULL * 1000 * 1000);
return RT_EOK;
}

View File

@ -10,9 +10,9 @@
#include "ktime.h"
rt_weak unsigned long rt_ktime_cputimer_getres(void)
rt_weak rt_uint64_t rt_ktime_cputimer_getres(void)
{
return ((1000UL * 1000 * 1000) * RT_KTIME_RESMUL) / RT_TICK_PER_SECOND;
return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / RT_TICK_PER_SECOND;
}
rt_weak unsigned long rt_ktime_cputimer_getfrq(void)

View File

@ -25,9 +25,9 @@ static rt_list_t _timer_list = RT_LIST_OBJECT_INIT(_timer_list);
static rt_ktime_hrtimer_t _nowtimer = RT_NULL;
static RT_DEFINE_SPINLOCK(_spinlock);
rt_weak unsigned long rt_ktime_hrtimer_getres(void)
rt_weak rt_uint64_t rt_ktime_hrtimer_getres(void)
{
return ((1000UL * 1000 * 1000) * RT_KTIME_RESMUL) / RT_TICK_PER_SECOND;
return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / RT_TICK_PER_SECOND;
}
rt_weak unsigned long rt_ktime_hrtimer_getfrq(void)
@ -379,7 +379,7 @@ rt_err_t rt_ktime_hrtimer_sleep(struct rt_ktime_hrtimer *timer, unsigned long cn
rt_err_t rt_ktime_hrtimer_ndelay(struct rt_ktime_hrtimer *timer, unsigned long ns)
{
unsigned long res = rt_ktime_cputimer_getres();
rt_uint64_t res = rt_ktime_cputimer_getres();
return rt_ktime_hrtimer_sleep(timer, (ns * RT_KTIME_RESMUL) / res);
}

View File

@ -12,9 +12,9 @@
static volatile unsigned long _init_cnt = 0;
unsigned long rt_ktime_cputimer_getres(void)
rt_uint64_t rt_ktime_cputimer_getres(void)
{
return ((1000UL * 1000 * 1000) * RT_KTIME_RESMUL) / CPUTIME_TIMER_FREQ;
return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / CPUTIME_TIMER_FREQ;
}
unsigned long rt_ktime_cputimer_getfrq(void)