SoW-2020-0002: Trace Hit Counters
[deliverable/lttng-modules.git] / include / lttng / events.h
index 6aa880f82eb1b8737dad767b0c5e94a23a159888..ebf981eb334c47aa084a198850ec973c4ffd5d00 100644 (file)
@@ -208,7 +208,7 @@ struct lttng_ctx {
 struct lttng_event_desc {
        const char *name;               /* lttng-modules name */
        const char *kname;              /* Linux kernel name (tracepoints) */
-       void *probe_callback;
+       void *probe_callback;           /* store-event and count-event probe */
        const struct lttng_event_ctx *ctx;      /* context */
        const struct lttng_event_field *fields; /* event payload */
        unsigned int nr_fields;
@@ -298,11 +298,13 @@ struct lttng_uprobe_handler {
 struct lttng_kprobe {
        struct kprobe kp;
        char *symbol_name;
+       uint64_t user_token;
 };
 
 struct lttng_uprobe {
        struct inode *inode;
        struct list_head head;
+       uint64_t user_token;
 };
 
 enum lttng_syscall_entryexit {
@@ -315,14 +317,47 @@ enum lttng_syscall_abi {
        LTTNG_SYSCALL_ABI_COMPAT,
 };
 
+struct lttng_syscall {
+       struct list_head node;                  /* chain registered syscall trigger */
+       unsigned int syscall_id;
+       bool is_compat;
+};
+
+enum lttng_key_token_type {
+       LTTNG_KEY_TOKEN_STRING = 0,
+       LTTNG_KEY_TOKEN_EVENT_NAME = 1,
+};
+
+#define LTTNG_KEY_TOKEN_STRING_LEN_MAX LTTNG_KERNEL_KEY_TOKEN_STRING_LEN_MAX
+struct lttng_key_token {
+       enum lttng_key_token_type type;
+       union {
+               char string[LTTNG_KEY_TOKEN_STRING_LEN_MAX];
+       } arg;
+};
+
+#define LTTNG_NR_KEY_TOKEN LTTNG_KERNEL_NR_KEY_TOKEN
+struct lttng_counter_key_dimension {
+       size_t nr_key_tokens;
+       struct lttng_key_token key_tokens[LTTNG_KERNEL_NR_KEY_TOKEN];
+};
+
+#define LTTNG_COUNTER_DIMENSION_MAX LTTNG_KERNEL_COUNTER_DIMENSION_MAX
+struct lttng_counter_key {
+       size_t nr_dimensions;
+       struct lttng_counter_key_dimension key_dimensions[LTTNG_COUNTER_DIMENSION_MAX];
+};
+
+#define LTTNG_KEY_TOKEN_STRING_LEN_MAX LTTNG_KERNEL_KEY_TOKEN_STRING_LEN_MAX
+
 /*
  * lttng_event structure is referred to by the tracing fast path. It must be
  * kept small.
  */
 struct lttng_event {
        enum lttng_event_type evtype;   /* First field. */
-       unsigned int id;
-       struct lttng_channel *chan;
+       struct lttng_event_container *container;
+       size_t id;
        int enabled;
        const struct lttng_event_desc *desc;
        void *filter;
@@ -333,6 +368,7 @@ struct lttng_event {
                struct {
                        struct lttng_krp *lttng_krp;
                        char *symbol_name;
+                       uint64_t user_token;
                } kretprobe;
                struct lttng_uprobe uprobe;
                struct {
@@ -346,11 +382,27 @@ struct lttng_event {
 
        /* Backward references: list of lttng_enabler_ref (ref to enablers) */
        struct list_head enablers_ref_head;
-       struct hlist_node hlist;        /* session ht of events */
+       struct hlist_node name_hlist;   /* session ht of events, per event name */
+       struct hlist_node key_hlist;    /* session ht of events, per key */
        int registered;                 /* has reg'd tracepoint probe */
        /* list of struct lttng_bytecode_runtime, sorted by seqnum */
        struct list_head filter_bytecode_runtime_head;
        int has_enablers_without_bytecode;
+
+       /* List node of actions to perform (for syscall events). */
+       struct hlist_node action_list;
+
+       char key[LTTNG_KEY_TOKEN_STRING_LEN_MAX];
+
+       /*
+        * For non-coalesce-hit event containers, each event is
+        * associated with a single event enabler user_token.
+        */
+       uint64_t user_token;
+};
+
+struct lttng_kernel_notifier_ctx {
+       int eval_capture;
 };
 
 // FIXME: Really similar to lttng_event above. Could those be merged ?
@@ -385,10 +437,12 @@ struct lttng_event_notifier {
        size_t num_captures;
        struct list_head capture_bytecode_runtime_head;
        int has_enablers_without_bytecode;
+       int eval_capture;               /* Should evaluate capture */
 
        void (*send_notification)(struct lttng_event_notifier *event_notifier,
                        struct lttng_probe_ctx *lttng_probe_ctx,
-                       const char *interpreter_stack_data);
+                       const char *interpreter_stack_data,
+                       struct lttng_kernel_notifier_ctx *notif_ctx);
        struct lttng_event_notifier_group *group; /* Weak ref */
 };
 
@@ -418,7 +472,8 @@ struct lttng_enabler {
 struct lttng_event_enabler {
        struct lttng_enabler base;
        struct list_head node;  /* per-session list of enablers */
-       struct lttng_channel *chan;
+       struct lttng_event_container *container;
+       struct lttng_counter_key key;
        /*
         * Unused, but kept around to make it explicit that the tracer can do
         * it.
@@ -567,35 +622,60 @@ struct lttng_event_notifier_ht {
        struct hlist_head table[LTTNG_EVENT_NOTIFIER_HT_SIZE];
 };
 
-struct lttng_channel {
-       unsigned int id;
-       struct channel *chan;           /* Channel buffers */
+enum lttng_event_container_type {
+       LTTNG_EVENT_CONTAINER_CHANNEL,
+       LTTNG_EVENT_CONTAINER_COUNTER,
+};
+
+/*
+ * An event can be contained within either a channel or a counter.
+ */
+struct lttng_event_container {
+       enum lttng_event_container_type type;
+
+       struct file *file;                      /* File associated to event container */
+       struct lttng_session *session;          /* Session containing the container */
        int enabled;
-       struct lttng_ctx *ctx;
-       /* Event ID management */
-       struct lttng_session *session;
-       struct file *file;              /* File associated to channel */
-       unsigned int free_event_id;     /* Next event ID to allocate */
-       struct list_head list;          /* Channel list */
-       struct lttng_channel_ops *ops;
-       struct lttng_transport *transport;
-       struct hlist_head *sc_table;    /* for syscall tracing */
+       struct hlist_head *sc_table;            /* for syscall tracing */
        struct hlist_head *compat_sc_table;
        struct hlist_head *sc_exit_table;       /* for syscall exit tracing */
        struct hlist_head *compat_sc_exit_table;
-       struct hlist_head sc_unknown;   /* for unknown syscalls */
+
+       /*
+        * Combining all unknown syscall events works as long as they
+        * are only matched by "all" syscalls enablers, but will require
+        * a design change when we allow matching by syscall number, for
+        * instance by allocating sc_tables accomodating NR_syscalls
+        * entries.
+        */
+       struct hlist_head sc_unknown;           /* for unknown syscalls */
        struct hlist_head sc_compat_unknown;
        struct hlist_head sc_exit_unknown;
        struct hlist_head compat_sc_exit_unknown;
+
        struct lttng_syscall_filter *sc_filter;
-       int header_type;                /* 0: unset, 1: compact, 2: large */
-       enum channel_type channel_type;
        int syscall_all_entry;
        int syscall_all_exit;
-       unsigned int metadata_dumped:1,
-               sys_enter_registered:1,
+       unsigned int sys_enter_registered:1,
                sys_exit_registered:1,
-               tstate:1;               /* Transient enable state */
+               tstate:1;                       /* Transient enable state */
+       bool coalesce_hits;
+};
+
+struct lttng_channel {
+       unsigned int id;
+       struct channel *chan;           /* Channel buffers */
+       struct lttng_ctx *ctx;
+       /* Event ID management */
+       unsigned int free_event_id;     /* Next event ID to allocate */
+       struct list_head list;          /* Channel list */
+       struct lttng_channel_ops *ops;
+       struct lttng_transport *transport;
+       int header_type;                /* 0: unset, 1: compact, 2: large */
+       enum channel_type channel_type;
+       unsigned int metadata_dumped:1;
+
+       struct lttng_event_container parent;
 };
 
 struct lttng_metadata_stream {
@@ -659,6 +739,7 @@ struct lttng_session {
        struct file *file;              /* File associated to session */
        struct list_head chan;          /* Channel list head */
        struct list_head events;        /* Event list head */
+       struct list_head counters;      /* Counters list head */
        struct list_head list;          /* Session list */
        unsigned int free_chan_id;      /* Next chan ID to allocate */
        uuid_le uuid;                   /* Trace session unique ID */
@@ -673,18 +754,38 @@ struct lttng_session {
                tstate:1;               /* Transient enable state */
        /* List of event enablers */
        struct list_head enablers_head;
-       /* Hash table of events */
-       struct lttng_event_ht events_ht;
+       /* Hash table of events indexed by event name */
+       struct lttng_event_ht events_name_ht;
+       /* Hash table of events indexed by key  */
+       struct lttng_event_ht events_key_ht;
        char name[LTTNG_KERNEL_SESSION_NAME_LEN];
        char creation_time[LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN];
 };
 
+struct lttng_counter_map_descriptor {
+       uint64_t user_token;
+       size_t array_index;
+       char key[LTTNG_KERNEL_COUNTER_KEY_LEN];
+};
+
+struct lttng_counter_map {
+       struct lttng_counter_map_descriptor *descriptors;
+       size_t nr_descriptors;
+       size_t alloc_len;
+       struct mutex lock;              /* counter map lock */
+};
+
 struct lttng_counter {
-       struct file *file;              /* File associated to counter. */
        struct file *owner;
        struct lttng_counter_transport *transport;
        struct lib_counter *counter;
        struct lttng_counter_ops *ops;
+       struct list_head node;          /* Counter list (in session) */
+
+       size_t free_index;              /* Next index to allocate */
+       struct lttng_counter_map map;
+
+       struct lttng_event_container parent;
 };
 
 struct lttng_event_notifier_group {
@@ -737,6 +838,34 @@ struct lttng_metadata_cache {
        uint64_t version;               /* Current version of the metadata */
 };
 
+static inline
+struct lttng_event_container *lttng_channel_get_event_container(struct lttng_channel *channel)
+{
+       return &channel->parent;
+}
+
+static inline
+struct lttng_event_container *lttng_counter_get_event_container(struct lttng_counter *counter)
+{
+       return &counter->parent;
+}
+
+static inline
+struct lttng_channel *lttng_event_container_get_channel(struct lttng_event_container *container)
+{
+       if (container->type != LTTNG_EVENT_CONTAINER_CHANNEL)
+               return NULL;
+       return container_of(container, struct lttng_channel, parent);
+}
+
+static inline
+struct lttng_counter *lttng_event_container_get_counter(struct lttng_event_container *container)
+{
+       if (container->type != LTTNG_EVENT_CONTAINER_COUNTER)
+               return NULL;
+       return container_of(container, struct lttng_counter, parent);
+}
+
 void lttng_lock_sessions(void);
 void lttng_unlock_sessions(void);
 
@@ -745,7 +874,8 @@ struct list_head *lttng_get_probe_list_head(void);
 struct lttng_event_enabler *lttng_event_enabler_create(
                enum lttng_enabler_format_type format_type,
                struct lttng_kernel_event *event_param,
-               struct lttng_channel *chan);
+               const struct lttng_counter_key *key,
+               struct lttng_event_container *container);
 
 int lttng_event_enabler_enable(struct lttng_event_enabler *event_enabler);
 int lttng_event_enabler_disable(struct lttng_event_enabler *event_enabler);
@@ -771,9 +901,6 @@ int lttng_session_metadata_regenerate(struct lttng_session *session);
 int lttng_session_statedump(struct lttng_session *session);
 void metadata_cache_destroy(struct kref *kref);
 
-struct lttng_counter *lttng_kernel_counter_create(
-               const char *counter_transport_name, size_t number_dimensions,
-               const size_t *dimensions_sizes);
 int lttng_kernel_counter_read(struct lttng_counter *counter,
                const size_t *dimension_indexes, int32_t cpu,
                int64_t *val, bool *overflow, bool *underflow);
@@ -788,8 +915,13 @@ struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
 int lttng_event_notifier_group_create_error_counter(
                struct file *event_notifier_group_file,
                const struct lttng_kernel_counter_conf *error_counter_conf);
+
 void lttng_event_notifier_group_destroy(
                struct lttng_event_notifier_group *event_notifier_group);
+int lttng_event_notifier_group_set_error_counter(
+               struct lttng_event_notifier_group *event_notifier_group,
+               const char *counter_transport_name,
+               size_t counter_len);
 
 struct lttng_channel *lttng_channel_create(struct lttng_session *session,
                                       const char *transport_name,
@@ -798,27 +930,27 @@ struct lttng_channel *lttng_channel_create(struct lttng_session *session,
                                       unsigned int switch_timer_interval,
                                       unsigned int read_timer_interval,
                                       enum channel_type channel_type);
-struct lttng_channel *lttng_global_channel_create(struct lttng_session *session,
-                                      int overwrite, void *buf_addr,
-                                      size_t subbuf_size, size_t num_subbuf,
-                                      unsigned int switch_timer_interval,
-                                      unsigned int read_timer_interval);
 
 void lttng_metadata_channel_destroy(struct lttng_channel *chan);
-struct lttng_event *lttng_event_create(struct lttng_channel *chan,
+struct lttng_event *lttng_event_create(struct lttng_event_container *container,
                                struct lttng_kernel_event *event_param,
+                               const struct lttng_counter_key *key,
                                void *filter,
                                const struct lttng_event_desc *event_desc,
-                               enum lttng_kernel_instrumentation itype);
-struct lttng_event *_lttng_event_create(struct lttng_channel *chan,
+                               enum lttng_kernel_instrumentation itype,
+                               uint64_t user_token);
+struct lttng_event *_lttng_event_create(struct lttng_event_container *container,
                                struct lttng_kernel_event *event_param,
+                               const struct lttng_counter_key *key,
                                void *filter,
                                const struct lttng_event_desc *event_desc,
-                               enum lttng_kernel_instrumentation itype);
-struct lttng_event *lttng_event_compat_old_create(struct lttng_channel *chan,
-               struct lttng_kernel_old_event *old_event_param,
-               void *filter,
-               const struct lttng_event_desc *internal_desc);
+                               enum lttng_kernel_instrumentation itype,
+                               uint64_t user_token);
+struct lttng_counter *lttng_session_create_counter(
+       struct lttng_session *session,
+       const char *counter_transport_name,
+       size_t number_dimensions, const size_t *dimensions_sizes,
+       bool coalesce_hits);
 
 struct lttng_event_notifier *lttng_event_notifier_create(
                                const struct lttng_event_desc *event_notifier_desc,
@@ -837,8 +969,8 @@ struct lttng_event_notifier *_lttng_event_notifier_create(
                                void *filter,
                                enum lttng_kernel_instrumentation itype);
 
-int lttng_channel_enable(struct lttng_channel *channel);
-int lttng_channel_disable(struct lttng_channel *channel);
+int lttng_event_container_enable(struct lttng_event_container *container);
+int lttng_event_container_disable(struct lttng_event_container *container);
 int lttng_event_enable(struct lttng_event *event);
 int lttng_event_disable(struct lttng_event *event);
 
@@ -890,16 +1022,13 @@ int lttng_desc_match_enabler(const struct lttng_event_desc *desc,
 
 #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
 int lttng_syscalls_register_event(struct lttng_event_enabler *event_enabler, void *filter);
-int lttng_syscalls_unregister_channel(struct lttng_channel *chan);
-int lttng_syscalls_destroy_event(struct lttng_channel *chan);
-int lttng_syscall_filter_enable_event(
-               struct lttng_channel *chan,
+int lttng_syscalls_unregister_event_container(struct lttng_event_container *event_container);
+int lttng_syscalls_destroy_event_container(struct lttng_event_container *container);
+int lttng_syscall_filter_enable_event(struct lttng_event_container *container,
                struct lttng_event *event);
-int lttng_syscall_filter_disable_event(
-               struct lttng_channel *chan,
+int lttng_syscall_filter_disable_event(struct lttng_event_container *container,
                struct lttng_event *event);
-
-long lttng_channel_syscall_mask(struct lttng_channel *channel,
+long lttng_event_container_syscall_mask(struct lttng_event_container *container,
                struct lttng_kernel_syscall_mask __user *usyscall_mask);
 
 int lttng_syscalls_register_event_notifier(
@@ -917,29 +1046,29 @@ static inline int lttng_syscalls_register_event(
        return -ENOSYS;
 }
 
-static inline int lttng_syscalls_unregister_channel(struct lttng_channel *chan)
+static inline int lttng_syscalls_unregister_event_container(struct lttng_event_container *event_container)
 {
        return 0;
 }
 
-static inline int lttng_syscalls_destroy(struct lttng_channel *chan)
+static inline int lttng_syscalls_destroy_event_container(struct lttng_event_container *event_container)
 {
        return 0;
 }
 
-static inline int lttng_syscall_filter_enable_event(struct lttng_channel *chan,
+static inline int lttng_syscall_filter_enable_event(struct lttng_event_container *event_container,
                struct lttng_event *event);
 {
        return -ENOSYS;
 }
 
-static inline int lttng_syscall_filter_disable_event(struct lttng_channel *chan,
+static inline int lttng_syscall_filter_disable_event(struct lttng_event_container *event_container,
                struct lttng_event *event);
 {
        return -ENOSYS;
 }
 
-static inline long lttng_channel_syscall_mask(struct lttng_channel *channel,
+static inline long lttng_channel_syscall_mask(struct lttng_event_container *event_container,
                struct lttng_kernel_syscall_mask __user *usyscall_mask)
 {
        return -ENOSYS;
This page took 0.030478 seconds and 5 git commands to generate.