From 48c210a79ce8444908458dd80e48fc513ee92e06 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 27 Jan 2022 16:09:14 -0500 Subject: [PATCH] Implement event counters Signed-off-by: Mathieu Desnoyers Change-Id: I9eadee226c78c6b48158a0670b9b50a8b6aab06e --- include/lttng/events-internal.h | 18 ++++--- src/lttng-events.c | 89 +++++++++++++++++++++++++-------- src/lttng-syscalls.c | 17 ++++--- 3 files changed, 90 insertions(+), 34 deletions(-) diff --git a/include/lttng/events-internal.h b/include/lttng/events-internal.h index af7127e9..80d81f3a 100644 --- a/include/lttng/events-internal.h +++ b/include/lttng/events-internal.h @@ -61,6 +61,7 @@ struct lttng_counter_dimension { enum lttng_kernel_event_enabler_type { LTTNG_EVENT_ENABLER_TYPE_RECORDER, LTTNG_EVENT_ENABLER_TYPE_NOTIFIER, + LTTNG_EVENT_ENABLER_TYPE_COUNTER, }; enum channel_type { @@ -201,6 +202,7 @@ struct lttng_kernel_channel_common_private { struct file *file; /* File associated to channel */ unsigned int tstate:1; /* Transient enable state */ + bool coalesce_hits; struct lttng_kernel_syscall_table syscall_table; }; @@ -684,10 +686,12 @@ struct lttng_event_ht *lttng_get_event_ht_from_enabler(struct lttng_event_enable { switch (event_enabler->enabler_type) { case LTTNG_EVENT_ENABLER_TYPE_RECORDER: + lttng_fallthrough; + case LTTNG_EVENT_ENABLER_TYPE_COUNTER: { - struct lttng_event_recorder_enabler *event_recorder_enabler = - container_of(event_enabler, struct lttng_event_recorder_enabler, parent.parent); - return &event_recorder_enabler->chan->parent.session->priv->events_name_ht; + struct lttng_event_enabler_session_common *event_enabler_session = + container_of(event_enabler, struct lttng_event_enabler_session_common, parent); + return &event_enabler_session->chan->session->priv->events_name_ht; } case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: { @@ -705,10 +709,12 @@ struct list_head *lttng_get_event_list_head_from_enabler(struct lttng_event_enab { switch (event_enabler->enabler_type) { case LTTNG_EVENT_ENABLER_TYPE_RECORDER: + lttng_fallthrough; + case LTTNG_EVENT_ENABLER_TYPE_COUNTER: { - struct lttng_event_recorder_enabler *event_recorder_enabler = - container_of(event_enabler, struct lttng_event_recorder_enabler, parent.parent); - return &event_recorder_enabler->chan->parent.session->priv->events_head; + struct lttng_event_enabler_session_common *event_enabler_session = + container_of(event_enabler, struct lttng_event_enabler_session_common, parent); + return &event_enabler_session->chan->session->priv->events_head; } case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: { diff --git a/src/lttng-events.c b/src/lttng-events.c index 9eac5055..50653430 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -895,6 +895,7 @@ bool lttng_kernel_event_id_available(struct lttng_event_enabler_common *event_en return false; } } + //TODO: LTTNG_EVENT_ENABLER_TYPE_COUNTER case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: return true; default: @@ -942,6 +943,7 @@ struct lttng_kernel_event_common *lttng_kernel_event_alloc(struct lttng_event_en event_recorder->priv->parent.id = chan->priv->free_event_id++; return &event_recorder->parent; } + //TODO: LTTNG_EVENT_ENABLER_TYPE_COUNTER case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: { struct lttng_event_notifier_enabler *event_notifier_enabler = @@ -1897,6 +1899,44 @@ bool lttng_desc_match_enabler(const struct lttng_kernel_event_desc *desc, return ret; } +static +bool match_event_session_token(struct lttng_kernel_event_session_common_private *event_session_priv, + uint64_t token) +{ + if (event_session_priv->chan->priv->coalesce_hits) + return true; + if (event_session_priv->parent.user_token == token) + return true; + return false; +} + +static +bool lttng_event_session_enabler_match_event_session(struct lttng_event_enabler_session_common *event_enabler_session, + struct lttng_kernel_event_session_common_private *event_session_priv) +{ + if (lttng_desc_match_enabler(event_session_priv->parent.desc, &event_enabler_session->parent) + && event_session_priv->chan == event_enabler_session->chan + && match_event_session_token(event_session_priv, event_enabler_session->parent.user_token)) + return true; + else + return false; +} + +static +int lttng_event_notifier_enabler_match_event_notifier( + struct lttng_event_notifier_enabler *event_notifier_enabler, + struct lttng_kernel_event_notifier_private *event_notifier_priv) +{ + int desc_matches = lttng_desc_match_enabler(event_notifier_priv->parent.desc, + lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)); + + if (desc_matches && event_notifier_priv->group == event_notifier_enabler->group && + event_notifier_priv->parent.user_token == event_notifier_enabler->parent.user_token) + return 1; + else + return 0; +} + bool lttng_event_enabler_match_event(struct lttng_event_enabler_common *event_enabler, struct lttng_kernel_event_common *event) { @@ -1905,31 +1945,22 @@ bool lttng_event_enabler_match_event(struct lttng_event_enabler_common *event_en switch (event_enabler->enabler_type) { case LTTNG_EVENT_ENABLER_TYPE_RECORDER: + lttng_fallthrough; + case LTTNG_EVENT_ENABLER_TYPE_COUNTER: { - struct lttng_event_recorder_enabler *event_recorder_enabler = - container_of(event_enabler, struct lttng_event_recorder_enabler, parent.parent); - struct lttng_kernel_event_recorder *event_recorder = - container_of(event, struct lttng_kernel_event_recorder, parent); - - if (lttng_desc_match_enabler(event->priv->desc, event_enabler) - && event_recorder->chan == event_recorder_enabler->chan) - return true; - else - return false; + struct lttng_event_enabler_session_common *event_enabler_session = + container_of(event_enabler, struct lttng_event_enabler_session_common, parent); + struct lttng_kernel_event_session_common_private *event_session_priv = + container_of(event->priv, struct lttng_kernel_event_session_common_private, parent); + return lttng_event_session_enabler_match_event_session(event_enabler_session, event_session_priv); } case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: { struct lttng_event_notifier_enabler *event_notifier_enabler = container_of(event_enabler, struct lttng_event_notifier_enabler, parent); - struct lttng_kernel_event_notifier *event_notifier = - container_of(event, struct lttng_kernel_event_notifier, parent); - - if (lttng_desc_match_enabler(event->priv->desc, event_enabler) - && event_notifier->priv->group == event_notifier_enabler->group - && event->priv->user_token == event_enabler->user_token) - return true; - else - return false; + struct lttng_kernel_event_notifier_private *event_notifier_priv = + container_of(event->priv, struct lttng_kernel_event_notifier_private, parent); + return lttng_event_notifier_enabler_match_event_notifier(event_notifier_enabler, event_notifier_priv); } default: WARN_ON_ONCE(1); @@ -1957,6 +1988,7 @@ bool lttng_event_enabler_desc_match_event(struct lttng_event_enabler_common *eve else return false; } + //TODO: LTTNG_EVENT_ENABLER_TYPE_COUNTER case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: { struct lttng_event_notifier_enabler *event_notifier_enabler = @@ -1998,6 +2030,7 @@ bool lttng_event_enabler_event_name_match_event(struct lttng_event_enabler_commo else return false; } + //TODO: LTTNG_EVENT_ENABLER_TYPE_COUNTER case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: { struct lttng_event_notifier_enabler *event_notifier_enabler = @@ -2123,6 +2156,8 @@ void lttng_event_enabler_init_event_capture(struct lttng_event_enabler_common *e { switch (event_enabler->enabler_type) { case LTTNG_EVENT_ENABLER_TYPE_RECORDER: + lttng_fallthrough; + case LTTNG_EVENT_ENABLER_TYPE_COUNTER: break; case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: { @@ -2378,6 +2413,14 @@ void lttng_event_enabler_destroy(struct lttng_event_enabler_common *event_enable kfree(event_notifier_enabler); break; } + case LTTNG_EVENT_ENABLER_TYPE_COUNTER: + { + struct lttng_event_counter_enabler *event_counter_enabler = + container_of(event_enabler, struct lttng_event_counter_enabler, parent.parent); + + kfree(event_counter_enabler); + break; + } default: WARN_ON_ONCE(1); } @@ -2653,10 +2696,12 @@ void lttng_event_enabler_sync(struct lttng_event_enabler_common *event_enabler) { switch (event_enabler->enabler_type) { case LTTNG_EVENT_ENABLER_TYPE_RECORDER: + lttng_fallthrough; + case LTTNG_EVENT_ENABLER_TYPE_COUNTER: { - struct lttng_event_recorder_enabler *event_recorder_enabler = - container_of(event_enabler, struct lttng_event_recorder_enabler, parent.parent); - lttng_session_lazy_sync_event_enablers(event_recorder_enabler->chan->parent.session); + struct lttng_event_enabler_session_common *event_enabler_session = + container_of(event_enabler, struct lttng_event_enabler_session_common, parent); + lttng_session_lazy_sync_event_enablers(event_enabler_session->chan->session); break; } case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: diff --git a/src/lttng-syscalls.c b/src/lttng-syscalls.c index fb7b32e1..7098ee7c 100644 --- a/src/lttng-syscalls.c +++ b/src/lttng-syscalls.c @@ -492,10 +492,12 @@ struct lttng_kernel_syscall_table *get_syscall_table_from_enabler(struct lttng_e { switch (event_enabler->enabler_type) { case LTTNG_EVENT_ENABLER_TYPE_RECORDER: + lttng_fallthrough; + case LTTNG_EVENT_ENABLER_TYPE_COUNTER: { - struct lttng_event_recorder_enabler *event_recorder_enabler = - container_of(event_enabler, struct lttng_event_recorder_enabler, parent.parent); - return &event_recorder_enabler->chan->priv->parent.syscall_table; + struct lttng_event_enabler_session_common *event_enabler_session = + container_of(event_enabler, struct lttng_event_enabler_session_common, parent); + return &event_enabler_session->chan->priv->syscall_table; } case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: { @@ -513,10 +515,13 @@ struct lttng_kernel_syscall_table *get_syscall_table_from_event(struct lttng_ker { switch (event->type) { case LTTNG_KERNEL_EVENT_TYPE_RECORDER: + lttng_fallthrough; + case LTTNG_KERNEL_EVENT_TYPE_COUNTER: { - struct lttng_kernel_event_recorder *event_recorder = - container_of(event, struct lttng_kernel_event_recorder, parent); - return &event_recorder->chan->priv->parent.syscall_table; + struct lttng_kernel_event_common_private *event_priv = event->priv; + struct lttng_kernel_event_session_common_private *event_session_priv = + container_of(event_priv, struct lttng_kernel_event_session_common_private, parent); + return &event_session_priv->chan->priv->syscall_table; } case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER: { -- 2.34.1