2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 #ifndef LTTNG_BUFFER_REGISTRY_H
19 #define LTTNG_BUFFER_REGISTRY_H
22 #include <urcu/list.h>
24 #include <lttng/lttng.h>
25 #include <common/hashtable/hashtable.h>
29 #include "ust-registry.h"
31 struct buffer_reg_stream
{
32 struct cds_list_head lnode
;
34 /* Original object data that MUST be copied over. */
35 struct lttng_ust_object_data
*ust
;
39 struct buffer_reg_channel
{
40 /* This key is the same as a tracing channel key. */
42 /* Key of the channel on the consumer side. */
43 uint64_t consumer_key
;
44 /* Stream registry object of this channel registry. */
45 struct cds_list_head streams
;
46 /* Total number of stream in the list. */
47 uint64_t stream_count
;
48 /* Used to ensure mutual exclusion to the stream's list. */
49 pthread_mutex_t stream_list_lock
;
50 /* Node for hash table usage. */
51 struct lttng_ht_node_u64 node
;
52 /* Size of subbuffers in this channel. */
55 /* Original object data that MUST be copied over. */
56 struct lttng_ust_object_data
*ust
;
60 struct buffer_reg_session
{
61 /* Registry per domain. */
63 struct ust_registry_session
*ust
;
66 /* Contains buffer registry channel indexed by tracing channel key. */
67 struct lttng_ht
*channels
;
71 * Registry object for per UID buffers.
73 struct buffer_reg_uid
{
75 * Keys to match this object in a hash table. The following three variables
76 * identify a unique per UID buffer registry.
78 uint64_t session_id
; /* Unique tracing session id. */
79 int bits_per_long
; /* ABI */
80 uid_t uid
; /* Owner. */
82 enum lttng_domain_type domain
;
83 struct buffer_reg_session
*registry
;
85 /* Indexed by session id. */
86 struct lttng_ht_node_u64 node
;
87 /* Node of a linked list used to teardown object at a destroy session. */
88 struct cds_list_head lnode
;
92 * Registry object for per PID buffers.
94 struct buffer_reg_pid
{
97 struct buffer_reg_session
*registry
;
99 /* Indexed by session id. */
100 struct lttng_ht_node_u64 node
;
103 /* Buffer registry per UID. */
104 void buffer_reg_init_uid_registry(void);
105 int buffer_reg_uid_create(uint64_t session_id
, uint32_t bits_per_long
, uid_t uid
,
106 enum lttng_domain_type domain
, struct buffer_reg_uid
**regp
);
107 void buffer_reg_uid_add(struct buffer_reg_uid
*reg
);
108 struct buffer_reg_uid
*buffer_reg_uid_find(uint64_t session_id
,
109 uint32_t bits_per_long
, uid_t uid
);
110 void buffer_reg_uid_remove(struct buffer_reg_uid
*regp
);
111 void buffer_reg_uid_destroy(struct buffer_reg_uid
*regp
,
112 struct consumer_output
*consumer
);
114 /* Buffer registry per PID. */
115 void buffer_reg_init_pid_registry(void);
116 int buffer_reg_pid_create(uint64_t session_id
, struct buffer_reg_pid
**regp
);
117 void buffer_reg_pid_add(struct buffer_reg_pid
*reg
);
118 struct buffer_reg_pid
*buffer_reg_pid_find(uint64_t session_id
);
119 void buffer_reg_pid_remove(struct buffer_reg_pid
*regp
);
120 void buffer_reg_pid_destroy(struct buffer_reg_pid
*regp
);
123 int buffer_reg_channel_create(uint64_t key
, struct buffer_reg_channel
**regp
);
124 void buffer_reg_channel_add(struct buffer_reg_session
*session
,
125 struct buffer_reg_channel
*channel
);
126 struct buffer_reg_channel
*buffer_reg_channel_find(uint64_t key
,
127 struct buffer_reg_uid
*reg
);
128 void buffer_reg_channel_remove(struct buffer_reg_session
*session
,
129 struct buffer_reg_channel
*regp
);
130 void buffer_reg_channel_destroy(struct buffer_reg_channel
*regp
,
131 enum lttng_domain_type domain
);
134 int buffer_reg_stream_create(struct buffer_reg_stream
**regp
);
135 void buffer_reg_stream_add(struct buffer_reg_stream
*stream
,
136 struct buffer_reg_channel
*channel
);
137 void buffer_reg_stream_destroy(struct buffer_reg_stream
*regp
,
138 enum lttng_domain_type domain
);
140 /* Global registry. */
141 void buffer_reg_destroy_registries(void);
143 #endif /* LTTNG_BUFFER_REGISTRY_H */