feat: 添加了udp程序核绑定

This commit is contained in:
yuanQie 2025-05-20 20:05:52 +08:00
parent 6cfb45a889
commit 3e587f356d
2 changed files with 58 additions and 40 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.out
.o
.vscode/

View File

@ -39,11 +39,14 @@
// Last Version: V1.0 // Last Version: V1.0
//---------------------------------------------------- //----------------------------------------------------
#include <arpa/inet.h> // udp #include <arpa/inet.h> // udp
#include <sched.h> // 绑定CPU
#include <pthread.h> // thread #include <pthread.h> // thread
#include <unistd.h> // POSIX api #include <unistd.h> // POSIX api
#include <fcntl.h> // open() #include <fcntl.h> // open()
#include <sys/mman.h> // MMAP #include <sys/mman.h> // MMAP
//---------------------------------------------------- //----------------------------------------------------
#define _GNU_SOURCE
#define SERVER_IP_CASE52 "172.29.118.76" // IP #define SERVER_IP_CASE52 "172.29.118.76" // IP
#define SERVER_PORT_CASE52 28864 // 端口 #define SERVER_PORT_CASE52 28864 // 端口
#define BUFFER_SIZE_CASE52 16016 // 用户缓冲区 #define BUFFER_SIZE_CASE52 16016 // 用户缓冲区
@ -587,67 +590,78 @@ int32_t test_case(uint32_t argc, int32_t* argvp)
//osp_set_task_orx(6, 95); //osp_set_task_orx(6, 95);
/********************************************************* */ /********************************************************* */
pthread_attr_t udp_attr; // 定义线程包
pthread_attr_init(&udp_attr); // 包初始化
cpu_set_t udp_cpuset; // CPU集合
CPU_ZERO(&udp_cpuset); // 集合初始化
CPU_SET(1, &udp_cpuset); // 选择核心2
pthread_attr_setaffinity_np(&udp_attr, sizeof(udp_cpuset), &udp_cpuset); // 绑定
pthread_t thread_udp; pthread_t thread_udp;
if (pthread_create(&thread_udp, NULL, handleUdpTransmission, NULL) != 0) if (pthread_create(&thread_udp, &udp_attr, handleUdpTransmission, NULL) != 0)
{ {
printf("[SOCKET]:thread error!\n"); printf("[SOCKET]:thread error!\n");
perror("pthread_create"); perror("pthread_create");
pthread_attr_destroy(&udp_attr);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
pthread_attr_destroy(&udp_attr); // 销毁
/********************************************************* */ /********************************************************* */
// 进入循环 // 进入循环
while(1) { while(1) {
msg_transfer_queue_polling(); msg_transfer_queue_polling();
if(1 == slot_ind_flag) // if(1 == slot_ind_flag)
{ // {
handler.inst_id = 0; // handler.inst_id = 0;
cu_flag = C_PLANE; // cu_flag = C_PLANE;
ret = msg_transfer_send_start(handler.value,cu_flag); // ret = msg_transfer_send_start(handler.value,cu_flag);
ret = msg_transfer_alloc_msg(handler.value, cu_flag, size, &buf, &availableSize, &offset); // ret = msg_transfer_alloc_msg(handler.value, cu_flag, size, &buf, &availableSize, &offset);
if ( SUCCESS != ret) { // if ( SUCCESS != ret) {
UCP_PRINT_ERROR("0,c_plane alloc error\r\n"); // UCP_PRINT_ERROR("0,c_plane alloc error\r\n");
continue; // continue;
} // }
ptr = (uint8_t *)buf; // ptr = (uint8_t *)buf;
*(uint32_t*)(ptr + 0) = gu32_value; // *(uint32_t*)(ptr + 0) = gu32_value;
*(uint32_t*)(ptr + 4) = gu32_tick_from_tx_ctrl; // *(uint32_t*)(ptr + 4) = gu32_tick_from_tx_ctrl;
*(uint32_t*)(ptr + 8) = gu32_tick_receive_ctrl; // *(uint32_t*)(ptr + 8) = gu32_tick_receive_ctrl;
*(uint32_t*)(ptr + 12) = read_stc_local_timer(); // *(uint32_t*)(ptr + 12) = read_stc_local_timer();
ret = msg_transfer_send_msg(handler.value, cu_flag, (uint8_t *)buf, offset, size); // ret = msg_transfer_send_msg(handler.value, cu_flag, (uint8_t *)buf, offset, size);
if ( SUCCESS != ret) { // if ( SUCCESS != ret) {
UCP_PRINT_ERROR("0,c_plane send error\r\n"); // UCP_PRINT_ERROR("0,c_plane send error\r\n");
} // }
ret = msg_transfer_send_end(handler.value,cu_flag); // ret = msg_transfer_send_end(handler.value,cu_flag);
/************U_PLANE***************/ // /************U_PLANE***************/
cu_flag = U_PLANE; // cu_flag = U_PLANE;
ret = msg_transfer_send_start(handler.value,cu_flag); // ret = msg_transfer_send_start(handler.value,cu_flag);
ret = msg_transfer_alloc_msg(handler.value, cu_flag, size, &buf, &availableSize, &offset); // ret = msg_transfer_alloc_msg(handler.value, cu_flag, size, &buf, &availableSize, &offset);
if ( SUCCESS != ret) { // if ( SUCCESS != ret) {
UCP_PRINT_ERROR("0,u_plane alloc error\r\n"); // UCP_PRINT_ERROR("0,u_plane alloc error\r\n");
continue; // continue;
} // }
ptr = (uint8_t *)buf; // ptr = (uint8_t *)buf;
*(uint32_t*)(ptr + 0) = gu32_value; // *(uint32_t*)(ptr + 0) = gu32_value;
*(uint32_t*)(ptr + 4) = gu32_tick_from_tx_ctrl; // *(uint32_t*)(ptr + 4) = gu32_tick_from_tx_ctrl;
*(uint32_t*)(ptr + 8) = gu32_tick_receive_ctrl; // *(uint32_t*)(ptr + 8) = gu32_tick_receive_ctrl;
*(uint32_t*)(ptr + 12) = read_stc_local_timer(); // *(uint32_t*)(ptr + 12) = read_stc_local_timer();
ret = msg_transfer_send_msg(handler.value, cu_flag, (uint8_t *)buf, offset, size); // ret = msg_transfer_send_msg(handler.value, cu_flag, (uint8_t *)buf, offset, size);
if ( SUCCESS != ret) { // if ( SUCCESS != ret) {
UCP_PRINT_ERROR("0,u_plane send error\r\n"); // UCP_PRINT_ERROR("0,u_plane send error\r\n");
} // }
ret = msg_transfer_send_end(handler.value,cu_flag); // ret = msg_transfer_send_end(handler.value,cu_flag);
} // }
} }
return 0; return 0;
} }