2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
22 extern uint32_t rdtsc_overhead;
23 extern uint32_t rdtsc_overhead_stats;
25 void clock_init(void);
32 struct time_unit_err {
33 struct time_unit time;
34 struct time_unit error;
37 extern uint64_t thresh;
38 extern uint64_t tsc_hz;
40 static uint64_t val_to_rate(uint64_t val, uint64_t delta_t)
43 return val * tsc_hz / delta_t;
44 } else if (val >> 2 < thresh) {
45 /* bytes per sec malls into this category ... */
46 return ((val >> 2) * tsc_hz) / (delta_t >> 2);
51 return val / (delta_t/tsc_hz);
55 /* The precision of the conversion is nano-second. */
56 uint64_t str_to_tsc(const char *from);
57 uint64_t sec_to_tsc(uint64_t sec);
58 uint64_t msec_to_tsc(uint64_t msec);
59 uint64_t usec_to_tsc(uint64_t usec);
60 uint64_t nsec_to_tsc(uint64_t nsec);
61 uint64_t freq_to_tsc(uint64_t times_per_sec);
62 uint64_t tsc_to_msec(uint64_t tsc);
63 uint64_t tsc_to_usec(uint64_t tsc);
64 uint64_t tsc_to_nsec(uint64_t tsc);
65 uint64_t tsc_to_sec(uint64_t tsc);
66 struct time_unit tsc_to_time_unit(uint64_t tsc);
67 uint64_t time_unit_to_usec(struct time_unit *time_unit);
68 uint64_t time_unit_to_nsec(struct time_unit *time_unit);
69 int time_unit_cmp(struct time_unit *left, struct time_unit *right);
72 void tsc_to_tv(struct timeval *tv, const uint64_t tsc);
73 void tv_to_tsc(const struct timeval *tv, uint64_t *tsc);
74 struct timeval tv_diff(const struct timeval *tv1, const struct timeval * tv2);
76 #endif /* _CLOCK_H_ */