+
+/* Returns an estimate of this process's CPU usage, as a percentage, over the
+ * past few seconds of wall-clock time. Returns -1 if no estimate is available
+ * (which will happen if the process has not been running long enough to have
+ * an estimate, and can happen for other reasons as well). */
+int
+get_cpu_usage(void)
+{
+ return get_cpu_tracker()->cpu_usage;
+}
+\f
+/* Unixctl interface. */
+
+/* "time/stop" stops the monotonic time returned by e.g. time_msec() from
+ * advancing, except due to later calls to "time/warp". */
+static void
+timeval_stop_cb(struct unixctl_conn *conn,
+ int argc OVS_UNUSED, const char *argv[] OVS_UNUSED,
+ void *aux OVS_UNUSED)
+{
+ ovs_rwlock_wrlock(&monotonic_clock.rwlock);
+ monotonic_clock.stopped = true;
+ xclock_gettime(monotonic_clock.id, &monotonic_clock.cache);
+ ovs_rwlock_unlock(&monotonic_clock.rwlock);
+
+ unixctl_command_reply(conn, NULL);
+}
+
+/* "time/warp MSECS" advances the current monotonic time by the specified
+ * number of milliseconds. Unless "time/stop" has also been executed, the
+ * monotonic clock continues to tick forward at the normal rate afterward.
+ *
+ * Does not affect wall clock readings. */
+static void
+timeval_warp_cb(struct unixctl_conn *conn,
+ int argc OVS_UNUSED, const char *argv[], void *aux OVS_UNUSED)
+{
+ struct timespec ts;
+ int msecs;
+
+ msecs = atoi(argv[1]);
+ if (msecs <= 0) {
+ unixctl_command_reply_error(conn, "invalid MSECS");
+ return;
+ }
+
+ ts.tv_sec = msecs / 1000;
+ ts.tv_nsec = (msecs % 1000) * 1000 * 1000;
+
+ ovs_rwlock_wrlock(&monotonic_clock.rwlock);
+ timespec_add(&monotonic_clock.warp, &monotonic_clock.warp, &ts);
+ ovs_rwlock_unlock(&monotonic_clock.rwlock);
+
+ unixctl_command_reply(conn, "warped");
+}
+
+void
+timeval_dummy_register(void)
+{
+ unixctl_command_register("time/stop", "", 0, 0, timeval_stop_cb, NULL);
+ unixctl_command_register("time/warp", "MSECS", 1, 1,
+ timeval_warp_cb, NULL);
+}