Setting time with ClockTime

I can not seem to set the time of the monotonic clock using ClockTime,
although the documentation implies you can.

It is necessary for me to set the monotonic clock in a test environment,
to verify that there are not rollover problems (the 64 bit value is being
truncated to 32 bit by a cover function to support some existing software
that expects a 32 bit rolling millisecond timer) in our software.

When I try to set CLOCK_MONOTONIC I get a EINVAL as the return code. I
can set CLOCK_REALTIME without problem. Is there some work around I can
use to allow setting of the monotonic clock ?

Rennie

Rennie Allen wrote:

I can not seem to set the time of the monotonic clock using ClockTime,
although the documentation implies you can.

That would be a mistake in the docs. When ‘id’ is CLOCK_MONOTONIC,
then ‘new’ must be NULL. From higher-level POSIX clock_*() docs,
it says:

“For this clock the value returned by clock_gettime() represents
the amount of time since an unspecified point in the past (eg system
start-up). This point does not change after system start-up time.
The value of the CLOCK_MONOTONIC cannot be set by clock_settime().”

Certainly the kernel code will EINVAL an attempt to do this. And if
you think about the conceptual meaning of CLOCK_MONOTONIC, changing
it does not make sense at all (no longer monotonically increasing).

John Garvey wrote:

Rennie Allen wrote:


Certainly the kernel code will EINVAL an attempt to do this. And if
you think about the conceptual meaning of CLOCK_MONOTONIC, changing
it does not make sense at all (no longer monotonically increasing).

If you think about what I am trying to do, it certainly does make sense.

I agree it makes no sense except for testing.

Rennie

Rennie Allen wrote:

John Garvey wrote:
Rennie Allen wrote:
Certainly the kernel code will EINVAL an attempt to do this. And if
you think about the conceptual meaning of CLOCK_MONOTONIC, changing
it does not make sense at all (no longer monotonically increasing).
If you think about what I am trying to do, it certainly does make sense.
I agree it makes no sense except for testing.

In that case you may be able to adopt the technique dagibbs suggested
elsewhere, map in the syspage rd/wr, and directly hit the “qtp->nsec”
field. Not at all suggesting you do this, of course …

John Garvey wrote:

Rennie Allen wrote:

In that case you may be able to adopt the technique dagibbs suggested
elsewhere, map in the syspage rd/wr, and directly hit the “qtp->nsec”
field. Not at all suggesting you do this, of course …

Yes, I did do this and it worked fine for my purposes, thank you and Will Miles.

Rennie