[PATCH][BZ #16145] Reduce lock contention in __tz_convert()

Mike Frysinger vapier@gentoo.org
Tue Feb 24 05:02:00 GMT 2015


On 12 Feb 2015 00:37, Kevin Easton wrote:
> This patch is an "easy win" partial fix for BZ #16145, which notes
> the heavy contention on tzset_lock when multiple threads are converting
> times with localtime_r().
> 
> In __tz_convert(), the lock does not need to be held after
> __tzfile_compute() / __tz_compute() have been called, so we can move the
> unlock up.  At this point there is still significant work to be done in
> __offtime(), so we see some improvement (in my testing with 8 cores
> banging on localtime_r(), ~20% improvement in throughput).

my reading of __offtime is that it only operates on its arguments (or const 
global data like __mon_yday).  it also looks expensive, so maybe we should 
hoist the remaining call outside of holding the lock ?  can you see if that'd 
have any measurable improvement ?

  ...
  int offtime = 0;
  if (!__use_tzfile)
    offtime = __offtime (...);

  __libc_lock_lock (tzset_lock);
  ...
  if (__use_tzfile)
    __tzfile_compute (*timer, use_localtime, &leap_correction,
                      &leap_extra_secs, tp);
  else
    { 
      if (!offtime)  // modified this one line.
        tp = NULL;
      else
        __tz_compute (*timer, tp, use_localtime);
      leap_correction = 0L;
      leap_extra_secs = 0;
    }

  __libc_lock_unlock (tzset_lock);

at any rate, this patch as-is lgtm
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20150224/f007ab38/attachment.sig>


More information about the Libc-alpha mailing list