Merge remote-tracking branch 'origin/softmodem-caps' into integration_2024_w22
This commit is contained in:
@@ -208,9 +208,11 @@ int config_cmdlineonly_get(configmodule_interface_t *cfg, paramdef_t *cfgoptions
|
||||
}
|
||||
} /* for loop on options */
|
||||
|
||||
printf("[CONFIG] %s: %i/%i parameters successfully set \n",
|
||||
((prefix == NULL)?"(root)":prefix),
|
||||
numdefvals,numoptions );
|
||||
printf_params(cfg,
|
||||
"[CONFIG] %s: %i/%i parameters successfully set \n",
|
||||
prefix == NULL ? "(root)" : prefix,
|
||||
numdefvals,
|
||||
numoptions);
|
||||
|
||||
if (fatalerror == 1) {
|
||||
fprintf(stderr,"[CONFIG] fatal errors found when assigning %s parameters \n",
|
||||
@@ -341,9 +343,20 @@ configmodule_interface_t *load_configmodule(int argc,
|
||||
atoken = strtok_r(NULL,":",&strtokctx);
|
||||
}
|
||||
|
||||
printf("[CONFIG] get parameters from %s ", cfgmode);
|
||||
for (i = 0; i < cfgptr->num_cfgP; i++) {
|
||||
printf("%s ", cfgptr->cfgP[i]);
|
||||
/* check if that file actually exists */
|
||||
if (access(cfgptr->cfgP[i], F_OK) != 0) {
|
||||
fprintf(stderr, "error: file %s does not exist\n", cfgptr->cfgP[i]);
|
||||
for (int j = 0; j < cfgptr->num_cfgP; ++j)
|
||||
free(cfgptr->cfgP[j]);
|
||||
free(modeparams);
|
||||
free(cfgptr->cfgmode);
|
||||
free(cfgptr->argv_info);
|
||||
free(cfgptr);
|
||||
if (cfgmode != NULL)
|
||||
free(cfgmode);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (cfgptr->rtflags & CONFIG_PRINTPARAMS) {
|
||||
|
||||
@@ -70,7 +70,7 @@ int read_strlist(configmodule_interface_t *cfg, paramdef_t *cfgoptions, config_s
|
||||
str=config_setting_get_string_elem(setting,i);
|
||||
|
||||
if (str==NULL) {
|
||||
printf("[LIBCONFIG] %s%i not found in config file\n", cfgoptions->optname,i);
|
||||
printf_params(cfg, "[LIBCONFIG] %s%i not found in config file\n", cfgoptions->optname,i);
|
||||
} else {
|
||||
snprintf(cfgoptions->strlistptr[i], DEFAULT_EXTRA_SZ, "%s",str);
|
||||
st++;
|
||||
@@ -481,9 +481,12 @@ int config_libconfig_get(configmodule_interface_t *cfg, paramdef_t *cfgoptions,
|
||||
}
|
||||
} /* for loop on options */
|
||||
|
||||
printf("[LIBCONFIG] %s: %i/%i parameters successfully set, (%i to default value)\n",
|
||||
((prefix == NULL)?"(root)":prefix),
|
||||
status,numoptions,numdefvals );
|
||||
printf_params(cfg,
|
||||
"[LIBCONFIG] %s: %i/%i parameters successfully set, (%i to default value)\n",
|
||||
prefix == NULL ? "(root)" : prefix,
|
||||
status,
|
||||
numoptions,
|
||||
numdefvals);
|
||||
|
||||
if (fatalerror == 1) {
|
||||
fprintf(stderr,"[LIBCONFIG] fatal errors found when processing %s \n", libconfig_privdata.configfile );
|
||||
@@ -517,8 +520,7 @@ int config_libconfig_getlist(configmodule_interface_t *cfg,
|
||||
status = ParamList->numelt = config_setting_length(setting);
|
||||
printf_params(cfg, "[LIBCONFIG] %i %s in config file %s \n", ParamList->numelt, listpath, libconfig_privdata.configfile);
|
||||
} else {
|
||||
printf("[LIBCONFIG] list %s not found in config file %s \n",
|
||||
listpath,libconfig_privdata.configfile );
|
||||
printf_params(cfg, "[LIBCONFIG] list %s not found in config file %s \n", listpath, libconfig_privdata.configfile);
|
||||
ParamList->numelt= 0;
|
||||
status = -1;
|
||||
}
|
||||
@@ -574,8 +576,10 @@ int config_libconfig_init(configmodule_interface_t *cfg)
|
||||
config_set_auto_convert (&(libconfig_privdata.cfg), CONFIG_TRUE);
|
||||
/* Read the file. If there is an error, report it and exit. */
|
||||
if( config_read_file(&(libconfig_privdata.cfg), libconfig_privdata.configfile) == CONFIG_FALSE) {
|
||||
fprintf(stderr,"[LIBCONFIG] %s %d file %s - line %d: %s\n",__FILE__, __LINE__,
|
||||
libconfig_privdata.configfile, config_error_line(&(libconfig_privdata.cfg)),
|
||||
fprintf(stderr,
|
||||
"[LIBCONFIG] file %s - line %d: %s\n",
|
||||
libconfig_privdata.configfile,
|
||||
config_error_line(&(libconfig_privdata.cfg)),
|
||||
config_error_text(&(libconfig_privdata.cfg)));
|
||||
config_destroy(&(libconfig_privdata.cfg));
|
||||
printf( "\n");
|
||||
|
||||
@@ -343,7 +343,7 @@ typedef struct timer_elm_s {
|
||||
tasks[newQueue]= new task_list_t;
|
||||
tasks[newQueue]->task_parms = {0};
|
||||
pthread_mutex_unlock (&lock_nb_queues);
|
||||
LOG_I(ITTI,"Starting itti queue: %s as task %d\n", taskInfo->name, newQueue);
|
||||
LOG_D(ITTI, "Starting itti queue: %s as task %d\n", taskInfo->name, newQueue);
|
||||
pthread_mutex_init(&tasks[newQueue]->queue_cond_lock, NULL);
|
||||
memcpy(&tasks[newQueue]->admin, taskInfo, sizeof(task_info_t));
|
||||
AssertFatal( ( tasks[newQueue]->epoll_fd = epoll_create1(0) ) >=0, "");
|
||||
|
||||
+63
-77
@@ -32,6 +32,7 @@
|
||||
#include "system.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
@@ -95,17 +96,6 @@ static void read_pipe(int p, char *b, int size) {
|
||||
size -= ret;
|
||||
}
|
||||
}
|
||||
int checkIfFedoraDistribution(void) {
|
||||
return !system("grep -iq 'ID_LIKE.*fedora' /etc/os-release ");
|
||||
}
|
||||
|
||||
int checkIfGenericKernelOnFedora(void) {
|
||||
return system("uname -a | grep -q rt");
|
||||
}
|
||||
|
||||
int checkIfInsideContainer(void) {
|
||||
return !system("egrep -q 'libpod|podman|kubepods' /proc/self/cgroup");
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
/* background process */
|
||||
@@ -225,43 +215,71 @@ int rt_sleep_ns (uint64_t x)
|
||||
return clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &myTime, NULL);
|
||||
}
|
||||
|
||||
void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name, int affinity, int priority){
|
||||
pthread_attr_t attr;
|
||||
#ifdef HAVE_LIB_CAP
|
||||
#include <sys/capability.h>
|
||||
/* \brief reports if the current thread has capability CAP_SYS_NICE, i.e. */
|
||||
bool has_cap_sys_nice(void)
|
||||
{
|
||||
/* get capabilities of calling PID */
|
||||
cap_t cap = cap_get_pid(0);
|
||||
cap_flag_value_t val;
|
||||
/* check to what CAP_SYS_NICE is currently ("effective capability") set */
|
||||
int ret = cap_get_flag(cap, CAP_SYS_NICE, CAP_EFFECTIVE, &val);
|
||||
AssertFatal(ret == 0, "Error in cap_get_flag(): ret %d errno %d\n", ret, errno);
|
||||
cap_free(cap);
|
||||
/* return true if CAP_SYS_NICE is currently set */
|
||||
return val == CAP_SET;
|
||||
}
|
||||
#else
|
||||
/* libcap has not been detected on this system. We do not need to require it --
|
||||
* we can try to read directly via a syscall. This is discouraged, though; from
|
||||
* the man page: "The portable interfaces are cap_set_proc(3) and
|
||||
* cap_get_proc(3); if possible, you should use those interfaces in
|
||||
* applications". */
|
||||
#include <sys/syscall.h> /* Definition of SYS_* constants */
|
||||
#include <linux/capability.h> /* capabilities used below */
|
||||
/* \brief reports if the current thread has capability CAP_SYS_NICE, i.e. */
|
||||
bool has_cap_sys_nice(void)
|
||||
{
|
||||
struct __user_cap_header_struct hdr = {.version = _LINUX_CAPABILITY_VERSION_3};
|
||||
struct __user_cap_data_struct cap[2];
|
||||
if (syscall(SYS_capget, &hdr, cap) == -1)
|
||||
return false;
|
||||
return (cap[0].effective & (1 << CAP_SYS_NICE)) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name, int affinity, int priority)
|
||||
{
|
||||
int ret;
|
||||
int settingPriority = 1;
|
||||
bool set_prio = has_cap_sys_nice();
|
||||
|
||||
pthread_attr_t attr;
|
||||
ret=pthread_attr_init(&attr);
|
||||
AssertFatal(ret == 0, "Error in pthread_attr_init(): ret: %d, errno: %d\n", ret, errno);
|
||||
|
||||
LOG_I(UTIL,"Creating thread %s with affinity %d and priority %d\n",name,affinity,priority);
|
||||
|
||||
if (checkIfFedoraDistribution())
|
||||
if (checkIfGenericKernelOnFedora())
|
||||
if (checkIfInsideContainer())
|
||||
settingPriority = 0;
|
||||
|
||||
if (settingPriority) {
|
||||
ret=pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
if (set_prio) {
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
AssertFatal(ret == 0, "Error in pthread_attr_setinheritsched(): ret: %d, errno: %d\n", ret, errno);
|
||||
ret=pthread_attr_setschedpolicy(&attr, SCHED_OAI);
|
||||
ret = pthread_attr_setschedpolicy(&attr, SCHED_OAI);
|
||||
AssertFatal(ret == 0, "Error in pthread_attr_setschedpolicy(): ret: %d, errno: %d\n", ret, errno);
|
||||
if(priority<sched_get_priority_min(SCHED_OAI) || priority>sched_get_priority_max(SCHED_OAI)) {
|
||||
LOG_E(UTIL,"Prio not possible: %d, min is %d, max: %d, forced in the range\n",
|
||||
priority,
|
||||
sched_get_priority_min(SCHED_OAI),
|
||||
sched_get_priority_max(SCHED_OAI));
|
||||
if(priority<sched_get_priority_min(SCHED_OAI))
|
||||
priority=sched_get_priority_min(SCHED_OAI);
|
||||
if(priority>sched_get_priority_max(SCHED_OAI))
|
||||
priority=sched_get_priority_max(SCHED_OAI);
|
||||
}
|
||||
AssertFatal(priority<=sched_get_priority_max(SCHED_OAI),"");
|
||||
struct sched_param sparam={0};
|
||||
AssertFatal(priority >= sched_get_priority_min(SCHED_OAI) && priority <= sched_get_priority_max(SCHED_OAI),
|
||||
"Scheduling priority %d not possible: must be within [%d, %d]\n",
|
||||
priority,
|
||||
sched_get_priority_min(SCHED_OAI),
|
||||
sched_get_priority_max(SCHED_OAI));
|
||||
AssertFatal(priority <= sched_get_priority_max(SCHED_OAI), "");
|
||||
struct sched_param sparam = {0};
|
||||
sparam.sched_priority = priority;
|
||||
ret=pthread_attr_setschedparam(&attr, &sparam);
|
||||
ret = pthread_attr_setschedparam(&attr, &sparam);
|
||||
AssertFatal(ret == 0, "Error in pthread_attr_setschedparam(): ret: %d errno: %d\n", ret, errno);
|
||||
LOG_I(UTIL, "%s() for %s: creating thread with affinity %x, priority %d\n", __func__, name, affinity, priority);
|
||||
} else {
|
||||
affinity = -1;
|
||||
priority = -1;
|
||||
LOG_I(UTIL, "%s() for %s: creating thread (no affinity, default priority)\n", __func__, name);
|
||||
}
|
||||
|
||||
LOG_I(UTIL,"threadCreate for %s, affinity %x, priority %d\n",name,affinity,priority);
|
||||
|
||||
ret=pthread_create(t, &attr, func, param);
|
||||
AssertFatal(ret == 0, "Error in pthread_create(): ret: %d, errno: %d\n", ret, errno);
|
||||
|
||||
@@ -314,11 +332,6 @@ void thread_top_init(char *thread_name,
|
||||
}
|
||||
}
|
||||
|
||||
if (checkIfFedoraDistribution())
|
||||
if (checkIfGenericKernelOnFedora())
|
||||
if (checkIfInsideContainer())
|
||||
settingPriority = 0;
|
||||
|
||||
if (settingPriority) {
|
||||
memset(&sparam, 0, sizeof(sparam));
|
||||
sparam.sched_priority = sched_get_priority_max(SCHED_FIFO);
|
||||
@@ -347,37 +360,10 @@ void thread_top_init(char *thread_name,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Block CPU C-states deep sleep
|
||||
void set_latency_target(void) {
|
||||
int ret;
|
||||
static int latency_target_fd=-1;
|
||||
uint32_t latency_target_value=2; // in microseconds
|
||||
if (latency_target_fd == -1) {
|
||||
if ( (latency_target_fd = open("/dev/cpu_dma_latency", O_RDWR)) != -1 ) {
|
||||
ret = write(latency_target_fd, &latency_target_value, sizeof(latency_target_value));
|
||||
if (ret == 0) {
|
||||
printf("# error setting cpu_dma_latency to %u!: %s\n", latency_target_value, strerror(errno));
|
||||
close(latency_target_fd);
|
||||
latency_target_fd=-1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (latency_target_fd != -1)
|
||||
LOG_I(HW,"# /dev/cpu_dma_latency set to %u us\n", latency_target_value);
|
||||
else
|
||||
LOG_E(HW,"Can't set /dev/cpu_dma_latency to %u us\n", latency_target_value);
|
||||
|
||||
// Set CPU frequency to it's maximum
|
||||
int system_ret = system("for d in /sys/devices/system/cpu/cpu[0-9]*; do cat $d/cpufreq/cpuinfo_max_freq > $d/cpufreq/scaling_min_freq; done");
|
||||
if (system_ret == -1) {
|
||||
LOG_E(HW, "Can't set cpu frequency: [%d] %s\n", errno, strerror(errno));
|
||||
return;
|
||||
}
|
||||
if (!((WIFEXITED(system_ret)) && (WEXITSTATUS(system_ret) == 0))) {
|
||||
LOG_E(HW, "Can't set cpu frequency\n");
|
||||
}
|
||||
mlockall(MCL_CURRENT | MCL_FUTURE);
|
||||
|
||||
/* \brief lock memory to RAM to avoid delays */
|
||||
void lock_memory_to_ram(void)
|
||||
{
|
||||
int rc = mlockall(MCL_CURRENT | MCL_FUTURE);
|
||||
if (rc != 0)
|
||||
LOG_W(UTIL, "mlockall() failed: %d, %s\n", errno, strerror(errno));
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#define _SYSTEM_H_OAI_
|
||||
#include <stdint.h>
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -42,8 +43,9 @@ int background_system(char *command);
|
||||
|
||||
void start_background_system(void);
|
||||
|
||||
void set_latency_target(void);
|
||||
void lock_memory_to_ram(void);
|
||||
|
||||
bool has_cap_sys_nice(void);
|
||||
void threadCreate(pthread_t *t, void *(*func)(void *), void *param, char *name, int affinity, int priority);
|
||||
|
||||
#define SCHED_OAI SCHED_RR
|
||||
@@ -61,9 +63,6 @@ void thread_top_init(char *thread_name,
|
||||
* Functions to check system at runtime.
|
||||
****************************************************/
|
||||
|
||||
int checkIfFedoraDistribution(void);
|
||||
int checkIfGenericKernelOnFedora(void);
|
||||
int checkIfInsideContainer(void);
|
||||
int rt_sleep_ns (uint64_t x);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -141,7 +141,6 @@ void initNamedTpool(char *params,tpool_t *pool, bool performanceMeas, char *name
|
||||
ptr=pool->allthreads;
|
||||
pool->allthreads=(struct one_thread *)malloc(sizeof(struct one_thread));
|
||||
pool->allthreads->next=ptr;
|
||||
printf("create a thread for core %d\n", atoi(curptr));
|
||||
pool->allthreads->coreID=atoi(curptr);
|
||||
pool->allthreads->id=pool->nbThreads;
|
||||
pool->allthreads->pool=pool;
|
||||
|
||||
@@ -118,21 +118,6 @@ char *itoa(int i) {
|
||||
return strdup(buffer);
|
||||
}
|
||||
|
||||
|
||||
void set_priority(int priority)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert a version string x.y.z into numbers.
|
||||
*
|
||||
|
||||
@@ -116,8 +116,6 @@ int hex_char_to_hex_value (char c);
|
||||
// Converts an hexadecimal ASCII coded string into its value.**
|
||||
int hex_string_to_hex_value (uint8_t *hex_value, const char *hex_string, int size);
|
||||
|
||||
void set_priority(int priority);
|
||||
|
||||
char *itoa(int i);
|
||||
|
||||
#define STRINGIFY(S) #S
|
||||
|
||||
Reference in New Issue
Block a user