Add RLC stats: avg time to tx for an RLC SDU
This commit is contained in:
committed by
Chieh-Chun Chen
parent
6a23bcfb42
commit
fad3f23164
@@ -1216,6 +1216,7 @@ add_library(UTIL
|
||||
${OPENAIR_DIR}/common/utils/system.c
|
||||
${OPENAIR_DIR}/common/utils/backtrace.c
|
||||
${OPENAIR_DIR}/common/utils/time_meas.c
|
||||
${OPENAIR_DIR}/common/utils/time_stat.c
|
||||
)
|
||||
|
||||
set(SECU_OSA_SRC
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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 "time_stat.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common/utils/LOG/log.h"
|
||||
|
||||
time_average_t *time_average_new(int duration, int initial_size)
|
||||
{
|
||||
time_average_t *ret;
|
||||
|
||||
/* let's only accept power of two initial_size */
|
||||
if (initial_size & (initial_size - 1)) {
|
||||
LOG_E(UTIL, "time_average_new: illegal initial_size %d, use power of two\n", initial_size);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = calloc(1, sizeof(time_average_t));
|
||||
if (ret == NULL) {
|
||||
LOG_E(UTIL, "out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret->duration = duration;
|
||||
ret->r.head = initial_size - 1;
|
||||
ret->r.maxsize = initial_size;
|
||||
ret->r.buffer = calloc(initial_size, sizeof(time_value_t));
|
||||
if (ret->r.buffer == NULL) {
|
||||
LOG_E(UTIL, "out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void time_average_free(time_average_t *t)
|
||||
{
|
||||
free(t->r.buffer);
|
||||
free(t);
|
||||
}
|
||||
|
||||
static void remove_old(time_average_t *t, uint64_t time)
|
||||
{
|
||||
/* remove old events */
|
||||
while (t->r.size && t->r.buffer[t->r.tail].time < time - t->duration) {
|
||||
t->accumulated_value -= t->r.buffer[t->r.tail].value;
|
||||
t->r.size--;
|
||||
t->r.tail++;
|
||||
t->r.tail %= t->r.maxsize;
|
||||
}
|
||||
}
|
||||
|
||||
void time_average_add(time_average_t *t, uint64_t time, uint64_t value)
|
||||
{
|
||||
remove_old(t, time);
|
||||
|
||||
if (t->r.size == t->r.maxsize) {
|
||||
t->r.maxsize *= 2;
|
||||
t->r.buffer = realloc(t->r.buffer, t->r.maxsize * sizeof(time_value_t));
|
||||
if (t->r.buffer == NULL) {
|
||||
LOG_E(UTIL, "out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
if (t->r.head < t->r.tail) {
|
||||
memcpy(&t->r.buffer[t->r.size], &t->r.buffer[0], (t->r.head + 1) * sizeof(time_value_t));
|
||||
t->r.head += t->r.size;
|
||||
}
|
||||
}
|
||||
|
||||
t->r.head++;
|
||||
t->r.head %= t->r.maxsize;
|
||||
t->r.buffer[t->r.head].time = time;
|
||||
t->r.buffer[t->r.head].value = value;
|
||||
|
||||
t->r.size++;
|
||||
|
||||
t->accumulated_value += value;
|
||||
}
|
||||
|
||||
double time_average_get_average(time_average_t *t, uint64_t time)
|
||||
{
|
||||
remove_old(t, time);
|
||||
|
||||
return (double)t->accumulated_value / t->r.size;
|
||||
}
|
||||
|
||||
uint64_t time_average_now(void)
|
||||
{
|
||||
struct timespec t;
|
||||
uint64_t ret;
|
||||
|
||||
if (clock_gettime(CLOCK_REALTIME, &t)) {
|
||||
LOG_E(UTIL, "clock_gettime failed\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = (uint64_t)t.tv_sec * (uint64_t)1000000 + t.tv_nsec / 1000;
|
||||
/* round up if necessary */
|
||||
if (t.tv_nsec % 1000 >= 500)
|
||||
ret++;
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef _COMMON_UTIL_TIME_STAT_H_
|
||||
#define _COMMON_UTIL_TIME_STAT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint64_t time; /* unit: microsecond */
|
||||
uint64_t value; /* unit: microsecond */
|
||||
} time_value_t;
|
||||
|
||||
typedef struct {
|
||||
int head;
|
||||
int tail;
|
||||
time_value_t *buffer;
|
||||
int maxsize;
|
||||
int size;
|
||||
} time_ring_t;
|
||||
|
||||
typedef struct {
|
||||
int duration; /* unit: microsecond */
|
||||
time_ring_t r;
|
||||
uint64_t accumulated_value;
|
||||
} time_average_t;
|
||||
|
||||
/* 'duration' is in unit microsecond */
|
||||
time_average_t *time_average_new(int duration, int initial_size);
|
||||
void time_average_free(time_average_t *t);
|
||||
|
||||
/* add a value tagged with time 'time' unit microsecond (it also modifies 't',
|
||||
* removing all data with time < 'time' - t->duration)
|
||||
*/
|
||||
void time_average_add(time_average_t *t, uint64_t time, uint64_t value);
|
||||
|
||||
/* get the average for time 'time' (it also modifies 't', removing all
|
||||
* data with time < 'time' - t->duration)
|
||||
*/
|
||||
double time_average_get_average(time_average_t *t, uint64_t time);
|
||||
|
||||
/* unit microsecond */
|
||||
uint64_t time_average_now(void);
|
||||
|
||||
#endif /* _COMMON_UTIL_TIME_STAT_H_ */
|
||||
@@ -29,12 +29,16 @@
|
||||
|
||||
#include "LOG/log.h"
|
||||
|
||||
#include "common/utils/time_stat.h"
|
||||
|
||||
static void nr_rlc_entity_get_stats(
|
||||
nr_rlc_entity_t *entity,
|
||||
nr_rlc_statistics_t *out)
|
||||
{
|
||||
// printf("Stats from the RLC entity asked\n");
|
||||
*out = entity->stats;
|
||||
out->txsdu_avg_time_to_tx = time_average_get_average(entity->txsdu_avg_time_to_tx,
|
||||
time_average_now());
|
||||
}
|
||||
|
||||
nr_rlc_entity_t *new_nr_rlc_entity_am(
|
||||
@@ -105,6 +109,11 @@ nr_rlc_entity_t *new_nr_rlc_entity_am(
|
||||
|
||||
ret->common.stats.mode = 0; /* 0 for AM */
|
||||
|
||||
/* let's take average over the last 100 milliseconds
|
||||
* initial_size of 1024 is arbitrary
|
||||
*/
|
||||
ret->common.txsdu_avg_time_to_tx = time_average_new(100 * 1000, 1024);
|
||||
|
||||
return (nr_rlc_entity_t *)ret;
|
||||
}
|
||||
|
||||
@@ -155,6 +164,11 @@ nr_rlc_entity_t *new_nr_rlc_entity_um(
|
||||
|
||||
ret->common.stats.mode = 1; /* 1 for UM */
|
||||
|
||||
/* let's take average over the last 100 milliseconds
|
||||
* initial_size of 1024 is arbitrary
|
||||
*/
|
||||
ret->common.txsdu_avg_time_to_tx = time_average_new(100 * 1000, 1024);
|
||||
|
||||
return (nr_rlc_entity_t *)ret;
|
||||
}
|
||||
|
||||
@@ -190,5 +204,10 @@ nr_rlc_entity_t *new_nr_rlc_entity_tm(
|
||||
|
||||
ret->common.stats.mode = 2; /* 2 for TM */
|
||||
|
||||
/* let's take average over the last 100 milliseconds
|
||||
* initial_size of 1024 is arbitrary
|
||||
*/
|
||||
ret->common.txsdu_avg_time_to_tx = time_average_new(100 * 1000, 1024);
|
||||
|
||||
return (nr_rlc_entity_t *)ret;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "common/utils/time_stat.h"
|
||||
|
||||
#define NR_SDU_MAX 16000 /* max NR PDCP SDU size is 9000, let's take more */
|
||||
|
||||
typedef struct {
|
||||
@@ -77,6 +79,16 @@ typedef struct {
|
||||
uint32_t rxsdu_bytes; /* number of bytes of SDUs received */
|
||||
uint32_t rxsdu_dd_pkts; /* number of dropped or discarded SDUs */
|
||||
uint32_t rxsdu_dd_bytes; /* number of bytes of SDUs dropped or discarded */
|
||||
|
||||
/* Average time for an SDU to be passed to MAC.
|
||||
* Actually measures the time it takes for any part of an SDU to be
|
||||
* passed to MAC for the first time, that is: the first TX of (part of) the
|
||||
* SDU.
|
||||
* Since the MAC schedules in advance, it does not measure the time of
|
||||
* transmission over the air, just the time to reach the MAC layer.
|
||||
*/
|
||||
double txsdu_avg_time_to_tx;
|
||||
|
||||
} nr_rlc_statistics_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -124,6 +136,7 @@ typedef struct nr_rlc_entity_t {
|
||||
nr_rlc_entity_buffer_status_t bstatus;
|
||||
|
||||
nr_rlc_statistics_t stats;
|
||||
time_average_t *txsdu_avg_time_to_tx;
|
||||
} nr_rlc_entity_t;
|
||||
|
||||
nr_rlc_entity_t *new_nr_rlc_entity_am(
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "nr_rlc_pdu.h"
|
||||
|
||||
#include "LOG/log.h"
|
||||
#include "common/utils/time_stat.h"
|
||||
|
||||
/* for a given SDU/SDU segment, computes the corresponding PDU header size */
|
||||
static int compute_pdu_header_size(nr_rlc_entity_am_t *entity,
|
||||
@@ -1620,6 +1621,14 @@ static int generate_tx_pdu(nr_rlc_entity_am_t *entity, char *buffer, int size)
|
||||
entity->common.stats.txpdu_pkts++;
|
||||
entity->common.stats.txpdu_bytes += ret_size;
|
||||
|
||||
if (sdu->sdu->time_of_arrival) {
|
||||
uint64_t time_now = time_average_now();
|
||||
uint64_t waited_time = time_now - sdu->sdu->time_of_arrival;
|
||||
/* set time_of_arrival to 0 so as to update stats only once */
|
||||
sdu->sdu->time_of_arrival = 0;
|
||||
time_average_add(entity->common.txsdu_avg_time_to_tx, time_now, waited_time);
|
||||
}
|
||||
|
||||
return ret_size;
|
||||
// return serialize_sdu(entity, sdu, buffer, size, p);
|
||||
}
|
||||
@@ -1708,6 +1717,8 @@ void nr_rlc_entity_am_recv_sdu(nr_rlc_entity_t *_entity,
|
||||
/* update buffer status */
|
||||
entity->common.bstatus.tx_size += compute_pdu_header_size(entity, sdu)
|
||||
+ sdu->size;
|
||||
|
||||
sdu->sdu->time_of_arrival = time_average_now();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
@@ -1949,6 +1960,7 @@ void nr_rlc_entity_am_delete(nr_rlc_entity_t *_entity)
|
||||
{
|
||||
nr_rlc_entity_am_t *entity = (nr_rlc_entity_am_t *)_entity;
|
||||
clear_entity(entity);
|
||||
time_average_free(entity->common.txsdu_avg_time_to_tx);
|
||||
free(entity);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "nr_rlc_pdu.h"
|
||||
#include "common/utils/time_stat.h"
|
||||
|
||||
#include "LOG/log.h"
|
||||
|
||||
@@ -78,6 +79,13 @@ static int generate_tx_pdu(nr_rlc_entity_tm_t *entity, char *buffer, int size)
|
||||
entity->common.stats.txpdu_pkts++;
|
||||
entity->common.stats.txpdu_bytes += size;
|
||||
|
||||
if (sdu->sdu->time_of_arrival) {
|
||||
uint64_t time_now = time_average_now();
|
||||
uint64_t waited_time = time_now - sdu->sdu->time_of_arrival;
|
||||
/* set time_of_arrival to 0 so as to update stats only once */
|
||||
sdu->sdu->time_of_arrival = 0;
|
||||
time_average_add(entity->common.txsdu_avg_time_to_tx, time_now, waited_time);
|
||||
}
|
||||
|
||||
/* update buffer status */
|
||||
entity->common.bstatus.tx_size -= sdu->size;
|
||||
@@ -189,6 +197,7 @@ void nr_rlc_entity_tm_delete(nr_rlc_entity_t *_entity)
|
||||
{
|
||||
nr_rlc_entity_tm_t *entity = (nr_rlc_entity_tm_t *)_entity;
|
||||
clear_entity(entity);
|
||||
time_average_free(entity->common.txsdu_avg_time_to_tx);
|
||||
free(entity);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "nr_rlc_pdu.h"
|
||||
|
||||
#include "LOG/log.h"
|
||||
#include "common/utils/time_stat.h"
|
||||
|
||||
/* for a given SDU/SDU segment, computes the corresponding PDU header size */
|
||||
static int compute_pdu_header_size(nr_rlc_entity_um_t *entity,
|
||||
@@ -516,12 +517,19 @@ static int generate_tx_pdu(nr_rlc_entity_um_t *entity, char *buffer, int size)
|
||||
ret = serialize_sdu(entity, sdu, buffer, size);
|
||||
|
||||
entity->tx_size -= sdu->size;
|
||||
nr_rlc_free_sdu_segment(sdu);
|
||||
|
||||
entity->common.stats.txpdu_pkts++;
|
||||
entity->common.stats.txpdu_bytes += size;
|
||||
|
||||
if (sdu->sdu->time_of_arrival) {
|
||||
uint64_t time_now = time_average_now();
|
||||
uint64_t waited_time = time_now - sdu->sdu->time_of_arrival;
|
||||
/* set time_of_arrival to 0 so as to update stats only once */
|
||||
sdu->sdu->time_of_arrival = 0;
|
||||
time_average_add(entity->common.txsdu_avg_time_to_tx, time_now, waited_time);
|
||||
}
|
||||
|
||||
nr_rlc_free_sdu_segment(sdu);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -736,6 +744,7 @@ void nr_rlc_entity_um_delete(nr_rlc_entity_t *_entity)
|
||||
{
|
||||
nr_rlc_entity_um_t *entity = (nr_rlc_entity_um_t *)_entity;
|
||||
clear_entity(entity);
|
||||
time_average_free(entity->common.txsdu_avg_time_to_tx);
|
||||
free(entity);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#ifndef _NR_RLC_SDU_H_
|
||||
#define _NR_RLC_SDU_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct nr_rlc_sdu_t {
|
||||
int sn;
|
||||
int upper_layer_id;
|
||||
@@ -34,6 +36,12 @@ typedef struct nr_rlc_sdu_t {
|
||||
* when it equals ref_count we can free the SDU
|
||||
* completely
|
||||
*/
|
||||
|
||||
/* for statistics, will be set to 0 after SDU (or first part of it) has
|
||||
* been serialized for MAC for the first time so that only the first
|
||||
* transmission is used for statistics
|
||||
*/
|
||||
uint64_t time_of_arrival; /* unit microsecond */
|
||||
} nr_rlc_sdu_t;
|
||||
|
||||
typedef struct nr_rlc_sdu_segment_t {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
CC=gcc
|
||||
CFLAGS=-Wall -g --coverage -I.
|
||||
CFLAGS=-Wall -g --coverage -I. -I../../../..
|
||||
|
||||
LIB=nr_rlc_entity.o nr_rlc_entity_am.o nr_rlc_entity_um.o nr_rlc_entity_tm.o \
|
||||
nr_rlc_pdu.o nr_rlc_sdu.o
|
||||
nr_rlc_pdu.o nr_rlc_sdu.o time_stat.o
|
||||
|
||||
tests:
|
||||
@./run_tests.sh
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "../../../../common/utils/time_stat.h"
|
||||
|
||||
time_average_t *time_average_new(int duration, int initial_size)
|
||||
{
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
void time_average_free(time_average_t *t)
|
||||
{
|
||||
}
|
||||
|
||||
void time_average_add(time_average_t *t, uint64_t time, uint64_t value)
|
||||
{
|
||||
}
|
||||
|
||||
double time_average_get_average(time_average_t *t, uint64_t time)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t time_average_now(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user