From ece3fb0f80ef1c2e105f05f31a8a8f0ffcb593e1 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 3 Apr 2017 20:13:24 -0400 Subject: [PATCH] Add inactivity notification MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jérémie Galarneau --- include/Makefile.am | 2 + .../graph/notification-inactivity-internal.h | 36 ++++ .../graph/notification-inactivity.h | 52 ++++++ lib/component/notification/Makefile.am | 3 +- lib/component/notification/inactivity.c | 163 ++++++++++++++++++ 5 files changed, 255 insertions(+), 1 deletion(-) create mode 100644 include/babeltrace/graph/notification-inactivity-internal.h create mode 100644 include/babeltrace/graph/notification-inactivity.h create mode 100644 lib/component/notification/inactivity.c diff --git a/include/Makefile.am b/include/Makefile.am index 5a8aefb8..ae8d6dcc 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 index 00000000..f3ae2e41 --- /dev/null +++ b/include/babeltrace/graph/notification-inactivity-internal.h @@ -0,0 +1,36 @@ +#ifndef BABELTRACE_COMPONENT_NOTIFICATION_INACTIVITY_INTERNAL_H +#define BABELTRACE_COMPONENT_NOTIFICATION_INACTIVITY_INTERNAL_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 + +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 index 00000000..e5914935 --- /dev/null +++ b/include/babeltrace/graph/notification-inactivity.h @@ -0,0 +1,52 @@ +#ifndef BABELTRACE_COMPONENT_NOTIFICATION_INACTIVITY_H +#define BABELTRACE_COMPONENT_NOTIFICATION_INACTIVITY_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 */ diff --git a/lib/component/notification/Makefile.am b/lib/component/notification/Makefile.am index 9cf17358..1b08e684 100644 --- a/lib/component/notification/Makefile.am +++ b/lib/component/notification/Makefile.am @@ -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 index 00000000..9f4cae3f --- /dev/null +++ b/lib/component/notification/inactivity.c @@ -0,0 +1,163 @@ +/* + * Copyright 2017 Philippe Proulx + * + * 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 +#include +#include +#include +#include +#include + +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(¬ification->parent, + BT_NOTIFICATION_TYPE_INACTIVITY, + bt_notification_inactivity_destroy); + ret_notif = ¬ification->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; +} -- 2.34.1