Files
openairinterface5g/openair2/LAYER2/nr_pdcp/nr_pdcp_timer_thread.c
T
Cedric Roux 9edc8cce0a nr pdcp: improvements
Implement data transfer (38.331 5.2):
    - transmit operation (in nr_pdcp_entity_recv_sdu)
    - receive operation (in nr_pdcp_entity_recv_pdu)
    - t-Reordering expiration

To keep track of time the function nr_pdcp_wakeup_timer_thread has been
added and is called by the gNB's MAC scheduler via nr_pdcp_tick.

(The UE has not been modified.)

A thread has been introduced to set time of all the existing PDCP
entities in the system. This probably does not scale well with many
PDCP entities (many UEs connected to the gNB). To be changed at some
point when needed. Hopefully, with a few UEs this mechanism won't be
too problematic (ie. won't cause realtime problems).

The problem with time in PDCP is that SDUs are kept if some are
missing, to do reordering. A timer is started and when it expires
we have to transmit the SDUs even if some are still missing. We
want to do that as soon as possible. So we have to check timers
often (every millisecond).

In RLC the time is set when there is some activity (SDU or PDU
received). In PDCP we cannot wait for this kind of activity. We
would keep packets longer than necessary, which may disturb
upper layers (think: TCP). That is why we introduced the thread,
as a simple mechanism to keep packets no longer than necessary.

The locking done by this thread may create realtime issues.

The whole logic of time keeping can be changed later if it turns
out that it is not efficient.

The functions dealing with DRB AM have been removed. All the types
of PDCP entities (DRB AM, DRB UM, SRB) use the same mechanism for
transmit and receive operations. So the code has been made common
for all those types.

We don't deal with:
    - entity re-establishment, entity release or entity suspend
    - SDU discard (the timer is present but not used)
    - status reporting
    - data recovery
    - data volume calculation
    - header compression / decompression

There is no plan to implement those features in a near future.

Integrity protection is not done yet, and will be implemented soon.
2021-03-03 14:06:31 +01:00

88 lines
3.0 KiB
C

/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "nr_pdcp_timer_thread.h"
#include <stdlib.h>
#include <pthread.h>
#include <stdint.h>
#include "LOG/log.h"
static pthread_mutex_t timer_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t timer_thread_cond = PTHREAD_COND_INITIALIZER;
static volatile uint64_t timer_thread_curtime = 0;
static void *nr_pdcp_timer_thread(void *_nr_pdcp_ue_manager)
{
nr_pdcp_ue_manager_t *nr_pdcp_ue_manager = (nr_pdcp_ue_manager_t *)_nr_pdcp_ue_manager;
nr_pdcp_ue_t **ue_list;
int ue_count;
int i;
int j;
uint64_t curtime = 0;
while (1) {
if (pthread_mutex_lock(&timer_thread_mutex) != 0) abort();
while (curtime == timer_thread_curtime)
if (pthread_cond_wait(&timer_thread_cond, &timer_thread_mutex) != 0) abort();
curtime = timer_thread_curtime;
if (pthread_mutex_unlock(&timer_thread_mutex) != 0) abort();
nr_pdcp_manager_lock(nr_pdcp_ue_manager);
ue_list = nr_pdcp_manager_get_ue_list(nr_pdcp_ue_manager);
ue_count = nr_pdcp_manager_get_ue_count(nr_pdcp_ue_manager);
for (i = 0; i < ue_count; i++) {
for (j = 0; j < 2; j++) {
if (ue_list[i]->srb[j] != NULL)
ue_list[i]->srb[j]->set_time(ue_list[i]->srb[j], curtime);
}
for (j = 0; j < 5; j++) {
if (ue_list[i]->drb[j] != NULL)
ue_list[i]->drb[j]->set_time(ue_list[i]->drb[j], curtime);
}
}
nr_pdcp_manager_unlock(nr_pdcp_ue_manager);
}
return NULL;
}
void nr_pdcp_init_timer_thread(nr_pdcp_ue_manager_t *nr_pdcp_ue_manager)
{
pthread_t t;
if (pthread_create(&t, NULL, nr_pdcp_timer_thread, nr_pdcp_ue_manager) != 0) {
LOG_E(PDCP, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__);
exit(1);
}
}
void nr_pdcp_wakeup_timer_thread(uint64_t time)
{
if (pthread_mutex_lock(&timer_thread_mutex)) abort();
timer_thread_curtime = time;
if (pthread_cond_broadcast(&timer_thread_cond)) abort();
if (pthread_mutex_unlock(&timer_thread_mutex)) abort();
}