FreeBSD Bugzilla – Attachment 232178 Details for
Bug 262215
Two imprecisions in cputime counters
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
updated patch
cputime-precision-new.patch (text/plain), 1.88 KB, created by
firk
on 2022-03-01 07:41:49 UTC
(
hide
)
Description:
updated patch
Filename:
MIME Type:
Creator:
firk
Created:
2022-03-01 07:41:49 UTC
Size:
1.88 KB
patch
obsolete
>diff -ur 12.3-releng/sys/kern/kern_tc.c 12.3-my/sys/kern/kern_tc.c >--- 12.3-releng/sys/kern/kern_tc.c 2022-02-13 15:26:52.000000000 +0300 >+++ 12.3-my/sys/kern/kern_tc.c 2022-02-27 00:38:49.000000000 +0300 >@@ -2094,20 +2094,14 @@ > * years) and in 64 bits at 4 GHz (146 years), but if we do a multiply > * before divide conversion (to retain precision) we find that the > * margin shrinks to 1.5 hours (one millionth of 146y). >- * With a three prong approach we never lose significant bits, no >- * matter what the cputick rate and length of timeinterval is. > */ > > uint64_t > cputick2usec(uint64_t tick) > { >- >- if (tick > 18446744073709551LL) /* floor(2^64 / 1000) */ >- return (tick / (cpu_tickrate() / 1000000LL)); >- else if (tick > 18446744073709LL) /* floor(2^64 / 1000000) */ >- return ((tick * 1000LL) / (cpu_tickrate() / 1000LL)); >- else >- return ((tick * 1000000LL) / cpu_tickrate()); >+ uint64_t tr; >+ tr = cpu_tickrate(); >+ return ((tick / tr) * 1000000ULL) + ((tick % tr) * 1000000ULL) / tr; > } > > cpu_tick_f *cpu_ticks = tc_cpu_ticks; >diff -ur 12.3-releng/sys/kern/kern_time.c 12.3-my/sys/kern/kern_time.c >--- 12.3-releng/sys/kern/kern_time.c 2022-02-13 15:26:53.000000000 +0300 >+++ 12.3-my/sys/kern/kern_time.c 2022-02-27 00:25:26.000000000 +0300 >@@ -243,9 +243,10 @@ > static inline void > cputick2timespec(uint64_t runtime, struct timespec *ats) > { >- runtime = cputick2usec(runtime); >- ats->tv_sec = runtime / 1000000; >- ats->tv_nsec = runtime % 1000000 * 1000; >+ uint64_t tr; >+ tr = cpu_tickrate(); >+ ats->tv_sec = runtime / tr; >+ ats->tv_nsec = ((runtime % tr) * 1000000000ULL) / tr; > } > > void >@@ -474,10 +475,7 @@ > case CLOCK_THREAD_CPUTIME_ID: > case CLOCK_PROCESS_CPUTIME_ID: > cputime: >- /* sync with cputick2usec */ >- ts->tv_nsec = 1000000 / cpu_tickrate(); >- if (ts->tv_nsec == 0) >- ts->tv_nsec = 1000; >+ ts->tv_nsec = 1000000000 / cpu_tickrate() + 1; > break; > default: > if ((int)clock_id < 0)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 262215
:
232127
| 232178