Changeset 952b42b6 in rtems


Ignore:
Timestamp:
Mar 14, 2017, 7:06:44 PM (3 years ago)
Author:
Eric van Gyzen <vangyzen@…>
Branches:
master
Children:
5167d0e
Parents:
a9219e7
git-author:
Eric van Gyzen <vangyzen@…> (03/14/17 19:06:44)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/12/17 05:04:11)
Message:

timecounter: Merge FreeBSD change r315280

When the RTC is adjusted, reevaluate absolute sleep times based on the RTC

POSIX 2008 says this about clock_settime(2):

If the value of the CLOCK_REALTIME clock is set via clock_settime(),
the new value of the clock shall be used to determine the time
of expiration for absolute time services based upon the
CLOCK_REALTIME clock. This applies to the time at which armed
absolute timers expire. If the absolute time requested at the
invocation of such a time service is before the new value of
the clock, the time service shall expire immediately as if the
clock had reached the requested time normally.

Setting the value of the CLOCK_REALTIME clock via clock_settime()
shall have no effect on threads that are blocked waiting for
a relative time service based upon this clock, including the
nanosleep() function; nor on the expiration of relative timers
based upon this clock. Consequently, these time services shall
expire when the requested relative interval elapses, independently
of the new or old value of the clock.

When the real-time clock is adjusted, such as by clock_settime(3),
wake any threads sleeping until an absolute real-clock time.
Such a sleep is indicated by a non-zero td_rtcgen. The sleep functions
will set that field to zero and return zero to tell the caller
to reevaluate its sleep duration based on the new value of the clock.

At present, this affects the following functions:

pthread_cond_timedwait(3)
pthread_mutex_timedlock(3)
pthread_rwlock_timedrdlock(3)
pthread_rwlock_timedwrlock(3)
sem_timedwait(3)
sem_clockwait_np(3)

I'm working on adding clock_nanosleep(2), which will also be affected.

Reported by: Sebastian Huber <sebastian.huber@…>
Reviewed by: jhb, kib
MFC after: 2 weeks
Relnotes: yes
Sponsored by: Dell EMC
Differential Revision: https://reviews.freebsd.org/D9791

Update #3175.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/src/kern_tc.c

    ra9219e7 r952b42b6  
    5757#include <sys/lock.h>
    5858#include <sys/mutex.h>
     59#include <sys/proc.h>
    5960#include <sys/sbuf.h>
     61#include <sys/sleepqueue.h>
    6062#include <sys/sysctl.h>
    6163#include <sys/syslog.h>
     
    232234    sysctl_kern_timecounter_adjprecision, "I",
    233235    "Allowed time interval deviation in percents");
     236
     237volatile int rtc_generation = 1;
    234238
    235239static int tc_chosen;   /* Non-zero if a specific tc was chosen via sysctl. */
     
    14111415}
    14121416
     1417static bool
     1418sleeping_on_old_rtc(struct thread *td)
     1419{
     1420
     1421        if (td->td_rtcgen != 0 && td->td_rtcgen != rtc_generation) {
     1422                td->td_rtcgen = 0;
     1423                return (true);
     1424        }
     1425        return (false);
     1426}
     1427
    14131428static struct mtx tc_setclock_mtx;
    14141429MTX_SYSINIT(tc_setclock_init, &tc_setclock_mtx, "tcsetc", MTX_SPIN);
     
    14471462        tc_windup(&bt);
    14481463        mtx_unlock_spin(&tc_setclock_mtx);
     1464        /* Avoid rtc_generation == 0, since td_rtcgen == 0 is special. */
     1465        atomic_add_rel_int(&rtc_generation, 2);
     1466        sleepq_chains_remove_matching(sleeping_on_old_rtc);
    14491467        if (timestepwarnings) {
    14501468                nanotime(&taft);
Note: See TracChangeset for help on using the changeset viewer.