1 /* Get frequency of the system processor. i386/Linux version.
2 Copyright (C) 2000-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
23 #include <libc-internal.h>
27 __get_clockfreq (void)
29 /* We read the information from the /proc filesystem. It contains at
34 We search for this line and convert the number in an integer. */
35 static hp_timing_t result
;
38 /* If this function was called before, we know the result. */
42 fd
= __open ("/proc/cpuinfo", O_RDONLY
);
43 if (__glibc_likely (fd
!= -1))
45 /* XXX AFAIK the /proc filesystem can generate "files" only up
46 to a size of 4096 bytes. */
50 n
= __read (fd
, buf
, sizeof buf
);
51 if (__builtin_expect (n
, 1) > 0)
53 char *mhz
= memmem (buf
, n
, "cpu MHz", 7);
55 if (__glibc_likely (mhz
!= NULL
))
58 int seen_decpoint
= 0;
61 /* Search for the beginning of the string. */
62 while (mhz
< endp
&& (*mhz
< '0' || *mhz
> '9') && *mhz
!= '\n')
65 while (mhz
< endp
&& *mhz
!= '\n')
67 if (*mhz
>= '0' && *mhz
<= '9')
80 /* Compensate for missing digits at the end. */