| 1 | // SPDX-License-Identifier: BSD-2-Clausecxx . . $ `<file>/src/rtc_thread.c`/ |
| 2 | /* |
| 3 | * Copyright (C) 2020-2025 Linutronix GmbH |
| 4 | * Author Kurt Kanzenbach <[email protected]> |
| 5 | */ |
| 6 | |
| 7 | #include <errno.h> |
| 8 | #include <pthread.h> |
| 9 | #include <signal.h> |
| 10 | #include <stdint.h> |
| 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
| 14 | #include <unistd.h> |
| 15 | |
| 16 | #include <arpa/inet.h> |
| 17 | |
| 18 | #include <linux/if_ether.h> |
| 19 | #include <linux/if_link.h> |
| 20 | #include <linux/if_packet.h> |
| 21 | #include <linux/if_vlan.h> |
| 22 | |
| 23 | #include "config.h"cxx . . $ `<file>/src/config.h`/ |
| 24 | #include "log.h"cxx . . $ `<file>/src/log.h`/ |
| 25 | #include "net.h"cxx . . $ `<file>/src/net.h`/ |
| 26 | #include "packet.h"cxx . . $ `<file>/src/packet.h`/ |
| 27 | #include "rtc_thread.h"cxx . . $ `<file>/src/rtc_thread.h`/ |
| 28 | #include "security.h"cxx . . $ `<file>/src/security.h`/ |
| 29 | #include "stat.h"cxx . . $ `<file>/src/stat.h`/ |
| 30 | #include "thread.h"cxx . . $ `<file>/src/thread.h`/ |
| 31 | #include "utils.h"cxx . . $ `<file>/src/utils.h`/ |
| 32 | #include "xdp.h"cxx . . $ `<file>/src/xdp.h`/ |
| 33 | |
| 34 | static void rtc_initialize_framescxx . . $ rtc_initialize_frames(e1a9c3903a216417).(struct thread_contextcxx . . $ thread_context# *thread_context, unsigned char *frame_data, |
| 35 | size_t num_frames, const unsigned char *source, |
| 36 | const unsigned char *destination) |
| 37 | { |
| 38 | const struct traffic_class_configcxx . . $ traffic_class_config# *rtc_config = thread_context->confcxx . . $ thread_context#conf.; |
| 39 | size_t i; |
| 40 | |
| 41 | for (i = 0; i < num_frames; ++i) { |
| 42 | unsigned char *frame = frame_idxcxx . . $ frame_idx(9d0786fb5198b4b4).(frame_data, i); |
| 43 | size_t frame_length = MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!; |
| 44 | |
| 45 | /* |
| 46 | * In case both AF_XDP and Tx HW Timestamp are enabled the payload starts at: |
| 47 | * frame_data + sizeof(struct xsk_tx_metadata) |
| 48 | */ |
| 49 | #ifdef TX_TIMESTAMP |
| 50 | if (rtc_config->xdp_enabled && rtc_config->tx_hwtstamp_enabled) { |
| 51 | frame += sizeof(struct xsk_tx_metadata); |
| 52 | frame_length -= sizeof(struct xsk_tx_metadata); |
| 53 | } |
| 54 | #endif |
| 55 | |
| 56 | initialize_profinet_framecxx . . $ initialize_profinet_frame(305659cd59e50ce5).(rtc_config->security_modecxx . . $ traffic_class_config#security_mode., frame, frame_length, source, |
| 57 | destination, rtc_config->payload_patterncxx . . $ traffic_class_config#payload_pattern., |
| 58 | rtc_config->payload_pattern_lengthcxx . . $ traffic_class_config#payload_pattern_length., |
| 59 | rtc_config->vidcxx . . $ traffic_class_config#vid. | rtc_config->pcpcxx . . $ traffic_class_config#pcp. << VLAN_PCP_SHIFTcxx . . $ `src/net_def.h:26:9`!, |
| 60 | thread_context->frame_idcxx . . $ thread_context#frame_id.); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | static int rtc_send_messagescxx . . $ rtc_send_messages(1230c857beb98e36).(struct thread_contextcxx . . $ thread_context# *thread_context, int socket_fd, |
| 65 | struct sockaddr_llcxx . . $ sockaddr_ll# *destination, unsigned char *frame_data, |
| 66 | size_t num_frames) |
| 67 | { |
| 68 | const struct traffic_class_configcxx . . $ traffic_class_config# *rtc_config = thread_context->confcxx . . $ thread_context#conf.; |
| 69 | struct packet_send_requestcxx . . $ packet_send_request# send_req = { |
| 70 | .traffic_class = stat_frame_type_to_stringcxx . . $ stat_frame_type_to_string(413bfe925ee921da).(RTC_FRAME_TYPEcxx . . $ RTC_FRAME_TYPE.), |
| 71 | .socket_fd = socket_fd, |
| 72 | .destination = destination, |
| 73 | .frame_data = frame_data, |
| 74 | .num_frames = num_frames, |
| 75 | .frame_length = rtc_config->frame_lengthcxx . . $ traffic_class_config#frame_length., |
| 76 | .duration = 0, |
| 77 | .tx_time_offset = 0, |
| 78 | .meta_data_offset = thread_context->meta_data_offsetcxx . . $ thread_context#meta_data_offset., |
| 79 | .mirror_enabled = rtc_config->rx_mirror_enabledcxx . . $ traffic_class_config#rx_mirror_enabled., |
| 80 | .tx_time_enabled = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, |
| 81 | }; |
| 82 | |
| 83 | return packet_send_messagescxx . . $ packet_send_messages(db4d6f7226235983).(thread_context->packet_contextcxx . . $ thread_context#packet_context., &send_req); |
| 84 | } |
| 85 | |
| 86 | static int rtc_send_framescxx . . $ rtc_send_frames(bbb668e7d71a4c9).(struct thread_contextcxx . . $ thread_context# *thread_context, unsigned char *frame_data, |
| 87 | size_t num_frames, int socket_fd, struct sockaddr_llcxx . . $ sockaddr_ll# *destination) |
| 88 | { |
| 89 | const struct traffic_class_configcxx . . $ traffic_class_config# *rtc_config = thread_context->confcxx . . $ thread_context#conf.; |
| 90 | int len, i; |
| 91 | |
| 92 | /* Send it */ |
| 93 | len = rtc_send_messagescxx . . $ rtc_send_messages(1230c857beb98e36).(thread_context, socket_fd, destination, frame_data, num_frames); |
| 94 | |
| 95 | for (i = 0; i < len; i++) { |
| 96 | uint64_tcxx . . $ uint64_t# sequence_counter; |
| 97 | |
| 98 | sequence_counter = get_sequence_countercxx . . $ get_sequence_counter(9512b04a879eebb0).(frame_data + i * rtc_config->frame_lengthcxx . . $ traffic_class_config#frame_length., |
| 99 | thread_context->meta_data_offsetcxx . . $ thread_context#meta_data_offset., |
| 100 | rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.); |
| 101 | |
| 102 | stat_frame_sentcxx . . $ stat_frame_sent(ca48c151307d73b6).(RTC_FRAME_TYPEcxx . . $ RTC_FRAME_TYPE., sequence_counter); |
| 103 | } |
| 104 | |
| 105 | return len; |
| 106 | } |
| 107 | |
| 108 | static int rtc_gen_and_send_framescxx . . $ rtc_gen_and_send_frames(2a5ba8d4c1205443).(struct thread_contextcxx . . $ thread_context# *thread_context, int socket_fd, |
| 109 | struct sockaddr_llcxx . . $ sockaddr_ll# *destination, uint64_tcxx . . $ uint64_t# sequence_counter_begin) |
| 110 | { |
| 111 | const struct traffic_class_configcxx . . $ traffic_class_config# *rtc_config = thread_context->confcxx . . $ thread_context#conf.; |
| 112 | struct timespeccxx . . $ timespec# tx_time = {}; |
| 113 | int len, i; |
| 114 | |
| 115 | clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., &tx_time); |
| 116 | |
| 117 | for (i = 0; i < rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; i++) { |
| 118 | struct prepare_frame_configcxx . . $ prepare_frame_config# frame_config; |
| 119 | int err; |
| 120 | |
| 121 | frame_config.modecxx . . $ prepare_frame_config#mode. = rtc_config->security_modecxx . . $ traffic_class_config#security_mode.; |
| 122 | frame_config.security_contextcxx . . $ prepare_frame_config#security_context. = thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.; |
| 123 | frame_config.iv_prefixcxx . . $ prepare_frame_config#iv_prefix. = (const unsigned char *)rtc_config->security_iv_prefixcxx . . $ traffic_class_config#security_iv_prefix.; |
| 124 | frame_config.payload_patterncxx . . $ prepare_frame_config#payload_pattern. = thread_context->payload_patterncxx . . $ thread_context#payload_pattern.; |
| 125 | frame_config.payload_pattern_lengthcxx . . $ prepare_frame_config#payload_pattern_length. = thread_context->payload_pattern_lengthcxx . . $ thread_context#payload_pattern_length.; |
| 126 | frame_config.frame_datacxx . . $ prepare_frame_config#frame_data. = frame_idxcxx . . $ frame_idx(9d0786fb5198b4b4).(thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data., i); |
| 127 | frame_config.frame_lengthcxx . . $ prepare_frame_config#frame_length. = rtc_config->frame_lengthcxx . . $ traffic_class_config#frame_length.; |
| 128 | frame_config.num_frames_per_cyclecxx . . $ prepare_frame_config#num_frames_per_cycle. = rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; |
| 129 | frame_config.sequence_countercxx . . $ prepare_frame_config#sequence_counter. = sequence_counter_begin + i; |
| 130 | frame_config.tx_timestampcxx . . $ prepare_frame_config#tx_timestamp. = ts_to_nscxx . . $ ts_to_ns(3d5e857b70563169).(&tx_time); |
| 131 | frame_config.meta_data_offsetcxx . . $ prepare_frame_config#meta_data_offset. = thread_context->meta_data_offsetcxx . . $ thread_context#meta_data_offset.; |
| 132 | |
| 133 | err = prepare_frame_for_txcxx . . $ prepare_frame_for_tx(f7c7fe1588440d5a).(&frame_config); |
| 134 | if (err) |
| 135 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtcTx: Failed to prepare frame for Tx!\n"); |
| 136 | } |
| 137 | |
| 138 | /* Send it */ |
| 139 | len = rtc_send_messagescxx . . $ rtc_send_messages(1230c857beb98e36).(thread_context, socket_fd, destination, |
| 140 | thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data., rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.); |
| 141 | |
| 142 | for (i = 0; i < len; i++) |
| 143 | stat_frame_sentcxx . . $ stat_frame_sent(ca48c151307d73b6).(RTC_FRAME_TYPEcxx . . $ RTC_FRAME_TYPE., sequence_counter_begin + i); |
| 144 | |
| 145 | return len; |
| 146 | } |
| 147 | |
| 148 | static void rtc_gen_and_send_xdp_framescxx . . $ rtc_gen_and_send_xdp_frames(dcf10771cc53a65b).(struct thread_contextcxx . . $ thread_context# *thread_context, |
| 149 | struct xdp_socketcxx . . $ xdp_socket# *xsk, uint64_tcxx . . $ uint64_t# sequence_counter, |
| 150 | uint32_tcxx . . $ uint32_t# *frame_number) |
| 151 | { |
| 152 | const struct traffic_class_configcxx . . $ traffic_class_config# *rtc_config = thread_context->confcxx . . $ thread_context#conf.; |
| 153 | struct xdp_gen_configcxx . . $ xdp_gen_config# xdp; |
| 154 | |
| 155 | xdp.modecxx . . $ xdp_gen_config#mode. = rtc_config->security_modecxx . . $ traffic_class_config#security_mode.; |
| 156 | xdp.security_contextcxx . . $ xdp_gen_config#security_context. = thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.; |
| 157 | xdp.iv_prefixcxx . . $ xdp_gen_config#iv_prefix. = (const unsigned char *)rtc_config->security_iv_prefixcxx . . $ traffic_class_config#security_iv_prefix.; |
| 158 | xdp.payload_patterncxx . . $ xdp_gen_config#payload_pattern. = thread_context->payload_patterncxx . . $ thread_context#payload_pattern.; |
| 159 | xdp.payload_pattern_lengthcxx . . $ xdp_gen_config#payload_pattern_length. = thread_context->payload_pattern_lengthcxx . . $ thread_context#payload_pattern_length.; |
| 160 | xdp.frame_lengthcxx . . $ xdp_gen_config#frame_length. = rtc_config->frame_lengthcxx . . $ traffic_class_config#frame_length.; |
| 161 | xdp.num_frames_per_cyclecxx . . $ xdp_gen_config#num_frames_per_cycle. = rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; |
| 162 | xdp.frame_numbercxx . . $ xdp_gen_config#frame_number. = frame_number; |
| 163 | xdp.sequence_counter_begincxx . . $ xdp_gen_config#sequence_counter_begin. = sequence_counter; |
| 164 | xdp.meta_data_offsetcxx . . $ xdp_gen_config#meta_data_offset. = thread_context->meta_data_offsetcxx . . $ thread_context#meta_data_offset.; |
| 165 | xdp.frame_typecxx . . $ xdp_gen_config#frame_type. = RTC_FRAME_TYPEcxx . . $ RTC_FRAME_TYPE.; |
| 166 | xdp.tx_timecxx . . $ xdp_gen_config#tx_time. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 167 | |
| 168 | xdp_gen_and_send_framescxx . . $ xdp_gen_and_send_frames(312660e902b5d61d).(xsk, &xdp); |
| 169 | } |
| 170 | |
| 171 | static void *rtc_tx_thread_routinecxx . . $ rtc_tx_thread_routine(9f162e79bfc6c74).(void *data) |
| 172 | { |
| 173 | struct thread_contextcxx . . $ thread_context# *thread_context = data; |
| 174 | const struct traffic_class_configcxx . . $ traffic_class_config# *rtc_config = thread_context->confcxx . . $ thread_context#conf.; |
| 175 | size_t received_frames_length = MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`! * rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; |
| 176 | struct security_contextcxx . . $ security_context# *security_context = thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.; |
| 177 | const uint64_tcxx . . $ uint64_t# cycle_time_ns = app_configcxx . . $ app_config..application_base_cycle_time_nscxx . . $ application_config#application_base_cycle_time_ns.; |
| 178 | unsigned char *received_frames = thread_context->rx_frame_datacxx . . $ thread_context#rx_frame_data.; |
| 179 | const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mirror_enabled = rtc_config->rx_mirror_enabledcxx . . $ traffic_class_config#rx_mirror_enabled.; |
| 180 | struct sockaddr_llcxx . . $ sockaddr_ll# destination; |
| 181 | unsigned char source[ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!]; |
| 182 | uint64_tcxx . . $ uint64_t# sequence_counter = 0; |
| 183 | struct timespeccxx . . $ timespec# wakeup_time; |
| 184 | unsigned int if_index; |
| 185 | int ret, socket_fd; |
| 186 | |
| 187 | socket_fd = thread_context->socket_fdcxx . . $ thread_context#socket_fd.; |
| 188 | |
| 189 | ret = get_interface_mac_addresscxx . . $ get_interface_mac_address(6007bd5416c53f30).(rtc_config->interfacecxx . . $ traffic_class_config#interface., source, ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 190 | if (ret < 0) { |
| 191 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtcTx: Failed to get Source MAC address!\n"); |
| 192 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 193 | } |
| 194 | |
| 195 | if_index = if_nametoindexcxx . . $ if_nametoindex(c61c63047ce273de).(rtc_config->interfacecxx . . $ traffic_class_config#interface.); |
| 196 | if (!if_index) { |
| 197 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtcTx: if_nametoindex() failed!\n"); |
| 198 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 199 | } |
| 200 | |
| 201 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&destination, '\0', sizeof(destination)); |
| 202 | destination.sll_familycxx . . $ sockaddr_ll#sll_family. = PF_PACKETcxx . . $ `<external>/8962547315054503424/socket.h:61:9`!; |
| 203 | destination.sll_ifindexcxx . . $ sockaddr_ll#sll_ifindex. = if_index; |
| 204 | destination.sll_halencxx . . $ sockaddr_ll#sll_halen. = ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!; |
| 205 | memcpycxx . . $ memcpy(cc817cb175f282d).(destination.sll_addrcxx . . $ sockaddr_ll#sll_addr., rtc_config->l2_destinationcxx . . $ traffic_class_config#l2_destination., ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 206 | |
| 207 | rtc_initialize_framescxx . . $ rtc_initialize_frames(e1a9c3903a216417).(thread_context, thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data., |
| 208 | rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle., source, rtc_config->l2_destinationcxx . . $ traffic_class_config#l2_destination.); |
| 209 | |
| 210 | prepare_opensslcxx . . $ prepare_openssl(180fdc1b6a791d79).(security_context); |
| 211 | rtc_initialize_framescxx . . $ rtc_initialize_frames(e1a9c3903a216417).(thread_context, thread_context->payload_patterncxx . . $ thread_context#payload_pattern., 1, source, |
| 212 | rtc_config->l2_destinationcxx . . $ traffic_class_config#l2_destination.); |
| 213 | thread_context->payload_patterncxx . . $ thread_context#payload_pattern. += |
| 214 | sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) + sizeof(struct profinet_secure_headercxx . . $ profinet_secure_header#); |
| 215 | thread_context->payload_pattern_lengthcxx . . $ thread_context#payload_pattern_length. = |
| 216 | rtc_config->frame_lengthcxx . . $ traffic_class_config#frame_length. - sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) - |
| 217 | sizeof(struct profinet_secure_headercxx . . $ profinet_secure_header#) - sizeof(struct security_checksumcxx . . $ security_checksum#); |
| 218 | |
| 219 | ret = get_thread_start_timecxx . . $ get_thread_start_time(72e9d11157e5bc5a).(app_configcxx . . $ app_config..application_tx_base_offset_nscxx . . $ application_config#application_tx_base_offset_ns., &wakeup_time); |
| 220 | if (ret) { |
| 221 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtcTx: Failed to calculate thread start time: %s!\n", |
| 222 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 223 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 224 | } |
| 225 | |
| 226 | while (!thread_context->stopcxx . . $ thread_context#stop.) { |
| 227 | if (!thread_context->is_firstcxx . . $ thread_context#is_first.) { |
| 228 | struct timespeccxx . . $ timespec# timeout; |
| 229 | |
| 230 | /* |
| 231 | * Wait until signalled. These RTC frames have to be sent after the TSN Low |
| 232 | * frames. |
| 233 | */ |
| 234 | clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(CLOCK_MONOTONICcxx . . $ `<external>/89459239771508533/time.h:48:10`!, &timeout); |
| 235 | timeout.tv_seccxx . . $ timespec#tv_sec.++; |
| 236 | |
| 237 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&thread_context->data_mutexcxx . . $ thread_context#data_mutex.); |
| 238 | ret = pthread_cond_timedwaitcxx . . $ pthread_cond_timedwait(d8fcb9edac03ad51).(&thread_context->data_cond_varcxx . . $ thread_context#data_cond_var., |
| 239 | &thread_context->data_mutexcxx . . $ thread_context#data_mutex., &timeout); |
| 240 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&thread_context->data_mutexcxx . . $ thread_context#data_mutex.); |
| 241 | |
| 242 | /* In case of shutdown a signal may be missing. */ |
| 243 | if (ret == ETIMEDOUTcxx . . $ `<external>/17922322188510340118/errno.h:94:9`!) |
| 244 | continue; |
| 245 | } else { |
| 246 | /* Wait until next period */ |
| 247 | increment_periodcxx . . $ increment_period(4d7c74d32dea27cd).(&wakeup_time, cycle_time_ns); |
| 248 | |
| 249 | do { |
| 250 | ret = clock_nanosleepcxx . . $ clock_nanosleep(99dc002056e22615).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., |
| 251 | TIMER_ABSTIMEcxx . . $ `<external>/89459239771508533/time.h:69:10`!, &wakeup_time, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 252 | } while (ret == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!); |
| 253 | |
| 254 | if (ret) { |
| 255 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., |
| 256 | "RtcTx: clock_nanosleep() failed: %s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(ret)); |
| 257 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Send RtcFrames, two possibilites: |
| 263 | * a) Generate it, or |
| 264 | * b) Use received ones if mirror enabled |
| 265 | */ |
| 266 | if (!mirror_enabled) { |
| 267 | rtc_gen_and_send_framescxx . . $ rtc_gen_and_send_frames(2a5ba8d4c1205443).(thread_context, socket_fd, &destination, |
| 268 | sequence_counter); |
| 269 | |
| 270 | sequence_counter += rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; |
| 271 | } else { |
| 272 | size_t len, num_frames; |
| 273 | |
| 274 | ring_buffer_fetchcxx . . $ ring_buffer_fetch(e8bf408057bf6314).(thread_context->mirror_buffercxx . . $ thread_context#mirror_buffer., received_frames, |
| 275 | received_frames_length, &len); |
| 276 | |
| 277 | /* Len should be a multiple of frame size */ |
| 278 | num_frames = len / rtc_config->frame_lengthcxx . . $ traffic_class_config#frame_length.; |
| 279 | rtc_send_framescxx . . $ rtc_send_frames(bbb668e7d71a4c9).(thread_context, received_frames, num_frames, socket_fd, |
| 280 | &destination); |
| 281 | } |
| 282 | |
| 283 | /* Signal next Tx thread */ |
| 284 | if (thread_context->nextcxx . . $ thread_context#next.) { |
| 285 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&thread_context->nextcxx . . $ thread_context#next.->data_mutexcxx . . $ thread_context#data_mutex.); |
| 286 | pthread_cond_signalcxx . . $ pthread_cond_signal(98095c34a2b0149d).(&thread_context->nextcxx . . $ thread_context#next.->data_cond_varcxx . . $ thread_context#data_cond_var.); |
| 287 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&thread_context->nextcxx . . $ thread_context#next.->data_mutexcxx . . $ thread_context#data_mutex.); |
| 288 | } |
| 289 | |
| 290 | if (thread_context->is_lastcxx . . $ thread_context#is_last.) |
| 291 | stat_updatecxx . . $ stat_update(49f6e7a06ebc5aa8).(); |
| 292 | } |
| 293 | |
| 294 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * This Tx thread routine differs to the standard one in terms of the sending interface. This one |
| 299 | * uses the AF_XDP user space interface. |
| 300 | */ |
| 301 | static void *rtc_xdp_tx_thread_routinecxx . . $ rtc_xdp_tx_thread_routine(9f162e79bfc6c74).(void *data) |
| 302 | { |
| 303 | struct thread_contextcxx . . $ thread_context# *thread_context = data; |
| 304 | const struct traffic_class_configcxx . . $ traffic_class_config# *rtc_config = thread_context->confcxx . . $ thread_context#conf.; |
| 305 | struct security_contextcxx . . $ security_context# *security_context = thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.; |
| 306 | const uint64_tcxx . . $ uint64_t# cycle_time_ns = app_configcxx . . $ app_config..application_base_cycle_time_nscxx . . $ application_config#application_base_cycle_time_ns.; |
| 307 | const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mirror_enabled = rtc_config->rx_mirror_enabledcxx . . $ traffic_class_config#rx_mirror_enabled.; |
| 308 | uint32_tcxx . . $ uint32_t# frame_number = XSK_RING_PROD__DEFAULT_NUM_DESCScxx . . $ `src/xdp.h:30:9`!; |
| 309 | const size_t num_frames = rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; |
| 310 | unsigned char source[ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!]; |
| 311 | uint64_tcxx . . $ uint64_t# sequence_counter = 0; |
| 312 | struct timespeccxx . . $ timespec# wakeup_time; |
| 313 | unsigned char *frame_data; |
| 314 | struct xdp_socketcxx . . $ xdp_socket# *xsk; |
| 315 | int ret; |
| 316 | |
| 317 | xsk = thread_context->xskcxx . . $ thread_context#xsk.; |
| 318 | xsk->tx_hwtscxx . . $ xdp_socket#tx_hwts..rttcxx . . $ xdp_tx_hwts#rtt. = &round_trip_contextscxx . . $ round_trip_contexts.[RTC_FRAME_TYPEcxx . . $ RTC_FRAME_TYPE.]; |
| 319 | xsk->tx_hwtscxx . . $ xdp_socket#tx_hwts..frames_per_cyclecxx . . $ xdp_tx_hwts#frames_per_cycle. = rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; |
| 320 | |
| 321 | ret = get_interface_mac_addresscxx . . $ get_interface_mac_address(6007bd5416c53f30).(rtc_config->interfacecxx . . $ traffic_class_config#interface., source, ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 322 | if (ret < 0) { |
| 323 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtcTx: Failed to get Source MAC address!\n"); |
| 324 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 325 | } |
| 326 | |
| 327 | /* First half of umem area is for Rx, the second half is for Tx. */ |
| 328 | frame_data = xsk_umem__get_datacxx . . $ xsk_umem__get_data(c096771c57425568).(xsk->umemcxx . . $ xdp_socket#umem..buffercxx . . $ xsk_umem_info#buffer., |
| 329 | XDP_FRAME_SIZEcxx . . $ `src/xdp.h:34:9`! * XSK_RING_PROD__DEFAULT_NUM_DESCScxx . . $ `src/xdp.h:30:9`!); |
| 330 | |
| 331 | /* Initialize all Tx frames */ |
| 332 | rtc_initialize_framescxx . . $ rtc_initialize_frames(e1a9c3903a216417).(thread_context, frame_data, XSK_RING_CONS__DEFAULT_NUM_DESCScxx . . $ `src/xdp.h:29:9`!, source, |
| 333 | rtc_config->l2_destinationcxx . . $ traffic_class_config#l2_destination.); |
| 334 | |
| 335 | prepare_opensslcxx . . $ prepare_openssl(180fdc1b6a791d79).(security_context); |
| 336 | rtc_initialize_framescxx . . $ rtc_initialize_frames(e1a9c3903a216417).(thread_context, thread_context->payload_patterncxx . . $ thread_context#payload_pattern., 1, source, |
| 337 | rtc_config->l2_destinationcxx . . $ traffic_class_config#l2_destination.); |
| 338 | thread_context->payload_patterncxx . . $ thread_context#payload_pattern. += |
| 339 | sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) + sizeof(struct profinet_secure_headercxx . . $ profinet_secure_header#); |
| 340 | thread_context->payload_pattern_lengthcxx . . $ thread_context#payload_pattern_length. = |
| 341 | rtc_config->frame_lengthcxx . . $ traffic_class_config#frame_length. - sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) - |
| 342 | sizeof(struct profinet_secure_headercxx . . $ profinet_secure_header#) - sizeof(struct security_checksumcxx . . $ security_checksum#); |
| 343 | |
| 344 | ret = get_thread_start_timecxx . . $ get_thread_start_time(72e9d11157e5bc5a).(app_configcxx . . $ app_config..application_tx_base_offset_nscxx . . $ application_config#application_tx_base_offset_ns., &wakeup_time); |
| 345 | if (ret) { |
| 346 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtcTx: Failed to calculate thread start time: %s!\n", |
| 347 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 348 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 349 | } |
| 350 | |
| 351 | while (!thread_context->stopcxx . . $ thread_context#stop.) { |
| 352 | if (!thread_context->is_firstcxx . . $ thread_context#is_first.) { |
| 353 | struct timespeccxx . . $ timespec# timeout; |
| 354 | |
| 355 | /* |
| 356 | * Wait until signalled. These RTC frames have to be sent after the TSN Low |
| 357 | * frames. |
| 358 | */ |
| 359 | clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(CLOCK_MONOTONICcxx . . $ `<external>/89459239771508533/time.h:48:10`!, &timeout); |
| 360 | timeout.tv_seccxx . . $ timespec#tv_sec.++; |
| 361 | |
| 362 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&thread_context->data_mutexcxx . . $ thread_context#data_mutex.); |
| 363 | ret = pthread_cond_timedwaitcxx . . $ pthread_cond_timedwait(d8fcb9edac03ad51).(&thread_context->data_cond_varcxx . . $ thread_context#data_cond_var., |
| 364 | &thread_context->data_mutexcxx . . $ thread_context#data_mutex., &timeout); |
| 365 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&thread_context->data_mutexcxx . . $ thread_context#data_mutex.); |
| 366 | |
| 367 | /* In case of shutdown a signal may be missing. */ |
| 368 | if (ret == ETIMEDOUTcxx . . $ `<external>/17922322188510340118/errno.h:94:9`!) |
| 369 | continue; |
| 370 | } else { |
| 371 | /* Wait until next period */ |
| 372 | increment_periodcxx . . $ increment_period(4d7c74d32dea27cd).(&wakeup_time, cycle_time_ns); |
| 373 | |
| 374 | do { |
| 375 | ret = clock_nanosleepcxx . . $ clock_nanosleep(99dc002056e22615).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., |
| 376 | TIMER_ABSTIMEcxx . . $ `<external>/89459239771508533/time.h:69:10`!, &wakeup_time, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 377 | } while (ret == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!); |
| 378 | |
| 379 | if (ret) { |
| 380 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., |
| 381 | "RtcTx: clock_nanosleep() failed: %s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(ret)); |
| 382 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | /* |
| 387 | * Send RtcFrames, two possibilites: |
| 388 | * a) Generate it, or |
| 389 | * b) Use received ones if mirror enabled |
| 390 | */ |
| 391 | if (!mirror_enabled) { |
| 392 | rtc_gen_and_send_xdp_framescxx . . $ rtc_gen_and_send_xdp_frames(dcf10771cc53a65b).(thread_context, xsk, sequence_counter, |
| 393 | &frame_number); |
| 394 | sequence_counter += num_frames; |
| 395 | } else { |
| 396 | unsigned int received; |
| 397 | uint64_tcxx . . $ uint64_t# i; |
| 398 | |
| 399 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&thread_context->xdp_data_mutexcxx . . $ thread_context#xdp_data_mutex.); |
| 400 | |
| 401 | received = thread_context->received_framescxx . . $ thread_context#received_frames.; |
| 402 | |
| 403 | sequence_counter = thread_context->rx_sequence_countercxx . . $ thread_context#rx_sequence_counter. - received; |
| 404 | |
| 405 | /* |
| 406 | * The XDP receiver stored the frames within the umem area and populated the |
| 407 | * Tx ring. Now, the Tx ring can be committed to the kernel. Furthermore, |
| 408 | * already transmitted frames from last cycle can be recycled for Rx. |
| 409 | */ |
| 410 | |
| 411 | xsk_ring_prod__submitcxx . . $ xsk_ring_prod__submit(9991f52d60245542).(&xsk->txcxx . . $ xdp_socket#tx., received); |
| 412 | |
| 413 | if (received > 0) { |
| 414 | if (rtc_config->tx_hwtstamp_enabledcxx . . $ traffic_class_config#tx_hwtstamp_enabled.) { |
| 415 | /* |
| 416 | * Once-per-cycle: record TX SW timestamp for the first |
| 417 | * packet in this cycle and count all frames |
| 418 | */ |
| 419 | stat_frames_sent_batchcxx . . $ stat_frames_sent_batch(1b9110cae93061b5).(RTC_FRAME_TYPEcxx . . $ RTC_FRAME_TYPE., sequence_counter, |
| 420 | received); |
| 421 | } else { |
| 422 | for (i = sequence_counter; i < sequence_counter + received; |
| 423 | ++i) |
| 424 | stat_frame_sentcxx . . $ stat_frame_sent(ca48c151307d73b6).(RTC_FRAME_TYPEcxx . . $ RTC_FRAME_TYPE., i); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | xsk->outstanding_txcxx . . $ xdp_socket#outstanding_tx. += received; |
| 429 | thread_context->received_framescxx . . $ thread_context#received_frames. = 0; |
| 430 | xdp_complete_txcxx . . $ xdp_complete_tx(5f53ef6b518fdd5d).(xsk); |
| 431 | |
| 432 | #ifdef TX_TIMESTAMP |
| 433 | if (received > 0 && rtc_config->tx_hwtstamp_enabled) { |
| 434 | /* |
| 435 | * TX HW timestamp becomes available in the next cycle |
| 436 | * after the packet is transmitted. |
| 437 | * This is one cycle later than SW timestamp tracked |
| 438 | * using sequence_counter |
| 439 | */ |
| 440 | xsk->tx_hwts.seq_lagged = sequence_counter; |
| 441 | } |
| 442 | #endif |
| 443 | |
| 444 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&thread_context->xdp_data_mutexcxx . . $ thread_context#xdp_data_mutex.); |
| 445 | } |
| 446 | |
| 447 | /* Signal next Tx thread */ |
| 448 | if (thread_context->nextcxx . . $ thread_context#next.) { |
| 449 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&thread_context->nextcxx . . $ thread_context#next.->data_mutexcxx . . $ thread_context#data_mutex.); |
| 450 | pthread_cond_signalcxx . . $ pthread_cond_signal(98095c34a2b0149d).(&thread_context->nextcxx . . $ thread_context#next.->data_cond_varcxx . . $ thread_context#data_cond_var.); |
| 451 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&thread_context->nextcxx . . $ thread_context#next.->data_mutexcxx . . $ thread_context#data_mutex.); |
| 452 | } |
| 453 | |
| 454 | if (thread_context->is_lastcxx . . $ thread_context#is_last.) |
| 455 | stat_updatecxx . . $ stat_update(49f6e7a06ebc5aa8).(); |
| 456 | } |
| 457 | |
| 458 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 459 | } |
| 460 | |
| 461 | static void *rtc_rx_thread_routinecxx . . $ rtc_rx_thread_routine(9f162e79bfc6c74).(void *data) |
| 462 | { |
| 463 | struct thread_contextcxx . . $ thread_context# *thread_context = data; |
| 464 | const uint64_tcxx . . $ uint64_t# cycle_time_ns = app_configcxx . . $ app_config..application_base_cycle_time_nscxx . . $ application_config#application_base_cycle_time_ns.; |
| 465 | struct timespeccxx . . $ timespec# wakeup_time; |
| 466 | int socket_fd, ret; |
| 467 | |
| 468 | socket_fd = thread_context->socket_fdcxx . . $ thread_context#socket_fd.; |
| 469 | |
| 470 | prepare_opensslcxx . . $ prepare_openssl(180fdc1b6a791d79).(thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context.); |
| 471 | |
| 472 | ret = get_thread_start_timecxx . . $ get_thread_start_time(72e9d11157e5bc5a).(app_configcxx . . $ app_config..application_rx_base_offset_nscxx . . $ application_config#application_rx_base_offset_ns., &wakeup_time); |
| 473 | if (ret) { |
| 474 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtcRx: Failed to calculate thread start time: %s!\n", |
| 475 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 476 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 477 | } |
| 478 | |
| 479 | while (!thread_context->stopcxx . . $ thread_context#stop.) { |
| 480 | struct packet_receive_requestcxx . . $ packet_receive_request# recv_req = { |
| 481 | .traffic_class = thread_context->traffic_classcxx . . $ thread_context#traffic_class., |
| 482 | .socket_fd = socket_fd, |
| 483 | .receive_function = receive_profinet_framecxx . . $ receive_profinet_frame(ddfd8079f1f43689)., |
| 484 | .data = thread_context, |
| 485 | }; |
| 486 | |
| 487 | /* Wait until next period. */ |
| 488 | increment_periodcxx . . $ increment_period(4d7c74d32dea27cd).(&wakeup_time, cycle_time_ns); |
| 489 | |
| 490 | do { |
| 491 | ret = clock_nanosleepcxx . . $ clock_nanosleep(99dc002056e22615).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., TIMER_ABSTIMEcxx . . $ `<external>/89459239771508533/time.h:69:10`!, |
| 492 | &wakeup_time, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 493 | } while (ret == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!); |
| 494 | |
| 495 | if (ret) { |
| 496 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtcRx: clock_nanosleep() failed: %s\n", |
| 497 | strerrorcxx . . $ strerror(ff224f080444ee45).(ret)); |
| 498 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 499 | } |
| 500 | |
| 501 | /* Receive Rtc frames. */ |
| 502 | packet_receive_messagescxx . . $ packet_receive_messages(dec9d97ca532b11c).(thread_context->packet_contextcxx . . $ thread_context#packet_context., &recv_req); |
| 503 | } |
| 504 | |
| 505 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 506 | } |
| 507 | |
| 508 | static void *rtc_xdp_rx_thread_routinecxx . . $ rtc_xdp_rx_thread_routine(9f162e79bfc6c74).(void *data) |
| 509 | { |
| 510 | struct thread_contextcxx . . $ thread_context# *thread_context = data; |
| 511 | const long long cycle_time_ns = app_configcxx . . $ app_config..application_base_cycle_time_nscxx . . $ application_config#application_base_cycle_time_ns.; |
| 512 | const struct traffic_class_configcxx . . $ traffic_class_config# *rtc_config = thread_context->confcxx . . $ thread_context#conf.; |
| 513 | const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mirror_enabled = rtc_config->rx_mirror_enabledcxx . . $ traffic_class_config#rx_mirror_enabled.; |
| 514 | const size_t frame_length = rtc_config->frame_lengthcxx . . $ traffic_class_config#frame_length.; |
| 515 | struct xdp_socketcxx . . $ xdp_socket# *xsk = thread_context->xskcxx . . $ thread_context#xsk.; |
| 516 | struct timespeccxx . . $ timespec# wakeup_time; |
| 517 | int ret; |
| 518 | |
| 519 | prepare_opensslcxx . . $ prepare_openssl(180fdc1b6a791d79).(thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context.); |
| 520 | |
| 521 | ret = get_thread_start_timecxx . . $ get_thread_start_time(72e9d11157e5bc5a).(app_configcxx . . $ app_config..application_rx_base_offset_nscxx . . $ application_config#application_rx_base_offset_ns., &wakeup_time); |
| 522 | if (ret) { |
| 523 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtcRx: Failed to calculate thread start time: %s!\n", |
| 524 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 525 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 526 | } |
| 527 | |
| 528 | while (!thread_context->stopcxx . . $ thread_context#stop.) { |
| 529 | unsigned int received; |
| 530 | |
| 531 | /* Wait until next period */ |
| 532 | increment_periodcxx . . $ increment_period(4d7c74d32dea27cd).(&wakeup_time, cycle_time_ns); |
| 533 | |
| 534 | do { |
| 535 | ret = clock_nanosleepcxx . . $ clock_nanosleep(99dc002056e22615).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., TIMER_ABSTIMEcxx . . $ `<external>/89459239771508533/time.h:69:10`!, |
| 536 | &wakeup_time, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 537 | } while (ret == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!); |
| 538 | |
| 539 | if (ret) { |
| 540 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtcRx: clock_nanosleep() failed: %s\n", |
| 541 | strerrorcxx . . $ strerror(ff224f080444ee45).(ret)); |
| 542 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 543 | } |
| 544 | |
| 545 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&thread_context->xdp_data_mutexcxx . . $ thread_context#xdp_data_mutex.); |
| 546 | received = xdp_receive_framescxx . . $ xdp_receive_frames(a8ae63e30c683a9b).(xsk, frame_length, mirror_enabled, |
| 547 | receive_profinet_framecxx . . $ receive_profinet_frame(ddfd8079f1f43689)., thread_context, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 548 | thread_context->received_framescxx . . $ thread_context#received_frames. = received; |
| 549 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&thread_context->xdp_data_mutexcxx . . $ thread_context#xdp_data_mutex.); |
| 550 | } |
| 551 | |
| 552 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 553 | } |
| 554 | |
| 555 | int rtc_threads_createcxx . . $ rtc_threads_create(8542e1c024f3ff56).(struct thread_contextcxx . . $ thread_context# *thread_context) |
| 556 | { |
| 557 | struct traffic_class_configcxx . . $ traffic_class_config# *rtc_config; |
| 558 | int ret; |
| 559 | |
| 560 | if (!config_is_traffic_class_activecxx . . $ config_is_traffic_class_active(c5f7da30cbc0f4e9).("Rtc")) |
| 561 | goto out; |
| 562 | |
| 563 | init_mutexcxx . . $ init_mutex(4f83bfebf4bb9c8b).(&thread_context->data_mutexcxx . . $ thread_context#data_mutex.); |
| 564 | init_mutexcxx . . $ init_mutex(4f83bfebf4bb9c8b).(&thread_context->xdp_data_mutexcxx . . $ thread_context#xdp_data_mutex.); |
| 565 | init_condition_variablecxx . . $ init_condition_variable(23b56462c1e1452f).(&thread_context->data_cond_varcxx . . $ thread_context#data_cond_var.); |
| 566 | |
| 567 | thread_context->confcxx . . $ thread_context#conf. = rtc_config = &app_configcxx . . $ app_config..classescxx . . $ application_config#classes.[RTC_FRAME_TYPEcxx . . $ RTC_FRAME_TYPE.]; |
| 568 | thread_context->frame_typecxx . . $ thread_context#frame_type. = RTC_FRAME_TYPEcxx . . $ RTC_FRAME_TYPE.; |
| 569 | thread_context->traffic_classcxx . . $ thread_context#traffic_class. = stat_frame_type_to_stringcxx . . $ stat_frame_type_to_string(413bfe925ee921da).(RTC_FRAME_TYPEcxx . . $ RTC_FRAME_TYPE.); |
| 570 | thread_context->frame_idcxx . . $ thread_context#frame_id. = |
| 571 | rtc_config->security_modecxx . . $ traffic_class_config#security_mode. == SECURITY_MODE_NONEcxx . . $ SECURITY_MODE_NONE. ? RTC_FRAMEIDcxx . . $ `src/net_def.h:45:9`! : RTC_SEC_FRAMEIDcxx . . $ `src/net_def.h:46:9`!; |
| 572 | |
| 573 | /* For XDP the frames are stored in a umem area. That memory is part of the socket. */ |
| 574 | if (!rtc_config->xdp_enabledcxx . . $ traffic_class_config#xdp_enabled.) { |
| 575 | thread_context->packet_contextcxx . . $ thread_context#packet_context. = packet_initcxx . . $ packet_init(6f6262789a319935).(rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.); |
| 576 | if (!thread_context->packet_contextcxx . . $ thread_context#packet_context.) { |
| 577 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to allocate Rtc packet context!\n"); |
| 578 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 579 | goto err_packet; |
| 580 | } |
| 581 | |
| 582 | thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data. = |
| 583 | calloccxx . . $ calloc(63a7bf2941bfcd7a).(rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle., MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!); |
| 584 | if (!thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data.) { |
| 585 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to allocate RtcTxFrameData!\n"); |
| 586 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 587 | goto err_tx; |
| 588 | } |
| 589 | |
| 590 | thread_context->rx_frame_datacxx . . $ thread_context#rx_frame_data. = |
| 591 | calloccxx . . $ calloc(63a7bf2941bfcd7a).(rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle., MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!); |
| 592 | if (!thread_context->rx_frame_datacxx . . $ thread_context#rx_frame_data.) { |
| 593 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to allocate RtcRxFrameData!\n"); |
| 594 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 595 | goto err_rx; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | thread_context->payload_patterncxx . . $ thread_context#payload_pattern. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!); |
| 600 | if (!thread_context->payload_patterncxx . . $ thread_context#payload_pattern.) { |
| 601 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to allocate RtcPayloadPattern!\n"); |
| 602 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 603 | goto err_payload; |
| 604 | } |
| 605 | thread_context->payload_pattern_lengthcxx . . $ thread_context#payload_pattern_length. = MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!; |
| 606 | |
| 607 | /* For XDP a AF_XDP socket is allocated. Otherwise a Linux raw socket is used. */ |
| 608 | if (rtc_config->xdp_enabledcxx . . $ traffic_class_config#xdp_enabled.) { |
| 609 | thread_context->socket_fdcxx . . $ thread_context#socket_fd. = 0; |
| 610 | thread_context->xskcxx . . $ thread_context#xsk. = xdp_open_socketcxx . . $ xdp_open_socket(ec858eaaf043e631).( |
| 611 | rtc_config->interfacecxx . . $ traffic_class_config#interface., app_configcxx . . $ app_config..application_xdp_programcxx . . $ application_config#application_xdp_program., |
| 612 | rtc_config->rx_queuecxx . . $ traffic_class_config#rx_queue., rtc_config->xdp_skb_modecxx . . $ traffic_class_config#xdp_skb_mode., rtc_config->xdp_zc_modecxx . . $ traffic_class_config#xdp_zc_mode., |
| 613 | rtc_config->xdp_wakeup_modecxx . . $ traffic_class_config#xdp_wakeup_mode., rtc_config->xdp_busy_poll_modecxx . . $ traffic_class_config#xdp_busy_poll_mode., falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, |
| 614 | rtc_config->tx_hwtstamp_enabledcxx . . $ traffic_class_config#tx_hwtstamp_enabled.); |
| 615 | if (!thread_context->xskcxx . . $ thread_context#xsk.) { |
| 616 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to create Rtc Xdp socket!\n"); |
| 617 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 618 | goto err_socket; |
| 619 | } |
| 620 | } else { |
| 621 | thread_context->xskcxx . . $ thread_context#xsk. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 622 | thread_context->socket_fdcxx . . $ thread_context#socket_fd. = create_rtc_socketcxx . . $ create_rtc_socket(b126dc7c1de90089).(); |
| 623 | if (thread_context->socket_fdcxx . . $ thread_context#socket_fd. < 0) { |
| 624 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to create RtcSocket!\n"); |
| 625 | ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 626 | goto err_socket; |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | /* Same as above. For XDP the umem area is used. */ |
| 631 | if (rtc_config->rx_mirror_enabledcxx . . $ traffic_class_config#rx_mirror_enabled. && !rtc_config->xdp_enabledcxx . . $ traffic_class_config#xdp_enabled.) { |
| 632 | /* Per period the expectation is: RtcNumFramesPerCycle * MAX_FRAME */ |
| 633 | thread_context->mirror_buffercxx . . $ thread_context#mirror_buffer. = |
| 634 | ring_buffer_allocatecxx . . $ ring_buffer_allocate(a00a27d6b402ebff).(MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`! * rtc_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.); |
| 635 | if (!thread_context->mirror_buffercxx . . $ thread_context#mirror_buffer.) { |
| 636 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to allocate Rtc Mirror RingBuffer!\n"); |
| 637 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 638 | goto err_thread; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | if (rtc_config->security_modecxx . . $ traffic_class_config#security_mode. != SECURITY_MODE_NONEcxx . . $ SECURITY_MODE_NONE.) { |
| 643 | thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context. = security_initcxx . . $ security_init(5357658aae651c5a).( |
| 644 | rtc_config->security_algorithmcxx . . $ traffic_class_config#security_algorithm., (unsigned char *)rtc_config->security_keycxx . . $ traffic_class_config#security_key.); |
| 645 | if (!thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.) { |
| 646 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to initialize Tx security context!\n"); |
| 647 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 648 | goto err_tx_sec; |
| 649 | } |
| 650 | |
| 651 | thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context. = security_initcxx . . $ security_init(5357658aae651c5a).( |
| 652 | rtc_config->security_algorithmcxx . . $ traffic_class_config#security_algorithm., (unsigned char *)rtc_config->security_keycxx . . $ traffic_class_config#security_key.); |
| 653 | if (!thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context.) { |
| 654 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to initialize Rx security context!\n"); |
| 655 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 656 | goto err_rx_sec; |
| 657 | } |
| 658 | } else { |
| 659 | thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 660 | thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 661 | } |
| 662 | |
| 663 | ret = create_rt_threadcxx . . $ create_rt_thread(670ec5a211ade64c).(&thread_context->tx_task_idcxx . . $ thread_context#tx_task_id., "RtcTxThread", |
| 664 | rtc_config->tx_thread_prioritycxx . . $ traffic_class_config#tx_thread_priority., rtc_config->tx_thread_cpucxx . . $ traffic_class_config#tx_thread_cpu., |
| 665 | rtc_config->xdp_enabledcxx . . $ traffic_class_config#xdp_enabled. ? rtc_xdp_tx_thread_routinecxx . . $ rtc_xdp_tx_thread_routine(9f162e79bfc6c74). |
| 666 | : rtc_tx_thread_routinecxx . . $ rtc_tx_thread_routine(9f162e79bfc6c74)., |
| 667 | thread_context); |
| 668 | if (ret) { |
| 669 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to create Rtc Tx thread!\n"); |
| 670 | goto err_thread_create1; |
| 671 | } |
| 672 | |
| 673 | ret = create_rt_threadcxx . . $ create_rt_thread(670ec5a211ade64c).(&thread_context->rx_task_idcxx . . $ thread_context#rx_task_id., "RtcRxThread", |
| 674 | rtc_config->rx_thread_prioritycxx . . $ traffic_class_config#rx_thread_priority., rtc_config->rx_thread_cpucxx . . $ traffic_class_config#rx_thread_cpu., |
| 675 | rtc_config->xdp_enabledcxx . . $ traffic_class_config#xdp_enabled. ? rtc_xdp_rx_thread_routinecxx . . $ rtc_xdp_rx_thread_routine(9f162e79bfc6c74). |
| 676 | : rtc_rx_thread_routinecxx . . $ rtc_rx_thread_routine(9f162e79bfc6c74)., |
| 677 | thread_context); |
| 678 | if (ret) { |
| 679 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to create Rtc Rx thread!\n"); |
| 680 | goto err_thread_create2; |
| 681 | } |
| 682 | |
| 683 | thread_context->meta_data_offsetcxx . . $ thread_context#meta_data_offset. = |
| 684 | get_meta_data_offsetcxx . . $ get_meta_data_offset(16cb9e606c8e3615).(RTC_FRAME_TYPEcxx . . $ RTC_FRAME_TYPE., rtc_config->security_modecxx . . $ traffic_class_config#security_mode.); |
| 685 | |
| 686 | out: |
| 687 | return 0; |
| 688 | |
| 689 | err_thread_create2: |
| 690 | thread_context->stopcxx . . $ thread_context#stop. = 1; |
| 691 | pthread_joincxx . . $ pthread_join(269902cf949f12c5).(thread_context->tx_task_idcxx . . $ thread_context#tx_task_id., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 692 | err_thread_create1: |
| 693 | security_exitcxx . . $ security_exit(180fdc1b6a791d79).(thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context.); |
| 694 | err_rx_sec: |
| 695 | security_exitcxx . . $ security_exit(180fdc1b6a791d79).(thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.); |
| 696 | err_tx_sec: |
| 697 | ring_buffer_freecxx . . $ ring_buffer_free(8f2cd700b00968de).(thread_context->mirror_buffercxx . . $ thread_context#mirror_buffer.); |
| 698 | err_thread: |
| 699 | if (thread_context->socket_fdcxx . . $ thread_context#socket_fd.) |
| 700 | closecxx . . $ close(7864480464b09eea).(thread_context->socket_fdcxx . . $ thread_context#socket_fd.); |
| 701 | if (thread_context->xskcxx . . $ thread_context#xsk.) |
| 702 | xdp_close_socketcxx . . $ xdp_close_socket(fc530d27d072e0f5).(thread_context->xskcxx . . $ thread_context#xsk., rtc_config->interfacecxx . . $ traffic_class_config#interface., |
| 703 | rtc_config->xdp_skb_modecxx . . $ traffic_class_config#xdp_skb_mode.); |
| 704 | err_socket: |
| 705 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->payload_patterncxx . . $ thread_context#payload_pattern.); |
| 706 | err_payload: |
| 707 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->rx_frame_datacxx . . $ thread_context#rx_frame_data.); |
| 708 | err_rx: |
| 709 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data.); |
| 710 | err_tx: |
| 711 | packet_freecxx . . $ packet_free(b20c0f701b2a2d37).(thread_context->packet_contextcxx . . $ thread_context#packet_context.); |
| 712 | err_packet: |
| 713 | return ret; |
| 714 | } |
| 715 | |
| 716 | void rtc_threads_freecxx . . $ rtc_threads_free(f7c2ab51214b7176).(struct thread_contextcxx . . $ thread_context# *thread_context) |
| 717 | { |
| 718 | struct traffic_class_configcxx . . $ traffic_class_config# *rtc_config; |
| 719 | |
| 720 | if (!thread_context) |
| 721 | return; |
| 722 | |
| 723 | rtc_config = thread_context->confcxx . . $ thread_context#conf.; |
| 724 | |
| 725 | if (thread_context->payload_patterncxx . . $ thread_context#payload_pattern.) { |
| 726 | thread_context->payload_patterncxx . . $ thread_context#payload_pattern. -= |
| 727 | sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) + sizeof(struct profinet_secure_headercxx . . $ profinet_secure_header#); |
| 728 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->payload_patterncxx . . $ thread_context#payload_pattern.); |
| 729 | } |
| 730 | |
| 731 | security_exitcxx . . $ security_exit(180fdc1b6a791d79).(thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.); |
| 732 | security_exitcxx . . $ security_exit(180fdc1b6a791d79).(thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context.); |
| 733 | |
| 734 | ring_buffer_freecxx . . $ ring_buffer_free(8f2cd700b00968de).(thread_context->mirror_buffercxx . . $ thread_context#mirror_buffer.); |
| 735 | |
| 736 | packet_freecxx . . $ packet_free(b20c0f701b2a2d37).(thread_context->packet_contextcxx . . $ thread_context#packet_context.); |
| 737 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data.); |
| 738 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->rx_frame_datacxx . . $ thread_context#rx_frame_data.); |
| 739 | |
| 740 | if (thread_context->socket_fdcxx . . $ thread_context#socket_fd. > 0) |
| 741 | closecxx . . $ close(7864480464b09eea).(thread_context->socket_fdcxx . . $ thread_context#socket_fd.); |
| 742 | |
| 743 | if (thread_context->xskcxx . . $ thread_context#xsk.) |
| 744 | xdp_close_socketcxx . . $ xdp_close_socket(fc530d27d072e0f5).(thread_context->xskcxx . . $ thread_context#xsk., rtc_config->interfacecxx . . $ traffic_class_config#interface., |
| 745 | rtc_config->xdp_skb_modecxx . . $ traffic_class_config#xdp_skb_mode.); |
| 746 | } |
| 747 | |
| 748 | void rtc_threads_wait_for_finishcxx . . $ rtc_threads_wait_for_finish(f7c2ab51214b7176).(struct thread_contextcxx . . $ thread_context# *thread_context) |
| 749 | { |
| 750 | if (!thread_context) |
| 751 | return; |
| 752 | |
| 753 | if (thread_context->rx_task_idcxx . . $ thread_context#rx_task_id.) |
| 754 | pthread_joincxx . . $ pthread_join(269902cf949f12c5).(thread_context->rx_task_idcxx . . $ thread_context#rx_task_id., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 755 | if (thread_context->tx_task_idcxx . . $ thread_context#tx_task_id.) |
| 756 | pthread_joincxx . . $ pthread_join(269902cf949f12c5).(thread_context->tx_task_idcxx . . $ thread_context#tx_task_id., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 757 | } |