public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/16996] New: get_nprocs caching breaks when 'time (NULL) == 0'
@ 2014-05-28 21:29 meadori at codesourcery dot com
2014-06-13 10:50 ` [Bug libc/16996] " cvs-commit at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: meadori at codesourcery dot com @ 2014-05-28 21:29 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=16996
Bug ID: 16996
Summary: get_nprocs caching breaks when 'time (NULL) == 0'
Product: glibc
Version: 2.21
Status: NEW
Severity: normal
Priority: P2
Component: libc
Assignee: unassigned at sourceware dot org
Reporter: meadori at codesourcery dot com
CC: drepper.fsp at gmail dot com
Currently the implementation of __get_nprocs uses a stactic variable to cache
the value of the current number of processors. The caching breaks when
'time (NULL) == 0':
$ cat nproc.c
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int main(int argc, char *argv[])
{
time_t t;
struct timeval tv = {0, 0};
printf("settimeofday({0, 0}, NULL) = %d\n", settimeofday(&tv, NULL));
t = time(NULL);
printf("Time: %d, CPUs: %d\n", (unsigned int)t, get_nprocs());
return 0;
}
$ gcc -O3 nproc.c
$ ./a.out
settimeofday({0, 0}, NULL) = -1
Time: 1401311578, CPUs: 4
$ sudo ./a.out
settimeofday({0, 0}, NULL) = 0
Time: 0, CPUs: 0
I know the circumstances of setting the time of day to (0, 0) are odd,
but it still shouldn't be so trivial to break the caching.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libc/16996] get_nprocs caching breaks when 'time (NULL) == 0'
2014-05-28 21:29 [Bug libc/16996] New: get_nprocs caching breaks when 'time (NULL) == 0' meadori at codesourcery dot com
@ 2014-06-13 10:50 ` cvs-commit at gcc dot gnu.org
2014-06-13 10:51 ` siddhesh at redhat dot com
2014-06-16 16:32 ` fweimer at redhat dot com
2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2014-06-13 10:50 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=16996
--- Comment #1 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 995a46bbfba9964e328e3947130919d8bd3cd62a (commit)
from febf6cc58c36cd5a978b8b5faedb5a932eb44c98 (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=995a46bbfba9964e328e3947130919d8bd3cd62a
commit 995a46bbfba9964e328e3947130919d8bd3cd62a
Author: Meador Inge <meadori@codesourcery.com>
Date: Fri Jun 13 14:02:04 2014 +0530
get_nprocs: Only return explictly set cache values (BZ #16996)
The implementation of __get_nprocs uses a stactic variable to cache
the value of the current number of processors. The caching breaks when
'time (NULL) == 0':
$ cat nproc.c
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int main(int argc, char *argv[])
{
time_t t;
struct timeval tv = {0, 0};
printf("settimeofday({0, 0}, NULL) = %d\n", settimeofday(&tv, NULL));
t = time(NULL);
printf("Time: %d, CPUs: %d\n", (unsigned int)t, get_nprocs());
return 0;
}
$ gcc -O3 nproc.c
$ ./a.out
settimeofday({0, 0}, NULL) = -1
Time: 1401311578, CPUs: 4
$ sudo ./a.out
settimeofday({0, 0}, NULL) = 0
Time: 0, CPUs: 0
The problem is with the condition used to check whether a cached
value should be returned or not:
static int cached_result;
static time_t timestamp;
time_t now = time (NULL);
time_t prev = timestamp;
atomic_read_barrier ();
if (now == prev)
return cached_result;
This patch fixes the problem by ensuring that 'cached_result' has
been set at least once before returning it.
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 6 ++++++
NEWS | 2 +-
sysdeps/unix/sysv/linux/getsysstats.c | 4 ++--
3 files changed, 9 insertions(+), 3 deletions(-)
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libc/16996] get_nprocs caching breaks when 'time (NULL) == 0'
2014-05-28 21:29 [Bug libc/16996] New: get_nprocs caching breaks when 'time (NULL) == 0' meadori at codesourcery dot com
2014-06-13 10:50 ` [Bug libc/16996] " cvs-commit at gcc dot gnu.org
@ 2014-06-13 10:51 ` siddhesh at redhat dot com
2014-06-16 16:32 ` fweimer at redhat dot com
2 siblings, 0 replies; 4+ messages in thread
From: siddhesh at redhat dot com @ 2014-06-13 10:51 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=16996
Siddhesh Poyarekar <siddhesh at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |siddhesh at redhat dot com
Resolution|--- |FIXED
--- Comment #2 from Siddhesh Poyarekar <siddhesh at redhat dot com> ---
Fixed in master.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libc/16996] get_nprocs caching breaks when 'time (NULL) == 0'
2014-05-28 21:29 [Bug libc/16996] New: get_nprocs caching breaks when 'time (NULL) == 0' meadori at codesourcery dot com
2014-06-13 10:50 ` [Bug libc/16996] " cvs-commit at gcc dot gnu.org
2014-06-13 10:51 ` siddhesh at redhat dot com
@ 2014-06-16 16:32 ` fweimer at redhat dot com
2 siblings, 0 replies; 4+ messages in thread
From: fweimer at redhat dot com @ 2014-06-16 16:32 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=16996
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] 4+ messages in thread
end of thread, other threads:[~2014-06-16 16:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-28 21:29 [Bug libc/16996] New: get_nprocs caching breaks when 'time (NULL) == 0' meadori at codesourcery dot com
2014-06-13 10:50 ` [Bug libc/16996] " cvs-commit at gcc dot gnu.org
2014-06-13 10:51 ` siddhesh at redhat dot com
2014-06-16 16:32 ` fweimer at redhat dot com
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).