public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/16145] New: localtime_r etc holds lock via __tz_convert
@ 2013-11-08 19:10 ben.maurer at gmail dot com
  2013-11-20 23:53 ` [Bug libc/16145] " camille at bountysource dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: ben.maurer at gmail dot com @ 2013-11-08 19:10 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=16145

            Bug ID: 16145
           Summary: localtime_r etc holds lock via __tz_convert
           Product: glibc
           Version: 2.18
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: ben.maurer at gmail dot com
                CC: drepper.fsp at gmail dot com

__tz_convert contains a lock tzset_lock. When doing profiling of a real world
application, I noticed that ~5% of our context switches came from this lock.

There should be a more efficient way to represent this lock -- for example, if
the timezone can be represented as a 32 bit integer, an atomic compare-and-swap
could be used to change it. Alternatively a sequence lock approach could be
used.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libc/16145] localtime_r etc holds lock via __tz_convert
  2013-11-08 19:10 [Bug libc/16145] New: localtime_r etc holds lock via __tz_convert ben.maurer at gmail dot com
@ 2013-11-20 23:53 ` camille at bountysource dot com
  2014-01-26  7:11 ` liubin123 at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: camille at bountysource dot com @ 2013-11-20 23:53 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16145

camille at bountysource dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |camille at bountysource dot com

--- Comment #2 from camille at bountysource dot com ---
Facebook posted a $100 bounty on this issue via Bountysource:
https://www.bountysource.com/issues/1326487

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libc/16145] localtime_r etc holds lock via __tz_convert
  2013-11-08 19:10 [Bug libc/16145] New: localtime_r etc holds lock via __tz_convert ben.maurer at gmail dot com
  2013-11-20 23:53 ` [Bug libc/16145] " camille at bountysource dot com
@ 2014-01-26  7:11 ` liubin123 at gmail dot com
  2014-06-13 12:20 ` fweimer at redhat dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: liubin123 at gmail dot com @ 2014-01-26  7:11 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16145

liubin <liubin123 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |liubin123 at gmail dot com

--- Comment #3 from liubin <liubin123 at gmail dot com> ---
Unfortunately,I also met this problem,there is two foolish way to avoid
__tz_convert

1. Don't call localtime_r between many concurrent threads,only call it update a
Global Variable in main loop if you can.
2. Transform time_t to localtime through calculate ,may be more slower

eg:

time_t now;
struct tm result;
time(&now)
localtime_safe(timep, 8, &result);

void localtime_safe(time_t time, long timezone, struct tm *tm_time)
{
    const char Days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    uint32_t n32_Pass4year;
    uint32_t n32_hpery;

    time=time + (timezone * 60 * 60);

    if(time < 0)
    {
        time = 0;
    }
    tm_time->tm_sec=(int)(time % 60);
    time /= 60;
    tm_time->tm_min=(int)(time % 60);
    time /= 60;
    n32_Pass4year=((unsigned int)time / (1461L * 24L));
    tm_time->tm_year=(n32_Pass4year << 2)+70;
    time %= 1461L * 24L;
    for (;;)
    {
        n32_hpery = 365 * 24;
        if ((tm_time->tm_year & 3) == 0)
        {
            n32_hpery += 24;
        }
        if (time < n32_hpery)
        {
            break;
        }
        tm_time->tm_year++;
        time -= n32_hpery;
    }
    tm_time->tm_hour=(int)(time % 24);
    time /= 24;
    time++;
    if ((tm_time->tm_year & 3) == 0)
    {
        if (time > 60)
        {
            time--;
        }
        else
        {
            if (time == 60)
            {
                tm_time->tm_mon = 1;
                tm_time->tm_mday = 29;
                return ;
            }
        }
    }
    for (tm_time->tm_mon = 0; Days[tm_time->tm_mon] < time;tm_time->tm_mon++)
    {
        time -= Days[tm_time->tm_mon];
    }

    tm_time->tm_mday = (int)(time);
    return;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libc/16145] localtime_r etc holds lock via __tz_convert
  2013-11-08 19:10 [Bug libc/16145] New: localtime_r etc holds lock via __tz_convert ben.maurer at gmail dot com
  2013-11-20 23:53 ` [Bug libc/16145] " camille at bountysource dot com
  2014-01-26  7:11 ` liubin123 at gmail dot com
@ 2014-06-13 12:20 ` fweimer at redhat dot com
  2015-02-25  5:00 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: fweimer at redhat dot com @ 2014-06-13 12:20 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16145

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libc/16145] localtime_r etc holds lock via __tz_convert
  2013-11-08 19:10 [Bug libc/16145] New: localtime_r etc holds lock via __tz_convert ben.maurer at gmail dot com
                   ` (2 preceding siblings ...)
  2014-06-13 12:20 ` fweimer at redhat dot com
@ 2015-02-25  5:00 ` cvs-commit at gcc dot gnu.org
  2015-08-27 22:18 ` [Bug time/16145] " jsm28 at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2015-02-25  5:00 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16145

--- Comment #4 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  6807b1db8233ed84671f061b5d825622233df303 (commit)
      from  b433df00ae7b72053b2aac5bea1ded269ea92589 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6807b1db8233ed84671f061b5d825622233df303

commit 6807b1db8233ed84671f061b5d825622233df303
Author: Kevin Easton <kevin@guarana.org>
Date:   Tue Feb 24 23:57:07 2015 -0500

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

    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).

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog    |    6 ++++++
 time/tzset.c |    4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug time/16145] localtime_r etc holds lock via __tz_convert
  2013-11-08 19:10 [Bug libc/16145] New: localtime_r etc holds lock via __tz_convert ben.maurer at gmail dot com
                   ` (3 preceding siblings ...)
  2015-02-25  5:00 ` cvs-commit at gcc dot gnu.org
@ 2015-08-27 22:18 ` jsm28 at gcc dot gnu.org
  2020-06-09 11:41 ` fweimer at redhat dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2015-08-27 22:18 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16145

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libc                        |time

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug time/16145] localtime_r etc holds lock via __tz_convert
  2013-11-08 19:10 [Bug libc/16145] New: localtime_r etc holds lock via __tz_convert ben.maurer at gmail dot com
                   ` (4 preceding siblings ...)
  2015-08-27 22:18 ` [Bug time/16145] " jsm28 at gcc dot gnu.org
@ 2020-06-09 11:41 ` fweimer at redhat dot com
  2020-08-26 19:12 ` crrodriguez at opensuse dot org
  2022-01-26  6:45 ` sam at gentoo dot org
  7 siblings, 0 replies; 9+ messages in thread
From: fweimer at redhat dot com @ 2020-06-09 11:41 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16145

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://sourceware.org/bugz
                   |                            |illa/show_bug.cgi?id=26097

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug time/16145] localtime_r etc holds lock via __tz_convert
  2013-11-08 19:10 [Bug libc/16145] New: localtime_r etc holds lock via __tz_convert ben.maurer at gmail dot com
                   ` (5 preceding siblings ...)
  2020-06-09 11:41 ` fweimer at redhat dot com
@ 2020-08-26 19:12 ` crrodriguez at opensuse dot org
  2022-01-26  6:45 ` sam at gentoo dot org
  7 siblings, 0 replies; 9+ messages in thread
From: crrodriguez at opensuse dot org @ 2020-08-26 19:12 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16145

Cristian Rodríguez <crrodriguez at opensuse dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |crrodriguez at opensuse dot org

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug time/16145] localtime_r etc holds lock via __tz_convert
  2013-11-08 19:10 [Bug libc/16145] New: localtime_r etc holds lock via __tz_convert ben.maurer at gmail dot com
                   ` (6 preceding siblings ...)
  2020-08-26 19:12 ` crrodriguez at opensuse dot org
@ 2022-01-26  6:45 ` sam at gentoo dot org
  7 siblings, 0 replies; 9+ messages in thread
From: sam at gentoo dot org @ 2022-01-26  6:45 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16145

Sam James <sam at gentoo dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sam at gentoo dot org

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-01-26  6:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-08 19:10 [Bug libc/16145] New: localtime_r etc holds lock via __tz_convert ben.maurer at gmail dot com
2013-11-20 23:53 ` [Bug libc/16145] " camille at bountysource dot com
2014-01-26  7:11 ` liubin123 at gmail dot com
2014-06-13 12:20 ` fweimer at redhat dot com
2015-02-25  5:00 ` cvs-commit at gcc dot gnu.org
2015-08-27 22:18 ` [Bug time/16145] " jsm28 at gcc dot gnu.org
2020-06-09 11:41 ` fweimer at redhat dot com
2020-08-26 19:12 ` crrodriguez at opensuse dot org
2022-01-26  6:45 ` sam at gentoo dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).