On Wed, May 23, 2012 at 09:50:13AM -0700, John Stultz wrote:On 05/23/2012 01:29 AM, Richard Cochran wrote:No, I really mean epoch (not the leap second value, but the value whenOkay, if you want it that way, then you will have to add the otherepoch + 1 here, right?
cases. For example:
switch (code) {
case INS:
if (U == epoch) {
U--;
T++;
code = OOP;
}
break;
case OOP:
if (U == epoch) {
the new TAI offset comes into effect).
Sorry about that. Here is a more exact pseudo code:code = WAIT;I'm a little unclear on the above, because it looks like you're
}
break;
case DEL:
if (U == epoch - 1) {
U++;
T--;
code = WAIT;
}
break;
default:
break;
}
return (U, code, T);
This is beginning to look a lot like the code in my patch. However,
your approach is somewhat simpler, because it assumes the tick will
never miss a second overflow.
modifying the state from the reader.
switch (time_state) {
case INS:
if (U == epoch) {
U--;
T++;
result_code = OOP;
}
break;
case OOP:
if (U == epoch) {
result_code = WAIT;
}
break;
case DEL:
if (U == epoch - 1) {
U++;
T--;
result_code = WAIT;
}
break;
default:
break;
}
return (U, result_code, T);
You're quite correct, sorry for the omission there.I still don't think it matters. If we know the when next leap secondAnd what if (U> next_leap + 1)?
is supposed to be, if the time_state is INS, then we can still
handle things without extra state.
if (unlikely(CODE == INS&& U == next_leap))
return (U-1, OOP, T+1);
if (unlikely(CODE == INS&& U == next_leap + 1))
return (U-1, WAIT, T+1);
In that case, you must also return WAIT. Are you going to add a test
for every second beyond 'next_leap'? I don't think so.
So what's wrong with the corrected line above?if (unlikely(CODE == DEL&& U == next_leap - 1))No, I think what you wrote above is not correct.
return (U+1, WAIT, T-1);
So even if we somehow sleep for two seconds over the leap second,
and then an application hits the read critical section before the
timer interrupt comes in the update the state, we can still provide
correct state transition in the reader.
So I've avoided the term epoch just to try not to confuse things with the unix epoch, that's why I've used next_leap, etc.Thus the only additional state you might need over what we alreadyAgain, you will need two things.
have is the next_leap value.
1. the epoch threshold value (not the leap second value)
2. whether the new epoch has been applied yet, or notI believe the internal time_state (along with the next leap second) already provides this.