Skip to content

Instantly share code, notes, and snippets.

@mwleeds
Created February 27, 2019 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwleeds/be278495bc4aaca494a0bb368ce996ba to your computer and use it in GitHub Desktop.
Save mwleeds/be278495bc4aaca494a0bb368ce996ba to your computer and use it in GitHub Desktop.
/* Test whether the adjtime() system call used by NTP affects the length of
* each CLOCK_BOOTTIME second (rather than just the length of each
* CLOCK_REALTIME second) by printing the value of CLOCK_BOOTTIME once every
* second, using a CLOCK_BOOTTIME timer. You're expected to get NTP to do
* adjustments externally. boottime-source.c and boottime-source.h are from
* https://github.com/endlessm/eos-payg
* Here are the compile commands used:
* gcc -c boottime-source.c `pkg-config --cflags --libs glib-2.0`
* gcc test-boottime-adjtime.c boottime-source.o `pkg-config --cflags --libs glib-2.0 gio-2.0`
**/
#include <gio/gio.h>
#include <glib.h>
#include <glib-object.h>
#include "boottime-source.h"
gint64 prev_prev_time;
gint64 prev_time;
static gboolean
timeout_cb (gpointer data)
{
gint64 time = epg_get_boottime ();
prev_prev_time = prev_time;
prev_time = time;
g_print ("Time = %" G_GINT64_FORMAT " (%" G_GINT64_FORMAT " seconds)\n", time, time / 1000000);
g_print ("Delta = %" G_GINT64_FORMAT "\n", (prev_time - prev_prev_time));
return G_SOURCE_CONTINUE;
}
int main(int argc, char **argv)
{
g_autoptr(GError) error = NULL;
g_autoptr(GSource) s = epg_boottime_source_new (1000, &error);
if (s == NULL)
{
g_warning ("%s", error->message);
return 1;
}
g_source_set_callback (s, timeout_cb, NULL, NULL);
g_source_attach (s, NULL);
while (TRUE)
g_main_context_iteration (NULL, TRUE);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment