mirror of
git://sourceware.org/git/glibc.git
synced 2025-01-18 12:16:13 +08:00
* sysdeps/unix/sysv/linux/getsysstats.c (__get_nprocs): Using
/proc is faster and sufficient. /sys is still needed for __get_nprocs_conf.
This commit is contained in:
parent
5e0923ab31
commit
0abf17decf
@ -1,3 +1,9 @@
|
|||||||
|
2007-08-01 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* sysdeps/unix/sysv/linux/getsysstats.c (__get_nprocs): Using
|
||||||
|
/proc is faster and sufficient. /sys is still needed for
|
||||||
|
__get_nprocs_conf.
|
||||||
|
|
||||||
2007-08-01 Jakub Jelinek <jakub@redhat.com>
|
2007-08-01 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
* sysdeps/unix/sysv/linux/i386/syscalls.list (fallocate): Add fallocate
|
* sysdeps/unix/sysv/linux/i386/syscalls.list (fallocate): Add fallocate
|
||||||
|
@ -68,9 +68,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static int
|
int
|
||||||
count_processors_in_proc (void)
|
__get_nprocs ()
|
||||||
{
|
{
|
||||||
|
/* XXX Here will come a test for the new system call. */
|
||||||
|
|
||||||
char buffer[8192];
|
char buffer[8192];
|
||||||
int result = 1;
|
int result = 1;
|
||||||
|
|
||||||
@ -102,62 +104,6 @@ count_processors_in_proc (void)
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
__get_nprocs ()
|
|
||||||
{
|
|
||||||
/* XXX Here will come a test for the new system call. */
|
|
||||||
|
|
||||||
/* Try to use the sysfs filesystem. It has actual information about
|
|
||||||
online processors. */
|
|
||||||
DIR *dir = __opendir ("/sys/devices/system/cpu");
|
|
||||||
if (dir != NULL)
|
|
||||||
{
|
|
||||||
int dfd = dirfd (dir);
|
|
||||||
int count = 0;
|
|
||||||
struct dirent64 *d;
|
|
||||||
|
|
||||||
while ((d = __readdir64 (dir)) != NULL)
|
|
||||||
/* NB: the sysfs has d_type support. */
|
|
||||||
if (d->d_type == DT_DIR && strncmp (d->d_name, "cpu", 3) == 0)
|
|
||||||
{
|
|
||||||
char *endp;
|
|
||||||
unsigned long int nr = strtoul (d->d_name + 3, &endp, 10);
|
|
||||||
if (nr != ULONG_MAX && endp != d->d_name + 3 && *endp == '\0')
|
|
||||||
{
|
|
||||||
/* Try reading the online file. */
|
|
||||||
char oname[_D_ALLOC_NAMLEN (d) + sizeof "/online"];
|
|
||||||
strcpy (stpcpy (oname, d->d_name), "/online");
|
|
||||||
|
|
||||||
/* We unconditionally use openat since the "online"
|
|
||||||
file became readable only after the openat system
|
|
||||||
call was introduced. */
|
|
||||||
char buf[1];
|
|
||||||
int fd = openat_not_cancel_3 (dfd, oname, O_RDONLY);
|
|
||||||
|
|
||||||
/* If we cannot read the online file we have to assume
|
|
||||||
the CPU is online. */
|
|
||||||
if (fd < 0)
|
|
||||||
++count;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (read_not_cancel (fd, buf, sizeof (buf)) < 0
|
|
||||||
|| buf[0] == '1')
|
|
||||||
++count;
|
|
||||||
|
|
||||||
close_not_cancel_no_status (fd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
__closedir (dir);
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count_processors_in_proc ();
|
|
||||||
}
|
|
||||||
weak_alias (__get_nprocs, get_nprocs)
|
weak_alias (__get_nprocs, get_nprocs)
|
||||||
|
|
||||||
|
|
||||||
@ -206,7 +152,7 @@ __get_nprocs_conf ()
|
|||||||
fclose (fp);
|
fclose (fp);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
result = count_processors_in_proc ();
|
result = __get_nprocs ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user