+ if (PREDICT_FALSE (c->round_to_units == 0.0))
+ {
+ f64 next_pow10, est_round_to_units;
+ /*
+ * Compute the first power of ten which is greater than
+ * 0.1% of the new clock rate. Save the result, and use it
+ * to round future results, so we don't end up calculating
+ * silly-looking clock rates.
+ */
+ est_round_to_units = ((f64) dtc / dtr) * 0.001;
+ next_pow10 = ceil (log10 (est_round_to_units));
+ c->round_to_units = pow (10.0, next_pow10);
+ }
+
+ /*
+ * Reject large frequency changes, another consequence of
+ * system clock changes particularly with old kernels.
+ */
+ new_clocks_per_second =
+ flt_round_nearest ((f64) dtc / (dtr * c->round_to_units))
+ * c->round_to_units;
+
+ /* Compute abs(rate change) */
+ delta = new_clocks_per_second - c->clocks_per_second;
+ if (delta < 0.0)
+ delta = -delta;
+
+ /* If rate change > 1%, reject it and try again */
+ if (PREDICT_FALSE ((delta / c->clocks_per_second) > .01))
+ {
+ clib_warning ("Rejecting large frequency change of %.2f%%",
+ (delta / c->clocks_per_second) * 100.0);
+ c->log2_clocks_per_frequency_verify = c->log2_clocks_per_second;
+ return;
+ }
+
+ /* Save total cpu time in seconds */
+ save_total_cpu_time_in_seconds = c->total_cpu_time * c->seconds_per_clock;
+
+ /* Recalculate clock rate */
+ c->clocks_per_second = new_clocks_per_second;