Module: kamailio
Branch: master
Commit: 55be13dfdb0db49358b6cd43b4916c0fb5fabc2e
URL:
https://github.com/kamailio/kamailio/commit/55be13dfdb0db49358b6cd43b4916c0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-09-04T14:39:27+02:00
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()
---
Modified: async_task.c
Modified: async_task.h
Modified: cfg.lex
Modified: cfg.y
---
Diff:
https://github.com/kamailio/kamailio/commit/55be13dfdb0db49358b6cd43b4916c0…
Patch:
https://github.com/kamailio/kamailio/commit/55be13dfdb0db49358b6cd43b4916c0…
---
diff --git a/async_task.c b/async_task.c
index 019f493..956bd9a 100644
--- a/async_task.c
+++ b/async_task.c
@@ -46,6 +46,7 @@
static int _async_task_workers = 0;
static int _async_task_sockets[2];
+static int _async_task_usleep = 0;
int async_task_run(int idx);
@@ -177,6 +178,19 @@ int async_task_set_workers(int n)
/**
*
*/
+int async_task_set_usleep(int n)
+{
+ int v;
+
+ v = _async_task_usleep;
+ _async_task_usleep = n;
+
+ return v;
+}
+
+/**
+ *
+ */
int async_task_push(async_task_t *task)
{
int len;
@@ -204,6 +218,7 @@ int async_task_run(int idx)
LM_DBG("async task worker %d ready\n", idx);
for( ; ; ) {
+ if(unlikely(_async_task_usleep)) sleep_us(_async_task_usleep);
if ((received = recvfrom(_async_task_sockets[0],
&ptask, sizeof(async_task_t*),
0, NULL, 0)) < 0) {
diff --git a/async_task.h b/async_task.h
index 321ad06..620009b 100644
--- a/async_task.h
+++ b/async_task.h
@@ -36,5 +36,6 @@ int async_task_child_init(int rank);
int async_task_initialized(void);
int async_task_set_workers(int n);
int async_task_push(async_task_t *task);
+int async_task_set_usleep(int n);
#endif
diff --git a/cfg.lex b/cfg.lex
index ef8c881..25468c7 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -400,6 +400,7 @@ SQL_BUFFER_SIZE sql_buffer_size
CHILDREN children
SOCKET_WORKERS socket_workers
ASYNC_WORKERS async_workers
+ASYNC_USLEEP async_usleep
CHECK_VIA check_via
PHONE2TEL phone2tel
MEMLOG "memlog"|"mem_log"
@@ -810,6 +811,7 @@ IMPORTFILE "import_file"
<INITIAL>{CHILDREN} { count(); yylval.strval=yytext; return CHILDREN; }
<INITIAL>{SOCKET_WORKERS} { count(); yylval.strval=yytext; return SOCKET_WORKERS;
}
<INITIAL>{ASYNC_WORKERS} { count(); yylval.strval=yytext; return ASYNC_WORKERS; }
+<INITIAL>{ASYNC_USLEEP} { count(); yylval.strval=yytext; return ASYNC_USLEEP; }
<INITIAL>{CHECK_VIA} { count(); yylval.strval=yytext; return CHECK_VIA; }
<INITIAL>{PHONE2TEL} { count(); yylval.strval=yytext; return PHONE2TEL; }
<INITIAL>{MEMLOG} { count(); yylval.strval=yytext; return MEMLOG; }
diff --git a/cfg.y b/cfg.y
index 154cb44..06682a1 100644
--- a/cfg.y
+++ b/cfg.y
@@ -446,6 +446,7 @@ extern char *default_routename;
%token CHILDREN
%token SOCKET_WORKERS
%token ASYNC_WORKERS
+%token ASYNC_USLEEP
%token CHECK_VIA
%token PHONE2TEL
%token MEMLOG
@@ -954,6 +955,8 @@ assign_stm:
| SOCKET_WORKERS EQUAL error { yyerror("number expected"); }
| ASYNC_WORKERS EQUAL NUMBER { async_task_set_workers($3); }
| ASYNC_WORKERS EQUAL error { yyerror("number expected"); }
+ | ASYNC_USLEEP EQUAL NUMBER { async_task_set_usleep($3); }
+ | ASYNC_USLEEP EQUAL error { yyerror("number expected"); }
| CHECK_VIA EQUAL NUMBER { check_via=$3; }
| CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
| PHONE2TEL EQUAL NUMBER { phone2tel=$3; }