Set alarm
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
void *calloc_or_fail(size_t size) {
|
void *calloc_or_fail(size_t size) {
|
||||||
@@ -137,3 +140,32 @@ void *memcpy1(void *dst,const void *src,size_t n) {
|
|||||||
asm volatile("rep movsb" : "+D" (dst) : "c"(n), "S"(src) : "cc","memory");
|
asm volatile("rep movsb" : "+D" (dst) : "c"(n), "S"(src) : "cc","memory");
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_priority(int priority)
|
||||||
|
{
|
||||||
|
/* When running with a realtime scheduler, a buggy run-away process can take
|
||||||
|
down the host requiring a reboot to recover. To avoid this scenario, we
|
||||||
|
use alarm(2) to set a maximum running time */
|
||||||
|
unsigned max_runtime_seconds = 10 * 60; /* default */
|
||||||
|
const char *env = getenv("MAX_RUNTIME_SECONDS");
|
||||||
|
if (env != NULL)
|
||||||
|
{
|
||||||
|
max_runtime_seconds = atoi(env);
|
||||||
|
}
|
||||||
|
unsigned was_alarm = alarm(max_runtime_seconds);
|
||||||
|
/* Normally, was_alarm should be 0 indicating there was no previous alarm set.
|
||||||
|
A non-zero value could indicate a mistake */
|
||||||
|
fprintf(stderr, "Set alarm for %u seconds, was %u (see $MAX_RUNTIME_SECONDS)\n",
|
||||||
|
max_runtime_seconds, was_alarm);
|
||||||
|
|
||||||
|
struct sched_param param =
|
||||||
|
{
|
||||||
|
.sched_priority = priority,
|
||||||
|
};
|
||||||
|
fprintf(stderr, "Calling sched_setscheduler(%d)\n", priority);
|
||||||
|
if (sched_setscheduler(0, SCHED_RR, ¶m) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "sched_setscheduler: %s\n", strerror(errno));
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ int hex_string_to_hex_value (uint8_t *hex_value, const char *hex_string, int siz
|
|||||||
|
|
||||||
void *memcpy1(void *dst,const void *src,size_t n);
|
void *memcpy1(void *dst,const void *src,size_t n);
|
||||||
|
|
||||||
|
void set_priority(int priority);
|
||||||
|
|
||||||
char *itoa(int i);
|
char *itoa(int i);
|
||||||
|
|
||||||
|
|||||||
@@ -415,6 +415,13 @@ void *rrc_enb_process_msg(void *notUsed) {
|
|||||||
|
|
||||||
|
|
||||||
int main( int argc, char **argv ) {
|
int main( int argc, char **argv ) {
|
||||||
|
set_priority(79);
|
||||||
|
if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "mlockall: %s\n", strerror(errno));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
//uint8_t beta_ACK=0,beta_RI=0,beta_CQI=2;
|
//uint8_t beta_ACK=0,beta_RI=0,beta_CQI=2;
|
||||||
PHY_VARS_NR_UE *UE[MAX_NUM_CCs];
|
PHY_VARS_NR_UE *UE[MAX_NUM_CCs];
|
||||||
start_background_system();
|
start_background_system();
|
||||||
|
|||||||
@@ -40,15 +40,9 @@ typedef struct {
|
|||||||
static nfapi_params_t nfapi_params = {0};
|
static nfapi_params_t nfapi_params = {0};
|
||||||
|
|
||||||
void set_thread_priority(int priority) {
|
void set_thread_priority(int priority) {
|
||||||
//printf("%s(priority:%d)\n", __FUNCTION__, priority);
|
set_priority(priority);
|
||||||
|
|
||||||
pthread_attr_t ptAttr;
|
pthread_attr_t ptAttr;
|
||||||
struct sched_param schedParam;
|
|
||||||
schedParam.__sched_priority = priority; //79;
|
|
||||||
|
|
||||||
if(sched_setscheduler(0, SCHED_RR, &schedParam) != 0) {
|
|
||||||
printf("Failed to set scheduler to SCHED_RR\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pthread_attr_setschedpolicy(&ptAttr, SCHED_RR) != 0) {
|
if(pthread_attr_setschedpolicy(&ptAttr, SCHED_RR) != 0) {
|
||||||
printf("Failed to set pthread sched policy SCHED_RR\n");
|
printf("Failed to set pthread sched policy SCHED_RR\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,14 +218,9 @@ void pnf_nfapi_trace(nfapi_trace_level_t nfapi_level, const char *message, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pnf_set_thread_priority(int priority) {
|
void pnf_set_thread_priority(int priority) {
|
||||||
|
set_priority(priority);
|
||||||
|
|
||||||
pthread_attr_t ptAttr;
|
pthread_attr_t ptAttr;
|
||||||
struct sched_param schedParam;
|
|
||||||
schedParam.__sched_priority = priority;
|
|
||||||
|
|
||||||
if(sched_setscheduler(0, SCHED_RR, &schedParam) != 0) {
|
|
||||||
printf("failed to set SCHED_RR\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pthread_attr_setschedpolicy(&ptAttr, SCHED_RR) != 0) {
|
if(pthread_attr_setschedpolicy(&ptAttr, SCHED_RR) != 0) {
|
||||||
printf("failed to set pthread SCHED_RR %d\n", errno);
|
printf("failed to set pthread SCHED_RR %d\n", errno);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -524,15 +524,7 @@ static void wait_nfapi_init(char *thread_name) {
|
|||||||
|
|
||||||
int main ( int argc, char **argv )
|
int main ( int argc, char **argv )
|
||||||
{
|
{
|
||||||
struct sched_param param =
|
set_priority(79);
|
||||||
{
|
|
||||||
.sched_priority = 79
|
|
||||||
};
|
|
||||||
if (sched_setscheduler( 0, SCHED_RR, ¶m ) == -1 )
|
|
||||||
{
|
|
||||||
fprintf(stderr, "sched_setscheduler: %s\n", strerror(errno));
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
|
if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "mlockall: %s\n", strerror(errno));
|
fprintf(stderr, "mlockall: %s\n", strerror(errno));
|
||||||
|
|||||||
@@ -547,15 +547,7 @@ AssertFatal(false,"");
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char **argv ) {
|
int main( int argc, char **argv ) {
|
||||||
struct sched_param param =
|
set_priority(79);
|
||||||
{
|
|
||||||
.sched_priority = 79
|
|
||||||
};
|
|
||||||
if (sched_setscheduler( 0, SCHED_RR, ¶m ) == -1 )
|
|
||||||
{
|
|
||||||
fprintf(stderr, "sched_setscheduler: %s\n", strerror(errno));
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
|
if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "mlockall: %s\n", strerror(errno));
|
fprintf(stderr, "mlockall: %s\n", strerror(errno));
|
||||||
|
|||||||
Reference in New Issue
Block a user