mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-17 01:02:12 +00:00
change -hp to -rp, add -lp and -np, no priority flags means auto which will do -rp if you have > 1 cpu
This commit is contained in:
parent
4ed900eb92
commit
c1dd008b1d
@ -255,6 +255,7 @@ struct switch_runtime {
|
|||||||
uint32_t db_handle_timeout;
|
uint32_t db_handle_timeout;
|
||||||
int curl_count;
|
int curl_count;
|
||||||
int ssl_count;
|
int ssl_count;
|
||||||
|
int cpu_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct switch_runtime runtime;
|
extern struct switch_runtime runtime;
|
||||||
|
@ -1978,8 +1978,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_management_exec(char *relative_oid,
|
|||||||
\brief Set the maximum priority the process can obtain
|
\brief Set the maximum priority the process can obtain
|
||||||
\return 0 on success
|
\return 0 on success
|
||||||
*/
|
*/
|
||||||
SWITCH_DECLARE(int32_t) set_high_priority(void);
|
|
||||||
SWITCH_DECLARE(int32_t) set_normal_priority(void);
|
SWITCH_DECLARE(int32_t) set_normal_priority(void);
|
||||||
|
SWITCH_DECLARE(int32_t) set_auto_priority(void);
|
||||||
|
SWITCH_DECLARE(int32_t) set_realtime_priority(void);
|
||||||
|
SWITCH_DECLARE(int32_t) set_low_priority(void);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Change user and/or group of the running process
|
\brief Change user and/or group of the running process
|
||||||
|
36
src/switch.c
36
src/switch.c
@ -358,7 +358,7 @@ int main(int argc, char *argv[])
|
|||||||
char *usageDesc;
|
char *usageDesc;
|
||||||
int alt_dirs = 0, log_set = 0, run_set = 0, do_kill = 0;
|
int alt_dirs = 0, log_set = 0, run_set = 0, do_kill = 0;
|
||||||
int known_opt;
|
int known_opt;
|
||||||
int high_prio = 0;
|
int priority = 0;
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
int do_wait = 0;
|
int do_wait = 0;
|
||||||
#endif
|
#endif
|
||||||
@ -408,7 +408,9 @@ int main(int argc, char *argv[])
|
|||||||
"\t-waste -- allow memory waste\n"
|
"\t-waste -- allow memory waste\n"
|
||||||
"\t-core -- dump cores\n"
|
"\t-core -- dump cores\n"
|
||||||
#endif
|
#endif
|
||||||
"\t-hp -- enable high priority settings\n"
|
"\t-rp -- enable high(realtime) priority settings\n"
|
||||||
|
"\t-lp -- enable low priority settings\n"
|
||||||
|
"\t-np -- enable normal priority settings (system defaults)\n"
|
||||||
"\t-vg -- run under valgrind\n"
|
"\t-vg -- run under valgrind\n"
|
||||||
"\t-nosql -- disable internal sql scoreboard\n"
|
"\t-nosql -- disable internal sql scoreboard\n"
|
||||||
"\t-heavy-timer -- Heavy Timer, possibly more accurate but at a cost\n"
|
"\t-heavy-timer -- Heavy Timer, possibly more accurate but at a cost\n"
|
||||||
@ -567,8 +569,18 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-hp")) {
|
if (local_argv[x] && (!strcmp(local_argv[x], "-hp") || !strcmp(local_argv[x], "-rp"))) {
|
||||||
high_prio++;
|
priority = 2;
|
||||||
|
known_opt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (local_argv[x] && !strcmp(local_argv[x], "-lp")) {
|
||||||
|
priority = -1;
|
||||||
|
known_opt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (local_argv[x] && !strcmp(local_argv[x], "-np")) {
|
||||||
|
priority = 1;
|
||||||
known_opt++;
|
known_opt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -828,11 +840,19 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
switch(priority) {
|
||||||
if (high_prio) {
|
case 2:
|
||||||
set_high_priority();
|
set_realtime_priority();
|
||||||
} else {
|
break;
|
||||||
|
case 1:
|
||||||
set_normal_priority();
|
set_normal_priority();
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
set_low_priority();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
set_auto_priority();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_core_setrlimits();
|
switch_core_setrlimits();
|
||||||
|
@ -648,8 +648,10 @@ SWITCH_DECLARE(void) switch_core_set_globals(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t set_low_priority(void)
|
SWITCH_DECLARE(int32_t) set_low_priority(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
|
SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
|
||||||
#else
|
#else
|
||||||
@ -679,13 +681,14 @@ static int32_t set_low_priority(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t set_priority(void)
|
SWITCH_DECLARE(int32_t) set_realtime_priority(void)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
|
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
|
||||||
#else
|
#else
|
||||||
#ifdef USE_SCHED_SETSCHEDULER
|
#ifdef USE_SCHED_SETSCHEDULER
|
||||||
/*
|
/*
|
||||||
@ -720,47 +723,20 @@ static int32_t set_priority(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SWITCH_DECLARE(int32_t) set_normal_priority(void)
|
SWITCH_DECLARE(int32_t) set_normal_priority(void)
|
||||||
{
|
{
|
||||||
return set_priority();
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(int32_t) set_high_priority(void)
|
SWITCH_DECLARE(int32_t) set_auto_priority(void)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
runtime.cpu_count = sysconf (_SC_NPROCESSORS_ONLN);
|
||||||
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
|
|
||||||
#else
|
|
||||||
int pri;
|
|
||||||
|
|
||||||
#ifdef USE_SETRLIMIT
|
/* If we have more than 1 cpu, we should use realtime priority so we can have priority threads */
|
||||||
struct rlimit lim = { RLIM_INFINITY, RLIM_INFINITY };
|
if (runtime.cpu_count > 1) {
|
||||||
#endif
|
return set_realtime_priority();
|
||||||
|
|
||||||
if ((pri = set_priority())) {
|
|
||||||
return pri;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_SETRLIMIT
|
|
||||||
/*
|
|
||||||
* The amount of memory which can be mlocked is limited for non-root users.
|
|
||||||
* FS will segfault (= hitting the limit) soon after mlockall has been called
|
|
||||||
* and we've switched to a different user.
|
|
||||||
* So let's try to remove the mlock limit here...
|
|
||||||
*/
|
|
||||||
if (setrlimit(RLIMIT_MEMLOCK, &lim) < 0) {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to disable memlock limit, application may crash if run as non-root user!\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_MLOCKALL
|
|
||||||
/*
|
|
||||||
* Pin memory pages to RAM to prevent being swapped to disk
|
|
||||||
*/
|
|
||||||
mlockall(MCL_CURRENT | MCL_FUTURE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1405,6 +1381,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
|
|||||||
runtime.min_dtmf_duration = SWITCH_MIN_DTMF_DURATION;
|
runtime.min_dtmf_duration = SWITCH_MIN_DTMF_DURATION;
|
||||||
runtime.odbc_dbtype = DBTYPE_DEFAULT;
|
runtime.odbc_dbtype = DBTYPE_DEFAULT;
|
||||||
runtime.dbname = NULL;
|
runtime.dbname = NULL;
|
||||||
|
runtime.cpu_count = sysconf (_SC_NPROCESSORS_ONLN);
|
||||||
|
|
||||||
|
|
||||||
/* INIT APR and Create the pool context */
|
/* INIT APR and Create the pool context */
|
||||||
if (apr_initialize() != SWITCH_STATUS_SUCCESS) {
|
if (apr_initialize() != SWITCH_STATUS_SUCCESS) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user