]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
change -hp to -rp, add -lp and -np, no priority flags means auto which will do -rp...
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 12 Sep 2011 21:13:19 +0000 (16:13 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 12 Sep 2011 21:13:19 +0000 (16:13 -0500)
src/include/private/switch_core_pvt.h
src/include/switch_core.h
src/switch.c
src/switch_core.c

index af82f1e88dd2ff9b053e7b679d6d31663f8ff384..31da5a9bf1d35a70424c0552d5393a1a20463e0e 100644 (file)
@@ -255,6 +255,7 @@ struct switch_runtime {
        uint32_t db_handle_timeout;
        int curl_count;
        int ssl_count;
+       int cpu_count;
 };
 
 extern struct switch_runtime runtime;
index 562262c82dfffd6fe9ab5d2cf9614ec6c69e8dfb..da6a2e6adae9a4b166d0ece34bd0614d9e5279a1 100644 (file)
@@ -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
   \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
index 4ef38111f2ebe9a88bfbcf56261176322d131fb0..4d4208ebdba64b7e632b2cfe4bebf5e21553359d 100644 (file)
@@ -358,7 +358,7 @@ int main(int argc, char *argv[])
        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
@@ -408,7 +408,9 @@ int main(int argc, char *argv[])
                "\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"
@@ -567,8 +569,18 @@ int main(int argc, char *argv[])
                }
 #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++;
                }
 
@@ -828,13 +840,21 @@ int main(int argc, char *argv[])
        }
 
 
-
-       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();
 
 
index ba0350a7fe8e03880566e56f73b0d1bcb8bc6a8f..4edf0dc576d40d803daf686fad6087b86d8b2803 100644 (file)
@@ -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
        SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
 #else
@@ -679,13 +681,14 @@ static int32_t set_low_priority(void)
        }
 #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
        /*
@@ -720,47 +723,20 @@ static int32_t set_priority(void)
        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;
 }
 
@@ -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.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) {