Commit | Line | Data |
---|---|---|
7972aab2 | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2013 David Goulet <dgoulet@efficios.com> |
7972aab2 | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: GPL-2.0-only |
7972aab2 | 5 | * |
7972aab2 DG |
6 | */ |
7 | ||
8 | #ifndef LTTNG_BUFFER_REGISTRY_H | |
9 | #define LTTNG_BUFFER_REGISTRY_H | |
10 | ||
11 | #include <stdint.h> | |
7972aab2 DG |
12 | #include <urcu/list.h> |
13 | ||
14 | #include <lttng/lttng.h> | |
15 | #include <common/hashtable/hashtable.h> | |
16 | ||
17 | #include "consumer.h" | |
75018ab6 | 18 | #include "lttng-ust-ctl.h" |
7972aab2 DG |
19 | #include "ust-registry.h" |
20 | ||
21 | struct buffer_reg_stream { | |
22 | struct cds_list_head lnode; | |
23 | union { | |
24 | /* Original object data that MUST be copied over. */ | |
25 | struct lttng_ust_object_data *ust; | |
26 | } obj; | |
27 | }; | |
28 | ||
ebdb334b JR |
29 | struct buffer_reg_map_counter { |
30 | struct cds_list_head lnode; | |
31 | union { | |
32 | /* Original object data that MUST be copied over. */ | |
33 | struct lttng_ust_object_data *ust; | |
34 | } obj; | |
35 | }; | |
36 | ||
7972aab2 DG |
37 | struct buffer_reg_channel { |
38 | /* This key is the same as a tracing channel key. */ | |
39 | uint32_t key; | |
40 | /* Key of the channel on the consumer side. */ | |
41 | uint64_t consumer_key; | |
42 | /* Stream registry object of this channel registry. */ | |
43 | struct cds_list_head streams; | |
5c786ded JD |
44 | /* Total number of stream in the list. */ |
45 | uint64_t stream_count; | |
7972aab2 DG |
46 | /* Used to ensure mutual exclusion to the stream's list. */ |
47 | pthread_mutex_t stream_list_lock; | |
48 | /* Node for hash table usage. */ | |
49 | struct lttng_ht_node_u64 node; | |
8c924c7b MD |
50 | /* Size of subbuffers in this channel. */ |
51 | size_t subbuf_size; | |
d07ceecd MD |
52 | /* Number of subbuffers per stream. */ |
53 | size_t num_subbuf; | |
7972aab2 DG |
54 | union { |
55 | /* Original object data that MUST be copied over. */ | |
56 | struct lttng_ust_object_data *ust; | |
57 | } obj; | |
58 | }; | |
59 | ||
ebdb334b JR |
60 | struct buffer_reg_map { |
61 | /* This key is the same as a tracing map key. */ | |
62 | uint32_t key; | |
63 | /* Per cpu counter registry object of this map registry. */ | |
64 | struct cds_list_head counters; | |
65 | /* Total number of stream in the list. */ | |
66 | uint64_t counter_count; | |
67 | /* Used to ensure mutual exclusion to the counter's list. */ | |
68 | pthread_mutex_t counter_list_lock; | |
69 | /* Node for hash table usage. */ | |
70 | struct lttng_ht_node_u64 node; | |
71 | union { | |
72 | /* Original object data that MUST be copied over. */ | |
73 | struct lttng_ust_object_data *ust; | |
74 | } obj; | |
75 | ||
76 | struct ustctl_daemon_counter *daemon_counter; | |
77 | }; | |
78 | ||
7972aab2 DG |
79 | struct buffer_reg_session { |
80 | /* Registry per domain. */ | |
81 | union { | |
82 | struct ust_registry_session *ust; | |
83 | } reg; | |
84 | ||
85 | /* Contains buffer registry channel indexed by tracing channel key. */ | |
86 | struct lttng_ht *channels; | |
ebdb334b JR |
87 | /* Contains buffer registry map indexed by tracing map key. */ |
88 | struct lttng_ht *maps; | |
7972aab2 DG |
89 | }; |
90 | ||
91 | /* | |
92 | * Registry object for per UID buffers. | |
93 | */ | |
94 | struct buffer_reg_uid { | |
95 | /* | |
96 | * Keys to match this object in a hash table. The following three variables | |
97 | * identify a unique per UID buffer registry. | |
98 | */ | |
d9bf3ca4 | 99 | uint64_t session_id; /* Unique tracing session id. */ |
7972aab2 DG |
100 | int bits_per_long; /* ABI */ |
101 | uid_t uid; /* Owner. */ | |
102 | ||
103 | enum lttng_domain_type domain; | |
104 | struct buffer_reg_session *registry; | |
105 | ||
106 | /* Indexed by session id. */ | |
107 | struct lttng_ht_node_u64 node; | |
108 | /* Node of a linked list used to teardown object at a destroy session. */ | |
109 | struct cds_list_head lnode; | |
d7ba1388 | 110 | |
3d071855 | 111 | char root_shm_path[PATH_MAX]; |
d7ba1388 | 112 | char shm_path[PATH_MAX]; |
7972aab2 DG |
113 | }; |
114 | ||
115 | /* | |
116 | * Registry object for per PID buffers. | |
117 | */ | |
118 | struct buffer_reg_pid { | |
d9bf3ca4 | 119 | uint64_t session_id; |
7972aab2 DG |
120 | |
121 | struct buffer_reg_session *registry; | |
122 | ||
123 | /* Indexed by session id. */ | |
d9bf3ca4 | 124 | struct lttng_ht_node_u64 node; |
d7ba1388 | 125 | |
3d071855 | 126 | char root_shm_path[PATH_MAX]; |
d7ba1388 | 127 | char shm_path[PATH_MAX]; |
7972aab2 DG |
128 | }; |
129 | ||
130 | /* Buffer registry per UID. */ | |
131 | void buffer_reg_init_uid_registry(void); | |
d9bf3ca4 | 132 | int buffer_reg_uid_create(uint64_t session_id, uint32_t bits_per_long, uid_t uid, |
d7ba1388 | 133 | enum lttng_domain_type domain, struct buffer_reg_uid **regp, |
3d071855 | 134 | const char *root_shm_path, const char *shm_path); |
7972aab2 | 135 | void buffer_reg_uid_add(struct buffer_reg_uid *reg); |
d9bf3ca4 | 136 | struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id, |
7972aab2 DG |
137 | uint32_t bits_per_long, uid_t uid); |
138 | void buffer_reg_uid_remove(struct buffer_reg_uid *regp); | |
139 | void buffer_reg_uid_destroy(struct buffer_reg_uid *regp, | |
140 | struct consumer_output *consumer); | |
141 | ||
142 | /* Buffer registry per PID. */ | |
143 | void buffer_reg_init_pid_registry(void); | |
d7ba1388 | 144 | int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp, |
3d071855 | 145 | const char *root_shm_path, const char *shm_path); |
7972aab2 | 146 | void buffer_reg_pid_add(struct buffer_reg_pid *reg); |
d9bf3ca4 | 147 | struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id); |
7972aab2 DG |
148 | void buffer_reg_pid_remove(struct buffer_reg_pid *regp); |
149 | void buffer_reg_pid_destroy(struct buffer_reg_pid *regp); | |
150 | ||
151 | /* Channel */ | |
152 | int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp); | |
153 | void buffer_reg_channel_add(struct buffer_reg_session *session, | |
154 | struct buffer_reg_channel *channel); | |
155 | struct buffer_reg_channel *buffer_reg_channel_find(uint64_t key, | |
156 | struct buffer_reg_uid *reg); | |
157 | void buffer_reg_channel_remove(struct buffer_reg_session *session, | |
158 | struct buffer_reg_channel *regp); | |
159 | void buffer_reg_channel_destroy(struct buffer_reg_channel *regp, | |
160 | enum lttng_domain_type domain); | |
161 | ||
ebdb334b JR |
162 | /* Map */ |
163 | int buffer_reg_map_create(uint64_t key, struct buffer_reg_map **regp); | |
164 | void buffer_reg_map_add(struct buffer_reg_session *session, | |
165 | struct buffer_reg_map *map); | |
166 | struct buffer_reg_map *buffer_reg_map_find(uint64_t key, | |
167 | struct buffer_reg_uid *reg); | |
168 | void buffer_reg_map_remove(struct buffer_reg_session *session, | |
169 | struct buffer_reg_map *regp); | |
170 | void buffer_reg_map_destroy(struct buffer_reg_map *regp, | |
171 | enum lttng_domain_type domain); | |
172 | ||
7972aab2 DG |
173 | /* Stream */ |
174 | int buffer_reg_stream_create(struct buffer_reg_stream **regp); | |
175 | void buffer_reg_stream_add(struct buffer_reg_stream *stream, | |
176 | struct buffer_reg_channel *channel); | |
177 | void buffer_reg_stream_destroy(struct buffer_reg_stream *regp, | |
178 | enum lttng_domain_type domain); | |
179 | ||
ebdb334b JR |
180 | /* Map counter */ |
181 | int buffer_reg_map_counter_create(struct buffer_reg_map_counter **regp); | |
182 | void buffer_reg_map_counter_add(struct buffer_reg_map_counter *map_counter, | |
183 | struct buffer_reg_map *map); | |
184 | void buffer_reg_map_counter_destroy(struct buffer_reg_map_counter *regp, | |
185 | enum lttng_domain_type domain); | |
186 | ||
7972aab2 DG |
187 | /* Global registry. */ |
188 | void buffer_reg_destroy_registries(void); | |
189 | ||
fb83fe64 JD |
190 | int buffer_reg_uid_consumer_channel_key( |
191 | struct cds_list_head *buffer_reg_uid_list, | |
76604852 | 192 | uint64_t chan_key, uint64_t *consumer_chan_key); |
fb83fe64 | 193 | |
7972aab2 | 194 | #endif /* LTTNG_BUFFER_REGISTRY_H */ |