Add inactivity notification
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 4 Apr 2017 00:13:24 +0000 (20:13 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:40 +0000 (12:57 -0400)
The new inactivity notification indicates that there's no activity to be
expected on the iterator pointing to it until a given time. You specify
the given time with one or more clock values which are associated to
clock classes. Those clock classes must be mapped to a priority in the
notification's clock class priority map.

This notification is similar to the event notification, except that it
does not contain any context or payload. Its purpose is to make the
graph more efficient with live sources which know that a given iterator
won't deliver any nofication which "occur" before a given time. For
example, a muxer can add this notification to its internal heap, just
like it adds event notifications. Most sinks should ignore this
notification.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/Makefile.am
include/babeltrace/graph/notification-inactivity-internal.h [new file with mode: 0644]
include/babeltrace/graph/notification-inactivity.h [new file with mode: 0644]
lib/component/notification/Makefile.am
lib/component/notification/inactivity.c [new file with mode: 0644]

index 5a8aefb872c40ad9007237e0f232138fbc0cee21..ae8d6dcc80fb4f9df73a8ae6bc1bc3bda14854e5 100644 (file)
@@ -49,6 +49,7 @@ babeltracegraphinclude_HEADERS = \
        babeltrace/graph/notification-eot.h \
        babeltrace/graph/notification-event.h \
        babeltrace/graph/notification-heap.h \
+       babeltrace/graph/notification-inactivity.h \
        babeltrace/graph/notification-iterator.h \
        babeltrace/graph/notification.h \
        babeltrace/graph/notification-packet.h \
@@ -116,6 +117,7 @@ noinst_HEADERS = \
        babeltrace/graph/component-source-internal.h \
        babeltrace/graph/notification-eot-internal.h \
        babeltrace/graph/notification-event-internal.h \
+       babeltrace/graph/notification-inactivity-internal.h \
        babeltrace/graph/notification-iterator-internal.h \
        babeltrace/graph/notification-internal.h \
        babeltrace/graph/notification-packet-internal.h \
diff --git a/include/babeltrace/graph/notification-inactivity-internal.h b/include/babeltrace/graph/notification-inactivity-internal.h
new file mode 100644 (file)
index 0000000..f3ae2e4
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef BABELTRACE_COMPONENT_NOTIFICATION_INACTIVITY_INTERNAL_H
+#define BABELTRACE_COMPONENT_NOTIFICATION_INACTIVITY_INTERNAL_H
+
+/*
+ * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <glib.h>
+
+struct bt_clock_class_priority_map;
+
+struct bt_notification_inactivity {
+       struct bt_notification parent;
+       struct bt_clock_class_priority_map *cc_prio_map;
+       GHashTable *clock_values;
+};
+
+#endif /* BABELTRACE_COMPONENT_NOTIFICATION_INACTIVITY_INTERNAL_H */
diff --git a/include/babeltrace/graph/notification-inactivity.h b/include/babeltrace/graph/notification-inactivity.h
new file mode 100644 (file)
index 0000000..e591493
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef BABELTRACE_COMPONENT_NOTIFICATION_INACTIVITY_H
+#define BABELTRACE_COMPONENT_NOTIFICATION_INACTIVITY_H
+
+/*
+ * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bt_notification;
+struct bt_clock_class_priority_map;
+
+extern struct bt_notification *bt_notification_inactivity_create(
+               struct bt_clock_class_priority_map *clock_class_priority_map);
+
+extern struct bt_clock_class_priority_map *
+bt_notification_inactivity_get_clock_class_priority_map(
+               struct bt_notification *notification);
+
+extern struct bt_ctf_clock_value *bt_notification_inactivity_get_clock_value(
+               struct bt_notification *notification,
+               struct bt_ctf_clock_class *clock_class);
+
+extern int bt_notification_inactivity_set_clock_value(
+               struct bt_notification *notification,
+               struct bt_ctf_clock_value *clock_value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_COMPONENT_NOTIFICATION_INACTIVITY_H */
index 9cf173586d72c2bd7c8fff49964f155711820c97..1b08e68448099a34c2972e440a0a38e2226c6630 100644 (file)
@@ -8,4 +8,5 @@ libcomponent_notification_la_SOURCES = \
        packet.c \
        event.c \
        stream.c \
-       heap.c
+       heap.c \
+       inactivity.c
diff --git a/lib/component/notification/inactivity.c b/lib/component/notification/inactivity.c
new file mode 100644 (file)
index 0000000..9f4cae3
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/object-internal.h>
+#include <babeltrace/compiler.h>
+#include <babeltrace/ctf-ir/clock-class.h>
+#include <babeltrace/graph/clock-class-priority-map.h>
+#include <babeltrace/graph/notification-internal.h>
+#include <babeltrace/graph/notification-inactivity-internal.h>
+
+static
+void bt_notification_inactivity_destroy(struct bt_object *obj)
+{
+       struct bt_notification_inactivity *notification =
+                       (struct bt_notification_inactivity *) obj;
+
+       bt_put(notification->cc_prio_map);
+
+       if (notification->clock_values) {
+               g_hash_table_destroy(notification->clock_values);
+       }
+
+       g_free(notification);
+}
+
+struct bt_notification *bt_notification_inactivity_create(
+               struct bt_clock_class_priority_map *cc_prio_map)
+{
+       struct bt_notification_inactivity *notification;
+       struct bt_notification *ret_notif = NULL;
+
+       if (!cc_prio_map) {
+               goto error;
+       }
+
+       notification = g_new0(struct bt_notification_inactivity, 1);
+       if (!notification) {
+               goto error;
+       }
+       bt_notification_init(&notification->parent,
+                       BT_NOTIFICATION_TYPE_INACTIVITY,
+                       bt_notification_inactivity_destroy);
+       ret_notif = &notification->parent;
+       notification->clock_values = g_hash_table_new_full(g_direct_hash,
+                       g_direct_equal, bt_put, bt_put);
+       if (!notification->clock_values) {
+               goto error;
+       }
+
+       notification->cc_prio_map = bt_get(cc_prio_map);
+       goto end;
+
+error:
+       BT_PUT(ret_notif);
+
+end:
+       return ret_notif;
+}
+
+extern struct bt_clock_class_priority_map *
+bt_notification_inactivity_get_clock_class_priority_map(
+               struct bt_notification *notification)
+{
+       struct bt_clock_class_priority_map *cc_prio_map = NULL;
+       struct bt_notification_inactivity *inactivity_notification;
+
+       if (bt_notification_get_type(notification) !=
+                       BT_NOTIFICATION_TYPE_INACTIVITY) {
+               goto end;
+       }
+
+       inactivity_notification = container_of(notification,
+                       struct bt_notification_inactivity, parent);
+       cc_prio_map = bt_get(inactivity_notification->cc_prio_map);
+end:
+       return cc_prio_map;
+}
+
+struct bt_ctf_clock_value *bt_notification_inactivity_get_clock_value(
+               struct bt_notification *notification,
+               struct bt_ctf_clock_class *clock_class)
+{
+       struct bt_ctf_clock_value *clock_value = NULL;
+       struct bt_notification_inactivity *inactivity_notification;
+
+       if (!notification || !clock_class) {
+               goto end;
+       }
+
+       if (bt_notification_get_type(notification) !=
+                       BT_NOTIFICATION_TYPE_INACTIVITY) {
+               goto end;
+       }
+
+       inactivity_notification = container_of(notification,
+                       struct bt_notification_inactivity, parent);
+       clock_value = g_hash_table_lookup(inactivity_notification->clock_values,
+               clock_class);
+       bt_get(clock_value);
+
+end:
+       return clock_value;
+}
+
+int bt_notification_inactivity_set_clock_value(
+               struct bt_notification *notification,
+               struct bt_ctf_clock_value *clock_value)
+{
+       int ret = 0;
+       uint64_t prio;
+       struct bt_ctf_clock_class *clock_class = NULL;
+       struct bt_notification_inactivity *inactivity_notification;
+
+       if (!notification || !clock_value || notification->frozen) {
+               ret = -1;
+               goto end;
+       }
+
+       if (bt_notification_get_type(notification) !=
+                       BT_NOTIFICATION_TYPE_INACTIVITY) {
+               goto end;
+       }
+
+       inactivity_notification = container_of(notification,
+                       struct bt_notification_inactivity, parent);
+       clock_class = bt_ctf_clock_value_get_class(clock_value);
+       ret = bt_clock_class_priority_map_get_clock_class_priority(
+               inactivity_notification->cc_prio_map, clock_class, &prio);
+       if (ret) {
+               /*
+                * Clock value's class is not mapped to a priority
+                * within the scope of this notification.
+                */
+               goto end;
+       }
+
+       g_hash_table_insert(inactivity_notification->clock_values,
+               clock_class, bt_get(clock_value));
+       clock_class = NULL;
+
+end:
+       bt_put(clock_class);
+       return ret;
+}
This page took 0.029154 seconds and 4 git commands to generate.