[asterisk-dev] [Code Review] Use kqueue(2) to reduce CPU consumption in *BSD and Mac OS X

Mark Michelson mmichelson at digium.com
Tue Mar 9 17:06:49 CST 2010



> On 2010-03-09 14:15:36, Mark Michelson wrote:
> > /trunk/main/stdtime/localtime.c, line 343
> > <https://reviewboard.asterisk.org/r/543/diff/1/?file=8488#file8488line343>
> >
> >     There is a race condition here. It is possible that this call to ast_cond_signal can be made prior to the other thread reaching its call to ast_cond_wait.
> >     
> >     The way to ensure happens-before behavior is to use a combination of a condition and a boolean.
> >     
> >     Thread 1:
> >     
> >     ast_mutex_lock(lock);
> >     if (!boolean)
> >         ast_cond_wait(cond, lock);
> >     }
> >     ast_mutex_unlock(lock);
> >     
> >     Thread 2:
> >     
> >     ast_mutex_lock(lock);
> >     boolean = 1;
> >     ast_cond_signal(cond);
> >     ast_mutex_unlock(lock);
> >     
> >
> 
> Tilghman Lesher wrote:
>     Fixed in a different way -- by adding a lock on the mutex before sending the signal.

Yep, that'll work since you lock the lock prior to creating the thread that will signal. Good call.


- Mark


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/543/#review1643
-----------------------------------------------------------


On 2010-03-09 16:23:56, Tilghman Lesher wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/543/
> -----------------------------------------------------------
> 
> (Updated 2010-03-09 16:23:56)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Summary
> -------
> 
> Currently, we use inotify(2), which is a Linux-only kernel API, to check as to whether timezone files have changed, which allows an admin to change the machine timezone on the fly, and we will reparse it.  The alternative currently is for us to sit in what is essentially a busy loop, checking whether a timezone file is changed.  For most situations, these files change very seldom, so this represents quite a bit of CPU consumption over the life of a process.
> 
> The BSDs (and Mac OS X) contain a similar interface, called kqueue(2).  This has been implemented for timezone files, which should conserve CPU usage while running Asterisk on those platforms.
> 
> 
> Diffs
> -----
> 
>   /trunk/configure.ac 251423 
>   /trunk/include/asterisk/autoconfig.h.in 251423 
>   /trunk/main/stdtime/localtime.c 251423 
> 
> Diff: https://reviewboard.asterisk.org/r/543/diff
> 
> 
> Testing
> -------
> 
> None yet; wanted to get some eyes on this before testing started.
> 
> 
> Thanks,
> 
> Tilghman
> 
>




More information about the asterisk-dev mailing list