Browse code

core: new parameter async_usleep

- add option to do usleep() before processing async tasks
- could help saving cpu usage on vms with immediate interruptions
triggered to recvfrom()

Daniel-Constantin Mierla authored on 04/09/2015 12:39:27
Showing 4 changed files
... ...
@@ -46,6 +46,7 @@
46 46
 
47 47
 static int _async_task_workers = 0;
48 48
 static int _async_task_sockets[2];
49
+static int _async_task_usleep = 0;
49 50
 
50 51
 int async_task_run(int idx);
51 52
 
... ...
@@ -177,6 +178,19 @@ int async_task_set_workers(int n)
177 177
 /**
178 178
  *
179 179
  */
180
+int async_task_set_usleep(int n)
181
+{
182
+	int v;
183
+
184
+	v = _async_task_usleep;
185
+	_async_task_usleep = n;
186
+
187
+	return v;
188
+}
189
+
190
+/**
191
+ *
192
+ */
180 193
 int async_task_push(async_task_t *task)
181 194
 {
182 195
 	int len;
... ...
@@ -204,6 +218,7 @@ int async_task_run(int idx)
204 204
 	LM_DBG("async task worker %d ready\n", idx);
205 205
 
206 206
 	for( ; ; ) {
207
+		if(unlikely(_async_task_usleep)) sleep_us(_async_task_usleep);
207 208
 		if ((received = recvfrom(_async_task_sockets[0],
208 209
 							&ptask, sizeof(async_task_t*),
209 210
 							0, NULL, 0)) < 0) {
... ...
@@ -36,5 +36,6 @@ int async_task_child_init(int rank);
36 36
 int async_task_initialized(void);
37 37
 int async_task_set_workers(int n);
38 38
 int async_task_push(async_task_t *task);
39
+int async_task_set_usleep(int n);
39 40
 
40 41
 #endif
... ...
@@ -400,6 +400,7 @@ SQL_BUFFER_SIZE sql_buffer_size
400 400
 CHILDREN children
401 401
 SOCKET_WORKERS socket_workers
402 402
 ASYNC_WORKERS async_workers
403
+ASYNC_USLEEP async_usleep
403 404
 CHECK_VIA	check_via
404 405
 PHONE2TEL	phone2tel
405 406
 MEMLOG		"memlog"|"mem_log"
... ...
@@ -810,6 +811,7 @@ IMPORTFILE      "import_file"
810 810
 <INITIAL>{CHILDREN}	{ count(); yylval.strval=yytext; return CHILDREN; }
811 811
 <INITIAL>{SOCKET_WORKERS}	{ count(); yylval.strval=yytext; return SOCKET_WORKERS; }
812 812
 <INITIAL>{ASYNC_WORKERS}	{ count(); yylval.strval=yytext; return ASYNC_WORKERS; }
813
+<INITIAL>{ASYNC_USLEEP}	{ count(); yylval.strval=yytext; return ASYNC_USLEEP; }
813 814
 <INITIAL>{CHECK_VIA}	{ count(); yylval.strval=yytext; return CHECK_VIA; }
814 815
 <INITIAL>{PHONE2TEL}	{ count(); yylval.strval=yytext; return PHONE2TEL; }
815 816
 <INITIAL>{MEMLOG}	{ count(); yylval.strval=yytext; return MEMLOG; }
... ...
@@ -446,6 +446,7 @@ extern char *default_routename;
446 446
 %token CHILDREN
447 447
 %token SOCKET_WORKERS
448 448
 %token ASYNC_WORKERS
449
+%token ASYNC_USLEEP
449 450
 %token CHECK_VIA
450 451
 %token PHONE2TEL
451 452
 %token MEMLOG
... ...
@@ -954,6 +955,8 @@ assign_stm:
954 954
 	| SOCKET_WORKERS EQUAL error { yyerror("number expected"); }
955 955
 	| ASYNC_WORKERS EQUAL NUMBER { async_task_set_workers($3); }
956 956
 	| ASYNC_WORKERS EQUAL error { yyerror("number expected"); }
957
+	| ASYNC_USLEEP EQUAL NUMBER { async_task_set_usleep($3); }
958
+	| ASYNC_USLEEP EQUAL error { yyerror("number expected"); }
957 959
 	| CHECK_VIA EQUAL NUMBER { check_via=$3; }
958 960
 	| CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
959 961
 	| PHONE2TEL EQUAL NUMBER { phone2tel=$3; }