Print this page
4764 Need a way to get tsc deltas
Reviewed by: Keith M Wesolowski <wesolows@foobazco.org>
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>
Approved by: Richard Lowe <richlowe@richlowe.net>


 219                 flags = clear_int_flag();
 220                 tsc = tsc_read() + tsc_sync_tick_delta[CPU->cpu_id];
 221                 restore_int_flag(flags);
 222 
 223                 /* See comments in tsc_gethrtime() above */
 224 
 225                 if (tsc >= tsc_last) {
 226                         tsc -= tsc_last;
 227                 } else if (tsc >= tsc_last - 2 * tsc_max_delta) {
 228                         tsc = 0;
 229                 }
 230 
 231                 hrt = tsc_hrtime_base;
 232 
 233                 TSC_CONVERT_AND_ADD(tsc, hrt, nsec_scale);
 234         } while ((old_hres_lock & ~1) != hres_lock);
 235 
 236         return (hrt);
 237 }
 238 













 239 /*
 240  * This is similar to the above, but it cannot actually spin on hres_lock.
 241  * As a result, it caches all of the variables it needs; if the variables
 242  * don't change, it's done.
 243  */
 244 hrtime_t
 245 dtrace_gethrtime(void)
 246 {
 247         uint32_t old_hres_lock;
 248         hrtime_t tsc, hrt;
 249         ulong_t flags;
 250 
 251         do {
 252                 old_hres_lock = hres_lock;
 253 
 254                 /*
 255                  * Interrupts are disabled to ensure that the thread isn't
 256                  * migrated between the tsc_read() and adding the CPU's
 257                  * TSC tick delta.
 258                  */




 219                 flags = clear_int_flag();
 220                 tsc = tsc_read() + tsc_sync_tick_delta[CPU->cpu_id];
 221                 restore_int_flag(flags);
 222 
 223                 /* See comments in tsc_gethrtime() above */
 224 
 225                 if (tsc >= tsc_last) {
 226                         tsc -= tsc_last;
 227                 } else if (tsc >= tsc_last - 2 * tsc_max_delta) {
 228                         tsc = 0;
 229                 }
 230 
 231                 hrt = tsc_hrtime_base;
 232 
 233                 TSC_CONVERT_AND_ADD(tsc, hrt, nsec_scale);
 234         } while ((old_hres_lock & ~1) != hres_lock);
 235 
 236         return (hrt);
 237 }
 238 
 239 hrtime_t
 240 tsc_gethrtime_tick_delta(void)
 241 {
 242         hrtime_t hrt;
 243         ulong_t flags;
 244 
 245         flags = clear_int_flag();
 246         hrt = tsc_sync_tick_delta[CPU->cpu_id];
 247         restore_int_flag(flags);
 248 
 249         return (hrt);
 250 }
 251 
 252 /*
 253  * This is similar to the above, but it cannot actually spin on hres_lock.
 254  * As a result, it caches all of the variables it needs; if the variables
 255  * don't change, it's done.
 256  */
 257 hrtime_t
 258 dtrace_gethrtime(void)
 259 {
 260         uint32_t old_hres_lock;
 261         hrtime_t tsc, hrt;
 262         ulong_t flags;
 263 
 264         do {
 265                 old_hres_lock = hres_lock;
 266 
 267                 /*
 268                  * Interrupts are disabled to ensure that the thread isn't
 269                  * migrated between the tsc_read() and adding the CPU's
 270                  * TSC tick delta.
 271                  */