This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Re: time to ticks converter optimization in pthread_cond_timedwait
- From: "W. Jensen" <waj4news at cox dot net>
- To: "Jonathan Larmour" <jifl at eCosCentric dot com>
- Cc: <ecos-patches at sources dot redhat dot com>
- Date: Mon, 9 Dec 2002 19:55:59 -0700
- Subject: Re: time to ticks converter optimization in pthread_cond_timedwait
- References: <005b01c273c2$467afc70$4e0910ac@engineering.intertel.com> <3DF5512E.8030104@eCosCentric.com>
ok, thanks.
----- Original Message -----
From: "Jonathan Larmour" <jifl@eCosCentric.com>
To: "Wade Jensen" <waj4news@cox.net>
Cc: <ecos-patches@sources.redhat.com>
Sent: Monday, December 09, 2002 7:27 PM
Subject: Re: time to ticks converter optimization in pthread_cond_timedwait
> Wade Jensen wrote:
> > Hello,
> >
> > Here is a patch that makes a simple optimization in
> > pthread_cond_timedwait. It will only initialize the time to ticks
> > converters on the first call the same way that is done many other places
> > in the code. It greatly improves the speed of the
> > pthread_cond_timedwait function.
>
> For some reason although I got your patch, and made a few tweaks myself, I
> never checked it in. I'm doing so now (attached).
>
> Jifl
> --
> eCosCentric http://www.eCosCentric.com/ <info@eCosCentric.com>
> --[ "You can complain because roses have thorns, or you ]--
> --[ can rejoice because thorns have roses." -Lincoln ]-- Opinions==mine
>
----------------------------------------------------------------------------
----
> Index: ChangeLog
> ===================================================================
> RCS file: /cvs/ecos/ecos/packages/compat/posix/current/ChangeLog,v
> retrieving revision 1.30
> diff -u -5 -p -r1.30 ChangeLog
> --- ChangeLog 26 Nov 2002 18:16:45 -0000 1.30
> +++ ChangeLog 10 Dec 2002 02:26:53 -0000
> @@ -1,5 +1,11 @@
> +2002-12-10 Wade Jensen <waj4news@cox.net>
> +2002-12-10 Jonathan Larmour <jifl@eCosCentric.com>
> +
> + * src/mutex.cxx (pthread_cond_timedwait): Initialize clock converters
> + only once ever.
> +
> 2002-11-26 Nick Garnett <nickg@ecoscentric.com>
>
> * src/signal.cxx: Changed the three routines added in the last
> change so that they can be called safely from non-POSIX threads.
>
> Index: src/mutex.cxx
> ===================================================================
> RCS file: /cvs/ecos/ecos/packages/compat/posix/current/src/mutex.cxx,v
> retrieving revision 1.3
> diff -u -5 -p -r1.3 mutex.cxx
> --- src/mutex.cxx 23 May 2002 22:59:59 -0000 1.3
> +++ src/mutex.cxx 10 Dec 2002 02:26:53 -0000
> @@ -39,11 +39,11 @@
> //####ECOSGPLCOPYRIGHTEND####
>
//==========================================================================
> //#####DESCRIPTIONBEGIN####
> //
> // Author(s): nickg
> -// Contributors: nickg, jlarmour
> +// Contributors: nickg, jlarmour, Wade Jensen
> // Date: 2000-03-27
> // Purpose: POSIX pthread implementation
> // Description: This file contains the implementation of the
POSIX pthread
> // functions.
> //
> @@ -498,16 +498,41 @@ externC int pthread_cond_timedwait (pthr
>
> PTHREAD_CHECK( cond );
> PTHREAD_CHECK( mutex );
> PTHREAD_CHECK( abstime );
>
> - cyg_tick_count ticks;
> - struct Cyg_Clock::converter ns_converter, sec_converter;
> -
> - Cyg_Clock::real_time_clock->get_other_to_clock_converter( 1,
&ns_converter );
> - Cyg_Clock::real_time_clock->get_other_to_clock_converter( 1000000000,
&sec_converter );
> + // Only initialize the converters once or they will consume a huge
> + // amount or runtime.
> +
> + static struct Cyg_Clock::converter ns_converter;
> + static struct Cyg_Clock::converter sec_converter;
> + static volatile cyg_atomic conv_init;
> + if (!conv_init)
> + {
>
> + // Try to avoid unnecessarily locking the scheduler when we are
not
> + // initializing the converters. Check the conv_init flag again
to
> + // avoid race conditions.
> +
> + struct Cyg_Clock::converter temp_ns_converter,
temp_sec_converter;
> +
> + Cyg_Clock::real_time_clock
> + ->get_other_to_clock_converter( 1, &temp_ns_converter );
> + Cyg_Clock::real_time_clock
> + ->get_other_to_clock_converter( 1000000000,
&temp_sec_converter );
> +
> + Cyg_Scheduler::lock();
> + if (!conv_init)
> + {
> + ns_converter = temp_ns_converter;
> + sec_converter = temp_sec_converter;
> + conv_init=1;
> + }
> + Cyg_Scheduler::unlock();
> + }
> +
> + cyg_tick_count ticks;
> ticks = Cyg_Clock::convert( abstime->tv_sec, &sec_converter );
> ticks += Cyg_Clock::convert( abstime->tv_nsec, &ns_converter );
>
> ((Cyg_Condition_Variable *)cond)->wait( *(Cyg_Mutex *)mutex, ticks );
>
>