4 * Babeltrace CTF IR - Stream
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <babeltrace/ctf-ir/clock.h>
30 #include <babeltrace/ctf-ir/clock-internal.h>
31 #include <babeltrace/ctf-writer/event.h>
32 #include <babeltrace/ctf-ir/event-internal.h>
33 #include <babeltrace/ctf-ir/field-types-internal.h>
34 #include <babeltrace/ctf-ir/fields-internal.h>
35 #include <babeltrace/ctf-ir/stream-internal.h>
36 #include <babeltrace/ctf-ir/stream-class-internal.h>
37 #include <babeltrace/ctf-ir/trace-internal.h>
38 #include <babeltrace/ctf-writer/writer-internal.h>
39 #include <babeltrace/ref.h>
40 #include <babeltrace/ctf-writer/functor-internal.h>
41 #include <babeltrace/compiler.h>
42 #include <babeltrace/align.h>
43 #include <babeltrace/ctf/ctf-index.h>
46 void bt_ctf_stream_destroy(struct bt_object
*obj
);
48 int set_structure_field_integer(struct bt_ctf_field
*, char *, uint64_t);
51 int set_packet_header_magic(struct bt_ctf_stream
*stream
)
54 struct bt_ctf_field_type
*magic_field_type
= NULL
;
55 struct bt_ctf_field
*magic_field
= bt_ctf_field_structure_get_field(
56 stream
->packet_header
, "magic");
59 /* No magic field found. Not an error, skip. */
63 if (!bt_ctf_field_validate(magic_field
)) {
64 /* Value already set. Not an error, skip. */
68 magic_field_type
= bt_ctf_field_get_type(magic_field
);
69 assert(magic_field_type
);
71 if (bt_ctf_field_type_get_type_id(magic_field_type
) !=
73 /* Magic field is not an integer. Not an error, skip. */
77 if (bt_ctf_field_type_integer_get_size(magic_field_type
) != 32) {
79 * Magic field is not of the expected size.
85 ret
= bt_ctf_field_type_integer_get_signed(magic_field_type
);
88 ret
= bt_ctf_field_signed_integer_set_value(magic_field
,
89 (int64_t) 0xC1FC1FC1);
91 ret
= bt_ctf_field_unsigned_integer_set_value(magic_field
,
92 (uint64_t) 0xC1FC1FC1);
96 bt_put(magic_field_type
);
101 int set_packet_header_uuid(struct bt_ctf_stream
*stream
)
104 struct bt_ctf_trace
*trace
= NULL
;
105 struct bt_ctf_field_type
*uuid_field_type
= NULL
;
106 struct bt_ctf_field_type
*element_field_type
= NULL
;
107 struct bt_ctf_field
*uuid_field
= bt_ctf_field_structure_get_field(
108 stream
->packet_header
, "uuid");
111 /* No uuid field found. Not an error, skip. */
115 if (!bt_ctf_field_validate(uuid_field
)) {
116 /* Value already set. Not an error, skip. */
120 uuid_field_type
= bt_ctf_field_get_type(uuid_field
);
121 assert(uuid_field_type
);
122 if (bt_ctf_field_type_get_type_id(uuid_field_type
) !=
124 /* UUID field is not an array. Not an error, skip. */
128 if (bt_ctf_field_type_array_get_length(uuid_field_type
) != 16) {
130 * UUID field is not of the expected size.
131 * Not an error, skip.
136 element_field_type
= bt_ctf_field_type_array_get_element_type(
138 assert(element_field_type
);
139 if (bt_ctf_field_type_get_type_id(element_field_type
) !=
141 /* UUID array elements are not integers. Not an error, skip */
145 trace
= (struct bt_ctf_trace
*) bt_object_get_parent(stream
);
146 for (i
= 0; i
< 16; i
++) {
147 struct bt_ctf_field
*uuid_element
=
148 bt_ctf_field_array_get_field(uuid_field
, i
);
150 ret
= bt_ctf_field_type_integer_get_signed(element_field_type
);
154 ret
= bt_ctf_field_signed_integer_set_value(
155 uuid_element
, (int64_t) trace
->uuid
[i
]);
157 ret
= bt_ctf_field_unsigned_integer_set_value(
159 (uint64_t) trace
->uuid
[i
]);
161 bt_put(uuid_element
);
169 bt_put(uuid_field_type
);
170 bt_put(element_field_type
);
175 int set_packet_header_stream_id(struct bt_ctf_stream
*stream
)
179 struct bt_ctf_field_type
*stream_id_field_type
= NULL
;
180 struct bt_ctf_field
*stream_id_field
= bt_ctf_field_structure_get_field(
181 stream
->packet_header
, "stream_id");
183 if (!stream_id_field
) {
184 /* No stream_id field found. Not an error, skip. */
188 if (!bt_ctf_field_validate(stream_id_field
)) {
189 /* Value already set. Not an error, skip. */
193 stream_id_field_type
= bt_ctf_field_get_type(stream_id_field
);
194 assert(stream_id_field_type
);
195 if (bt_ctf_field_type_get_type_id(stream_id_field_type
) !=
197 /* stream_id field is not an integer. Not an error, skip. */
201 stream_id
= stream
->stream_class
->id
;
202 ret
= bt_ctf_field_type_integer_get_signed(stream_id_field_type
);
205 ret
= bt_ctf_field_signed_integer_set_value(stream_id_field
,
206 (int64_t) stream_id
);
208 ret
= bt_ctf_field_unsigned_integer_set_value(stream_id_field
,
209 (uint64_t) stream_id
);
212 bt_put(stream_id_field
);
213 bt_put(stream_id_field_type
);
218 int set_packet_header(struct bt_ctf_stream
*stream
)
222 ret
= set_packet_header_magic(stream
);
227 ret
= set_packet_header_uuid(stream
);
232 ret
= set_packet_header_stream_id(stream
);
241 void release_event(struct bt_ctf_event
*event
)
243 if (bt_object_get_ref_count(event
)) {
245 * The event is being orphaned, but it must guarantee the
246 * existence of its event class for the duration of its
249 bt_get(event
->event_class
);
250 BT_PUT(event
->base
.parent
);
252 bt_object_release(event
);
257 int create_stream_file(struct bt_ctf_writer
*writer
,
258 struct bt_ctf_stream
*stream
)
261 GString
*filename
= g_string_new(stream
->stream_class
->name
->str
);
263 if (stream
->stream_class
->name
->len
== 0) {
266 ret
= bt_ctf_stream_class_get_id(stream
->stream_class
);
272 g_string_printf(filename
, "stream_%" PRId64
, ret
);
275 g_string_append_printf(filename
, "_%" PRIu32
, stream
->id
);
276 fd
= openat(writer
->trace_dir_fd
, filename
->str
,
277 O_RDWR
| O_CREAT
| O_TRUNC
,
278 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
280 g_string_free(filename
, TRUE
);
285 int set_stream_fd(struct bt_ctf_stream
*stream
, int fd
)
289 if (stream
->pos
.fd
!= -1) {
294 ctf_init_pos(&stream
->pos
, NULL
, fd
, O_RDWR
);
300 struct bt_ctf_stream
*bt_ctf_stream_create(
301 struct bt_ctf_stream_class
*stream_class
,
305 struct bt_ctf_stream
*stream
= NULL
;
306 struct bt_ctf_trace
*trace
= NULL
;
307 struct bt_ctf_writer
*writer
= NULL
;
313 trace
= bt_ctf_stream_class_get_trace(stream_class
);
318 stream
= g_new0(struct bt_ctf_stream
, 1);
323 bt_object_init(stream
, bt_ctf_stream_destroy
);
325 * Acquire reference to parent since stream will become publicly
326 * reachable; it needs its parent to remain valid.
328 bt_object_set_parent(stream
, trace
);
329 stream
->id
= stream_class
->next_stream_id
++;
330 stream
->stream_class
= stream_class
;
334 stream
->name
= g_string_new(name
);
340 if (trace
->is_created_by_writer
) {
342 writer
= (struct bt_ctf_writer
*)
343 bt_object_get_parent(trace
);
346 stream
->packet_context
= bt_ctf_field_create(
347 stream_class
->packet_context_type
);
348 if (!stream
->packet_context
) {
352 /* Initialize events_discarded */
353 ret
= set_structure_field_integer(stream
->packet_context
,
354 "events_discarded", 0);
359 stream
->events
= g_ptr_array_new_with_free_func(
360 (GDestroyNotify
) release_event
);
361 if (!stream
->events
) {
365 /* A trace is not allowed to have a NULL packet header */
366 assert(trace
->packet_header_type
);
367 stream
->packet_header
=
368 bt_ctf_field_create(trace
->packet_header_type
);
369 if (!stream
->packet_header
) {
374 * Attempt to populate the default trace packet header fields
375 * (magic, uuid and stream_id). This will _not_ fail shall the
376 * fields not be found or be of an incompatible type; they will
377 * simply not be populated automatically. The user will have to
378 * make sure to set the trace packet header fields himself
381 ret
= set_packet_header(stream
);
386 /* Create file associated with this stream */
387 fd
= create_stream_file(writer
, stream
);
392 ret
= set_stream_fd(stream
, fd
);
397 /* Freeze the writer */
398 bt_ctf_writer_freeze(writer
);
400 /* Non-writer stream indicated by a negative FD */
401 ret
= set_stream_fd(stream
, -1);
406 stream
->clock_values
= g_hash_table_new_full(g_direct_hash
,
407 g_direct_equal
, NULL
, g_free
);
410 /* Add this stream to the trace's streams */
411 g_ptr_array_add(trace
->streams
, stream
);
423 struct bt_ctf_stream_class
*bt_ctf_stream_get_class(
424 struct bt_ctf_stream
*stream
)
426 struct bt_ctf_stream_class
*stream_class
= NULL
;
432 stream_class
= stream
->stream_class
;
433 bt_get(stream_class
);
438 int bt_ctf_stream_get_discarded_events_count(
439 struct bt_ctf_stream
*stream
, uint64_t *count
)
443 struct bt_ctf_field
*events_discarded_field
= NULL
;
444 struct bt_ctf_field_type
*events_discarded_field_type
= NULL
;
446 if (!stream
|| !count
|| !stream
->packet_context
||
447 stream
->pos
.fd
< 0) {
452 events_discarded_field
= bt_ctf_field_structure_get_field(
453 stream
->packet_context
, "events_discarded");
454 if (!events_discarded_field
) {
459 events_discarded_field_type
= bt_ctf_field_get_type(
460 events_discarded_field
);
461 if (!events_discarded_field_type
) {
466 field_signed
= bt_ctf_field_type_integer_get_signed(
467 events_discarded_field_type
);
468 if (field_signed
< 0) {
474 int64_t signed_count
;
476 ret
= bt_ctf_field_signed_integer_get_value(
477 events_discarded_field
, &signed_count
);
481 if (signed_count
< 0) {
486 *count
= (uint64_t) signed_count
;
488 ret
= bt_ctf_field_unsigned_integer_get_value(
489 events_discarded_field
, count
);
495 bt_put(events_discarded_field
);
496 bt_put(events_discarded_field_type
);
500 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream
*stream
,
501 uint64_t event_count
)
505 uint64_t previous_count
;
507 struct bt_ctf_field
*events_discarded_field
= NULL
;
508 struct bt_ctf_field_type
*events_discarded_field_type
= NULL
;
510 if (!stream
|| !stream
->packet_context
|| stream
->pos
.fd
< 0) {
514 ret
= bt_ctf_stream_get_discarded_events_count(stream
,
520 events_discarded_field
= bt_ctf_field_structure_get_field(
521 stream
->packet_context
, "events_discarded");
522 if (!events_discarded_field
) {
526 events_discarded_field_type
= bt_ctf_field_get_type(
527 events_discarded_field
);
528 if (!events_discarded_field_type
) {
532 field_signed
= bt_ctf_field_type_integer_get_signed(
533 events_discarded_field_type
);
534 if (field_signed
< 0) {
538 new_count
= previous_count
+ event_count
;
540 ret
= bt_ctf_field_signed_integer_set_value(
541 events_discarded_field
, (int64_t) new_count
);
546 ret
= bt_ctf_field_unsigned_integer_set_value(
547 events_discarded_field
, new_count
);
554 bt_put(events_discarded_field
);
555 bt_put(events_discarded_field_type
);
558 int bt_ctf_stream_append_event(struct bt_ctf_stream
*stream
,
559 struct bt_ctf_event
*event
)
563 if (!stream
|| !event
|| stream
->pos
.fd
< 0) {
569 * The event is not supposed to have a parent stream at this
570 * point. The only other way an event can have a parent stream
571 * is if it was assigned when setting a packet to the event,
572 * in which case the packet's stream is not a writer stream,
573 * and thus the user is trying to append an event which belongs
576 if (event
->base
.parent
) {
581 bt_object_set_parent(event
, stream
);
582 ret
= bt_ctf_event_populate_event_header(event
);
587 /* Make sure the various scopes of the event are set */
588 ret
= bt_ctf_event_validate(event
);
593 /* Save the new event and freeze it */
594 bt_ctf_event_freeze(event
);
595 g_ptr_array_add(stream
->events
, event
);
598 * Event had to hold a reference to its event class as long as it wasn't
599 * part of the same trace hierarchy. From now on, the event and its
600 * class share the same lifetime guarantees and the reference is no
603 bt_put(event
->event_class
);
610 * Orphan the event; we were not successful in associating it to
613 bt_object_set_parent(event
, NULL
);
618 struct bt_ctf_field
*bt_ctf_stream_get_packet_context(
619 struct bt_ctf_stream
*stream
)
621 struct bt_ctf_field
*packet_context
= NULL
;
623 if (!stream
|| stream
->pos
.fd
< 0) {
627 packet_context
= stream
->packet_context
;
628 if (packet_context
) {
629 bt_get(packet_context
);
632 return packet_context
;
636 int bt_ctf_stream_set_packet_context(struct bt_ctf_stream
*stream
,
637 struct bt_ctf_field
*field
)
640 struct bt_ctf_field_type
*field_type
;
642 if (!stream
|| !field
|| stream
->pos
.fd
< 0) {
647 field_type
= bt_ctf_field_get_type(field
);
648 if (bt_ctf_field_type_compare(field_type
,
649 stream
->stream_class
->packet_context_type
)) {
656 bt_put(stream
->packet_context
);
657 stream
->packet_context
= field
;
663 struct bt_ctf_field
*bt_ctf_stream_get_packet_header(
664 struct bt_ctf_stream
*stream
)
666 struct bt_ctf_field
*packet_header
= NULL
;
668 if (!stream
|| stream
->pos
.fd
< 0) {
672 packet_header
= stream
->packet_header
;
674 bt_get(packet_header
);
677 return packet_header
;
681 int bt_ctf_stream_set_packet_header(struct bt_ctf_stream
*stream
,
682 struct bt_ctf_field
*field
)
685 struct bt_ctf_trace
*trace
= NULL
;
686 struct bt_ctf_field_type
*field_type
= NULL
;
688 if (!stream
|| !field
|| stream
->pos
.fd
< 0) {
693 trace
= (struct bt_ctf_trace
*) bt_object_get_parent(stream
);
694 field_type
= bt_ctf_field_get_type(field
);
695 if (bt_ctf_field_type_compare(field_type
, trace
->packet_header_type
)) {
701 bt_put(stream
->packet_header
);
702 stream
->packet_header
= field
;
710 int get_event_header_timestamp(struct bt_ctf_field
*event_header
, uint64_t *timestamp
)
713 struct bt_ctf_field
*timestamp_field
= NULL
;
714 struct bt_ctf_field_type
*timestamp_field_type
= NULL
;
716 timestamp_field
= bt_ctf_field_structure_get_field(event_header
,
718 if (!timestamp_field
) {
723 timestamp_field_type
= bt_ctf_field_get_type(timestamp_field
);
724 assert(timestamp_field_type
);
725 if (bt_ctf_field_type_get_type_id(timestamp_field_type
) !=
731 if (bt_ctf_field_type_integer_get_signed(timestamp_field_type
)) {
734 ret
= bt_ctf_field_signed_integer_get_value(timestamp_field
,
739 *timestamp
= (uint64_t) val
;
741 ret
= bt_ctf_field_unsigned_integer_get_value(timestamp_field
,
748 bt_put(timestamp_field
);
749 bt_put(timestamp_field_type
);
753 int bt_ctf_stream_flush(struct bt_ctf_stream
*stream
)
757 uint64_t timestamp_begin
, timestamp_end
, events_discarded
;
758 struct bt_ctf_field
*integer
= NULL
;
759 struct ctf_stream_pos packet_context_pos
;
761 if (!stream
|| stream
->pos
.fd
< 0) {
763 * Stream does not have an associated fd. It is,
764 * therefore, not a stream being used to write events.
770 if (!stream
->events
->len
) {
774 ret
= bt_ctf_field_validate(stream
->packet_header
);
779 /* mmap the next packet */
780 ctf_packet_seek(&stream
->pos
.parent
, 0, SEEK_CUR
);
782 ret
= bt_ctf_field_serialize(stream
->packet_header
, &stream
->pos
);
787 /* Set the default context attributes if present and unset. */
788 if (!get_event_header_timestamp(
789 ((struct bt_ctf_event
*) g_ptr_array_index(
790 stream
->events
, 0))->event_header
, ×tamp_begin
)) {
791 ret
= set_structure_field_integer(stream
->packet_context
,
792 "timestamp_begin", timestamp_begin
);
798 if (!get_event_header_timestamp(
799 ((struct bt_ctf_event
*) g_ptr_array_index(
800 stream
->events
, stream
->events
->len
- 1))->event_header
,
803 ret
= set_structure_field_integer(stream
->packet_context
,
804 "timestamp_end", timestamp_end
);
809 ret
= set_structure_field_integer(stream
->packet_context
,
810 "content_size", UINT64_MAX
);
815 ret
= set_structure_field_integer(stream
->packet_context
,
816 "packet_size", UINT64_MAX
);
821 /* Write packet context */
822 memcpy(&packet_context_pos
, &stream
->pos
,
823 sizeof(struct ctf_stream_pos
));
824 ret
= bt_ctf_field_serialize(stream
->packet_context
,
830 ret
= bt_ctf_stream_get_discarded_events_count(stream
,
836 /* Unset the packet context's fields. */
837 ret
= bt_ctf_field_reset(stream
->packet_context
);
842 /* Set the previous number of discarded events. */
843 ret
= set_structure_field_integer(stream
->packet_context
,
844 "events_discarded", events_discarded
);
849 for (i
= 0; i
< stream
->events
->len
; i
++) {
850 struct bt_ctf_event
*event
= g_ptr_array_index(
853 ret
= bt_ctf_field_reset(event
->event_header
);
858 /* Write event header */
859 ret
= bt_ctf_field_serialize(event
->event_header
,
865 /* Write stream event context */
866 if (event
->stream_event_context
) {
867 ret
= bt_ctf_field_serialize(
868 event
->stream_event_context
, &stream
->pos
);
874 /* Write event content */
875 ret
= bt_ctf_event_serialize(event
, &stream
->pos
);
882 * Update the packet total size and content size and overwrite the
884 * Copy base_mma as the packet may have been remapped (e.g. when a
885 * packet is resized).
887 packet_context_pos
.base_mma
= stream
->pos
.base_mma
;
888 ret
= set_structure_field_integer(stream
->packet_context
,
889 "content_size", stream
->pos
.offset
);
894 ret
= set_structure_field_integer(stream
->packet_context
,
895 "packet_size", stream
->pos
.packet_size
);
900 ret
= bt_ctf_field_serialize(stream
->packet_context
,
901 &packet_context_pos
);
906 g_ptr_array_set_size(stream
->events
, 0);
907 stream
->flushed_packet_count
++;
913 void bt_ctf_stream_get(struct bt_ctf_stream
*stream
)
918 void bt_ctf_stream_put(struct bt_ctf_stream
*stream
)
924 void bt_ctf_stream_destroy(struct bt_object
*obj
)
926 struct bt_ctf_stream
*stream
;
928 stream
= container_of(obj
, struct bt_ctf_stream
, base
);
929 ctf_fini_pos(&stream
->pos
);
930 if (stream
->pos
.fd
>= 0 && close(stream
->pos
.fd
)) {
934 if (stream
->events
) {
935 g_ptr_array_free(stream
->events
, TRUE
);
939 g_string_free(stream
->name
, TRUE
);
942 if (stream
->clock_values
) {
943 g_hash_table_destroy(stream
->clock_values
);
946 bt_put(stream
->packet_header
);
947 bt_put(stream
->packet_context
);
952 int set_structure_field_integer(struct bt_ctf_field
*structure
, char *name
,
956 struct bt_ctf_field_type
*field_type
= NULL
;
957 struct bt_ctf_field
*integer
=
958 bt_ctf_field_structure_get_field(structure
, name
);
960 if (!structure
|| !name
) {
966 /* Field not found, not an error. */
970 /* Make sure the payload has not already been set. */
971 if (!bt_ctf_field_validate(integer
)) {
972 /* Payload already set, not an error */
976 field_type
= bt_ctf_field_get_type(integer
);
977 /* Something is serioulsly wrong */
979 if (bt_ctf_field_type_get_type_id(field_type
) != CTF_TYPE_INTEGER
) {
981 * The user most likely meant for us to populate this field
982 * automatically. However, we can only do this if the field
983 * is an integer. Return an error.
989 if (bt_ctf_field_type_integer_get_signed(field_type
)) {
990 ret
= bt_ctf_field_signed_integer_set_value(integer
,
993 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, value
);
1002 const char *bt_ctf_stream_get_name(struct bt_ctf_stream
*stream
)
1004 const char *name
= NULL
;
1010 name
= stream
->name
? stream
->name
->str
: NULL
;
1017 void bt_ctf_stream_update_clock_value(struct bt_ctf_stream
*stream
,
1018 struct bt_ctf_field
*value_field
)
1020 struct bt_ctf_field_type
*value_type
= NULL
;
1021 struct bt_ctf_clock
*clock
= NULL
;
1022 uint64_t requested_new_value
;
1023 uint64_t requested_new_value_mask
;
1024 uint64_t *cur_value
;
1025 uint64_t cur_value_masked
;
1026 int requested_new_value_size
;
1031 assert(value_field
);
1032 value_type
= bt_ctf_field_get_type(value_field
);
1034 clock
= bt_ctf_field_type_integer_get_mapped_clock(value_type
);
1036 requested_new_value_size
=
1037 bt_ctf_field_type_integer_get_size(value_type
);
1038 assert(requested_new_value_size
> 0);
1039 ret
= bt_ctf_field_unsigned_integer_get_value(value_field
,
1040 &requested_new_value
);
1042 cur_value
= g_hash_table_lookup(stream
->clock_values
, clock
);
1046 * Updating the value of a clock which is not registered
1047 * yet, so register it with the new value as its initial
1050 uint64_t *requested_new_value_ptr
= g_new0(uint64_t, 1);
1052 *requested_new_value_ptr
= requested_new_value
;
1053 g_hash_table_insert(stream
->clock_values
, clock
,
1054 requested_new_value_ptr
);
1059 * Special case for a 64-bit new value, which is the limit
1060 * of a clock value as of this version: overwrite the
1061 * current value directly.
1063 if (requested_new_value_size
== 64) {
1064 *cur_value
= requested_new_value
;
1068 requested_new_value_mask
= (1ULL << requested_new_value_size
) - 1;
1069 cur_value_masked
= *cur_value
& requested_new_value_mask
;
1071 if (requested_new_value
< cur_value_masked
) {
1073 * It looks like a wrap happened on the number of bits
1074 * of the requested new value. Assume that the clock
1075 * value wrapped only one time.
1077 *cur_value
+= requested_new_value_mask
+ 1;
1080 /* Clear the low bits of the current clock value */
1081 *cur_value
&= ~requested_new_value_mask
;
1083 /* Set the low bits of the current clock value */
1084 *cur_value
|= requested_new_value
;