Merge remote-tracking branch 'origin/develop' into NR_UL_VRB_MAP_improv
This commit is contained in:
@@ -49,7 +49,6 @@ The list of components defined within oai can be retrieved from the [config mod
|
||||
[CONFIG] log_config.perf_log_level set to default value "info"
|
||||
[CONFIG] log_config.oip_log_level set to default value "info"
|
||||
[CONFIG] log_config.cli_log_level set to default value "info"
|
||||
[CONFIG] log_config.msc_log_level set to default value "info"
|
||||
[CONFIG] log_config.ocm_log_level set to default value "info"
|
||||
[CONFIG] log_config.udp_log_level set to default value "info"
|
||||
[CONFIG] log_config.gtpv1u_log_level set to default value "info"
|
||||
@@ -108,8 +107,6 @@ The list of components defined within oai can be retrieved from the [config mod
|
||||
[CONFIG] log_config.oip_log_infile set to default value
|
||||
[CONFIG] cli_log_infile: 0
|
||||
[CONFIG] log_config.cli_log_infile set to default value
|
||||
[CONFIG] msc_log_infile: 0
|
||||
[CONFIG] log_config.msc_log_infile set to default value
|
||||
[CONFIG] ocm_log_infile: 0
|
||||
[CONFIG] log_config.ocm_log_infile set to default value
|
||||
[CONFIG] udp_log_infile: 0
|
||||
|
||||
+16
-1
@@ -411,6 +411,16 @@ int register_log_component(char *name,
|
||||
return computed_compidx;
|
||||
}
|
||||
|
||||
static void unregister_all_log_components(void)
|
||||
{
|
||||
log_component_t* lc = &g_log->log_component[0];
|
||||
while (lc->name) {
|
||||
free((char *)lc->name); // defined as const, but assigned through strdup()
|
||||
free(lc->filelog_name);
|
||||
lc++;
|
||||
}
|
||||
}
|
||||
|
||||
int isLogInitDone (void)
|
||||
{
|
||||
if (g_log == NULL)
|
||||
@@ -449,7 +459,6 @@ int logInit (void)
|
||||
register_log_component("OCG","",OCG);
|
||||
register_log_component("PERF","",PERF);
|
||||
register_log_component("OIP","",OIP);
|
||||
register_log_component("MSC","log",MSC);
|
||||
register_log_component("OCM","log",OCM);
|
||||
register_log_component("HW","",HW);
|
||||
register_log_component("OSA","",OSA);
|
||||
@@ -503,6 +512,12 @@ int logInit (void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void logTerm(void)
|
||||
{
|
||||
unregister_all_log_components();
|
||||
free_and_zero(g_log);
|
||||
}
|
||||
|
||||
#include <sys/syscall.h>
|
||||
static inline int log_header(log_component_t *c,
|
||||
char *log_buffer,
|
||||
|
||||
+1
-125
@@ -212,7 +212,6 @@ typedef enum {
|
||||
PERF,
|
||||
OIP,
|
||||
CLI,
|
||||
MSC,
|
||||
OCM,
|
||||
UDP_,
|
||||
GTPU,
|
||||
@@ -303,6 +302,7 @@ extern "C" {
|
||||
# include "log_if.h"
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int logInit (void);
|
||||
void logTerm (void);
|
||||
int isLogInitDone (void);
|
||||
void logRecord_mt(const char *file, const char *func, int line,int comp, int level, const char *format, ...) __attribute__ ((format (printf, 6, 7)));
|
||||
void vlogRecord_mt(const char *file, const char *func, int line, int comp, int level, const char *format, va_list args );
|
||||
@@ -473,130 +473,6 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
|
||||
|
||||
/* @}*/
|
||||
|
||||
static __inline__ uint64_t rdtsc(void) {
|
||||
uint32_t a, d;
|
||||
__asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
|
||||
return (((uint64_t)d)<<32) | ((uint64_t)a);
|
||||
}
|
||||
|
||||
#define DEBUG_REALTIME 1
|
||||
#if DEBUG_REALTIME
|
||||
|
||||
extern double cpuf;
|
||||
|
||||
static inline uint64_t checkTCPU(int timeout,
|
||||
char *file,
|
||||
int line)
|
||||
{
|
||||
static uint64_t __thread lastCPUTime=0;
|
||||
static uint64_t __thread last=0;
|
||||
uint64_t cur=rdtsc();
|
||||
struct timespec CPUt;
|
||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &CPUt);
|
||||
uint64_t CPUTime=CPUt.tv_sec*1000*1000+CPUt.tv_nsec/1000;
|
||||
double microCycles=(double)(cpuf*1000);
|
||||
int duration=(int)((cur-last)/microCycles);
|
||||
|
||||
if ( last!=0 && duration > timeout ) {
|
||||
//struct timespec ts;
|
||||
//clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
printf("%s:%d lte-ue delay %d (exceed %d), CPU for this period: %lld\n", file, line,
|
||||
duration, timeout, (long long)CPUTime-lastCPUTime );
|
||||
}
|
||||
|
||||
last=cur;
|
||||
lastCPUTime=CPUTime;
|
||||
return cur;
|
||||
}
|
||||
|
||||
static inline unsigned long long checkT(int timeout,
|
||||
char *file,
|
||||
int line)
|
||||
{
|
||||
static unsigned long long __thread last=0;
|
||||
unsigned long long cur=rdtsc();
|
||||
int microCycles=(int)(cpuf*1000);
|
||||
int duration=(int)((cur-last)/microCycles);
|
||||
|
||||
if ( last!=0 && duration > timeout )
|
||||
printf("%s:%d lte-ue delay %d (exceed %d)\n", file, line,
|
||||
duration, timeout);
|
||||
|
||||
last=cur;
|
||||
return cur;
|
||||
}
|
||||
|
||||
typedef struct m {
|
||||
uint64_t iterations;
|
||||
uint64_t sum;
|
||||
uint64_t maxArray[11];
|
||||
} Meas;
|
||||
|
||||
static inline void printMeas(char *txt,
|
||||
Meas *M,
|
||||
int period)
|
||||
{
|
||||
if (M->iterations%period == 0 ) {
|
||||
char txt2[512];
|
||||
sprintf(txt2,"%s avg=%" PRIu64 " iterations=%" PRIu64 " max=%"
|
||||
PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 "\n",
|
||||
txt,
|
||||
M->sum/M->iterations,
|
||||
M->iterations,
|
||||
M->maxArray[1],M->maxArray[2], M->maxArray[3],M->maxArray[4], M->maxArray[5],
|
||||
M->maxArray[6],M->maxArray[7], M->maxArray[8],M->maxArray[9],M->maxArray[10]);
|
||||
#if T_TRACER
|
||||
LOG_W(PHY,"%s",txt2);
|
||||
#else
|
||||
printf("%s",txt2);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline int cmpint(const void *a,
|
||||
const void *b)
|
||||
{
|
||||
uint64_t *aa=(uint64_t *)a;
|
||||
uint64_t *bb=(uint64_t *)b;
|
||||
return (int)(*aa-*bb);
|
||||
}
|
||||
|
||||
static inline void updateTimes(uint64_t start,
|
||||
Meas *M,
|
||||
int period,
|
||||
char *txt)
|
||||
{
|
||||
if (start!=0) {
|
||||
uint64_t end=rdtsc();
|
||||
long long diff=(end-start)/(cpuf*1000);
|
||||
M->maxArray[0]=diff;
|
||||
M->sum+=diff;
|
||||
M->iterations++;
|
||||
qsort(M->maxArray, 11, sizeof(uint64_t), cmpint);
|
||||
printMeas(txt,M,period);
|
||||
}
|
||||
}
|
||||
|
||||
#define check(a) do { checkT(a,__FILE__,__LINE__); } while (0)
|
||||
#define checkcpu(a) do { checkTCPU(a,__FILE__,__LINE__); } while (0)
|
||||
#define initRefTimes(a) static __thread Meas a= {0}
|
||||
#define pickTime(a) uint64_t a=rdtsc()
|
||||
#define readTime(a) a
|
||||
#define initStaticTime(a) static __thread uint64_t a={0}
|
||||
#define pickStaticTime(a) do { a=rdtsc(); } while (0)
|
||||
|
||||
#else
|
||||
#define check(a) do {} while (0)
|
||||
#define checkcpu(a) do {} while (0)
|
||||
#define initRefTimes(a) do {} while (0)
|
||||
#define initStaticTime(a) do {} while (0)
|
||||
#define pickTime(a) do {} while (0)
|
||||
#define readTime(a) 0
|
||||
#define pickStaticTime(a) do {} while (0)
|
||||
#define updateTimes(a,b,c,d) do {} while (0)
|
||||
#define printMeas(a,b,c) do {} while (0)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -25,14 +25,21 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <platform_types.h>
|
||||
#include "backtrace.h"
|
||||
|
||||
#define _Assert_Exit_ \
|
||||
fprintf(stderr, "\nExiting execution\n"); \
|
||||
fflush(stdout); \
|
||||
fflush(stderr); \
|
||||
abort();
|
||||
#define _Assert_Exit_ \
|
||||
if (getenv("gdbStacks")) { \
|
||||
char tmp [1000]; \
|
||||
sprintf(tmp,"gdb -ex='set confirm off' -ex 'thread apply all bt' -ex q -p %d < /dev/null", getpid()); \
|
||||
__attribute__((unused)) int dummy=system(tmp); \
|
||||
} \
|
||||
fprintf(stderr, "\nExiting execution\n"); \
|
||||
fflush(stdout); \
|
||||
fflush(stderr); \
|
||||
abort();
|
||||
|
||||
#define _Assert_(cOND, aCTION, fORMAT, aRGS...) \
|
||||
do { \
|
||||
|
||||
@@ -69,7 +69,6 @@ char *loader_format_shlibpath(char *modname, char *version)
|
||||
char *tmpstr;
|
||||
char *shlibpath =NULL;
|
||||
char *shlibversion=NULL;
|
||||
char *cfgprefix;
|
||||
paramdef_t LoaderParams[] ={{"shlibpath", NULL, 0, strptr:&shlibpath, defstrval:NULL, TYPE_STRING, 0, NULL},
|
||||
{"shlibversion", NULL, 0, strptr:&shlibversion, defstrval:"", TYPE_STRING, 0, NULL}};
|
||||
|
||||
@@ -81,16 +80,11 @@ int ret;
|
||||
/* looks for specific path for this module in the config file */
|
||||
/* specific value for a module path and version is located in a modname subsection of the loader section */
|
||||
/* shared lib name is formatted as lib<module name><module version>.so */
|
||||
cfgprefix = malloc(sizeof(LOADER_CONFIG_PREFIX)+strlen(modname)+16);
|
||||
if (cfgprefix == NULL) {
|
||||
fprintf(stderr,"[LOADER] %s %d malloc error loading module %s, %s\n",__FILE__, __LINE__, modname, strerror(errno));
|
||||
exit_fun("[LOADER] unrecoverable error");
|
||||
} else {
|
||||
sprintf(cfgprefix,LOADER_CONFIG_PREFIX ".%s",modname);
|
||||
int ret = config_get( LoaderParams,sizeof(LoaderParams)/sizeof(paramdef_t),cfgprefix);
|
||||
if (ret <0) {
|
||||
fprintf(stderr,"[LOADER] %s %d couldn't retrieve config from section %s\n",__FILE__, __LINE__,cfgprefix);
|
||||
}
|
||||
char cfgprefix[sizeof(LOADER_CONFIG_PREFIX)+strlen(modname)+16];
|
||||
sprintf(cfgprefix,LOADER_CONFIG_PREFIX ".%s",modname);
|
||||
ret = config_get( LoaderParams,sizeof(LoaderParams)/sizeof(paramdef_t),cfgprefix);
|
||||
if (ret <0) {
|
||||
fprintf(stderr,"[LOADER] %s %d couldn't retrieve config from section %s\n",__FILE__, __LINE__,cfgprefix);
|
||||
}
|
||||
/* no specific path, use loader default shared lib path */
|
||||
if (shlibpath == NULL) {
|
||||
@@ -142,6 +136,7 @@ int load_module_version_shlib(char *modname, char *version, loader_shlibfunc_t *
|
||||
}
|
||||
|
||||
shlib_path = loader_format_shlibpath(modname, version);
|
||||
printf("shlib_path %s\n", shlib_path);
|
||||
|
||||
for (int i = 0; i < loader_data.numshlibs; i++) {
|
||||
if (strcmp(loader_data.shlibs[i].name, modname) == 0) {
|
||||
@@ -198,15 +193,17 @@ int load_module_version_shlib(char *modname, char *version, loader_shlibfunc_t *
|
||||
}
|
||||
|
||||
if (farray) {
|
||||
if (!loader_data.shlibs[lib_idx].funcarray) {
|
||||
loader_data.shlibs[lib_idx].funcarray = malloc(numf*sizeof(loader_shlibfunc_t));
|
||||
if (!loader_data.shlibs[lib_idx].funcarray) {
|
||||
loader_shlibdesc_t *shlib = &loader_data.shlibs[lib_idx];
|
||||
if (!shlib->funcarray) {
|
||||
shlib->funcarray = calloc(numf, sizeof(loader_shlibfunc_t));
|
||||
if (!shlib->funcarray) {
|
||||
fprintf(stderr, "[LOADER] load_module_shlib(): unable to allocate memory\n");
|
||||
ret = -1;
|
||||
goto load_module_shlib_exit;
|
||||
}
|
||||
shlib->len_funcarray = numf;
|
||||
shlib->numfunc = 0;
|
||||
}
|
||||
loader_data.shlibs[lib_idx].numfunc = 0;
|
||||
for (int i = 0; i < numf; i++) {
|
||||
farray[i].fptr = dlsym(lib_handle,farray[i].fname);
|
||||
if (!farray[i].fptr) {
|
||||
@@ -215,9 +212,32 @@ int load_module_version_shlib(char *modname, char *version, loader_shlibfunc_t *
|
||||
ret = -1;
|
||||
goto load_module_shlib_exit;
|
||||
}
|
||||
loader_data.shlibs[lib_idx].funcarray[i].fname=strdup(farray[i].fname);
|
||||
loader_data.shlibs[lib_idx].funcarray[i].fptr = farray[i].fptr;
|
||||
loader_data.shlibs[lib_idx].numfunc++;
|
||||
/* check whether this function has been loaded before */
|
||||
int j = 0;
|
||||
for (; j < shlib->numfunc; ++j) {
|
||||
if (shlib->funcarray[j].fptr == farray[i].fptr) {
|
||||
int rc = strcmp(shlib->funcarray[i].fname, farray[i].fname);
|
||||
AssertFatal(rc == 0,
|
||||
"reloading the same fptr with different fnames (%s, %s)\n",
|
||||
shlib->funcarray[i].fname, farray[i].fname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == shlib->numfunc) {
|
||||
if (shlib->numfunc == shlib->len_funcarray) {
|
||||
loader_shlibfunc_t *n = realloc(shlib->funcarray, shlib->numfunc * 2 * sizeof(loader_shlibfunc_t));
|
||||
if (!n) {
|
||||
fprintf(stderr, "[LOADER] %s(): unable to allocate memory\n", __func__);
|
||||
ret = -1;
|
||||
goto load_module_shlib_exit;
|
||||
}
|
||||
shlib->funcarray = n;
|
||||
shlib->len_funcarray = shlib->numfunc * 2;
|
||||
}
|
||||
shlib->funcarray[j].fname = strdup(farray[i].fname);
|
||||
shlib->funcarray[j].fptr = farray[i].fptr;
|
||||
shlib->numfunc++;
|
||||
}
|
||||
} /* for int i... */
|
||||
} else { /* farray ! NULL */
|
||||
sprintf(afname,"%s_getfarray",modname);
|
||||
@@ -248,3 +268,18 @@ void * get_shlibmodule_fptr(char *modname, char *fname)
|
||||
} /* for i loop on modules */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void loader_reset()
|
||||
{
|
||||
for (int i = 0; i < loader_data.numshlibs && loader_data.shlibs[i].name != NULL; i++) {
|
||||
loader_shlibdesc_t *shlib = &loader_data.shlibs[i];
|
||||
free(shlib->name);
|
||||
free(shlib->thisshlib_path);
|
||||
for (int j = 0; j < shlib->numfunc; ++j)
|
||||
free(shlib->funcarray[j].fname);
|
||||
free(shlib->funcarray);
|
||||
shlib->numfunc = 0;
|
||||
shlib->len_funcarray = 0;
|
||||
}
|
||||
free(loader_data.shlibs);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ typedef struct {
|
||||
char *thisshlib_path;
|
||||
uint32_t numfunc;
|
||||
loader_shlibfunc_t *funcarray;
|
||||
uint32_t len_funcarray;
|
||||
}loader_shlibdesc_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -90,5 +91,6 @@ extern void * get_shlibmodule_fptr(char *modname, char *fname);
|
||||
extern loader_data_t loader_data;
|
||||
#endif /* LOAD_MODULE_SHLIB_MAIN */
|
||||
#define load_module_shlib(M, F, N, I) load_module_version_shlib(M, NULL, F, N, I)
|
||||
void loader_reset();
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/*! \file ue_power.h
|
||||
* \brief support routines used in MAC and PHY
|
||||
* \author R. Knopp, F. Kaltenberger
|
||||
* \date 2020
|
||||
* \version 0.1
|
||||
* \company Eurecom
|
||||
* \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr
|
||||
* \note
|
||||
* \warning
|
||||
*/
|
||||
|
||||
int16_t estimate_ue_tx_power(int norm,uint32_t tbs, uint32_t nb_rb, uint8_t control_only, lte_prefix_type_t ncp, uint8_t use_srs);
|
||||
|
||||
@@ -1,785 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/*! \file msc.c
|
||||
* \brief Message chart generator logging utility (generated files to processed by a script to produce a mscgen input file for generating a sequence diagram document)
|
||||
* \author Lionel GAUTHIER
|
||||
* \date 2015
|
||||
* \email: lionel.gauthier@eurecom.fr
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#define MSC_LIBRARY
|
||||
#include "msc.h"
|
||||
|
||||
#include "liblfds611.h"
|
||||
#include "intertask_interface.h"
|
||||
|
||||
|
||||
|
||||
#include "assertions.h"
|
||||
|
||||
//-------------------------------
|
||||
#define MSC_MAX_QUEUE_ELEMENTS 1024
|
||||
#define MSC_MAX_PROTO_NAME_LENGTH 16
|
||||
#define MSC_MAX_MESSAGE_LENGTH 512
|
||||
|
||||
//-------------------------------
|
||||
|
||||
FILE *g_msc_fd;
|
||||
char g_msc_proto2str[MAX_MSC_PROTOS][MSC_MAX_PROTO_NAME_LENGTH];
|
||||
|
||||
msc_interface_t msc_interface;
|
||||
|
||||
typedef unsigned long msc_message_number_t;
|
||||
typedef struct msc_queue_item_s {
|
||||
char *message_str;
|
||||
uint32_t message_str_size;
|
||||
uint8_t *message_bin;
|
||||
uint32_t message_bin_size;
|
||||
} msc_queue_item_t;
|
||||
|
||||
msc_message_number_t g_message_number = 0;
|
||||
struct lfds611_queue_state *g_msc_message_queue_p = NULL;
|
||||
struct lfds611_stack_state *g_msc_memory_stack_p = NULL;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void *msc_task(void *args_p)
|
||||
//------------------------------------------------------------------------------
|
||||
{
|
||||
MessageDef *received_message_p = NULL;
|
||||
// const char *msg_name = NULL;
|
||||
// instance_t instance = 0;
|
||||
long timer_id;
|
||||
itti_mark_task_ready(TASK_MSC);
|
||||
msc_start_use();
|
||||
timer_setup(0, // seconds
|
||||
50000, // usec
|
||||
TASK_MSC,
|
||||
INSTANCE_DEFAULT,
|
||||
TIMER_PERIODIC,
|
||||
NULL,
|
||||
&timer_id);
|
||||
|
||||
while(1) {
|
||||
itti_receive_msg(TASK_MSC, &received_message_p);
|
||||
|
||||
if (received_message_p != NULL) {
|
||||
// msg_name = ITTI_MSG_NAME (received_message_p);
|
||||
// instance = ITTI_MSG_DESTINATION_INSTANCE (received_message_p);
|
||||
switch (ITTI_MSG_ID(received_message_p)) {
|
||||
case TIMER_HAS_EXPIRED: {
|
||||
msc_flush_messages();
|
||||
}
|
||||
break;
|
||||
|
||||
case TERMINATE_MESSAGE: {
|
||||
fprintf(stderr, " *** Exiting MSC thread\n");
|
||||
timer_remove(timer_id);
|
||||
msc_end();
|
||||
itti_exit_task();
|
||||
}
|
||||
break;
|
||||
|
||||
case MESSAGE_TEST: {
|
||||
}
|
||||
break;
|
||||
|
||||
default: {
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "Task MSC exiting\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
int msc_init(const msc_env_t envP, const int max_threadsP)
|
||||
//------------------------------------------------------------------------------
|
||||
{
|
||||
int i;
|
||||
int rv;
|
||||
void *pointer_p;
|
||||
char msc_filename[256];
|
||||
fprintf(stderr, "Initializing MSC logs\n");
|
||||
rv = snprintf(msc_filename, 256, "/tmp/openair.msc.%i.log", envP); // TODO NAME
|
||||
|
||||
if ((0 >= rv) || (256 < rv)) {
|
||||
fprintf(stderr, "Error in MSC log file name");
|
||||
}
|
||||
|
||||
g_msc_fd = fopen(msc_filename,"w");
|
||||
AssertFatal(g_msc_fd != NULL, "Could not open MSC log file %s : %s", msc_filename, strerror(errno));
|
||||
rv = lfds611_stack_new(&g_msc_memory_stack_p, (lfds611_atom_t)max_threadsP + 2);
|
||||
|
||||
if (0 >= rv) {
|
||||
AssertFatal (0, "lfds611_stack_new failed!\n");
|
||||
}
|
||||
|
||||
rv = lfds611_queue_new(&g_msc_message_queue_p, (lfds611_atom_t)MSC_MAX_QUEUE_ELEMENTS);
|
||||
AssertFatal (rv, "lfds611_queue_new failed!\n");
|
||||
AssertFatal (g_msc_message_queue_p != NULL, "g_msc_message_queue_p is NULL!\n");
|
||||
msc_start_use();
|
||||
|
||||
for (i=0; i < max_threadsP * 30; i++) {
|
||||
pointer_p = malloc(MSC_MAX_MESSAGE_LENGTH);
|
||||
AssertFatal (pointer_p, "malloc failed!\n");
|
||||
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, pointer_p );
|
||||
AssertFatal (rv, "lfds611_stack_guaranteed_push failed for item %d\n", i);
|
||||
}
|
||||
|
||||
for (i = MIN_MSC_PROTOS; i < MAX_MSC_PROTOS; i++) {
|
||||
switch (i) {
|
||||
case MSC_IP_UE:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "IP_UE");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_IP_ENB:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "IP_ENB");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if (envP == MSC_E_UTRAN_LIPA) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_NAS_UE:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_UE");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_RRC_UE:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RRC_UE");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_PDCP_UE:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PDCP_UE");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_RLC_UE:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RLC_UE");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_MAC_UE:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MAC_UE");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_PHY_UE:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PHY_UE");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_PHY_ENB:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PHY_ENB");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_MAC_ENB:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MAC_ENB");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_RLC_ENB:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RLC_ENB");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_PDCP_ENB:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PDCP_ENB");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_RRC_ENB:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RRC_ENB");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_S1AP_ENB:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S1AP_ENB");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_MME_GW) || (envP == MSC_MME)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_GTPU_ENB:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "GTPU_ENB");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_GTPU_SGW:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "GTPU_SGW");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_MME_GW) || (envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_S1AP_MME:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S1AP_MME");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_MME_GW) || (envP == MSC_MME) || (envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_MMEAPP_MME:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MME_APP");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_NAS_MME:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_MME");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
msc_log_declare_proto(i);
|
||||
break;
|
||||
|
||||
case MSC_NAS_EMM_MME:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_EMM");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_NAS_ESM_MME:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_ESM");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_SP_GWAPP_MME:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "SP_GW_MME");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if (envP == MSC_MME_GW) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_S11_MME:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S11_MME");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if (envP == MSC_MME) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_S6A_MME:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S6A");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSC_HSS:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "HSS");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
|
||||
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
|
||||
msc_log_declare_proto(i);
|
||||
}
|
||||
|
||||
break;
|
||||
case MSC_F1AP_CU:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "F1AP_CU");
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
|
||||
//if ((envP == MSC_E_UTRAN) || (envP == MSC_MME_GW) || (envP == MSC_MME)) {
|
||||
msc_log_declare_proto(i);
|
||||
//}
|
||||
break;
|
||||
case MSC_F1AP_DU:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "F1AP_DU");
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
|
||||
//if ((envP == MSC_E_UTRAN) || (envP == MSC_MME_GW) || (envP == MSC_MME)) {
|
||||
msc_log_declare_proto(i);
|
||||
//}
|
||||
break;
|
||||
default:
|
||||
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "UNKNOWN");
|
||||
|
||||
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
|
||||
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rv = itti_create_task (TASK_MSC, msc_task, NULL);
|
||||
AssertFatal (rv == 0, "Create task for MSC failed!\n");
|
||||
fprintf(stderr, "Initializing MSC logs Done\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void msc_start_use(void)
|
||||
//------------------------------------------------------------------------------
|
||||
{
|
||||
lfds611_queue_use(g_msc_message_queue_p);
|
||||
lfds611_stack_use(g_msc_memory_stack_p);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void msc_flush_messages(void)
|
||||
//------------------------------------------------------------------------------
|
||||
{
|
||||
int rv;
|
||||
msc_queue_item_t *item_p = NULL;
|
||||
|
||||
while ((rv = lfds611_queue_dequeue( g_msc_message_queue_p, (void **)&item_p )) == 1) {
|
||||
if (NULL != item_p->message_str) {
|
||||
fputs(item_p->message_str, g_msc_fd);
|
||||
// TODO BIN DATA
|
||||
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, item_p->message_str );
|
||||
}
|
||||
|
||||
// TODO FREE BIN DATA
|
||||
free(item_p);
|
||||
}
|
||||
|
||||
fflush(g_msc_fd);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void msc_end(void)
|
||||
//------------------------------------------------------------------------------
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (NULL != g_msc_fd ) {
|
||||
msc_flush_messages();
|
||||
rv = fflush(g_msc_fd);
|
||||
|
||||
if (rv != 0) {
|
||||
fprintf(stderr, "Error while flushing stream of MSC log file: %s", strerror(errno));
|
||||
}
|
||||
|
||||
rv = fclose(g_msc_fd);
|
||||
|
||||
if (rv != 0) {
|
||||
fprintf(stderr, "Error while closing MSC log file: %s", strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void msc_log_declare_proto(
|
||||
const msc_proto_t protoP
|
||||
)
|
||||
//------------------------------------------------------------------------------
|
||||
{
|
||||
int rv = 0;
|
||||
msc_queue_item_t *new_item_p = NULL;
|
||||
char *char_message_p = NULL;
|
||||
|
||||
if ((MIN_MSC_PROTOS <= protoP) && (MAX_MSC_PROTOS > protoP)) {
|
||||
// may be build a memory pool for that also ?
|
||||
new_item_p = malloc(sizeof(msc_queue_item_t));
|
||||
|
||||
if (NULL != new_item_p) {
|
||||
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
|
||||
|
||||
if (0 == rv) {
|
||||
msc_flush_messages();
|
||||
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
|
||||
}
|
||||
|
||||
if (1 == rv) {
|
||||
rv = snprintf(char_message_p, MSC_MAX_MESSAGE_LENGTH, "%"PRIu64" [PROTO] %d %s\n", __sync_fetch_and_add (&g_message_number, 1), protoP, &g_msc_proto2str[protoP][0]);
|
||||
|
||||
if (0 > rv) {
|
||||
fprintf(stderr, "Error while declaring new protocol in MSC: %s", strerror(errno));
|
||||
}
|
||||
|
||||
new_item_p->message_str = char_message_p;
|
||||
new_item_p->message_str_size = rv;
|
||||
new_item_p->message_bin = NULL;
|
||||
new_item_p->message_bin_size = 0;
|
||||
rv = lfds611_queue_enqueue( g_msc_message_queue_p, new_item_p );
|
||||
|
||||
if (0 == rv) {
|
||||
rv = lfds611_queue_guaranteed_enqueue(g_msc_message_queue_p, new_item_p );
|
||||
|
||||
if (0 == rv) {
|
||||
fprintf(stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
|
||||
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
|
||||
free(new_item_p);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
} else {
|
||||
fprintf(stderr, "Error while lfds611_stack_pop()\n");
|
||||
}
|
||||
|
||||
free(new_item_p);
|
||||
} else {
|
||||
fprintf(stderr, "Error while malloc in MSC");
|
||||
}
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void msc_log_event(
|
||||
const msc_proto_t protoP,
|
||||
char *format, ...)
|
||||
//------------------------------------------------------------------------------
|
||||
{
|
||||
va_list args;
|
||||
int rv;
|
||||
int rv2;
|
||||
msc_queue_item_t *new_item_p = NULL;
|
||||
char *char_message_p = NULL;
|
||||
|
||||
if ((MIN_MSC_PROTOS > protoP) || (MAX_MSC_PROTOS <= protoP)) {
|
||||
return;
|
||||
}
|
||||
|
||||
new_item_p = malloc(sizeof(msc_queue_item_t));
|
||||
|
||||
if (NULL != new_item_p) {
|
||||
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
|
||||
|
||||
if (0 == rv) {
|
||||
msc_flush_messages();
|
||||
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
|
||||
}
|
||||
|
||||
if (1 == rv) {
|
||||
rv = snprintf(char_message_p, MSC_MAX_MESSAGE_LENGTH, "%"PRIu64" [EVENT] %d ", __sync_fetch_and_add (&g_message_number, 1), protoP);
|
||||
|
||||
if ((0 > rv) || (MSC_MAX_MESSAGE_LENGTH < rv)) {
|
||||
fprintf(stderr, "Error while logging MSC event : %s", &g_msc_proto2str[protoP][0]);
|
||||
goto error_event;
|
||||
}
|
||||
|
||||
va_start(args, format);
|
||||
rv2 = vsnprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, format, args);
|
||||
va_end(args);
|
||||
|
||||
if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
|
||||
fprintf(stderr, "Error while logging MSC event : %s", &g_msc_proto2str[protoP][0]);
|
||||
goto error_event;
|
||||
}
|
||||
|
||||
rv += rv2;
|
||||
rv2 = snprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, "\n");
|
||||
|
||||
if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
|
||||
fprintf(stderr, "Error while logging MSC event : %s", &g_msc_proto2str[protoP][0]);
|
||||
goto error_event;
|
||||
}
|
||||
|
||||
rv += rv2;
|
||||
new_item_p->message_str = char_message_p;
|
||||
new_item_p->message_str_size = rv;
|
||||
new_item_p->message_bin = NULL;
|
||||
new_item_p->message_bin_size = 0;
|
||||
rv = lfds611_queue_enqueue( g_msc_message_queue_p, new_item_p );
|
||||
|
||||
if (0 == rv) {
|
||||
fprintf(stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
|
||||
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
|
||||
free(new_item_p);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Error while lfds611_stack_pop()\n");
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
error_event:
|
||||
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
|
||||
free(new_item_p);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void msc_log_message(
|
||||
const char *const message_operationP,
|
||||
const msc_proto_t proto1P,
|
||||
const msc_proto_t proto2P,
|
||||
const uint8_t *const bytesP,
|
||||
const unsigned int num_bytes,
|
||||
char *format, ...)
|
||||
//------------------------------------------------------------------------------
|
||||
{
|
||||
va_list args;
|
||||
uint64_t mac = 0; // TO DO mac on bytesP param
|
||||
int rv;
|
||||
int rv2;
|
||||
msc_queue_item_t *new_item_p = NULL;
|
||||
char *char_message_p = NULL;
|
||||
|
||||
if ((MIN_MSC_PROTOS > proto1P) || (MAX_MSC_PROTOS <= proto1P) ||
|
||||
(MIN_MSC_PROTOS > proto2P) || (MAX_MSC_PROTOS <= proto2P) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
new_item_p = malloc(sizeof(msc_queue_item_t));
|
||||
|
||||
if (NULL != new_item_p) {
|
||||
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
|
||||
|
||||
if (0 == rv) {
|
||||
msc_flush_messages();
|
||||
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
|
||||
}
|
||||
|
||||
if (1 == rv) {
|
||||
rv = snprintf(char_message_p, MSC_MAX_MESSAGE_LENGTH, "%"PRIu64" [MESSAGE] %d %s %d %"PRIu64" ",
|
||||
__sync_fetch_and_add (&g_message_number, 1), proto1P, message_operationP, proto2P, mac);
|
||||
|
||||
if ((0 > rv) || (MSC_MAX_MESSAGE_LENGTH < rv)) {
|
||||
fprintf(stderr, "Error while logging MSC message : %s/%s", &g_msc_proto2str[proto1P][0], &g_msc_proto2str[proto2P][0]);
|
||||
goto error_event;
|
||||
}
|
||||
|
||||
va_start(args, format);
|
||||
rv2 = vsnprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, format, args);
|
||||
va_end(args);
|
||||
|
||||
if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
|
||||
fprintf(stderr, "Error while logging MSC message : %s/%s", &g_msc_proto2str[proto1P][0], &g_msc_proto2str[proto2P][0]);
|
||||
goto error_event;
|
||||
}
|
||||
|
||||
rv += rv2;
|
||||
rv2 = snprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, "\n");
|
||||
|
||||
if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
|
||||
fprintf(stderr, "Error while logging MSC message : %s/%s", &g_msc_proto2str[proto1P][0], &g_msc_proto2str[proto2P][0]);
|
||||
goto error_event;
|
||||
}
|
||||
|
||||
rv += rv2;
|
||||
new_item_p->message_str = char_message_p;
|
||||
new_item_p->message_str_size = rv;
|
||||
new_item_p->message_bin = NULL; // TO DO
|
||||
new_item_p->message_bin_size = 0; // TO DO
|
||||
rv = lfds611_queue_enqueue( g_msc_message_queue_p, new_item_p );
|
||||
|
||||
if (0 == rv) {
|
||||
fprintf(stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
|
||||
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
|
||||
free(new_item_p);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Error while lfds611_stack_pop()\n");
|
||||
msc_flush_messages();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
error_event:
|
||||
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
|
||||
free(new_item_p);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// function called when oai loader loads the msc shared lib
|
||||
int msc_autoinit(msc_interface_t *msc_interface)
|
||||
//------------------------------------------------------------------------------
|
||||
{
|
||||
msc_interface->msc_init = msc_init;
|
||||
msc_interface->msc_start_use = msc_start_use;
|
||||
msc_interface->msc_end = msc_end;
|
||||
msc_interface->msc_log_event = msc_log_event;
|
||||
msc_interface->msc_log_message = msc_log_message;
|
||||
msc_interface->msc_loaded = 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* 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 MSC_H_
|
||||
#define MSC_H_
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
MIN_MSC_ENV = 0,
|
||||
MSC_E_UTRAN = MIN_MSC_ENV,
|
||||
MSC_E_UTRAN_LIPA,
|
||||
MSC_MME_GW,
|
||||
MSC_MME,
|
||||
MSC_SP_GW,
|
||||
MAX_MSC_ENV
|
||||
} msc_env_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
MIN_MSC_PROTOS = 0,
|
||||
MSC_IP_UE = MIN_MSC_PROTOS,
|
||||
MSC_NAS_UE,
|
||||
MSC_RRC_UE,
|
||||
MSC_PDCP_UE,
|
||||
MSC_RLC_UE,
|
||||
MSC_MAC_UE,
|
||||
MSC_PHY_UE,
|
||||
MSC_PHY_ENB,
|
||||
MSC_MAC_ENB,
|
||||
MSC_RLC_ENB,
|
||||
MSC_PDCP_ENB,
|
||||
MSC_PDCP_GNB,
|
||||
MSC_RRC_ENB,
|
||||
MSC_RRC_GNB,
|
||||
MSC_IP_ENB,
|
||||
MSC_S1AP_ENB,
|
||||
MSC_NGAP_GNB,
|
||||
MSC_GTPU_ENB,
|
||||
MSC_GTPU_GNB,
|
||||
MSC_GTPU_SGW,
|
||||
MSC_S1AP_MME,
|
||||
MSC_NGAP_AMF,
|
||||
MSC_MMEAPP_MME,
|
||||
MSC_NAS_MME,
|
||||
MSC_NAS_EMM_MME,
|
||||
MSC_NAS_ESM_MME,
|
||||
MSC_SP_GWAPP_MME,
|
||||
MSC_S11_MME,
|
||||
MSC_S6A_MME,
|
||||
MSC_HSS,
|
||||
MSC_F1AP_CU,
|
||||
MSC_F1AP_DU,
|
||||
MSC_X2AP_SRC_ENB,
|
||||
MSC_X2AP_TARGET_ENB,
|
||||
MAX_MSC_PROTOS,
|
||||
} msc_proto_t;
|
||||
|
||||
|
||||
|
||||
// Access stratum
|
||||
#define MSC_AS_TIME_FMT "%05u:%02u"
|
||||
|
||||
#define MSC_AS_TIME_ARGS(CTXT_Pp) \
|
||||
(CTXT_Pp)->frame, \
|
||||
(CTXT_Pp)->subframe
|
||||
|
||||
typedef int(*msc_init_t)(const msc_env_t, const int );
|
||||
typedef void(*msc_start_use_t)(void );
|
||||
typedef void(*msc_end_t)(void);
|
||||
typedef void(*msc_log_event_t)(const msc_proto_t,char *, ...);
|
||||
typedef void(*msc_log_message_t)(const char *const, const msc_proto_t, const msc_proto_t,
|
||||
const uint8_t *const, const unsigned int, char *, ...);
|
||||
typedef struct msc_interface {
|
||||
int msc_loaded;
|
||||
msc_init_t msc_init;
|
||||
msc_start_use_t msc_start_use;
|
||||
msc_end_t msc_end;
|
||||
msc_log_event_t msc_log_event;
|
||||
msc_log_message_t msc_log_message;
|
||||
} msc_interface_t;
|
||||
|
||||
#ifdef MSC_LIBRARY
|
||||
int msc_init(const msc_env_t envP, const int max_threadsP);
|
||||
void msc_start_use(void);
|
||||
void msc_flush_messages(void);
|
||||
void msc_end(void);
|
||||
void msc_log_declare_proto(const msc_proto_t protoP);
|
||||
void msc_log_event(const msc_proto_t protoP,char *format, ...);
|
||||
void msc_log_message(
|
||||
const char *const message_operationP,
|
||||
const msc_proto_t receiverP,
|
||||
const msc_proto_t senderP,
|
||||
const uint8_t *const bytesP,
|
||||
const unsigned int num_bytes,
|
||||
char *format, ...);
|
||||
|
||||
#else
|
||||
|
||||
#define MESSAGE_CHART_GENERATOR msc_interface.msc_loaded
|
||||
|
||||
extern msc_interface_t msc_interface;
|
||||
#define MSC_INIT(arg1,arg2) if(msc_interface.msc_loaded) msc_interface.msc_init(arg1,arg2)
|
||||
#define MSC_START_USE if(msc_interface.msc_loaded) msc_interface.msc_start_use
|
||||
#define MSC_END if(msc_interface.msc_loaded) msc_interface.msc_end
|
||||
#define MSC_LOG_EVENT(mScPaRaMs, fORMAT, aRGS...) if(msc_interface.msc_loaded) msc_interface.msc_log_event(mScPaRaMs, fORMAT, ##aRGS)
|
||||
#define MSC_LOG_RX_MESSAGE(rECEIVER, sENDER, bYTES, nUMbYTES, fORMAT, aRGS...) if(msc_interface.msc_loaded) msc_interface.msc_log_message("<-",rECEIVER, sENDER, (const uint8_t *)bYTES, nUMbYTES, fORMAT, ##aRGS)
|
||||
#define MSC_LOG_RX_DISCARDED_MESSAGE(rECEIVER, sENDER, bYTES, nUMbYTES, fORMAT, aRGS...) if(msc_interface.msc_loaded) msc_interface.msc_log_message("x-",rECEIVER, sENDER, (const uint8_t *)bYTES, nUMbYTES, fORMAT, ##aRGS)
|
||||
#define MSC_LOG_TX_MESSAGE(sENDER, rECEIVER, bYTES, nUMbYTES, fORMAT, aRGS...) if(msc_interface.msc_loaded) msc_interface.msc_log_message("->",sENDER, rECEIVER, (const uint8_t *)bYTES, nUMbYTES, fORMAT, ##aRGS)
|
||||
#define MSC_LOG_TX_MESSAGE_FAILED(sENDER, rECEIVER, bYTES, nUMbYTES, fORMAT, aRGS...) if(msc_interface.msc_loaded) msc_interface.msc_log_message("-x",sENDER, rECEIVER, (const uint8_t *)bYTES, nUMbYTES, fORMAT, ##aRGS)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -36,6 +36,27 @@
|
||||
|
||||
const char *duplex_mode[]={"FDD","TDD"};
|
||||
|
||||
int tables_5_3_2[5][11] = {
|
||||
{25, 52, 79, 106, 133, 160, 216, 270, -1, -1, -1}, // 15 FR1
|
||||
{11, 24, 38, 51, 65, 78, 106, 133, 162, 217, 273}, // 30 FR1
|
||||
{-1, 11, 18, 24, 31, 38, 51, 65, 79, 107, 135}, // 60 FR1
|
||||
{66, 132, 264, -1 , -1, -1, -1, -1, -1, -1, -1}, // 60 FR2
|
||||
{32, 66, 132, 264, -1, -1, -1, -1, -1, -1, -1} // 120FR2
|
||||
};
|
||||
|
||||
int get_supported_band_index(int scs, int band, int n_rbs){
|
||||
|
||||
int scs_index = scs;
|
||||
if (band>256)
|
||||
scs_index++;
|
||||
for (int i=0; i<11; i++) {
|
||||
if(n_rbs == tables_5_3_2[scs][i])
|
||||
return i;
|
||||
}
|
||||
return (-1); // not found
|
||||
}
|
||||
|
||||
|
||||
// Table 5.2-1 NR operating bands in FR1 & FR2 (3GPP TS 38.101)
|
||||
// Table 5.4.2.3-1 Applicable NR-ARFCN per operating band in FR1 & FR2 (3GPP TS 38.101)
|
||||
// Notes:
|
||||
@@ -231,7 +252,6 @@ uint32_t nr_get_code_rate(uint8_t Imcs, uint8_t table_idx) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void get_coreset_rballoc(uint8_t *FreqDomainResource,int *n_rb,int *rb_offset) {
|
||||
|
||||
uint8_t count=0, start=0, start_set=0;
|
||||
@@ -483,6 +503,7 @@ int get_nr_table_idx(int nr_bandP, uint8_t scs_index) {
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
int get_subband_size(int NPRB,int size) {
|
||||
// implements table 5.2.1.4-2 from 36.214
|
||||
//
|
||||
|
||||
@@ -80,6 +80,7 @@ void SLIV2SL(int SLIV,int *S,int *L);
|
||||
int get_dmrs_port(int nl, uint16_t dmrs_ports);
|
||||
uint16_t SL_to_bitmap(int startSymbolIndex, int nrOfSymbols);
|
||||
int get_nb_periods_per_frame(uint8_t tdd_period);
|
||||
int get_supported_band_index(int scs, int band, int n_rbs);
|
||||
long rrc_get_max_nr_csrs(uint8_t max_rbs, long b_SRS);
|
||||
|
||||
#define CEILIDIV(a,b) ((a+b-1)/b)
|
||||
|
||||
@@ -256,8 +256,8 @@ typedef struct IttiMsgText_s {
|
||||
#include <openair3/MME_APP/mme_app.h>
|
||||
//#include <proto.h>
|
||||
|
||||
#include <openair3/GTPV1-U/gtpv1u_eNB_task.h>
|
||||
#include <openair3/GTPV1-U/gtpv1u_gNB_task.h>
|
||||
#include <openair3/ocp-gtpu/gtpv1u_eNB_task.h>
|
||||
#include <openair3/ocp-gtpu/gtpv1u_gNB_task.h>
|
||||
void *rrc_enb_process_itti_msg(void *);
|
||||
#include <openair3/SCTP/sctp_eNB_task.h>
|
||||
#include <openair3/NGAP/ngap_gNB.h>
|
||||
@@ -338,10 +338,7 @@ void *rrc_enb_process_msg(void *);
|
||||
TASK_DEF(TASK_RRC_NRUE, TASK_PRIORITY_MED, 200, NULL, NULL) \
|
||||
TASK_DEF(TASK_NAS_UE, TASK_PRIORITY_MED, 200, NULL, NULL) \
|
||||
TASK_DEF(TASK_RAL_UE, TASK_PRIORITY_MED, 200, NULL, NULL) \
|
||||
TASK_DEF(TASK_MSC, TASK_PRIORITY_MED, 200, NULL, NULL)\
|
||||
TASK_DEF(TASK_GTPV1_U, TASK_PRIORITY_MED, 1000,NULL, NULL)\
|
||||
TASK_DEF(OCP_GTPV1_U, TASK_PRIORITY_MED, 1000,NULL, NULL)\
|
||||
TASK_DEF(TASK_UDP, TASK_PRIORITY_MED, 1000, NULL, NULL)\
|
||||
TASK_DEF(TASK_CU_F1, TASK_PRIORITY_MED, 200, NULL, NULL) \
|
||||
TASK_DEF(TASK_DU_F1, TASK_PRIORITY_MED, 200, NULL, NULL) \
|
||||
TASK_DEF(TASK_RRC_UE_SIM, TASK_PRIORITY_MED, 200, NULL, NULL) \
|
||||
@@ -560,7 +557,6 @@ MessageDef *itti_alloc_new_message_sized(
|
||||
This function should be called from the main thread after having created all ITTI tasks.
|
||||
**/
|
||||
void itti_wait_tasks_end(void);
|
||||
#define ADDED_QUEUES_MAX 10 // Fix me: MSC component too hard to understand, we keep room for 10 queues created dynamically
|
||||
void itti_set_task_real_time(task_id_t task_id);
|
||||
|
||||
/** \brief Send a termination message to all tasks.
|
||||
|
||||
@@ -62,7 +62,6 @@ component verbosity level enabled
|
||||
16 PERF: medium info N
|
||||
17 OIP: medium info N
|
||||
18 CLI: medium info N
|
||||
19 MSC: medium info N
|
||||
20 OCM: medium info N
|
||||
21 UDP: medium info N
|
||||
22 GTPV1U: medium info N
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
|
||||
static char *grouptypes[] = {"ltestats","cpustats"};
|
||||
static double cpufreq;
|
||||
extern notifiedFIFO_t measur_fifo;
|
||||
#define TELNET_NUM_MEASURTYPES (sizeof(grouptypes)/sizeof(char *))
|
||||
|
||||
#define HDR "---------------------------------"
|
||||
|
||||
@@ -43,9 +43,9 @@ int main(int argc, char *argv[]) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uint64_t deb=rdtsc();
|
||||
uint64_t deb=rdtsc_oai();
|
||||
usleep(100000);
|
||||
cpuCyclesMicroSec=(rdtsc()-deb)/100000;
|
||||
cpuCyclesMicroSec=(rdtsc_oai()-deb)/100000;
|
||||
printf("Cycles per µs: %lu\n",cpuCyclesMicroSec);
|
||||
printf("Key" SEP "delay to process" SEP "processing time" SEP "delay to be read answer\n");
|
||||
notifiedFIFO_elt_t doneRequest;
|
||||
|
||||
@@ -72,11 +72,11 @@ void *one_thread(void *arg) {
|
||||
do {
|
||||
notifiedFIFO_elt_t *elt=pullNotifiedFifoRemember(&tp->incomingFifo, myThread);
|
||||
|
||||
if (tp->measurePerf) elt->startProcessingTime=rdtsc();
|
||||
if (tp->measurePerf) elt->startProcessingTime=rdtsc_oai();
|
||||
|
||||
elt->processingFunc(NotifiedFifoData(elt));
|
||||
|
||||
if (tp->measurePerf) elt->endProcessingTime=rdtsc();
|
||||
if (tp->measurePerf) elt->endProcessingTime=rdtsc_oai();
|
||||
|
||||
if (elt->reponseFifo) {
|
||||
// Check if the job is still alive, else it has been aborted
|
||||
@@ -97,7 +97,7 @@ void initNamedTpool(char *params,tpool_t *pool, bool performanceMeas, char *name
|
||||
char *measr=getenv("threadPoolMeasurements");
|
||||
pool->measurePerf=performanceMeas;
|
||||
// force measurement if the output is defined
|
||||
pool->measurePerf=measr!=NULL;
|
||||
pool->measurePerf |= measr!=NULL;
|
||||
|
||||
if (measr) {
|
||||
mkfifo(measr,0666);
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <assertions.h>
|
||||
#include <LOG/log.h>
|
||||
#include <common/utils/system.h>
|
||||
//#include <stdatomic.h>
|
||||
#include "assertions.h"
|
||||
#include "common/utils/time_meas.h"
|
||||
#include "common/utils/system.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define THREADINIT PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
|
||||
@@ -60,10 +60,10 @@ typedef struct notifiedFIFO_elt_s {
|
||||
struct notifiedFIFO_s *reponseFifo;
|
||||
void (*processingFunc)(void *);
|
||||
bool malloced;
|
||||
uint64_t creationTime;
|
||||
uint64_t startProcessingTime;
|
||||
uint64_t endProcessingTime;
|
||||
uint64_t returnTime;
|
||||
oai_cputime_t creationTime;
|
||||
oai_cputime_t startProcessingTime;
|
||||
oai_cputime_t endProcessingTime;
|
||||
oai_cputime_t returnTime;
|
||||
void *msgData;
|
||||
} notifiedFIFO_elt_t;
|
||||
|
||||
@@ -97,12 +97,11 @@ static inline void *NotifiedFifoData(notifiedFIFO_elt_t *elt) {
|
||||
|
||||
static inline void delNotifiedFIFO_elt(notifiedFIFO_elt_t *elt) {
|
||||
if (elt->malloced) {
|
||||
elt->malloced=false;
|
||||
elt->malloced = false;
|
||||
free(elt);
|
||||
} else
|
||||
printf("delNotifiedFIFO on something not allocated by newNotifiedFIFO\n");
|
||||
|
||||
//LOG_W(UTIL,"delNotifiedFIFO on something not allocated by newNotifiedFIFO\n");
|
||||
}
|
||||
/* it is allowed to call delNotifiedFIFO_elt when the memory is managed by
|
||||
* the caller */
|
||||
}
|
||||
|
||||
static inline void initNotifiedFIFO_nothreadSafe(notifiedFIFO_t *nf) {
|
||||
@@ -141,8 +140,7 @@ static inline notifiedFIFO_elt_t *pullNotifiedFIFO_nothreadSafe(notifiedFIFO_t
|
||||
|
||||
notifiedFIFO_elt_t *ret=nf->outF;
|
||||
|
||||
if (nf->outF==nf->outF->next)
|
||||
LOG_E(UTIL,"Circular list in thread pool: push several times the same buffer is forbidden\n");
|
||||
AssertFatal(nf->outF != nf->outF->next,"Circular list in thread pool: push several times the same buffer is forbidden\n");
|
||||
|
||||
nf->outF=nf->outF->next;
|
||||
|
||||
@@ -174,6 +172,20 @@ static inline notifiedFIFO_elt_t *pollNotifiedFIFO(notifiedFIFO_t *nf) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline time_stats_t exec_time_stats_NotifiedFIFO(const notifiedFIFO_elt_t* elt)
|
||||
{
|
||||
time_stats_t ts = {0};
|
||||
if (elt->startProcessingTime == 0 && elt->endProcessingTime == 0)
|
||||
return ts; /* no measurements done */
|
||||
ts.in = elt->startProcessingTime;
|
||||
ts.diff = elt->endProcessingTime - ts.in;
|
||||
ts.p_time = ts.diff;
|
||||
ts.diff_square = ts.diff * ts.diff;
|
||||
ts.max = ts.diff;
|
||||
ts.trials = 1;
|
||||
return ts;
|
||||
}
|
||||
|
||||
// This function aborts all messages matching the key
|
||||
// If the queue is used in thread pools, it doesn't cancels already running processing
|
||||
// because the message has already been picked
|
||||
@@ -224,18 +236,18 @@ typedef struct thread_pool {
|
||||
} tpool_t;
|
||||
|
||||
static inline void pushTpool(tpool_t *t, notifiedFIFO_elt_t *msg) {
|
||||
if (t->measurePerf) msg->creationTime=rdtsc();
|
||||
if (t->measurePerf) msg->creationTime=rdtsc_oai();
|
||||
|
||||
if ( t->activated)
|
||||
pushNotifiedFIFO(&t->incomingFifo, msg);
|
||||
else {
|
||||
if (t->measurePerf)
|
||||
msg->startProcessingTime=rdtsc();
|
||||
msg->startProcessingTime=rdtsc_oai();
|
||||
|
||||
msg->processingFunc(NotifiedFifoData(msg));
|
||||
|
||||
if (t->measurePerf)
|
||||
msg->endProcessingTime=rdtsc();
|
||||
msg->endProcessingTime=rdtsc_oai();
|
||||
|
||||
if (msg->reponseFifo)
|
||||
pushNotifiedFIFO(msg->reponseFifo, msg);
|
||||
@@ -246,7 +258,7 @@ static inline notifiedFIFO_elt_t *pullTpool(notifiedFIFO_t *responseFifo, tpool_
|
||||
notifiedFIFO_elt_t *msg= pullNotifiedFIFO(responseFifo);
|
||||
AssertFatal(t->traceFd, "Thread pool used while not initialized");
|
||||
if (t->measurePerf)
|
||||
msg->returnTime=rdtsc();
|
||||
msg->returnTime=rdtsc_oai();
|
||||
|
||||
if (t->traceFd > 0)
|
||||
if(write(t->traceFd, msg, sizeof(*msg)));
|
||||
@@ -261,7 +273,7 @@ static inline notifiedFIFO_elt_t *tryPullTpool(notifiedFIFO_t *responseFifo, tpo
|
||||
return NULL;
|
||||
|
||||
if (t->measurePerf)
|
||||
msg->returnTime=rdtsc();
|
||||
msg->returnTime=rdtsc_oai();
|
||||
|
||||
if (t->traceFd)
|
||||
if(write(t->traceFd, msg, sizeof(*msg)));
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include "time_meas.h"
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "assertions.h"
|
||||
#include <pthread.h>
|
||||
#include "common/config/config_userapi.h"
|
||||
#include <common/utils/threadPool/thread-pool.h>
|
||||
// global var for openair performance profiler
|
||||
int opp_enabled = 0;
|
||||
double cpu_freq_GHz __attribute__ ((aligned(32)));
|
||||
|
||||
double cpu_freq_GHz __attribute__ ((aligned(32)))=0.0;
|
||||
static uint32_t max_cpumeasur;
|
||||
static time_stats_t **measur_table;
|
||||
notifiedFIFO_t measur_fifo;
|
||||
double get_cpu_freq_GHz(void)
|
||||
{
|
||||
if (cpu_freq_GHz <1 ) {
|
||||
time_stats_t ts = {0};
|
||||
reset_meas(&ts);
|
||||
ts.trials++;
|
||||
ts.in = rdtsc_oai();
|
||||
sleep(1);
|
||||
ts.diff = (rdtsc_oai()-ts.in);
|
||||
cpu_freq_GHz = (double)ts.diff/1000000000;
|
||||
printf("CPU Freq is %f \n", cpu_freq_GHz);
|
||||
}
|
||||
return cpu_freq_GHz;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void print_meas_now(time_stats_t *ts,
|
||||
const char *name,
|
||||
FILE *file_name)
|
||||
{
|
||||
if (opp_enabled) {
|
||||
//static double cpu_freq_GHz = 3.2;
|
||||
|
||||
//if (cpu_freq_GHz == 0.0)
|
||||
//cpu_freq_GHz = get_cpu_freq_GHz(); // super slow
|
||||
if (ts->trials>0) {
|
||||
//fprintf(file_name,"Name %25s: Processing %15.3f ms for SF %d, diff_now %15.3f \n", name,(ts->p_time/(cpu_freq_GHz*1000000.0)),subframe,ts->p_time);
|
||||
fprintf(file_name,"%15.3f us, diff_now %15.3f \n",(ts->p_time/(cpu_freq_GHz*1000.0)),(double)ts->p_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_meas(time_stats_t *ts,
|
||||
const char *name,
|
||||
time_stats_t *total_exec_time,
|
||||
time_stats_t *sf_exec_time)
|
||||
{
|
||||
if (opp_enabled) {
|
||||
static int first_time = 0;
|
||||
static double cpu_freq_GHz = 0.0;
|
||||
|
||||
if (cpu_freq_GHz == 0.0)
|
||||
cpu_freq_GHz = get_cpu_freq_GHz();
|
||||
|
||||
if (first_time == 0) {
|
||||
first_time=1;
|
||||
|
||||
if ((total_exec_time == NULL) || (sf_exec_time== NULL))
|
||||
fprintf(stderr, "%25s %25s %25s %25s %25s %6f\n","Name","Total","Per Trials", "Num Trials","CPU_F_GHz", cpu_freq_GHz);
|
||||
else
|
||||
fprintf(stderr, "%25s %25s %25s %20s %15s %6f\n","Name","Total","Average/Frame","Trials", "CPU_F_GHz", cpu_freq_GHz);
|
||||
}
|
||||
|
||||
if (ts->trials>0) {
|
||||
//printf("%20s: total: %10.3f ms, average: %10.3f us (%10d trials)\n", name, ts->diff/cpu_freq_GHz/1000000.0, ts->diff/ts->trials/cpu_freq_GHz/1000.0, ts->trials);
|
||||
if ((total_exec_time == NULL) || (sf_exec_time== NULL)) {
|
||||
fprintf(stderr, "%25s: %15.3f us; %15d; %15.3f us;\n",
|
||||
name,
|
||||
(ts->diff/ts->trials/cpu_freq_GHz/1000.0),
|
||||
ts->trials,
|
||||
ts->max/cpu_freq_GHz/1000.0);
|
||||
} else {
|
||||
fprintf(stderr, "%25s: %15.3f ms (%5.2f%%); %15.3f us (%5.2f%%); %15d;\n",
|
||||
name,
|
||||
(ts->diff/cpu_freq_GHz/1000000.0),
|
||||
((ts->diff/cpu_freq_GHz/1000000.0)/(total_exec_time->diff/cpu_freq_GHz/1000000.0))*100, // percentage
|
||||
(ts->diff/ts->trials/cpu_freq_GHz/1000.0),
|
||||
((ts->diff/ts->trials/cpu_freq_GHz/1000.0)/(sf_exec_time->diff/sf_exec_time->trials/cpu_freq_GHz/1000.0))*100, // percentage
|
||||
ts->trials);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int print_meas_log(time_stats_t *ts,
|
||||
const char *name,
|
||||
time_stats_t *total_exec_time,
|
||||
time_stats_t *sf_exec_time,
|
||||
char *output)
|
||||
{
|
||||
int stroff = 0;
|
||||
static int first_time = 0;
|
||||
static double cpu_freq_GHz = 0.0;
|
||||
|
||||
if (cpu_freq_GHz == 0.0)
|
||||
cpu_freq_GHz = get_cpu_freq_GHz();
|
||||
|
||||
if (first_time == 0) {
|
||||
first_time=1;
|
||||
|
||||
if ((total_exec_time == NULL) || (sf_exec_time== NULL))
|
||||
stroff += sprintf(output, "%25s %25s %25s %25s %25s %6f\n","Name","Total","Per Trials", "Num Trials","CPU_F_GHz", cpu_freq_GHz);
|
||||
else
|
||||
stroff += sprintf(output+stroff, "%25s %25s %25s %20s %15s %6f\n","Name","Total","Average/Frame","Trials", "CPU_F_GHz", cpu_freq_GHz);
|
||||
}
|
||||
|
||||
if (ts->trials>0) {
|
||||
//printf("%20s: total: %10.3f ms, average: %10.3f us (%10d trials)\n", name, ts->diff/cpu_freq_GHz/1000000.0, ts->diff/ts->trials/cpu_freq_GHz/1000.0, ts->trials);
|
||||
if ((total_exec_time == NULL) || (sf_exec_time== NULL)) {
|
||||
stroff += sprintf(output+stroff, "%25s: %15.3f us; %15d; %15.3f us;\n",
|
||||
name,
|
||||
(ts->diff/ts->trials/cpu_freq_GHz/1000.0),
|
||||
ts->trials,
|
||||
ts->max/cpu_freq_GHz/1000.0);
|
||||
} else {
|
||||
stroff += sprintf(output+stroff, "%25s: %15.3f ms (%5.2f%%); %15.3f us (%5.2f%%); %15d;\n",
|
||||
name,
|
||||
(ts->diff/cpu_freq_GHz/1000000.0),
|
||||
((ts->diff/cpu_freq_GHz/1000000.0)/(total_exec_time->diff/cpu_freq_GHz/1000000.0))*100, // percentage
|
||||
(ts->diff/ts->trials/cpu_freq_GHz/1000.0),
|
||||
((ts->diff/ts->trials/cpu_freq_GHz/1000.0)/(sf_exec_time->diff/sf_exec_time->trials/cpu_freq_GHz/1000.0))*100, // percentage
|
||||
ts->trials);
|
||||
}
|
||||
}
|
||||
return stroff;
|
||||
}
|
||||
|
||||
double get_time_meas_us(time_stats_t *ts)
|
||||
{
|
||||
static double cpu_freq_GHz = 0.0;
|
||||
|
||||
if (cpu_freq_GHz == 0.0)
|
||||
cpu_freq_GHz = get_cpu_freq_GHz();
|
||||
|
||||
if (ts->trials>0)
|
||||
return (ts->diff/ts->trials/cpu_freq_GHz/1000.0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* function for the asynchronous measurment module: cpu stat are sent to a dedicated thread
|
||||
* which is in charge of computing the cpu time spent in a given function/algorithm...
|
||||
*/
|
||||
|
||||
time_stats_t *register_meas(char *name)
|
||||
{
|
||||
for (int i=0; i<max_cpumeasur; i++) {
|
||||
if (measur_table[i] == NULL) {
|
||||
measur_table[i] = (time_stats_t *)malloc(sizeof(time_stats_t));
|
||||
memset(measur_table[i] ,0,sizeof(time_stats_t));
|
||||
measur_table[i]->meas_name = strdup(name);
|
||||
measur_table[i]->meas_index = i;
|
||||
measur_table[i]->tpoolmsg =newNotifiedFIFO_elt(sizeof(time_stats_msg_t),0,NULL,NULL);
|
||||
measur_table[i]->tstatptr = (time_stats_msg_t *)NotifiedFifoData(measur_table[i]->tpoolmsg);
|
||||
return measur_table[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void free_measurtbl(void) {
|
||||
for (int i=0; i<max_cpumeasur; i++) {
|
||||
if (measur_table[i] != NULL) {
|
||||
free(measur_table[i]->meas_name);
|
||||
delNotifiedFIFO_elt(measur_table[i]->tpoolmsg);
|
||||
free(measur_table[i]);
|
||||
}
|
||||
}
|
||||
//free the fifo...
|
||||
}
|
||||
|
||||
void run_cpumeasur(void) {
|
||||
struct sched_param schedp;
|
||||
pthread_setname_np(pthread_self(), "measur");
|
||||
schedp.sched_priority=0;
|
||||
int rt=pthread_setschedparam(pthread_self(), SCHED_IDLE, &schedp);
|
||||
AssertFatal(rt==0, "couldn't set measur thread priority: %s\n",strerror(errno));
|
||||
initNotifiedFIFO(&measur_fifo);
|
||||
while(1) {
|
||||
notifiedFIFO_elt_t *msg = pullNotifiedFIFO(&measur_fifo);
|
||||
time_stats_msg_t *tsm = (time_stats_msg_t *)NotifiedFifoData(msg);
|
||||
switch(tsm->msgid) {
|
||||
case TIMESTAT_MSGID_START:
|
||||
measur_table[tsm->timestat_id]->in=tsm->ts;
|
||||
(measur_table[tsm->timestat_id]->trials)++;
|
||||
break;
|
||||
case TIMESTAT_MSGID_STOP:
|
||||
/// process duration is the difference between two clock points
|
||||
measur_table[tsm->timestat_id]->p_time = (tsm->ts - measur_table[tsm->timestat_id]->in);
|
||||
measur_table[tsm->timestat_id]->diff += measur_table[tsm->timestat_id]->p_time;
|
||||
if ( measur_table[tsm->timestat_id]->p_time > measur_table[tsm->timestat_id]->max )
|
||||
measur_table[tsm->timestat_id]->max = measur_table[tsm->timestat_id]->p_time;
|
||||
break;
|
||||
case TIMESTAT_MSGID_DISPLAY:
|
||||
{
|
||||
char aline[256];
|
||||
int start, stop;
|
||||
if (tsm->displayFunc != NULL) {
|
||||
if(tsm->timestat_id >= 0) {
|
||||
start=tsm->timestat_id ;
|
||||
stop=start+1;
|
||||
}
|
||||
else {
|
||||
start=0;
|
||||
stop=max_cpumeasur ;
|
||||
}
|
||||
for (int i=start ; i<stop ; i++) {
|
||||
if (measur_table[i] != NULL) {
|
||||
sprintf(aline,"%s: %15.3f us ",measur_table[i]->meas_name, measur_table[i]->trials==0?0:( (measur_table[i]->trials/measur_table[i]->diff )/ cpu_freq_GHz /1000 ));
|
||||
tsm->displayFunc(aline);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TIMESTAT_MSGID_END:
|
||||
free_measurtbl();
|
||||
delNotifiedFIFO_elt(msg);
|
||||
pthread_exit(NULL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
delNotifiedFIFO_elt(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void init_meas(void) {
|
||||
pthread_t thid;
|
||||
paramdef_t cpumeasur_params[] = CPUMEASUR_PARAMS_DESC;
|
||||
int numparams=sizeof(cpumeasur_params)/sizeof(paramdef_t);
|
||||
int rt = config_get( cpumeasur_params,numparams,CPUMEASUR_SECTION);
|
||||
AssertFatal(rt >= 0, "cpumeasur configuration couldn't be performed");
|
||||
measur_table=calloc(max_cpumeasur,sizeof( time_stats_t *));
|
||||
AssertFatal(measur_table!=NULL, "couldn't allocate %u cpu measurements entries\n",max_cpumeasur);
|
||||
rt=pthread_create(&thid,NULL, (void *(*)(void *))run_cpumeasur, NULL);
|
||||
AssertFatal(rt==0, "couldn't create cpu measurment thread: %s\n",strerror(errno));
|
||||
}
|
||||
|
||||
void send_meas(time_stats_t *ts, int msgid) {
|
||||
if (MEASURE_ENABLED(ts) ) {
|
||||
ts->tstatptr->timestat_id=ts->meas_index;
|
||||
ts->tstatptr->msgid = msgid ;
|
||||
ts->tstatptr->ts = rdtsc_oai();
|
||||
pushNotifiedFIFO(&measur_fifo, ts->tpoolmsg);
|
||||
}
|
||||
}
|
||||
|
||||
void end_meas(void) {
|
||||
notifiedFIFO_elt_t *nfe = newNotifiedFIFO_elt(sizeof(time_stats_msg_t),0,NULL,NULL);
|
||||
time_stats_msg_t *msg = (time_stats_msg_t *)NotifiedFifoData(nfe);
|
||||
msg->msgid = TIMESTAT_MSGID_END ;
|
||||
pushNotifiedFIFO(&measur_fifo, nfe);
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* 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 __TIME_MEAS_DEFS__H__
|
||||
#define __TIME_MEAS_DEFS__H__
|
||||
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/types.h>
|
||||
// global var to enable openair performance profiler
|
||||
extern int opp_enabled;
|
||||
extern double cpu_freq_GHz __attribute__ ((aligned(32)));;
|
||||
// structure to store data to compute cpu measurment
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
typedef long long oai_cputime_t;
|
||||
#elif defined(__arm__)
|
||||
typedef uint32_t oai_cputime_t;
|
||||
#else
|
||||
#error "building on unsupported CPU architecture"
|
||||
#endif
|
||||
|
||||
#define TIMESTAT_MSGID_START 0 /*!< \brief send time at measure starting point */
|
||||
#define TIMESTAT_MSGID_STOP 1 /*!< \brief send time at measure end point */
|
||||
#define TIMESTAT_MSGID_ENABLE 2 /*!< \brief enable measure point */
|
||||
#define TIMESTAT_MSGID_DISABLE 3 /*!< \brief disable measure point */
|
||||
#define TIMESTAT_MSGID_DISPLAY 10 /*!< \brief display measure */
|
||||
#define TIMESTAT_MSGID_END 11 /*!< \brief stops the measure threads and free assocated resources */
|
||||
typedef void(*meas_printfunc_t)(const char* format, ...);
|
||||
typedef struct {
|
||||
int msgid; /*!< \brief message id, as defined by TIMESTAT_MSGID_X macros */
|
||||
int timestat_id; /*!< \brief points to the time_stats_t entry in cpumeas table */
|
||||
oai_cputime_t ts; /*!< \brief time stamp */
|
||||
meas_printfunc_t displayFunc; /*!< \brief function to call when DISPLAY message is received*/
|
||||
} time_stats_msg_t;
|
||||
|
||||
struct notifiedFIFO_elt_s;
|
||||
typedef struct time_stats {
|
||||
oai_cputime_t in; /*!< \brief time at measure starting point */
|
||||
oai_cputime_t diff; /*!< \brief average difference between time at starting point and time at endpoint*/
|
||||
oai_cputime_t p_time; /*!< \brief absolute process duration */
|
||||
oai_cputime_t diff_square; /*!< \brief process duration square */
|
||||
oai_cputime_t max; /*!< \brief maximum difference between time at starting point and time at endpoint*/
|
||||
int trials; /*!< \brief number of start point - end point iterations */
|
||||
int meas_flag; /*!< \brief 1: stop_meas not called (consecutive calls of start_meas) */
|
||||
char *meas_name; /*!< \brief name to use when printing the measure (not used for PHY simulators)*/
|
||||
int meas_index; /*!< \brief index of this measure in the measure array (not used for PHY simulators)*/
|
||||
int meas_enabled; /*!< \brief per measure enablement flag. send_meas tests this flag, unused today in start_meas and stop_meas*/
|
||||
struct notifiedFIFO_elt_s *tpoolmsg; /*!< \brief message pushed to the cpu measurment queue to report a measure START or STOP */
|
||||
time_stats_msg_t *tstatptr; /*!< \brief pointer to the time_stats_msg_t data in the tpoolmsg, stored here for perf considerations*/
|
||||
} time_stats_t;
|
||||
#define MEASURE_ENABLED(X) (X->meas_enabled)
|
||||
|
||||
|
||||
|
||||
|
||||
static inline void start_meas(time_stats_t *ts) __attribute__((always_inline));
|
||||
static inline void stop_meas(time_stats_t *ts) __attribute__((always_inline));
|
||||
|
||||
|
||||
void print_meas_now(time_stats_t *ts, const char *name, FILE *file_name);
|
||||
void print_meas(time_stats_t *ts, const char *name, time_stats_t *total_exec_time, time_stats_t *sf_exec_time);
|
||||
int print_meas_log(time_stats_t *ts, const char *name, time_stats_t *total_exec_time, time_stats_t *sf_exec_time, char *output);
|
||||
double get_time_meas_us(time_stats_t *ts);
|
||||
double get_cpu_freq_GHz(void);
|
||||
|
||||
#if defined(__i386__)
|
||||
static inline unsigned long long rdtsc_oai(void) __attribute__((always_inline));
|
||||
static inline unsigned long long rdtsc_oai(void) {
|
||||
unsigned long long int x;
|
||||
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
|
||||
return x;
|
||||
}
|
||||
#elif defined(__x86_64__)
|
||||
static inline unsigned long long rdtsc_oai(void) __attribute__((always_inline));
|
||||
static inline unsigned long long rdtsc_oai(void) {
|
||||
unsigned long long a, d;
|
||||
__asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
|
||||
return (d<<32) | a;
|
||||
}
|
||||
|
||||
#elif defined(__arm__)
|
||||
static inline uint32_t rdtsc_oai(void) __attribute__((always_inline));
|
||||
static inline uint32_t rdtsc_oai(void) {
|
||||
uint32_t r = 0;
|
||||
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(r) );
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define CPUMEAS_DISABLE 0
|
||||
#define CPUMEAS_ENABLE 1
|
||||
#define CPUMEAS_GETSTATE 2
|
||||
static inline int cpumeas(int action) {
|
||||
switch (action) {
|
||||
case CPUMEAS_ENABLE:
|
||||
opp_enabled = 1;
|
||||
break;
|
||||
|
||||
case CPUMEAS_DISABLE:
|
||||
opp_enabled = 0;
|
||||
break;
|
||||
|
||||
case CPUMEAS_GETSTATE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return opp_enabled;
|
||||
}
|
||||
|
||||
static inline void start_meas(time_stats_t *ts) {
|
||||
if (opp_enabled) {
|
||||
if (ts->meas_flag==0) {
|
||||
ts->trials++;
|
||||
ts->in = rdtsc_oai();
|
||||
ts->meas_flag=1;
|
||||
} else {
|
||||
ts->in = rdtsc_oai();
|
||||
}
|
||||
if ((ts->trials&16383)<10) ts->max=0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void stop_meas(time_stats_t *ts) {
|
||||
if (opp_enabled) {
|
||||
long long out = rdtsc_oai();
|
||||
ts->diff += (out-ts->in);
|
||||
/// process duration is the difference between two clock points
|
||||
ts->p_time = (out-ts->in);
|
||||
ts->diff_square += (out-ts->in)*(out-ts->in);
|
||||
|
||||
if ((out-ts->in) > ts->max)
|
||||
ts->max = out-ts->in;
|
||||
|
||||
ts->meas_flag=0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void reset_meas(time_stats_t *ts) {
|
||||
ts->in=0;
|
||||
ts->diff=0;
|
||||
ts->p_time=0;
|
||||
ts->diff_square=0;
|
||||
ts->max=0;
|
||||
ts->trials=0;
|
||||
ts->meas_flag=0;
|
||||
}
|
||||
|
||||
static inline void copy_meas(time_stats_t *dst_ts,time_stats_t *src_ts) {
|
||||
if (opp_enabled) {
|
||||
dst_ts->trials=src_ts->trials;
|
||||
dst_ts->diff=src_ts->diff;
|
||||
dst_ts->max=src_ts->max;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void merge_meas(time_stats_t *dst_ts, const time_stats_t *src_ts)
|
||||
{
|
||||
if (!opp_enabled)
|
||||
return;
|
||||
dst_ts->trials += src_ts->trials;
|
||||
dst_ts->diff += src_ts->diff;
|
||||
if (src_ts->max > dst_ts->max)
|
||||
dst_ts->max = src_ts->max;
|
||||
}
|
||||
|
||||
#define CPUMEASUR_SECTION "cpumeasur"
|
||||
|
||||
#define CPUMEASUR_PARAMS_DESC { \
|
||||
{"max_cpumeasur", "Max number of cpu measur entries", 0, uptr:&max_cpumeasur, defintval:100, TYPE_UINT, 0},\
|
||||
}
|
||||
|
||||
void init_meas(void);
|
||||
time_stats_t *register_meas(char *name);
|
||||
#define START_MEAS(X) send_meas(X, TIMESTAT_MSGID_START)
|
||||
#define STOP_MEAS(X) send_meas(X, TIMESTAT_MSGID_STOP)
|
||||
void send_meas(time_stats_t *ts, int msgid);
|
||||
void end_meas(void);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user