浏览代码

Merge pull request #733 from gaaf/rtimer-mode

Let multiple processes handle an rtimer
Daniel-Constantin Mierla 9 年之前
父节点
当前提交
e769f2e573
共有 3 个文件被更改,包括 28 次插入11 次删除
  1. 3 1
      modules/rtimer/README
  2. 3 2
      modules/rtimer/doc/rtimer_admin.xml
  3. 22 8
      modules/rtimer/rtimer_mod.c

+ 3 - 1
modules/rtimer/README

@@ -87,7 +87,9 @@ Chapter 1. Admin Guide
    The parameter can be set multiple times to get more timers in same
    The parameter can be set multiple times to get more timers in same
    configuration file.
    configuration file.
      * name - name of the timer.
      * name - name of the timer.
-     * mode - if set to 1, will create a new timer process.
+     * mode - if set to 0, the timer will use the main (shared) timer. Any
+       number > 0 will create the specified amount of new timer processes
+       (which will only be handling this timer).
      * interval - timer interval in seconds or micro-seconds (the value
      * interval - timer interval in seconds or micro-seconds (the value
        must be ended in 'u'). For micro-seconds intervals, mode is set
        must be ended in 'u'). For micro-seconds intervals, mode is set
        always to 1.
        always to 1.

+ 3 - 2
modules/rtimer/doc/rtimer_admin.xml

@@ -81,8 +81,9 @@
 		</listitem>
 		</listitem>
 		<listitem>
 		<listitem>
 		<para>
 		<para>
-			<emphasis>mode</emphasis> - if set to 1, will create a new timer
-			process.
+			<emphasis>mode</emphasis> - if set to 0, the timer will use the main
+			(shared) timer. Any number > 0 will create the specified amount of
+			new timer processes (which will only be handling this timer).
 		</para>
 		</para>
 		</listitem>
 		</listitem>
 		<listitem>
 		<listitem>

+ 22 - 8
modules/rtimer/rtimer_mod.c

@@ -127,7 +127,7 @@ static int mod_init(void)
 				return -1;
 				return -1;
 			}
 			}
 		} else {
 		} else {
-			register_basic_timers(1);
+			register_basic_timers(it->mode);
 		}
 		}
 		it = it->next;
 		it = it->next;
 	}
 	}
@@ -138,6 +138,9 @@ static int mod_init(void)
 static int child_init(int rank)
 static int child_init(int rank)
 {
 {
 	stm_timer_t *it;
 	stm_timer_t *it;
+	int i;
+	char si_desc[MAX_PT_DESC];
+
 	if(_stm_list==NULL)
 	if(_stm_list==NULL)
 		return 0;
 		return 0;
 
 
@@ -147,18 +150,20 @@ static int child_init(int rank)
 	it = _stm_list;
 	it = _stm_list;
 	while(it)
 	while(it)
 	{
 	{
-		if(it->mode!=0)
+		for(i=0; i<it->mode; i++)
 		{
 		{
+			snprintf(si_desc, MAX_PT_DESC, "RTIMER EXEC child=%d timer=%.*s",
+			         i, it->name.len, it->name.s);
 			if(it->flags & RTIMER_INTERVAL_USEC)
 			if(it->flags & RTIMER_INTERVAL_USEC)
 			{
 			{
-				if(fork_basic_utimer(PROC_TIMER, "RTIMER USEC EXEC", 1 /*socks flag*/,
+				if(fork_basic_utimer(PROC_TIMER, si_desc, 1 /*socks flag*/,
 								stm_timer_exec, (void*)it, it->interval
 								stm_timer_exec, (void*)it, it->interval
 								/*usec*/)<0) {
 								/*usec*/)<0) {
 					LM_ERR("failed to start utimer routine as process\n");
 					LM_ERR("failed to start utimer routine as process\n");
 					return -1; /* error */
 					return -1; /* error */
 				}
 				}
 			} else {
 			} else {
-				if(fork_basic_timer(PROC_TIMER, "RTIMER SEC EXEC", 1 /*socks flag*/,
+				if(fork_basic_timer(PROC_TIMER, si_desc, 1 /*socks flag*/,
 								stm_timer_exec, (void*)it, it->interval
 								stm_timer_exec, (void*)it, it->interval
 								/*sec*/)<0) {
 								/*sec*/)<0) {
 					LM_ERR("failed to start timer routine as process\n");
 					LM_ERR("failed to start timer routine as process\n");
@@ -224,17 +229,26 @@ int stm_t_param(modparam_t type, void *val)
 			tmp.name = pit->body;
 			tmp.name = pit->body;
 		} else if(pit->name.len==4
 		} else if(pit->name.len==4
 				&& strncasecmp(pit->name.s, "mode", 4)==0) {
 				&& strncasecmp(pit->name.s, "mode", 4)==0) {
-			if(tmp.mode==0)
-				str2int(&pit->body, &tmp.mode);
+			if(tmp.mode==0) {
+				if (str2int(&pit->body, &tmp.mode) < 0) {
+					LM_ERR("invalid mode: %.*s\n", pit->body.len, pit->body.s);
+					return -1;
+				}
+			}
 		}  else if(pit->name.len==8
 		}  else if(pit->name.len==8
 				&& strncasecmp(pit->name.s, "interval", 8)==0) {
 				&& strncasecmp(pit->name.s, "interval", 8)==0) {
 			if(pit->body.s[pit->body.len-1]=='u'
 			if(pit->body.s[pit->body.len-1]=='u'
 					|| pit->body.s[pit->body.len-1]=='U') {
 					|| pit->body.s[pit->body.len-1]=='U') {
 				pit->body.len--;
 				pit->body.len--;
 				tmp.flags |= RTIMER_INTERVAL_USEC;
 				tmp.flags |= RTIMER_INTERVAL_USEC;
-				tmp.mode = 1;
+				if (tmp.mode==0) {
+					tmp.mode = 1;
+				}
+			}
+			if (str2int(&pit->body, &tmp.interval) < 0) {
+				LM_ERR("invalid interval: %.*s\n", pit->body.len, pit->body.s);
+					return -1;
 			}
 			}
-			str2int(&pit->body, &tmp.interval);
 		}
 		}
 	}
 	}
 	if(tmp.name.s==NULL)
 	if(tmp.name.s==NULL)