| 1 | /* |
| 2 | * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef _LTT_TRACE_KERNEL_H |
| 9 | #define _LTT_TRACE_KERNEL_H |
| 10 | |
| 11 | #include <urcu/list.h> |
| 12 | |
| 13 | #include <lttng/lttng.h> |
| 14 | #include <lttng/map/map.h> |
| 15 | #include <common/lttng-kernel.h> |
| 16 | #include <common/lttng-kernel-old.h> |
| 17 | #include <common/defaults.h> |
| 18 | |
| 19 | #include "consumer.h" |
| 20 | #include "tracker.h" |
| 21 | |
| 22 | /* Kernel event list */ |
| 23 | struct ltt_kernel_event_list { |
| 24 | struct cds_list_head head; |
| 25 | }; |
| 26 | |
| 27 | /* Channel stream list */ |
| 28 | struct ltt_kernel_stream_list { |
| 29 | struct cds_list_head head; |
| 30 | }; |
| 31 | |
| 32 | /* Channel list */ |
| 33 | struct ltt_kernel_channel_list { |
| 34 | struct cds_list_head head; |
| 35 | }; |
| 36 | |
| 37 | /* map list */ |
| 38 | struct ltt_kernel_map_list { |
| 39 | struct cds_list_head head; |
| 40 | }; |
| 41 | |
| 42 | struct ltt_kernel_context { |
| 43 | struct lttng_kernel_context ctx; |
| 44 | struct cds_list_head list; |
| 45 | /* Indicates whether or not the context is in a list. */ |
| 46 | bool in_list; |
| 47 | }; |
| 48 | |
| 49 | /* Kernel event */ |
| 50 | struct ltt_kernel_event { |
| 51 | int fd; |
| 52 | int enabled; |
| 53 | enum lttng_event_type type; |
| 54 | struct lttng_kernel_event *event; |
| 55 | struct cds_list_head list; |
| 56 | char *filter_expression; |
| 57 | struct lttng_bytecode *filter; |
| 58 | struct lttng_userspace_probe_location *userspace_probe_location; |
| 59 | }; |
| 60 | |
| 61 | /* Kernel event notifier */ |
| 62 | struct ltt_kernel_event_notifier_rule { |
| 63 | int fd; |
| 64 | uint64_t error_counter_index; |
| 65 | int enabled; |
| 66 | enum lttng_event_type type; |
| 67 | struct lttng_trigger *trigger; |
| 68 | uint64_t token; |
| 69 | const struct lttng_bytecode *filter; |
| 70 | struct lttng_userspace_probe_location *userspace_probe_location; |
| 71 | struct cds_lfht_node ht_node; |
| 72 | /* call_rcu delayed reclaim. */ |
| 73 | struct rcu_head rcu_node; |
| 74 | }; |
| 75 | |
| 76 | /* Kernel event counter */ |
| 77 | struct ltt_kernel_event_counter { |
| 78 | int fd; |
| 79 | int enabled; |
| 80 | uint64_t action_tracer_token; |
| 81 | struct lttng_kernel_event *event; |
| 82 | struct lttng_event_rule *event_rule; |
| 83 | const struct lttng_bytecode *filter; |
| 84 | struct lttng_userspace_probe_location *userspace_probe_location; |
| 85 | struct cds_list_head list; |
| 86 | struct lttng_ht_node_u64 ht_node; |
| 87 | |
| 88 | /* refcounted */ |
| 89 | struct lttng_map_key *key; |
| 90 | /* call_rcu delayed reclaim. */ |
| 91 | struct rcu_head rcu_node; |
| 92 | }; |
| 93 | |
| 94 | /* Kernel channel */ |
| 95 | struct ltt_kernel_channel { |
| 96 | int fd; |
| 97 | uint64_t key; /* Key to reference this channel with the consumer. */ |
| 98 | int enabled; |
| 99 | unsigned int stream_count; |
| 100 | unsigned int event_count; |
| 101 | bool published_to_notification_thread; |
| 102 | struct cds_list_head ctx_list; |
| 103 | struct lttng_channel *channel; |
| 104 | struct ltt_kernel_event_list events_list; |
| 105 | struct ltt_kernel_stream_list stream_list; |
| 106 | struct cds_list_head list; |
| 107 | /* Session pointer which has a reference to this object. */ |
| 108 | struct ltt_kernel_session *session; |
| 109 | bool sent_to_consumer; |
| 110 | }; |
| 111 | |
| 112 | /* Kernel map */ |
| 113 | struct ltt_kernel_map { |
| 114 | int fd; |
| 115 | uint64_t key; /* Key to reference this map with the notification thread. */ |
| 116 | int enabled; |
| 117 | unsigned int event_count; |
| 118 | struct lttng_map *map; |
| 119 | struct lttng_kernel_counter_conf counter_conf; |
| 120 | struct lttng_ht *event_counters_ht; |
| 121 | struct cds_list_head list; |
| 122 | /* Session pointer which has a reference to this object. */ |
| 123 | struct ltt_kernel_session *session; |
| 124 | }; |
| 125 | |
| 126 | /* Metadata */ |
| 127 | struct ltt_kernel_metadata { |
| 128 | int fd; |
| 129 | uint64_t key; /* Key to reference this channel with the consumer. */ |
| 130 | struct lttng_channel *conf; |
| 131 | }; |
| 132 | |
| 133 | /* Channel stream */ |
| 134 | struct ltt_kernel_stream { |
| 135 | int fd; |
| 136 | int state; |
| 137 | int cpu; |
| 138 | bool sent_to_consumer; |
| 139 | /* Format is %s_%d respectively channel name and CPU number. */ |
| 140 | char name[DEFAULT_STREAM_NAME_LEN]; |
| 141 | uint64_t tracefile_size; |
| 142 | uint64_t tracefile_count; |
| 143 | struct cds_list_head list; |
| 144 | }; |
| 145 | |
| 146 | /* Kernel session */ |
| 147 | struct ltt_kernel_session { |
| 148 | int fd; |
| 149 | int metadata_stream_fd; |
| 150 | int consumer_fds_sent; |
| 151 | unsigned int channel_count; |
| 152 | unsigned int map_count; |
| 153 | unsigned int stream_count_global; |
| 154 | struct ltt_kernel_metadata *metadata; |
| 155 | struct ltt_kernel_channel_list channel_list; |
| 156 | struct ltt_kernel_map_list map_list; |
| 157 | /* UID/GID of the user owning the session */ |
| 158 | uid_t uid; |
| 159 | gid_t gid; |
| 160 | struct consumer_output *consumer; |
| 161 | /* Tracing session id */ |
| 162 | uint64_t id; |
| 163 | /* Session is active or not meaning it has been started or stopped. */ |
| 164 | unsigned int active:1; |
| 165 | /* Tell or not if the session has to output the traces. */ |
| 166 | unsigned int output_traces; |
| 167 | unsigned int snapshot_mode; |
| 168 | unsigned int has_non_default_channel; |
| 169 | bool is_live_session; |
| 170 | /* Current trace chunk of the ltt_session. */ |
| 171 | struct lttng_trace_chunk *current_trace_chunk; |
| 172 | /* Tracker lists */ |
| 173 | struct process_attr_tracker *tracker_pid; |
| 174 | struct process_attr_tracker *tracker_vpid; |
| 175 | struct process_attr_tracker *tracker_uid; |
| 176 | struct process_attr_tracker *tracker_vuid; |
| 177 | struct process_attr_tracker *tracker_gid; |
| 178 | struct process_attr_tracker *tracker_vgid; |
| 179 | }; |
| 180 | |
| 181 | /* |
| 182 | * Lookup functions. NULL is returned if not found. |
| 183 | */ |
| 184 | struct ltt_kernel_event *trace_kernel_get_event_by_name( |
| 185 | char *name, struct ltt_kernel_channel *channel, |
| 186 | enum lttng_event_type type); |
| 187 | struct ltt_kernel_event *trace_kernel_find_event( |
| 188 | struct ltt_kernel_event_list *events_list, |
| 189 | uint64_t tracer_token, char *name, |
| 190 | enum lttng_event_type type, |
| 191 | struct lttng_bytecode *filter); |
| 192 | struct ltt_kernel_channel *trace_kernel_get_channel_by_name( |
| 193 | const char *name, struct ltt_kernel_session *session); |
| 194 | |
| 195 | struct ltt_kernel_map *trace_kernel_get_map_by_name( |
| 196 | const char *name, struct ltt_kernel_session *session); |
| 197 | |
| 198 | /* |
| 199 | * Create functions malloc() the data structure. |
| 200 | */ |
| 201 | struct ltt_kernel_session *trace_kernel_create_session(void); |
| 202 | struct ltt_kernel_channel *trace_kernel_create_channel( |
| 203 | struct lttng_channel *chan); |
| 204 | struct ltt_kernel_map *trace_kernel_create_map(const struct lttng_map *map); |
| 205 | enum lttng_error_code trace_kernel_create_event(struct lttng_event *ev, |
| 206 | char *filter_expression, struct lttng_bytecode *filter, |
| 207 | struct ltt_kernel_event **kernel_event); |
| 208 | struct ltt_kernel_metadata *trace_kernel_create_metadata(void); |
| 209 | struct ltt_kernel_stream *trace_kernel_create_stream(const char *name, |
| 210 | unsigned int count); |
| 211 | struct ltt_kernel_context *trace_kernel_create_context( |
| 212 | struct lttng_kernel_context *ctx); |
| 213 | enum lttng_error_code trace_kernel_create_event_notifier_rule( |
| 214 | struct lttng_trigger *trigger, |
| 215 | uint64_t token, |
| 216 | uint64_t error_counter_index, |
| 217 | struct ltt_kernel_event_notifier_rule **event_notifier_rule); |
| 218 | struct ltt_kernel_context *trace_kernel_copy_context( |
| 219 | struct ltt_kernel_context *ctx); |
| 220 | enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule( |
| 221 | const struct lttng_event_rule *rule, |
| 222 | struct lttng_kernel_event_notifier *kernel_event_notifier); |
| 223 | enum lttng_error_code trace_kernel_init_event_counter_from_event_rule( |
| 224 | const struct lttng_event_rule *rule, |
| 225 | struct lttng_kernel_counter_event *kernel_counter_event); |
| 226 | |
| 227 | /* |
| 228 | * Destroy functions free() the data structure and remove from linked list if |
| 229 | * it's applies. |
| 230 | */ |
| 231 | void trace_kernel_destroy_session(struct ltt_kernel_session *session); |
| 232 | void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata); |
| 233 | void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel); |
| 234 | void trace_kernel_destroy_map(struct ltt_kernel_map *map); |
| 235 | void trace_kernel_destroy_event(struct ltt_kernel_event *event); |
| 236 | void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream); |
| 237 | void trace_kernel_destroy_context(struct ltt_kernel_context *ctx); |
| 238 | void trace_kernel_destroy_event_notifier_rule(struct ltt_kernel_event_notifier_rule *rule); |
| 239 | void trace_kernel_destroy_event_counter( |
| 240 | struct ltt_kernel_event_counter *event_counter); |
| 241 | void trace_kernel_free_session(struct ltt_kernel_session *session); |
| 242 | |
| 243 | #endif /* _LTT_TRACE_KERNEL_H */ |