apps: drop redundant 64-bit casts on tv_sec/tv_nsec arithmetic#3476
Open
xiaoxiang781216 wants to merge 1 commit into
Open
apps: drop redundant 64-bit casts on tv_sec/tv_nsec arithmetic#3476xiaoxiang781216 wants to merge 1 commit into
xiaoxiang781216 wants to merge 1 commit into
Conversation
Now that time_t is unconditionally 64-bit (signed int64_t) and the
struct timespec fields tv_sec / tv_nsec are wide enough on their own,
the explicit (uint64_t)/(int64_t)/(int) casts that used to guard the
multiplications and subtractions in *_us / *_ms / *_ns helpers are no
longer needed. Drop them to keep the timekeeping math readable and
consistent with the previous sclock_t/time_t cleanup.
Files touched:
- benchmarks/cyclictest/cyclictest.c: timediff_us()
- benchmarks/sd_bench/sd_bench_main.c: get_time_delta_us()
- examples/oneshot/oneshot_main.c: maxus computation
- examples/watchdog/watchdog_main.c: current_time_ms (x2)
- industry/nxmodbus/nxmb_internal.h: nxmb_util_clock_ms()
- netutils/ntpclient/ntpclient.c: timespec2ntp()
- netutils/ptpd/ptpd.c: ptp_adjtime()
- system/dd/dd_main.c: elapsed accounting
- testing/drivers/drivertest/drivertest_posix_timer.c:
get_timestamp()
- testing/drivers/sd_stress/sd_stress_main.c:get_time_delta()
- testing/sched/getprime/getprime_main.c: elapsed accounting
- testing/sched/pthread_mutex_perf/pthread_mutex_perf.c:
timespec_avg()
No behavioural change.
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Contributor
|
Thank you @xiaoxiang781216 :-) CI failed, restarted :-) There is small typo to fix in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up cleanup to the recent
time_t/clock_t64-bit consolidation(commits "drop CONFIG_SYSTEM_TIME64 conditionals" and
"replace sclock_t with clock_t and drop redundant time_t/off_t casts").
NuttX's
time_tis now unconditionally a signed 64-bit type, so theexplicit
(uint64_t),(int64_t), and(int)casts that used to besprinkled around
tv_sec/tv_nsecarithmetic — to avoid 32-bitmultiplication/subtraction overflow back when
time_tcould be 32-bit —are no longer needed. This PR drops those now-redundant casts to keep
the timekeeping helpers readable and consistent with the rest of the
recently-cleaned-up code.
Files touched (one-liners each):
benchmarks/cyclictest/cyclictest.c—timediff_us()benchmarks/sd_bench/sd_bench_main.c—get_time_delta_us()examples/oneshot/oneshot_main.c—maxuscomputationexamples/watchdog/watchdog_main.c—current_time_ms(×2)industry/nxmodbus/nxmb_internal.h—nxmb_util_clock_ms()netutils/ntpclient/ntpclient.c—timespec2ntp()netutils/ptpd/ptpd.c—ptp_adjtime()system/dd/dd_main.c—elapsedaccountingtesting/drivers/drivertest/drivertest_posix_timer.c—get_timestamp()testing/drivers/sd_stress/sd_stress_main.c—get_time_delta()testing/sched/getprime/getprime_main.c—elapsedaccountingtesting/sched/pthread_mutex_perf/pthread_mutex_perf.c—timespec_avg()Impact
compiler (the dropped casts were already no-ops once
time_tbecame 64-bit).
time_t/tv_sec/tv_nsecwidths areunchanged; this PR only removes pleonastic casts.
No behavioural change is intended.
Testing
Build-tested host-side together with the corresponding
nuttx-sidetime_t/clock_tcleanups; the touched helpers all expand to thesame arithmetic as before because the dropped casts no longer
widen anything.
sim:nsh(coversexamples/watchdog,examples/oneshot,system/dd,testing/sched/*,benchmarks/cyclictest,benchmarks/sd_bench,testing/drivers/*)sim:netnsh(coversnetutils/ntpclient,netutils/ptpd,industry/nxmodbus)No new compiler warnings; no functional difference observed in the
benchmark / test outputs before and after the change.