\brief Set the maximum priority the process can obtain
\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_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
char *usageDesc;
int alt_dirs = 0, log_set = 0, run_set = 0, do_kill = 0;
int known_opt;
- int high_prio = 0;
+ int priority = 0;
#ifndef WIN32
int do_wait = 0;
#endif
"\t-waste -- allow memory waste\n"
"\t-core -- dump cores\n"
#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-nosql -- disable internal sql scoreboard\n"
"\t-heavy-timer -- Heavy Timer, possibly more accurate but at a cost\n"
}
#endif
- if (local_argv[x] && !strcmp(local_argv[x], "-hp")) {
- high_prio++;
+ if (local_argv[x] && (!strcmp(local_argv[x], "-hp") || !strcmp(local_argv[x], "-rp"))) {
+ 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++;
}
}
-
- if (high_prio) {
- set_high_priority();
- } else {
+ switch(priority) {
+ case 2:
+ set_realtime_priority();
+ break;
+ case 1:
set_normal_priority();
+ break;
+ case -1:
+ set_low_priority();
+ break;
+ default:
+ set_auto_priority();
+ break;
}
-
+
switch_core_setrlimits();
}
-static int32_t set_low_priority(void)
+SWITCH_DECLARE(int32_t) set_low_priority(void)
{
+
+
#ifdef WIN32
SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
#else
}
#endif
#endif
+
return 0;
}
-static int32_t set_priority(void)
+SWITCH_DECLARE(int32_t) set_realtime_priority(void)
{
#ifdef WIN32
- SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
+ SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
#else
#ifdef USE_SCHED_SETSCHEDULER
/*
return 0;
}
-
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
- SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
-#else
- int pri;
-
-#ifdef USE_SETRLIMIT
- struct rlimit lim = { RLIM_INFINITY, RLIM_INFINITY };
-#endif
-
- if ((pri = set_priority())) {
- return pri;
- }
+ runtime.cpu_count = sysconf (_SC_NPROCESSORS_ONLN);
-#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");
+ /* If we have more than 1 cpu, we should use realtime priority so we can have priority threads */
+ if (runtime.cpu_count > 1) {
+ return set_realtime_priority();
}
-#endif
-#ifdef USE_MLOCKALL
- /*
- * Pin memory pages to RAM to prevent being swapped to disk
- */
- mlockall(MCL_CURRENT | MCL_FUTURE);
-#endif
-
-#endif
return 0;
}
runtime.min_dtmf_duration = SWITCH_MIN_DTMF_DURATION;
runtime.odbc_dbtype = DBTYPE_DEFAULT;
runtime.dbname = NULL;
+ runtime.cpu_count = sysconf (_SC_NPROCESSORS_ONLN);
+
/* INIT APR and Create the pool context */
if (apr_initialize() != SWITCH_STATUS_SUCCESS) {