Page MenuHomeFreeBSD

D34558.diff
No OneTemporary

D34558.diff

diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c
--- a/lib/libkvm/kvm_proc.c
+++ b/lib/libkvm/kvm_proc.c
@@ -94,15 +94,10 @@
static uint64_t
cputick2usec(uint64_t tick)
{
-
if (cpu_tick_frequency == 0)
return (0);
- if (tick > 18446744073709551) /* floor(2^64 / 1000) */
- return (tick / (cpu_tick_frequency / 1000000));
- else if (tick > 18446744073709) /* floor(2^64 / 1000000) */
- return ((tick * 1000) / (cpu_tick_frequency / 1000));
- else
- return ((tick * 1000000) / cpu_tick_frequency);
+ return ((tick / cpu_tick_frequency) * 1000000ULL) +
+ ((tick % cpu_tick_frequency) * 1000000ULL) / cpu_tick_frequency;
}
/*
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
--- a/sys/kern/kern_tc.c
+++ b/sys/kern/kern_tc.c
@@ -2155,20 +2155,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 --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -245,9 +245,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
@@ -477,10 +478,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)

File Metadata

Mime Type
text/plain
Expires
Thu, May 1, 9:49 AM (17 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17878859
Default Alt Text
D34558.diff (2 KB)

Event Timeline