How to use sem_timedwait?

Goran Mekić meka at tilda.center
Thu Dec 15 00:29:39 UTC 2016


On Wed, Dec 14, 2016 at 01:56:00PM -0700, Ian Lepore wrote:
> On Wed, 2016-12-14 at 08:42 +0100, Goran Mekić wrote:
> One of the things you did with that code is measured how much time it
> took to format and print the "It should have ended..." line.  If you
> want to capture how long you were asleep you need the clock_gettime()
> to be the next thing you call after sem_timedwait().  Even the time to
> access errno may be non-trivial if it's actually a thread-local
> variable.
>
> If you want to get better sleep-timing performance (at the expense of
> less power-saving efficiency), try setting
>
>   sysctl kern.timecounter.alloweddeviation=0
>
> That will prevent the aggregation of timeouts scheduled near each other
> to all happen at the same time, resulting in more wakeups, each of
> which is more accurate (more wakeups = more power used).
>
> -- Ian
>

This is exactly what I've needed. Thank you so much. If you can tell me any other tip to make the difference even smaller, I'd be grateful. Currently, it goes from 0.1ms to 1ms. Great improvement! Once more, thank you very much!

Regards,
meka
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20161215/0b70523b/attachment.sig>


More information about the freebsd-hackers mailing list