On 2018-09-19 00:46, Thomas Gleixner wrote: > On Tue, 18 Sep 2018, Andy Lutomirski wrote: >>> >> >> Do we do better if we use signed arithmetic for the whole calculation? >> Then a small backwards movement would result in a small backwards result. >> Or we could offset everything so that we’d have to go back several >> hundred ms before we cross zero. > > That would be probably the better solution as signed math would be > problematic when the resulting ns value becomes negative. As the delta is > really small, otherwise the TSC sync check would have caught it, the caller > should never be able to observe time going backwards. > > I'll have a look into that. It needs some thought vs. the fractional part > of the base time, but it should be not rocket science to get that > correct. Famous last words... Does the sentinel need to be U64_MAX? What if vgetcyc and its minions returned gtod->cycle_last-1 (for some value of 1), and the caller just does "if ((s64)cycles - (s64)last < 0) return fallback; ns += (cycles-last)* ...". That should just be a "sub ; js ; ". It's an extra load of ->cycle_last, but only on the path where we're heading for the fallback anyway. The value of 1 can be adjusted so that in the "js" path, we could detect and accept an rdtsc_ordered() call that's just a few 10s of cycles behind last and treat that as 0 and continue back on the normal path. But maybe it's hard to get gcc to generate the expected code. Rasmus _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel