CUSTOM: liver timer: immediate liver timer control on data pending and destroy
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.c
index 54c22df766f2badb44a9a1e4ae66dab17984c2c4..b27af473f2e1892e99aed613141b19ddc12cefef 100644 (file)
@@ -33,6 +33,7 @@
 #include <common/common.h>
 #include <common/sessiond-comm/sessiond-comm.h>
 
+#include "consumer.h"
 #include "buffer-registry.h"
 #include "fd-limit.h"
 #include "health-sessiond.h"
@@ -502,6 +503,7 @@ void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan,
                lttng_fd_put(LTTNG_FD_APPS, 1);
                free(ua_chan->obj);
        }
+
        call_rcu(&ua_chan->rcu_head, delete_ust_app_channel_rcu);
 }
 
@@ -4084,7 +4086,9 @@ int ust_app_create_channel_glb(struct ltt_ust_session *usess,
                         */
                        continue;
                }
-               if (!trace_ust_pid_tracker_lookup(usess, app->pid)) {
+               if (!(trace_ust_id_tracker_lookup(LTTNG_TRACKER_VPID, usess, app->pid)
+                               && trace_ust_id_tracker_lookup(LTTNG_TRACKER_VUID, usess, app->uid)
+                               && trace_ust_id_tracker_lookup(LTTNG_TRACKER_VGID, usess, app->gid))) {
                        /* Skip. */
                        continue;
                }
@@ -4910,6 +4914,222 @@ int ust_app_stop_trace_all(struct ltt_ust_session *usess)
        return 0;
 }
 
+/*
+ * Force stop live timers associated with the ust session.
+ */
+int ust_force_stop_live_timer(struct ltt_ust_session *usess)
+{
+       int ret = 0;
+
+       if (usess->live_timer_interval == 0) {
+               goto skip;
+       }
+
+       DBG("Stop all live timer associated with UST session %p.", usess);
+
+       rcu_read_lock();
+
+       switch (usess->buffer_type) {
+       case LTTNG_BUFFER_PER_UID:
+       {
+               struct buffer_reg_uid *reg;
+               struct lttng_ht_iter iter;
+
+               cds_list_for_each_entry(reg, &usess->buffer_reg_uid_list, lnode) {
+                       struct ust_registry_session *ust_session_reg;
+                       struct buffer_reg_channel *reg_chan;
+                       struct consumer_socket *socket;
+
+                       /* Get consumer socket to use */
+                       socket = consumer_find_socket_by_bitness(reg->bits_per_long,
+                                       usess->consumer);
+                       if (!socket) {
+                               /* Ignore request if no consumer is found for the session. */
+                               continue;
+                       }
+
+                       cds_lfht_for_each_entry(reg->registry->channels->ht, &iter.iter,
+                                       reg_chan, node.node) {
+                               ret = consumer_channel_stop_live_timer(socket, reg_chan->consumer_key);
+                               if (ret) {
+                                       ERR("Error stopping live timer for channel %" PRIu64, reg_chan->consumer_key);
+                               }
+                       }
+               }
+               break;
+       }
+       case LTTNG_BUFFER_PER_PID:
+       {
+               struct lttng_ht_iter iter_i;
+               struct ust_app *app;
+               uint64_t chan_reg_key;
+
+               cds_lfht_for_each_entry(ust_app_ht->ht, &iter_i.iter, app,
+                                       pid_n.node) {
+                       int ret;
+                       struct ust_app_session *ua_sess;
+                       struct lttng_ht_iter iter_j, iter_k;
+                       struct lttng_ht_node_u64 *node;
+                       struct ust_app_channel *ua_chan;
+
+                       DBG("Stopping live timer associated with ust app pid "
+                           "%d",
+                           app->pid);
+
+                       if (!app->compatible) {
+                               goto end;
+                       }
+
+                       __lookup_session_by_app(usess, app, &iter_j);
+                       node = lttng_ht_iter_get_node_u64(&iter_j);
+                       if (node == NULL) {
+                               /* Session is being or is deleted. */
+                               goto end;
+                       }
+                       ua_sess = caa_container_of(node, struct ust_app_session,
+                                                  node);
+
+                       health_code_update();
+
+                       cds_lfht_for_each_entry(ua_sess->channels->ht,
+                                               &iter_k.iter, ua_chan,
+                                               node.node) {
+                               struct consumer_socket *consumer_socket;
+
+                               /* Stop live timer immediately if any */
+                               consumer_socket =
+                                   consumer_find_socket_by_bitness(
+                                       app->bits_per_long,
+                                       ua_chan->session->consumer);
+                               ret = consumer_channel_stop_live_timer(
+                                   consumer_socket, ua_chan->key);
+                               if (ret) {
+                                       ERR("Error stopping live timer");
+                               }
+                       }
+                       break;
+               }
+               break;
+       }
+       default:
+               break;
+       }
+
+end:
+       rcu_read_unlock();
+       health_code_update();
+skip:
+       return ret;
+}
+
+/*
+ * Force start live timers associated with the ust session.
+ */
+int ust_force_start_live_timer(struct ltt_ust_session *usess)
+{
+       int ret = 0;
+
+       if (usess->live_timer_interval == 0) {
+               goto skip;
+       }
+
+       DBG("Start all live timer associated with UST session %p", usess);
+
+       rcu_read_lock();
+
+       switch (usess->buffer_type) {
+       case LTTNG_BUFFER_PER_UID:
+       {
+               struct buffer_reg_uid *reg;
+               struct lttng_ht_iter iter;
+
+               cds_list_for_each_entry(reg, &usess->buffer_reg_uid_list, lnode) {
+                       struct ust_registry_session *ust_session_reg;
+                       struct buffer_reg_channel *reg_chan;
+                       struct consumer_socket *socket;
+
+                       /* Get consumer socket to use */
+                       socket = consumer_find_socket_by_bitness(reg->bits_per_long,
+                                       usess->consumer);
+                       if (!socket) {
+                               /* Ignore request if no consumer is found for the session. */
+                               continue;
+                       }
+
+                       cds_lfht_for_each_entry(reg->registry->channels->ht, &iter.iter,
+                                       reg_chan, node.node) {
+                               ret = consumer_channel_start_live_timer(socket, reg_chan->consumer_key);
+                               if (ret) {
+                                       ERR("Error stopping live timer for channel %" PRIu64, reg_chan->consumer_key);
+                               }
+                       }
+               }
+               break;
+       }
+       case LTTNG_BUFFER_PER_PID:
+       {
+               struct lttng_ht_iter iter_i;
+               struct ust_app *app;
+               uint64_t chan_reg_key;
+
+               cds_lfht_for_each_entry(ust_app_ht->ht, &iter_i.iter, app,
+                                       pid_n.node) {
+                       int ret;
+                       struct ust_app_session *ua_sess;
+                       struct lttng_ht_iter iter_j, iter_k;
+                       struct lttng_ht_node_u64 *node;
+                       struct ust_app_channel *ua_chan;
+
+                       DBG("Stopping live timer associated with ust app pid "
+                           "%d",
+                           app->pid);
+
+                       if (!app->compatible) {
+                               goto end;
+                       }
+
+                       __lookup_session_by_app(usess, app, &iter_j);
+                       node = lttng_ht_iter_get_node_u64(&iter_j);
+                       if (node == NULL) {
+                               /* Session is being or is deleted. */
+                               goto end;
+                       }
+                       ua_sess = caa_container_of(node, struct ust_app_session,
+                                                  node);
+
+                       health_code_update();
+
+                       cds_lfht_for_each_entry(ua_sess->channels->ht,
+                                               &iter_k.iter, ua_chan,
+                                               node.node) {
+                               struct consumer_socket *consumer_socket;
+
+                               /* Stop live timer immediately if any */
+                               consumer_socket =
+                                   consumer_find_socket_by_bitness(
+                                       app->bits_per_long,
+                                       ua_chan->session->consumer);
+                               ret = consumer_channel_start_live_timer(
+                                   consumer_socket, ua_chan->key);
+                               if (ret) {
+                                       ERR("Error stopping live timer");
+                               }
+                       }
+                       break;
+               }
+               break;
+       }
+       default:
+               break;
+       }
+
+end:
+       rcu_read_unlock();
+       health_code_update();
+skip:
+       return ret;
+}
+
 /*
  * Destroy app UST session.
  */
@@ -5059,7 +5279,9 @@ void ust_app_global_update(struct ltt_ust_session *usess, struct ust_app *app)
                return;
        }
 
-       if (trace_ust_pid_tracker_lookup(usess, app->pid)) {
+       if (trace_ust_id_tracker_lookup(LTTNG_TRACKER_VPID, usess, app->pid)
+                       && trace_ust_id_tracker_lookup(LTTNG_TRACKER_VUID, usess, app->uid)
+                       && trace_ust_id_tracker_lookup(LTTNG_TRACKER_VGID, usess, app->gid)) {
                ust_app_global_create(usess, app);
        } else {
                ust_app_global_destroy(usess, app);
@@ -5862,6 +6084,11 @@ int ust_app_snapshot_record(struct ltt_ust_session *usess,
                        struct buffer_reg_channel *reg_chan;
                        struct consumer_socket *socket;
 
+                       if (!reg->registry->reg.ust->metadata_key) {
+                               /* Skip since no metadata is present */
+                               continue;
+                       }
+
                        /* Get consumer socket to use to push the metadata.*/
                        socket = consumer_find_socket_by_bitness(reg->bits_per_long,
                                        usess->consumer);
This page took 0.031529 seconds and 5 git commands to generate.