瀏覽代碼

- new script config vars: mlock_pages, shm_force_alloc, real_time,
rt_prio, rt_policy, rt_timer1_prio, rt_timer1_policy, rt_timer2_prio,
rt_timer2_policy (for more info see NEWS)

Andrei Pelinescu-Onciul 18 年之前
父節點
當前提交
71a0a583d1
共有 6 個文件被更改,包括 177 次插入5 次删除
  1. 26 0
      NEWS
  2. 30 0
      cfg.lex
  3. 30 0
      cfg.y
  4. 5 5
      core_cmd.c
  5. 83 0
      daemonize.c
  6. 3 0
      daemonize.h

+ 26 - 0
NEWS

@@ -71,10 +71,36 @@ modules:
                         - t_set_retr(t1, t2) - changes the retransmissions
                            intervals on the fly, on a per transaction basis.
 core:
+             - support for locking ser's pages in memory, pre-mapping
+               all the shared memory on startup (fill it with 0)
+             - real time options
+             - devel: new PROC_INIT rank, init_child(PROC_INIT) called first
              - futex support on linux (better behaviour when waiting on 
                long held locks, almost no performance impact otherwise)
 
 new config variables:
+  mlock_pages = yes |no (default no) - locks all ser pages into memory making 
+    it unswappable (in general one doesn't want his sip proxy swapped out :-))
+  shm_force_alloc = yes | no (default no) - tries to pre-fault all the 
+    shared memory, before starting. When on start time will increase, but
+    combined with mlock_pages will guarantee ser will get all its memory from
+    the beginning (no more kswapd slow downs)
+  real_time = <int> (flags) (default off). - sets real time priority
+     for all the ser processes, or the timers. 
+     Possible values:   0  - off
+                        1  - the "fast" timer
+                        2  - the "slow" timer
+                        4  - all processes, except the timers
+     Example: real_time= 7 => everything switched to real time priority.
+  rt_prio = <int> (default 0) - real time priority used for everything except
+     the timers, if real_time is enabled
+  rt_policy= <0..3> (default 0)- real time scheduling policy, 0 = SCHED_OTHER,
+     1= SCHED_RR and 2=SCHED_FIFO
+  rt_timer1_prio=<int> (default 0) - like rt_prio but for the "fast" timer
+     process (if real_time & 1)
+  rt_timer1_policy=<0..3> (default 0) - like rt_policy but for the "fast" timer
+  rt_timer2_prio=<int> (default 0) - like rt_prio but for the "slow" timer
+  rt_timer2_policy=<0..3> (default 0) - like rt_policy but for the "slow" timer
   tcp_source_ipv4 = IPv4 address
   tcp_source_ipv6 = IPv6 address
     Set the given source IP for all outbound TCP connections.

+ 30 - 0
cfg.lex

@@ -64,6 +64,9 @@
  *              options (andrei)
  *  2006-10-13  added STUN_ALLOW_STUN, STUN_ALLOW_FP, STUN_REFRESH_INTERVAL
  *              (vlada)
+ *  2007-06-07  added SHM_FORCE_ALLOC, MLOCK_PAGES, REAL_TIME, RT_PRIO,
+ *              RT_POLICY, RT_TIMER1_PRIO, RT_TIMER1_POLICY, RT_TIMER2_PRIO,
+ *              RT_TIMER2_POLICY (andrei)
  */
 
 
@@ -290,6 +293,15 @@ ADVERTISED_ADDRESS	"advertised_address"
 ADVERTISED_PORT		"advertised_port"
 DISABLE_CORE		"disable_core_dump"
 OPEN_FD_LIMIT		"open_files_limit"
+SHM_FORCE_ALLOC		"shm_force_alloc"
+MLOCK_PAGES			"mlock_pages"
+REAL_TIME			"real_time"
+RT_PRIO				"rt_prio"
+RT_POLICY			"rt_policy"
+RT_TIMER1_PRIO		"rt_timer1_prio"|"rt_fast_timer_prio"|"rt_ftimer_prio"
+RT_TIMER1_POLICY	"rt_timer1_policy"|"rt_ftimer_policy"
+RT_TIMER2_PRIO		"rt_timer2_prio"|"rt_stimer_prio"
+RT_TIMER2_POLICY	"rt_timer2_policy"|"rt_stimer_policy"
 MCAST_LOOPBACK		"mcast_loopback"
 MCAST_TTL		"mcast_ttl"
 TOS			"tos"
@@ -535,6 +547,24 @@ EAT_ABLE	[\ \t\b\r]
 									return DISABLE_CORE; }
 <INITIAL>{OPEN_FD_LIMIT}		{	count(); yylval.strval=yytext;
 									return OPEN_FD_LIMIT; }
+<INITIAL>{SHM_FORCE_ALLOC}		{	count(); yylval.strval=yytext;
+									return SHM_FORCE_ALLOC; }
+<INITIAL>{MLOCK_PAGES}		{	count(); yylval.strval=yytext;
+									return MLOCK_PAGES; }
+<INITIAL>{REAL_TIME}		{	count(); yylval.strval=yytext;
+									return REAL_TIME; }
+<INITIAL>{RT_PRIO}		{	count(); yylval.strval=yytext;
+									return RT_PRIO; }
+<INITIAL>{RT_POLICY}		{	count(); yylval.strval=yytext;
+									return RT_POLICY; }
+<INITIAL>{RT_TIMER1_PRIO}		{	count(); yylval.strval=yytext;
+									return RT_TIMER1_PRIO; }
+<INITIAL>{RT_TIMER1_POLICY}		{	count(); yylval.strval=yytext;
+									return RT_TIMER1_POLICY; }
+<INITIAL>{RT_TIMER2_PRIO}		{	count(); yylval.strval=yytext;
+									return RT_TIMER2_PRIO; }
+<INITIAL>{RT_TIMER2_POLICY}		{	count(); yylval.strval=yytext;
+									return RT_TIMER2_POLICY; }
 <INITIAL>{MCAST_LOOPBACK}		{	count(); yylval.strval=yytext;
 									return MCAST_LOOPBACK; }
 <INITIAL>{MCAST_TTL}		{	count(); yylval.strval=yytext;

+ 30 - 0
cfg.y

@@ -78,6 +78,9 @@
  *              (vlada)
  * 2007-02-09  separated command needed for tls-in-core and for tls in general
  *              (andrei)
+ *  2007-06-07  added SHM_FORCE_ALLOC, MLOCK_PAGES, REAL_TIME, RT_PRIO,
+ *              RT_POLICY, RT_TIMER1_PRIO, RT_TIMER1_POLICY, RT_TIMER2_PRIO,
+ *              RT_TIMER2_POLICY (andrei)
  */
 
 %{
@@ -328,6 +331,15 @@ static struct socket_id* mk_listen_id(char*, int, int);
 %token ADVERTISED_PORT
 %token DISABLE_CORE
 %token OPEN_FD_LIMIT
+%token SHM_FORCE_ALLOC
+%token MLOCK_PAGES
+%token REAL_TIME
+%token RT_PRIO
+%token RT_POLICY
+%token RT_TIMER1_PRIO
+%token RT_TIMER1_POLICY
+%token RT_TIMER2_PRIO
+%token RT_TIMER2_POLICY
 %token MCAST_LOOPBACK
 %token MCAST_TTL
 %token TOS
@@ -897,6 +909,24 @@ assign_stm:
 	| DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
 	| OPEN_FD_LIMIT EQUAL NUMBER { open_files_limit=$3; }
 	| OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
+	| SHM_FORCE_ALLOC EQUAL NUMBER { shm_force_alloc=$3; }
+	| SHM_FORCE_ALLOC EQUAL error { yyerror("boolean value expected"); }
+	| MLOCK_PAGES EQUAL NUMBER { mlock_pages=$3; }
+	| MLOCK_PAGES EQUAL error { yyerror("boolean value expected"); }
+	| REAL_TIME EQUAL NUMBER { real_time=$3; }
+	| REAL_TIME EQUAL error { yyerror("boolean value expected"); }
+	| RT_PRIO EQUAL NUMBER { rt_prio=$3; }
+	| RT_PRIO EQUAL error { yyerror("boolean value expected"); }
+	| RT_POLICY EQUAL NUMBER { rt_policy=$3; }
+	| RT_POLICY EQUAL error { yyerror("boolean value expected"); }
+	| RT_TIMER1_PRIO EQUAL NUMBER { rt_timer1_prio=$3; }
+	| RT_TIMER1_PRIO EQUAL error { yyerror("boolean value expected"); }
+	| RT_TIMER1_POLICY EQUAL NUMBER { rt_timer1_policy=$3; }
+	| RT_TIMER1_POLICY EQUAL error { yyerror("boolean value expected"); }
+	| RT_TIMER2_PRIO EQUAL NUMBER { rt_timer2_prio=$3; }
+	| RT_TIMER2_PRIO EQUAL error { yyerror("boolean value expected"); }
+	| RT_TIMER2_POLICY EQUAL NUMBER { rt_timer2_policy=$3; }
+	| RT_TIMER2_POLICY EQUAL error { yyerror("boolean value expected"); }
 	| MCAST_LOOPBACK EQUAL NUMBER {
 		#ifdef USE_MCAST
 			mcast_loopback=$3;

+ 5 - 5
core_cmd.c

@@ -289,11 +289,11 @@ static void core_shmmem(rpc_t* rpc, void* c)
 	shm_info(&mi);
 	rpc->add(c, "{", &handle);
 	rpc->struct_add(handle, "ddddd",
-		"total", mi.total_size,
-		"free", mi.free,
-		"used", mi.real_used,
-		"max_used", mi.max_used,
-		"fragments", mi.total_frags
+		"total", (unsigned int)mi.total_size,
+		"free", (unsigned int)mi.free,
+		"used", (unsigned int)mi.real_used,
+		"max_used", (unsigned int)mi.max_used,
+		"fragments", (unsigned int)mi.total_frags
 	);
 }
 

+ 83 - 0
daemonize.c

@@ -32,6 +32,8 @@
  *  2004-03-04  moved setuid/setgid in do_suid() (andrei)
  *  2004-03-25  added increase_open_fds & set_core_dump (andrei)
  *  2004-05-03  applied pgid patch from janakj
+ *  2007-06-07  added mlock_pages (no swap) support (andrei)
+  *             added set_rt_prio() (andrei)
  */
 
 
@@ -56,6 +58,15 @@
 #include <sys/resource.h> /* setrlimit */
 #include <unistd.h>
 
+#ifdef HAVE_SCHED_SETSCHEDULER
+#include <sched.h>
+#endif
+
+#ifdef _POSIX_MEMLOCK
+#define HAVE_MLOCKALL
+#include <sys/mman.h>
+#endif
+
 #include "daemonize.h"
 #include "globals.h"
 #include "dprint.h"
@@ -337,3 +348,75 @@ done:
 error:
 	return -1;
 }
+
+
+
+/* lock pages in memory (make the process not swapable) */
+int mem_lock_pages()
+{
+#ifdef HAVE_MLOCKALL
+	if (mlockall(MCL_CURRENT|MCL_FUTURE) !=0){
+		LOG(L_WARN,"failed to lock the memory pages (disable swap): %s [%d]\n",
+				strerror(errno), errno);
+		goto error;
+	}
+	return 0;
+error:
+	return -1;
+#else /* if MLOCKALL not defined return error */
+		LOG(L_WARN,"failed to lock the memory pages: no mlockall support\n");
+	return -1;
+#endif 
+}
+
+
+/* tries to set real time priority 
+ * policy: 0 - SCHED_OTHER, 1 - SCHED_RR, 2 - SCHED_FIFO */
+int set_rt_prio(int prio, int policy)
+{
+#ifdef HAVE_SCHED_SETSCHEDULER
+	struct sched_param sch_p;
+	int min_prio, max_prio;
+	int sched_policy;
+	
+	switch(policy){
+		case 0:
+			sched_policy=SCHED_OTHER;
+			break;
+		case 1:
+			sched_policy=SCHED_RR;
+			break;
+		case 2:
+			sched_policy=SCHED_FIFO;
+			break;
+		default:
+			LOG(L_WARN, "WARNING: invalid scheduling policy,using"
+						" SCHED_OTHER\n");
+			sched_policy=SCHED_OTHER;
+	}
+	memset(&sch_p, 0, sizeof(sch_p));
+	max_prio=sched_get_priority_max(policy);
+	min_prio=sched_get_priority_min(policy);
+	if (prio<min_prio){
+		LOG(L_WARN, "scheduling priority %d too small, using minimum value"
+					" (%d)\n", prio, min_prio);
+		prio=min_prio;
+	}else if (prio>max_prio){
+		LOG(L_WARN, "scheduling priority %d too big, using maximum value"
+					" (%d)\n", prio, max_prio);
+		prio=max_prio;
+	}
+	sch_p.sched_priority=prio;
+	if (sched_setscheduler(0, sched_policy, &sch_p) != 0){
+		LOG(L_WARN, "could not switch to real time priority: %s [%d]\n",
+					strerror(errno), errno);
+		return -1;
+	};
+	return 0;
+#else
+	LOG(L_WARN, "real time support not available\n");
+	return -1;
+#endif
+}
+
+

+ 3 - 0
daemonize.h

@@ -29,6 +29,7 @@
  * History:
  * --------
  *  2004-02-20  created by andrei
+ *  2007-06-07 added mem_lock_pages() (andrei)
  */
 
 #ifndef _daemonize_h
@@ -38,6 +39,8 @@ int daemonize(char* name);
 int do_suid();
 int increase_open_fds(int target);
 int set_core_dump(int enable, int size);
+int mem_lock_pages();
+int set_rt_prio(int prio, int policy);
 
 
 #endif