Commit 40fcd549 authored by frtabu's avatar frtabu

enhance cpu measurment implementation

parent 61c9fa94
......@@ -682,7 +682,6 @@ void run_telnetclt(void) {
pthread_setname_np(pthread_self(), "telnetclt");
set_sched(pthread_self(),0,telnetparams.priority);
sock = socket(AF_INET, SOCK_STREAM, 0);
// FIELD *field[4];
if (sock < 0)
fprintf(stderr,"[TELNETSRV] Error %s on socket call\n",strerror(errno));
char prompt[sizeof(TELNET_PROMPT_PREFIX)+10];
......@@ -695,49 +694,16 @@ void run_telnetclt(void) {
if(connect(sock, (void *) &name, sizeof(name)))
fprintf(stderr,"[TELNETSRV] Error %s on connect call\n",strerror(errno));
// (void) initscr(); /* initialize the curses library */
// keypad(stdscr, TRUE); /* enable keyboard mapping */
// (void) nonl(); /* tell curses not to do NL->CR/NL on output */
// (void) cbreak(); /* take input chars one at a time, no wait for \n */
// (void) echo(); /* echo input - in color */
// WINDOW *inputw = newwin(10, 132, 0, 0);
// int row,col;
// getmaxyx(stdscr,row,col);
// field[0] = new_field((row-2)/2, col, 0, 0, 0, 0);
// field[1] = new_field((row-2)/2, col, (row-2)/2, 0, 0, 0);
// field[2] = new_field(1, col, row-2, 0, 0, 0);
// field[3] = NULL;
/* Set field options */
// field_opts_off(field[0], O_ACTIVE);
// field_opts_off(field[1], O_ACTIVE);
// set_field_back(field[0], A_UNDERLINE); /* Print a line for the option */
// field_opts_off(field[0], O_AUTOSKIP); /* Don't go to next field when this */
/* Field is filled up */
// set_field_back(field[1], A_UNDERLINE);
// field_opts_off(field[1], O_AUTOSKIP);
/* Create the form and post it */
// FORM *my_form = new_form(field);
// post_form(my_form);
// refresh();
// echo();
struct timeval ts;
ts.tv_sec = 1; // 1 second
ts.tv_usec = 0;
while (1) {
// select setup
fd_set fds;
FD_ZERO(&fds);
FD_SET(sock, &fds);
FD_SET(STDIN_FILENO , &fds);
// wait for data
int nready = select(sock + 1, &fds, (fd_set *) 0, (fd_set *) 0, &ts);
// mvprintw(row-2,0,"select: %i \n",nready);
if (nready < 0) {
perror("select. Error");
break;
......@@ -767,22 +733,13 @@ void run_telnetclt(void) {
char *inbuf=NULL;
size_t inlen=0;
inlen = getline( &inbuf,&inlen, stdin);
// mvprintw(row-1,0,inbuf);
if ( inlen > 0 ) {
if ( send(sock, inbuf,inlen, 0) < 0)
break;
}
free(inbuf);
// refresh();
}
}
/* nocbreak();
unpost_form(my_form);
free_form(my_form);
free_field(field[0]);
free_field(field[1]);
free_field(field[2]);
endwin();*/
close(sock);
return;
} /* run_telnetclt */
......
......@@ -18,7 +18,7 @@
* 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>
......@@ -26,6 +26,7 @@
#include <string.h>
#include "assertions.h"
#ifndef PHYSIM
#include <pthread.h>
#include "common/config/config_userapi.h"
#endif
// global var for openair performance profiler
......@@ -35,7 +36,8 @@ double cpu_freq_GHz __attribute__ ((aligned(32)));
double cpu_freq_GHz __attribute__ ((aligned(32)))=0.0;
#ifndef PHYSIM
static uint32_t max_cpumeasur;
time_stats_t **measur_table;
static time_stats_t **measur_table;
notifiedFIFO_t measur_fifo;
#endif
double get_cpu_freq_GHz(void)
{
......@@ -159,14 +161,46 @@ int register_meas(char *name, time_stats_t *dst_ts)
return -1;
}
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;
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 ret = config_get( cpumeasur_params,numparams,CPUMEASUR_SECTION);
AssertFatal(ret >= 0, "cpumeasur configuration couldn't be performed");
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));
}
#endif
......@@ -31,6 +31,9 @@
#include <pthread.h>
#include <linux/kernel.h>
#include <linux/types.h>
#ifndef PHYSIM
#include "common/utils/threadPool/thread-pool.h"
#endif
// global var to enable openair performance profiler
extern int opp_enabled;
extern double cpu_freq_GHz __attribute__ ((aligned(32)));;
......@@ -58,6 +61,13 @@ typedef struct {
} time_stats_t;
#endif
#define TIMESTAT_MSGID_START 0
#define TIMESTAT_MSGID_STOP 1
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_TYPE ts; /*!< \brief time stamp */
} time_stats_msg_t;
static inline void start_meas(time_stats_t *ts) __attribute__((always_inline));
static inline void stop_meas(time_stats_t *ts) __attribute__((always_inline));
......@@ -122,6 +132,20 @@ static inline void stop_meas(time_stats_t *ts) {
}
}
static inline void send_meas(int measur_idx) {
if (opp_enabled) {
extern notifiedFIFO_t measur_fifo;
notifiedFIFO_elt_t *msg =newNotifiedFIFO_elt(sizeof(time_stats_msg_t),0,NULL,NULL);
time_stats_msg_t *tsm = (time_stats_msg_t *)NotifiedFifoData(msg);
tsm->ts = rdtsc_oai();
pushNotifiedFIFO(&measur_fifo, msg);
}
}
static inline void reset_meas(time_stats_t *ts) {
ts->in=0;
ts->diff=0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment