openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/sys-utils/hwclock.c
static void adjust_drift_factor(const struct hwclock_control* ctl,
                                struct adjtime* adjtime_p,
                                const struct timeval nowtime,
                                const struct timeval hclocktime)
{
    if (!ctl->update)
    {
        if (ctl->verbose)
            printf(_("Not adjusting drift factor because the "
                     "--update-drift option was not used.\n"));
    }
    else if (adjtime_p->last_calib_time == 0)
    {
        if (ctl->verbose)
            printf(_("Not adjusting drift factor because last "
                     "calibration time is zero,\n"
                     "so history is bad and calibration startover "
                     "is necessary.\n"));
    }
    else if ((hclocktime.tv_sec - adjtime_p->last_calib_time) < 4 * 60 * 60)
    {
        if (ctl->verbose)
            printf(_("Not adjusting drift factor because it has "
                     "been less than four hours since the last "
                     "calibration.\n"));
    }
    else
    {
        /*
         * At adjustment time we drift correct the hardware clock
         * according to the contents of the adjtime file and refresh
         * its last adjusted timestamp.
         *
         * At calibration time we set the Hardware Clock and refresh
         * both timestamps in <*adjtime_p>.
         *
         * Here, with the --update-drift option, we also update the
         * drift factor in <*adjtime_p>.
         *
         * Let us do computation in doubles. (Floats almost suffice,
         * but 195 days + 1 second equals 195 days in floats.)
         */
        const double sec_per_day = 24.0 * 60.0 * 60.0;
        double factor_adjust;
        double drift_factor;
        struct timeval last_calib;

        last_calib = t2tv(adjtime_p->last_calib_time);
        /*
         * Correction to apply to the current drift factor.
         *
         * Simplified: uncorrected_drift / days_since_calibration.
         *
         * hclocktime is fully corrected with the current drift factor.
         * Its difference from nowtime is the missed drift correction.
         */
        factor_adjust = time_diff(nowtime, hclocktime) /
                        (time_diff(nowtime, last_calib) / sec_per_day);

        drift_factor = adjtime_p->drift_factor + factor_adjust;
        if (fabs(drift_factor) > MAX_DRIFT)
        {
            if (ctl->verbose)
                printf(_("Clock drift factor was calculated as "
                         "%f seconds/day.\n"
                         "It is far too much. Resetting to zero.\n"),
                       drift_factor);
            drift_factor = 0;
        }
        else
        {
            if (ctl->verbose)
                printf(_("Clock drifted %f seconds in the past "
                         "%f seconds\nin spite of a drift factor of "
                         "%f seconds/day.\n"
                         "Adjusting drift factor by %f seconds/day\n"),
                       time_diff(nowtime, hclocktime),
                       time_diff(nowtime, last_calib), adjtime_p->drift_factor,
                       factor_adjust);
        }

        adjtime_p->drift_factor = drift_factor;
    }
    adjtime_p->last_calib_time = nowtime.tv_sec;

    adjtime_p->last_adj_time = nowtime.tv_sec;

    adjtime_p->not_adjusted = 0;

    adjtime_p->dirty = 1;
}
/*
 * Refresh the last calibrated and last adjusted timestamps in <*adjtime_p>
 * to facilitate future drift calculations based on this set point.
 *
 * With the --update-drift option:
 * Update the drift factor in <*adjtime_p> based on the fact that the
 * Hardware Clock was just calibrated to <nowtime> and before that was
 * set to the <hclocktime> time scale.
 */
Refresh the last calibrated and last adjusted timestamps in <*adjtime_p>
to facilitate future drift calculations based on this set point.

With the --update-drift option:
Update the drift factor in <*adjtime_p> based on the fact that the
Hardware Clock was just calibrated to  and before that was
set to the  time scale.
Refresh the last calibrated and last adjusted timestamps in < * adjtime_p > to facilitate future drift calculations based on this set point . With the -- update - drift option : Update the drift factor in < * adjtime_p > based on the fact that the Hardware Clock was just calibrated to and before that was set to the time scale .
static void adjust_drift_factor(const struct hwclock_control* ctl,
                                struct adjtime* adjtime_p,
                                const struct timeval nowtime,
                                const struct timeval hclocktime)
{
    if (!ctl->update)
    {
        if (ctl->verbose)
            printf(_("Not adjusting drift factor because the "
                     "--update-drift option was not used.\n"));
    }
    else if (adjtime_p->last_calib_time == 0)
    {
        if (ctl->verbose)
            printf(_("Not adjusting drift factor because last "
                     "calibration time is zero,\n"
                     "so history is bad and calibration startover "
                     "is necessary.\n"));
    }
    else if ((hclocktime.tv_sec - adjtime_p->last_calib_time) < 4 * 60 * 60)
    {
        if (ctl->verbose)
            printf(_("Not adjusting drift factor because it has "
                     "been less than four hours since the last "
                     "calibration.\n"));
    }
    else
    {
        const double sec_per_day = 24.0 * 60.0 * 60.0;
        double factor_adjust;
        double drift_factor;
        struct timeval last_calib;
        last_calib = t2tv(adjtime_p->last_calib_time);
        factor_adjust = time_diff(nowtime, hclocktime) /
                        (time_diff(nowtime, last_calib) / sec_per_day);
        drift_factor = adjtime_p->drift_factor + factor_adjust;
        if (fabs(drift_factor) > MAX_DRIFT)
        {
            if (ctl->verbose)
                printf(_("Clock drift factor was calculated as "
                         "%f seconds/day.\n"
                         "It is far too much. Resetting to zero.\n"),
                       drift_factor);
            drift_factor = 0;
        }
        else
        {
            if (ctl->verbose)
                printf(_("Clock drifted %f seconds in the past "
                         "%f seconds\nin spite of a drift factor of "
                         "%f seconds/day.\n"
                         "Adjusting drift factor by %f seconds/day\n"),
                       time_diff(nowtime, hclocktime),
                       time_diff(nowtime, last_calib), adjtime_p->drift_factor,
                       factor_adjust);
        }
        adjtime_p->drift_factor = drift_factor;
    }
    adjtime_p->last_calib_time = nowtime.tv_sec;
    adjtime_p->last_adj_time = nowtime.tv_sec;
    adjtime_p->not_adjusted = 0;
    adjtime_p->dirty = 1;
}
static void adjust_drift_factor ( const struct hwclock_control * ctl , struct adjtime * adjtime_p , const struct timeval nowtime , const struct timeval hclocktime ) { if ( ! ctl -> update ) { if ( ctl -> verbose ) printf ( _ ( " " " \n " ) ) ; } else if ( adjtime_p -> last_calib_time == 0 ) { if ( ctl -> verbose ) printf ( _ ( " " " \n " " " " \n " ) ) ; } else if ( ( hclocktime . tv_sec - adjtime_p -> last_calib_time ) < 4 * 60 * 60 ) { if ( ctl -> verbose ) printf ( _ ( " " " " " \n " ) ) ; } else { const double sec_per_day = 24.0 * 60.0 * 60.0 ; double factor_adjust ; double drift_factor ; struct timeval last_calib ; last_calib = t2tv ( adjtime_p -> last_calib_time ) ; factor_adjust = time_diff ( nowtime , hclocktime ) / ( time_diff ( nowtime , last_calib ) / sec_per_day ) ; drift_factor = adjtime_p -> drift_factor + factor_adjust ; if ( fabs ( drift_factor ) > MAX_DRIFT ) { if ( ctl -> verbose ) printf ( _ ( " " " \n " " \n " ) , drift_factor ) ; drift_factor = 0 ; } else { if ( ctl -> verbose ) printf ( _ ( " " " \n " " \n " " \n " ) , time_diff ( nowtime , hclocktime ) , time_diff ( nowtime , last_calib ) , adjtime_p -> drift_factor , factor_adjust ) ; } adjtime_p -> drift_factor = drift_factor ; } adjtime_p -> last_calib_time = nowtime . tv_sec ; adjtime_p -> last_adj_time = nowtime . tv_sec ; adjtime_p -> not_adjusted = 0 ; adjtime_p -> dirty = 1 ; }
Refresh the last calibrated and last adjusted timestamps in <*adjtime_p>
 to facilitate future drift calculations based on this set point.
Refresh the last calibrated and last adjusted timestamps in < * adjtime_p > to facilitate future drift calculations based on this set point .
/*
         * At adjustment time we drift correct the hardware clock
         * according to the contents of the adjtime file and refresh
         * its last adjusted timestamp.
         *
         * At calibration time we set the Hardware Clock and refresh
         * both timestamps in <*adjtime_p>.
         *
         * Here, with the --update-drift option, we also update the
         * drift factor in <*adjtime_p>.
         *
         * Let us do computation in doubles. (Floats almost suffice,
         * but 195 days + 1 second equals 195 days in floats.)
         */ /*
         * Correction to apply to the current drift factor.
         *
         * Simplified: uncorrected_drift / days_since_calibration.
         *
         * hclocktime is fully corrected with the current drift factor.
         * Its difference from nowtime is the missed drift correction.
         */