Browse code

- added the new PROC_INIT rank and the init_child(PROC_INIT) calls (see doc/modules_init.txt for more info) - introduced new options for locking pages in memory, pre-faulting the shared memory pages and real time mode

Andrei Pelinescu-Onciul authored on 07/06/2007 21:40:14
Showing 3 changed files
... ...
@@ -175,12 +175,27 @@ extern str default_global_address;
175 175
 extern str default_global_port;
176 176
 
177 177
 /* how much time to allow for shutdown, before killing everything */
178
-int ser_kill_timeout;
178
+extern int ser_kill_timeout;
179 179
 
180 180
 /* core dump and file limits */
181 181
 extern int disable_core_dump;
182 182
 extern int open_files_limit;
183 183
 
184
+/* memory lock/pre-fault */
185
+extern int shm_force_alloc;
186
+extern int mlock_pages;
187
+
188
+/* real time stuff */
189
+extern int real_time; 
190
+extern int rt_prio;
191
+extern int rt_policy; /* SCHED_OTHER */
192
+extern int rt_timer1_prio;  /* "fast" timer */
193
+extern int rt_timer2_prio;  /* "slow" timer */
194
+extern int rt_timer1_policy; /* "fast" timer, SCHED_OTHER */
195
+extern int rt_timer2_policy; /* "slow" timer, SCHED_OTHER */
196
+
197
+
198
+
184 199
 /* resolver */
185 200
 extern int dns_retr_time;
186 201
 extern int dns_retr_no;
... ...
@@ -189,19 +204,21 @@ extern int dns_search_list;
189 189
 #ifdef USE_DNS_CACHE
190 190
 extern int use_dns_cache; /* 1 if the cache is enabled, 0 otherwise */
191 191
 extern int use_dns_failover; /* 1 if failover is enabled, 0 otherwise */
192
-unsigned int dns_cache_max_mem; /* maximum memory used for the cached entries*/
193
-unsigned int dns_neg_cache_ttl; /* neg. cache ttl */
194
-unsigned int dns_cache_max_ttl; /* maximum ttl */
195
-unsigned int dns_cache_min_ttl; /* minimum ttl */
196
-unsigned int dns_timer_interval; /* gc timer interval in s */
197
-int dns_flags; /* default flags used for the  dns_*resolvehost 
192
+extern unsigned int dns_cache_max_mem; /* maximum memory used for the cached 
193
+										  entries*/
194
+extern unsigned int dns_neg_cache_ttl; /* neg. cache ttl */
195
+extern unsigned int dns_cache_max_ttl; /* maximum ttl */
196
+extern unsigned int dns_cache_min_ttl; /* minimum ttl */
197
+extern unsigned int dns_timer_interval; /* gc timer interval in s */
198
+extern int dns_flags; /* default flags used for the  dns_*resolvehost 
198 199
                     (compatibility wrappers) */
199 200
 #endif
200 201
 #ifdef USE_DST_BLACKLIST
201 202
 extern int use_dst_blacklist; /* 1 if the blacklist is enabled */
202
-unsigned int  blst_max_mem; /* maximum memory used for the blacklist entries*/
203
-unsigned int blst_timeout; /* blacklist entry ttl */
204
-unsigned int blst_timer_interval; /* blacklist gc timer interval (in s)*/
203
+extern unsigned int  blst_max_mem; /* maximum memory used for the blacklist 
204
+									  entries*/
205
+extern unsigned int blst_timeout; /* blacklist entry ttl */
206
+extern unsigned int blst_timer_interval; /*blacklist gc timer interval (in s)*/
205 207
 #endif
206 208
 
207 209
 #endif
... ...
@@ -72,6 +72,8 @@
72 72
  *               safer shutdown on start-up error (andrei)
73 73
  * 2007-02-09  TLS support split into tls-in-core (CORE_TLS) and generic TLS 
74 74
  *             (USE_TLS)  (andrei)
75
+ * 2007-06-07  added support for locking pages in mem. and using real time
76
+ *              scheduling policies (andrei)
75 77
  */
76 78
 
77 79
 
... ...
@@ -330,6 +332,24 @@ int sock_mode= S_IRUSR| S_IWUSR| S_IRGRP| S_IWGRP; /* rw-rw---- */
330 330
 /* more config stuff */
331 331
 int disable_core_dump=0; /* by default enabled */
332 332
 int open_files_limit=-1; /* don't touch it by default */
333
+
334
+/* memory options */
335
+int shm_force_alloc=0; /* force immediate (on startup) page allocation
336
+						  (by writting 0 in the pages), useful if
337
+						  mlock_pages is also 1 */
338
+int mlock_pages=0; /* default off, try to disable swapping */
339
+
340
+/* real time options */
341
+int real_time=0; /* default off, flags: 1 on only timer, 2  slow timer,
342
+					                    4 all procs (7=all) */
343
+int rt_prio=0;  
344
+int rt_policy=0; /* SCHED_OTHER */
345
+int rt_timer1_prio=0;  /* "fast" timer */
346
+int rt_timer2_prio=0;  /* "slow" timer */
347
+int rt_timer1_policy=0; /* "fast" timer, SCHED_OTHER */
348
+int rt_timer2_policy=0; /* "slow" timer, SCHED_OTHER */
349
+
350
+
333 351
 /* a hint to reply modules whether they should send reply
334 352
    to IP advertised in Via or IP from which a request came
335 353
 */
... ...
@@ -903,6 +923,9 @@ int main_loop()
903 903
 					/* child */
904 904
 					/* timer!*/
905 905
 					/* process_bit = 0; */
906
+					if (real_time&2)
907
+						set_rt_prio(rt_timer2_prio, rt_timer2_policy);
908
+					
906 909
 					if (arm_slow_timer()<0) goto error;
907 910
 					slow_timer_main();
908 911
 				}else{
... ...
@@ -919,6 +942,8 @@ int main_loop()
919 919
 					/* child */
920 920
 					/* timer!*/
921 921
 					/* process_bit = 0; */
922
+					if (real_time&1)
923
+						set_rt_prio(rt_timer1_prio, rt_timer1_policy);
922 924
 					if (arm_timer()<0) goto error;
923 925
 					timer_main();
924 926
 				}else{
... ...
@@ -931,18 +956,37 @@ int main_loop()
931 931
 			"stand-alone receiver @ %s:%s",
932 932
 			 bind_address->name.s, bind_address->port_no_str.s );
933 933
 
934
+		/* init childs with rank==PROC_INIT before forking any process, 
935
+		 * this is a place for delayed (after mod_init) initializations
936
+		 * (e.g. shared vars that depend on the total number of processes
937
+		 * that is known only after all mod_inits have been executed )
938
+		 * WARNING: the same init_child will be called latter, a second time
939
+		 * for the "main" process with rank PROC_MAIN (make sure things are 
940
+		 * not initialized twice)*/
941
+		if (init_child(PROC_INIT) < 0) {
942
+			LOG(L_ERR, "ERROR: main_dontfork: init_child(PROC_INT) --"
943
+						" exiting\n");
944
+			goto error;
945
+		}
946
+	
947
+	/* call it also w/ PROC_MAIN to make sure modules that init things only
948
+	 * in PROC_MAIN get a chance to run */
949
+	if (init_child(PROC_MAIN) < 0) {
950
+		LOG(L_ERR, "ERROR: main_dontfork: init_child(PROC_MAIN) -- exiting\n");
951
+		goto error;
952
+	}
934 953
 
935
-		     /* We will call child_init even if we
936
-		      * do not fork - and it will be called with rank 1 because
937
-		      * in fact we behave like a child, not like main process
938
-		      */
954
+		/* We will call child_init even if we
955
+		 * do not fork - and it will be called with rank 1 because
956
+		 * in fact we behave like a child, not like main process
957
+		 */
939 958
 
940 959
 		if (init_child(1) < 0) {
941 960
 			LOG(L_ERR, "main_dontfork: init_child failed\n");
942 961
 			goto error;
943 962
 		}
944 963
 		return udp_rcv_loop();
945
-	}else{
964
+	}else{ /* fork: */
946 965
 
947 966
 		for(si=udp_listen;si;si=si->next){
948 967
 			/* create the listening socket (for each address)*/
... ...
@@ -994,6 +1038,20 @@ int main_loop()
994 994
 			 * so we open all first*/
995 995
 		if (do_suid()==-1) goto error; /* try to drop privileges */
996 996
 
997
+		/* init childs with rank==PROC_INIT before forking any process, 
998
+		 * this is a place for delayed (after mod_init) initializations
999
+		 * (e.g. shared vars that depend on the total number of processes
1000
+		 * that is known only after all mod_inits have been executed )
1001
+		 * WARNING: the same init_child will be called latter, a second time
1002
+		 * for the "main" process with rank PROC_MAIN (make sure things are 
1003
+		 * not initialized twice)*/
1004
+		if (init_child(PROC_INIT) < 0) {
1005
+			LOG(L_ERR, "ERROR: main: error in init_child(PROC_INT) --"
1006
+					" exiting\n");
1007
+			goto error;
1008
+		}
1009
+
1010
+
997 1011
 		/* udp processes */
998 1012
 		for(si=udp_listen; si; si=si->next){
999 1013
 			for(i=0;i<children_no;i++){
... ...
@@ -1021,7 +1079,6 @@ int main_loop()
1021 1021
 	/*this is the main process*/
1022 1022
 	bind_address=0;				/* main proc -> it shouldn't send anything, */
1023 1023
 
1024
-
1025 1024
 	{
1026 1025
 #ifdef USE_SLOW_TIMER
1027 1026
 		/* fork again for the "slow" timer process*/
... ...
@@ -1031,6 +1088,8 @@ int main_loop()
1031 1031
 			goto error;
1032 1032
 		}else if (pid==0){
1033 1033
 			/* child */
1034
+			if (real_time&2)
1035
+				set_rt_prio(rt_timer2_prio, rt_timer2_policy);
1034 1036
 			if (arm_slow_timer()<0) goto error;
1035 1037
 			slow_timer_main();
1036 1038
 		}else{
... ...
@@ -1045,6 +1104,8 @@ int main_loop()
1045 1045
 			goto error;
1046 1046
 		}else if (pid==0){
1047 1047
 			/* child */
1048
+			if (real_time&1)
1049
+				set_rt_prio(rt_timer1_prio, rt_timer1_policy);
1048 1050
 			if (arm_timer()<0) goto error;
1049 1051
 			timer_main();
1050 1052
 		}else{
... ...
@@ -1055,7 +1116,7 @@ int main_loop()
1055 1055
  *  fork  a tcp capable process, the corresponding tcp. comm. fds in pt[] must
1056 1056
  *  be set before calling tcp_main_loop()) */
1057 1057
 	if (init_child(PROC_MAIN) < 0) {
1058
-		LOG(L_ERR, "main: error in init_child\n");
1058
+		LOG(L_ERR, "ERROR: main: error in init_child\n");
1059 1059
 		goto error;
1060 1060
 	}
1061 1061
 
... ...
@@ -1504,7 +1565,7 @@ try_again:
1504 1504
 	 *     -it must be after we know uid (so that in the SYSV sems case,
1505 1505
 	 *        the sems will have the correct euid)
1506 1506
 	 * --andrei */
1507
-	if (init_shm_mallocs()==-1)
1507
+	if (init_shm_mallocs(shm_force_alloc)==-1)
1508 1508
 		goto error;
1509 1509
 	if (init_atomic_ops()==-1)
1510 1510
 		goto error;
... ...
@@ -1556,6 +1617,11 @@ try_again:
1556 1556
 			goto error;
1557 1557
 		}
1558 1558
 	}
1559
+	if (mlock_pages)
1560
+		mem_lock_pages();
1561
+	
1562
+	if (real_time&4)
1563
+			set_rt_prio(rt_prio, rt_policy);
1559 1564
 	
1560 1565
 	if (init_modules() != 0) {
1561 1566
 		fprintf(stderr, "ERROR: error while initializing modules\n");
... ...
@@ -38,6 +38,9 @@
38 38
  *  2004-09-19  switched to version.h for the module versions checks (andrei)
39 39
  *  2004-12-03  changed param_func_t to (modparam_t, void*), killed
40 40
  *               param_func_param_t   (andrei)
41
+ *  2007-06-07  added PROC_INIT, called in the main process context
42
+ *               (same as PROC_MAIN), buf guaranteed to be called before
43
+ *               any other process is forked (andrei)
41 44
  */
42 45
 
43 46
 
... ...
@@ -88,6 +91,16 @@ typedef int (*param_func_t)( modparam_t type, void* val);
88 88
 #define PROC_FIFO      PROC_RPC  /* FIFO attendant process */
89 89
 #define PROC_TCP_MAIN -4  /* TCP main process */
90 90
 #define PROC_UNIXSOCK -5  /* Unix socket server */
91
+#define PROC_INIT     -127 /* special rank, the context is the main ser
92
+							  process, but this is guaranteed to be executed
93
+							  before any process is forked, so it can be used
94
+							  to setup shared variables that depend on some
95
+							  after mod_init available information (e.g.
96
+							  total number of processes).
97
+							 WARNING: child_init(PROC_MAIN) is again called
98
+							 in the same process (main), but latter 
99
+							 (before tcp), so make sure you don't init things 
100
+							 twice, bot in PROC_MAIN and PROC_INT */
91 101
 #define PROC_NOCHLDINIT -128 /* no child init functions will be called
92 102
                                 if this rank is used in fork_process() */
93 103