[aravis/realtime] gv_stream: WIP for realtime support
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis/realtime] gv_stream: WIP for realtime support
- Date: Tue, 18 Mar 2014 16:06:34 +0000 (UTC)
commit ae14e320a45b94c68870be6da0470bae972427df
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Tue Mar 18 17:05:43 2014 +0100
gv_stream: WIP for realtime support
src/arvmisc.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/arvmisc.h | 2 +
tests/.gitignore | 1 +
tests/Makefile.am | 5 ++-
tests/dbus.c | 68 ++++++++++++++++++++++++++++++++++++++++++++
tests/misc.c | 9 ++++++
6 files changed, 165 insertions(+), 1 deletions(-)
---
diff --git a/src/arvmisc.c b/src/arvmisc.c
index 2e555a7..cd9ee15 100644
--- a/src/arvmisc.c
+++ b/src/arvmisc.c
@@ -26,6 +26,87 @@
#include <math.h>
#include <stdio.h>
#include <zlib.h>
+#include <errno.h>
+#include <gio/gio.h>
+
+#ifdef __linux__
+
+#include <linux/sched.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
+
+gboolean
+arv_make_realtime (void)
+{
+ struct sched_param p;
+
+ memset (&p, 0, sizeof(p));
+ p.sched_priority = 3;
+
+ if (sched_setscheduler (0, SCHED_RR|SCHED_RESET_ON_FORK, &p) < 0 && errno == EPERM) {
+ GDBusProxy *proxy;
+ GVariant *answer;
+ pid_t thread_id;
+ GError *error = NULL;
+ gint32 priority = p.sched_priority;
+
+ thread_id = syscall(SYS_gettid);
+
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.RealtimeKit1",
+ "/org/freedesktop/RealtimeKit1",
+ "org.freedesktop.RealtimeKit1",
+ NULL, &error);
+
+ if (error != NULL) {
+ g_warning ("[::make_realtime] Failed to create dbus proxy (%s)",
+ error->message);
+ g_clear_pointer (&error, g_error_free);
+ }
+
+ answer = g_dbus_proxy_get_cached_property (proxy, "MaxRealtimePriority");
+
+ if (answer == NULL) {
+ g_warning ("[::make_realtime] Failed to get MaxRealtimePriority");
+ } else {
+ g_variant_unref (answer);
+ }
+
+ priority = g_variant_get_int32 (answer);
+
+ answer = g_dbus_proxy_call_sync (proxy,
+ "MakeThreadRealtime",
+ g_variant_new ("(tu)", thread_id, priority),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+ if (error != NULL) {
+ g_warning ("[::make_realtime] Failed to set realtime scheduling using rtkit (%s)",
+ error->message);
+ g_clear_pointer (&error, g_error_free);
+ }
+
+ g_object_unref (proxy);
+
+ if (answer != NULL)
+ g_variant_unref (answer);
+ else
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+#else
+
+gboolean
+arv_make_realtime (void)
+{
+ return FALSE;
+}
+
+#endif
/**
* SECTION: arvstatistic
diff --git a/src/arvmisc.h b/src/arvmisc.h
index 3b944dc..2320cfb 100644
--- a/src/arvmisc.h
+++ b/src/arvmisc.h
@@ -27,6 +27,8 @@
G_BEGIN_DECLS
+gboolean arv_make_realtime (void);
+
typedef struct _ArvStatistic ArvStatistic;
ArvStatistic * arv_statistic_new (guint n_histograms, guint n_bins, guint bin_step,
int offset);
diff --git a/tests/.gitignore b/tests/.gitignore
index cf27c42..8925eeb 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -5,6 +5,7 @@ misc
fake
cpp
arv-test
+dbus
arv-genicam-test
arv-evaluator-test
arv-zip-test
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6fdba2f..02700de 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -32,7 +32,7 @@ arv_example_LDADD = $(test_progs_ldadd)
time_test_SOURCES = timetest.c
time_test_LDADD = $(test_progs_ldadd)
-TEST_PROGS += evaluator buffer misc fake genicam
+TEST_PROGS += evaluator buffer misc fake genicam dbus
if ARAVIS_BUILD_CPP_TEST
TEST_PROGS += cpp
endif
@@ -56,6 +56,9 @@ genicam_SOURCES = genicam.c
genicam_CFLAGS = -DGENICAM_FILENAME="\"$(top_srcdir)/tests/data/genicam.xml\""
genicam_LDADD = $(test_progs_ldadd)
+dbus_SOURCES = dbus.c
+dbus_LDADD = $(test_progs_ldadd)
+
cpp_SOURCES = cpp.cc
cpp_LDADD = $(test_progs_ldadd)
diff --git a/tests/dbus.c b/tests/dbus.c
new file mode 100644
index 0000000..fa45679
--- /dev/null
+++ b/tests/dbus.c
@@ -0,0 +1,68 @@
+#include <gio/gio.h>
+#include <linux/sched.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <memory.h>
+#include <errno.h>
+
+gboolean
+arv_make_realtime (void)
+{
+ GDBusProxy *proxy;
+ GVariant *answer;
+ pid_t thread_id;
+ GError *error = NULL;
+ gint32 priority = 19;
+
+ thread_id = syscall(SYS_gettid);
+
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.RealtimeKit1",
+ "/org/freedesktop/RealtimeKit1",
+ "org.freedesktop.RealtimeKit1",
+ NULL, &error);
+
+ if (error != NULL) {
+ g_warning ("[::make_realtime] Failed to create dbus proxy (%s)",
+ error->message);
+ g_clear_pointer (&error, g_error_free);
+ }
+
+ answer = g_dbus_proxy_get_cached_property (proxy, "MaxRealtimePriority");
+
+ if (answer == NULL) {
+ g_warning ("[::make_realtime] Failed to get MaxRealtimePriority");
+ } else {
+ priority = g_variant_get_int32 (answer);
+ g_variant_unref (answer);
+ }
+
+ g_message ("thread_id = %d", thread_id);
+ g_message ("priority = %d", priority);
+
+ answer = g_dbus_proxy_call_sync (proxy,
+ "MakeThreadRealtime",
+ g_variant_new ("(tu)", thread_id, priority),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+ if (error != NULL) {
+ g_warning ("[::make_realtime] Failed to set realtime scheduling using rtkit (%s)",
+ error->message);
+ g_clear_pointer (&error, g_error_free);
+ }
+
+ g_object_unref (proxy);
+
+ if (answer != NULL)
+ g_variant_unref (answer);
+ else
+ return FALSE;
+}
+
+int
+main (int argc, char **argv)
+{
+ arv_make_realtime ();
+}
diff --git a/tests/misc.c b/tests/misc.c
index b95262b..9d32c5b 100644
--- a/tests/misc.c
+++ b/tests/misc.c
@@ -81,6 +81,14 @@ arv_str_strip_test (void)
g_assert (arv_str_strip (NULL, NULL, REPLACEMENT_CHARACTER) == NULL);
}
+static void
+arv_make_realtime_test (void)
+{
+ arv_make_realtime ();
+
+ sleep (20);
+}
+
int
main (int argc, char *argv[])
{
@@ -93,6 +101,7 @@ main (int argc, char *argv[])
g_test_add_func ("/buffer/unaligned-from-le", unaligned_from_le_ptr_test);
g_test_add_func ("/str/arv-str-strip", arv_str_strip_test);
+ g_test_add_func ("/sys/arv-make-realtime", arv_make_realtime_test);
result = g_test_run();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]