当前位置:网站首页>[openairinterface5g] high level module interface and ITTI entity thread creation

[openairinterface5g] high level module interface and ITTI entity thread creation

2022-06-22 06:23:00 No.7 Huazai


OAI High rise structure

OAI L3 It is mainly divided into RRC,NGAP,SCTP In the third part of :

  • RRC Responsible for radio resource management , Be responsible for making gNB And UE Establishing a connection , And signaling encoding and decoding .
  • NGAP be responsible for gNB And AMF Establishing a connection , Signaling NGAP Encode, decode and forward .
  • SCTP Be similar to TCP, Provide reliable network transmission , be responsible for AMF And gNB Between NGAP Sending and receiving messages .

Between modules ,OAI Used ITTI The public management module is responsible for standardizing entity management , Thread management , Queue management , Memory management, etc , Ensure the standardization of resource use of each module .
 Insert picture description here

High level module transmission interface

OAI The main program calls itti_create_task() establish RRC、NGAP、SCTP as well as PDCP The main thread , Thread creation can be performed CPU Kernel binding ( At present OAI The program does not enable kernel binding ). After thread creation , Use in each module while(1) Cycle call itti_receive_msg() Get data from the message queue of this module , Process according to the flow after decoding , Called when a message is sent iiti_send_msg_to_task() Push data into the queue of the target module .SCTP And AMF Between SCTP Connect for messaging .

ITTI Entity thread creation

Entity creation

Entity creation is actually OAI Modules task Object creation , And the corresponding thread creation , Each module is usually a main thread , And include possible worker threads . In thread while() The loop ensures that the entity is always running , This is a conventional approach .

  int itti_create_task(task_id_t task_id,
                       void *(*start_routine)(void *),
                       void *args_p) {
    
    task_list_t *t=tasks[task_id];
    threadCreate (&t->thread, start_routine, args_p, (char *)itti_get_task_name(task_id),-1,OAI_PRIORITY_RT);
    LOG_I(TMR,"Created Posix thread %s\n",  itti_get_task_name(task_id) );
    return 0;
  }

main call itti_create_task Function to create an entity , among
task_id: Module entity ID, Such as TASK_RRC_GNB
start_routine: Name of the thread function created
args_p: Parameters passed ,OAI Inside are NULL
In code tasks An array is a collection of entities , Contains the common attributes of each entity , Easy to access at any time .
threadCreate The function is responsible for thread creation

Thread creation

The thread creation process is as follows , See notes for creation steps

void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name, int affinity, int priority){
    
  pthread_attr_t attr;
  int ret;
  int settingPriority = 1;
  // Initializes the properties of the thread object 
  ret=pthread_attr_init(&attr);
  AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
  // Set the thread to the detached state 
  ret=pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
  // Set the scheduling policy that the thread does not inherit from the parent thread 
  ret=pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
  AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
  if (checkIfFedoraDistribution())
    if (checkIfGenericKernelOnFedora())
      if (checkIfInsideContainer())
        settingPriority = 0;
  /*SCHED_OAI, Its macro is defined as #define SCHED_OAI SCHED_RR, That is, the thread adopts polling scheduling   Each module can determine its own priority according to its needs */
  if (settingPriority) {
    
    ret=pthread_attr_setschedpolicy(&attr, SCHED_OAI);
    AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
    if(priority<sched_get_priority_min(SCHED_OAI) || priority>sched_get_priority_max(SCHED_FIFO)) {
    
      LOG_E(TMR,"Prio not possible: %d, min is %d, max: %d, forced in the range\n",
                priority,
                sched_get_priority_min(SCHED_OAI),
                sched_get_priority_max(SCHED_OAI));
      if(priority<sched_get_priority_min(SCHED_OAI))
        priority=sched_get_priority_min(SCHED_OAI);
      if(priority>sched_get_priority_max(SCHED_OAI))
        priority=sched_get_priority_max(SCHED_OAI);
    }
    AssertFatal(priority<=sched_get_priority_max(SCHED_OAI),"");
    struct sched_param sparam={
    0};
    sparam.sched_priority = priority;
    // Set thread priority 
    ret=pthread_attr_setschedparam(&attr, &sparam);
    AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
  }
  // Create a thread using the previously set property variable 
  ret=pthread_create(t, &attr, func, param);
  AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
  // Set the thread name 
  pthread_setname_np(*t, name);
  if (affinity != -1 ) {
    
    cpu_set_t cpuset;
    CPU_ZERO(&cpuset);
    CPU_SET(affinity, &cpuset);
    AssertFatal( pthread_setaffinity_np(*t, sizeof(cpu_set_t), &cpuset) == 0, "Error setting processor affinity");
  }
  // Destroy thread property variables 
  pthread_attr_destroy(&attr);
}

Thread to exit

Be responsible for exiting the current thread , Regular functions .

  void itti_exit_task(void) {
    
    pthread_exit (NULL);
  }

Entity properties

Entity attributes are defined as follows :

  typedef struct task_list_s {
    
    task_info_t admin;
    pthread_t thread;
    pthread_mutex_t queue_cond_lock;
    std::vector<MessageDef *> message_queue;
    std::map<long,timer_elm_t> timer_map;
    uint64_t next_timer=UINT64_MAX;
    struct epoll_event *events =NULL;
    int nb_fd_epoll=0;
    int nb_events=0;
    int epoll_fd=-1;
    int sem_fd=-1;
  } task_list_t;

admin: Entity information , Including scheduling priority , The queue length , The entity name , Thread functions
thread: Threads ID
queue_cond_lock: Queue lock
message_queue: Message queue , Each module has its own message queue , Responsible for storing messages sent by other modules
timer_map: Timer
next_timer: Due time

原网站

版权声明
本文为[No.7 Huazai]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220619529633.html