From 599faa1c75b3c429745e0d4a983670c3dd205092 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 31 Mar 2017 01:12:08 -0400 Subject: [PATCH] Event notification: pass CC priority map on creation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit An event notification must have an associated clock class priority map to indicate the ranks of its event's clock values. As of this patch, a ctf.fs source component always set the priority of all the parsed clock classes to 0. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- .../graph/notification-event-internal.h | 2 + include/babeltrace/graph/notification-event.h | 8 +- lib/component/notification/event.c | 85 ++++++++++++++++++- plugins/ctf/common/notif-iter/notif-iter.c | 10 ++- plugins/ctf/common/notif-iter/notif-iter.h | 4 + plugins/ctf/fs/data-stream.c | 3 +- plugins/ctf/fs/fs.c | 43 ++++++++++ plugins/ctf/fs/fs.h | 2 + 8 files changed, 152 insertions(+), 5 deletions(-) diff --git a/include/babeltrace/graph/notification-event-internal.h b/include/babeltrace/graph/notification-event-internal.h index 939b7711..8fffd47e 100644 --- a/include/babeltrace/graph/notification-event-internal.h +++ b/include/babeltrace/graph/notification-event-internal.h @@ -29,6 +29,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -37,6 +38,7 @@ extern "C" { struct bt_notification_event { struct bt_notification parent; struct bt_ctf_event *event; + struct bt_clock_class_priority_map *cc_prio_map; }; #ifdef __cplusplus diff --git a/include/babeltrace/graph/notification-event.h b/include/babeltrace/graph/notification-event.h index e5947b7e..f386abb2 100644 --- a/include/babeltrace/graph/notification-event.h +++ b/include/babeltrace/graph/notification-event.h @@ -33,6 +33,7 @@ extern "C" { struct bt_notification; struct bt_ctf_event; +struct bt_clock_class_priority_map; /***BT_NOTIFICATION_TYPE_EVENT ***/ /** @@ -44,7 +45,8 @@ struct bt_ctf_event; * @see #bt_notification_type */ extern struct bt_notification *bt_notification_event_create( - struct bt_ctf_event *event); + struct bt_ctf_event *event, + struct bt_clock_class_priority_map *clock_class_priority_map); /** * Get an event notification's event. @@ -57,6 +59,10 @@ extern struct bt_notification *bt_notification_event_create( extern struct bt_ctf_event *bt_notification_event_get_event( struct bt_notification *notification); +extern struct bt_clock_class_priority_map * +bt_notification_event_get_clock_class_priority_map( + struct bt_notification *notification); + #ifdef __cplusplus } #endif diff --git a/lib/component/notification/event.c b/lib/component/notification/event.c index faf96352..c3c461a1 100644 --- a/lib/component/notification/event.c +++ b/lib/component/notification/event.c @@ -25,6 +25,11 @@ */ #include +#include +#include +#include +#include +#include #include static @@ -34,14 +39,64 @@ void bt_notification_event_destroy(struct bt_object *obj) (struct bt_notification_event *) obj; BT_PUT(notification->event); + BT_PUT(notification->cc_prio_map); g_free(notification); } -struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event) +static +bool validate_clock_classes(struct bt_notification_event *notif) +{ + /* + * For each clock class found in the event's trace, get the + * event's clock value for this clock class, and if it exists, + * make sure that this clock class has a priority in the + * notification's clock class priority map. + */ + bool is_valid = true; + int ret; + int count; + size_t i; + struct bt_ctf_event_class *event_class = NULL; + struct bt_ctf_stream_class *stream_class = NULL; + struct bt_ctf_trace *trace = NULL; + uint64_t prio; + + event_class = bt_ctf_event_get_class(notif->event); + assert(event_class); + stream_class = bt_ctf_event_class_get_stream_class(event_class); + assert(stream_class); + trace = bt_ctf_stream_class_get_trace(stream_class); + assert(trace); + count = bt_ctf_trace_get_clock_class_count(trace); + assert(count >= 0); + + for (i = 0; i < count; i++) { + struct bt_ctf_clock_class *clock_class = + bt_ctf_trace_get_clock_class(trace, i); + + assert(clock_class); + ret = bt_clock_class_priority_map_get_clock_class_priority( + notif->cc_prio_map, clock_class, &prio); + bt_put(clock_class); + if (ret) { + is_valid = false; + goto end; + } + } + +end: + bt_put(trace); + bt_put(stream_class); + bt_put(event_class); + return is_valid; +} + +struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event, + struct bt_clock_class_priority_map *cc_prio_map) { struct bt_notification_event *notification; - if (!event) { + if (!event || !cc_prio_map) { goto error; } @@ -55,6 +110,13 @@ struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event) BT_NOTIFICATION_TYPE_EVENT, bt_notification_event_destroy); notification->event = bt_get(event); + notification->cc_prio_map = bt_get(cc_prio_map); + + if (!validate_clock_classes(notification)) { + bt_put(notification); + goto error; + } + return ¬ification->parent; error: return NULL; @@ -76,3 +138,22 @@ struct bt_ctf_event *bt_notification_event_get_event( end: return event; } + +extern struct bt_clock_class_priority_map * +bt_notification_event_get_clock_class_priority_map( + struct bt_notification *notification) +{ + struct bt_clock_class_priority_map *cc_prio_map = NULL; + struct bt_notification_event *event_notification; + + if (bt_notification_get_type(notification) != + BT_NOTIFICATION_TYPE_EVENT) { + goto end; + } + + event_notification = container_of(notification, + struct bt_notification_event, parent); + cc_prio_map = bt_get(event_notification->cc_prio_map); +end: + return cc_prio_map; +} diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index d82c9b85..319575df 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -161,6 +162,9 @@ struct bt_ctf_notif_iter { struct bt_ctf_event_class *event_class; } meta; + /* Clock class priority map (owned by this) */ + struct bt_clock_class_priority_map *cc_prio_map; + /* Current packet (NULL if not created yet) */ struct bt_ctf_packet *packet; @@ -2195,7 +2199,7 @@ void notify_event(struct bt_ctf_notif_iter *notit, goto end; } - ret = bt_notification_event_create(event); + ret = bt_notification_event_create(event, notit->cc_prio_map); if (!ret) { goto end; } @@ -2303,6 +2307,7 @@ end: BT_HIDDEN struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace, + struct bt_clock_class_priority_map *cc_prio_map, size_t max_request_sz, struct bt_ctf_notif_iter_medium_ops medops, void *data, FILE *err_stream) @@ -2327,6 +2332,7 @@ struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace, }; assert(trace); + assert(cc_prio_map); assert(medops.request_bytes); assert(medops.get_stream); notit = g_new0(struct bt_ctf_notif_iter, 1); @@ -2345,6 +2351,7 @@ struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace, PERR("Failed to initialize stream clock states\n"); goto error; } + notit->cc_prio_map = bt_get(cc_prio_map); notit->meta.trace = bt_get(trace); notit->medium.medops = medops; notit->medium.max_request_sz = max_request_sz; @@ -2388,6 +2395,7 @@ error: void bt_ctf_notif_iter_destroy(struct bt_ctf_notif_iter *notit) { + BT_PUT(notit->cc_prio_map); BT_PUT(notit->meta.trace); BT_PUT(notit->meta.stream_class); BT_PUT(notit->meta.event_class); diff --git a/plugins/ctf/common/notif-iter/notif-iter.h b/plugins/ctf/common/notif-iter/notif-iter.h index fd56575a..b8b91c5e 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.h +++ b/plugins/ctf/common/notif-iter/notif-iter.h @@ -32,6 +32,7 @@ #include #include #include +#include #include /** @@ -233,6 +234,8 @@ struct bt_ctf_notif_iter_notif_event { * incremented. * * @param trace Trace to read + * @param cc_prio_map Clock class priority map to use when + * creating the event notifications * @param max_request_sz Maximum buffer size, in bytes, to * request to * bt_ctf_notif_iter_medium_ops::request_bytes() @@ -245,6 +248,7 @@ struct bt_ctf_notif_iter_notif_event { */ BT_HIDDEN struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace, + struct bt_clock_class_priority_map *cc_prio_map, size_t max_request_sz, struct bt_ctf_notif_iter_medium_ops medops, void *medops_data, FILE *err_stream); diff --git a/plugins/ctf/fs/data-stream.c b/plugins/ctf/fs/data-stream.c index b4bb087a..70bdf5a8 100644 --- a/plugins/ctf/fs/data-stream.c +++ b/plugins/ctf/fs/data-stream.c @@ -370,7 +370,8 @@ struct ctf_fs_stream *ctf_fs_stream_create( } stream->notif_iter = bt_ctf_notif_iter_create(ctf_fs->metadata->trace, - ctf_fs->page_size, medops, stream, ctf_fs->error_fp); + ctf_fs->cc_prio_map, ctf_fs->page_size, medops, stream, + ctf_fs->error_fp); if (!stream->notif_iter) { goto error; } diff --git a/plugins/ctf/fs/fs.c b/plugins/ctf/fs/fs.c index ea45fbca..ea33974b 100644 --- a/plugins/ctf/fs/fs.c +++ b/plugins/ctf/fs/fs.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -140,6 +141,7 @@ void ctf_fs_destroy_data(struct ctf_fs_component *ctf_fs) g_free(ctf_fs->metadata); } + bt_put(ctf_fs->cc_prio_map); g_free(ctf_fs); } @@ -325,6 +327,42 @@ end: return ret; } +static +int create_cc_prio_map(struct ctf_fs_component *ctf_fs) +{ + int ret = 0; + size_t i; + int count; + + assert(ctf_fs); + ctf_fs->cc_prio_map = bt_clock_class_priority_map_create(); + if (!ctf_fs->cc_prio_map) { + ret = -1; + goto end; + } + + count = bt_ctf_trace_get_clock_class_count(ctf_fs->metadata->trace); + assert(count >= 0); + + for (i = 0; i < count; i++) { + struct bt_ctf_clock_class *clock_class = + bt_ctf_trace_get_clock_class(ctf_fs->metadata->trace, + i); + + assert(clock_class); + ret = bt_clock_class_priority_map_add_clock_class( + ctf_fs->cc_prio_map, clock_class, 0); + BT_PUT(clock_class); + + if (ret) { + goto end; + } + } + +end: + return ret; +} + static struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, struct bt_value *params) @@ -380,6 +418,11 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, goto error; } + ret = create_cc_prio_map(ctf_fs); + if (ret) { + goto error; + } + ret = create_ports(ctf_fs); if (ret) { goto error; diff --git a/plugins/ctf/fs/fs.h b/plugins/ctf/fs/fs.h index 0a34856a..72010298 100644 --- a/plugins/ctf/fs/fs.h +++ b/plugins/ctf/fs/fs.h @@ -30,6 +30,7 @@ #include #include +#include #include "data-stream.h" #define CTF_FS_COMPONENT_DESCRIPTION \ @@ -90,6 +91,7 @@ struct ctf_fs_component { size_t page_size; struct ctf_fs_component_options options; struct ctf_fs_metadata *metadata; + struct bt_clock_class_priority_map *cc_prio_map; /* Array of struct ctf_fs_port_data *, owned by this */ GPtrArray *port_data; -- 2.34.1