4 * LTTng UST vpid context.
6 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <sys/types.h>
27 #include <lttng/ust-events.h>
28 #include <lttng/ust-tracer.h>
29 #include <lttng/ringbuffer-config.h>
32 * We cache the result to ensure we don't trigger a system call for
35 static pid_t cached_vpid
;
38 pid_t
wrapper_getvpid(void)
42 vpid
= CMM_LOAD_SHARED(cached_vpid
);
43 if (caa_unlikely(!vpid
)) {
45 CMM_STORE_SHARED(cached_vpid
, vpid
);
51 * Upon fork or clone, the PID assigned to our thread is not the same as
54 void lttng_context_vpid_reset(void)
56 CMM_STORE_SHARED(cached_vpid
, 0);
60 size_t vpid_get_size(struct lttng_ctx_field
*field
, size_t offset
)
64 size
+= lib_ring_buffer_align(offset
, lttng_alignof(pid_t
));
65 size
+= sizeof(pid_t
);
70 void vpid_record(struct lttng_ctx_field
*field
,
71 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
72 struct lttng_channel
*chan
)
74 pid_t vpid
= wrapper_getvpid();
76 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(vpid
));
77 chan
->ops
->event_write(ctx
, &vpid
, sizeof(vpid
));
81 void vpid_get_value(struct lttng_ctx_field
*field
,
82 struct lttng_ctx_value
*value
)
84 value
->u
.s64
= wrapper_getvpid();
87 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
)
89 struct lttng_ctx_field
*field
;
91 field
= lttng_append_context(ctx
);
94 if (lttng_find_context(*ctx
, "vpid")) {
95 lttng_remove_context_field(ctx
, field
);
98 field
->event_field
.name
= "vpid";
99 field
->event_field
.type
.atype
= atype_integer
;
100 field
->event_field
.type
.u
.integer
.size
= sizeof(pid_t
) * CHAR_BIT
;
101 field
->event_field
.type
.u
.integer
.alignment
= lttng_alignof(pid_t
) * CHAR_BIT
;
102 field
->event_field
.type
.u
.integer
.signedness
= lttng_is_signed_type(pid_t
);
103 field
->event_field
.type
.u
.integer
.reverse_byte_order
= 0;
104 field
->event_field
.type
.u
.integer
.base
= 10;
105 field
->event_field
.type
.u
.integer
.encoding
= lttng_encode_none
;
106 field
->get_size
= vpid_get_size
;
107 field
->record
= vpid_record
;
108 field
->get_value
= vpid_get_value
;
109 lttng_context_update(*ctx
);