]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/powerpc/test-gettimebasefreq.c
6b1c812a9f906c7f2c2d18c02173f2cd42584006
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / powerpc / test-gettimebasefreq.c
1 /* Check __ppc_get_timebase_freq() for architecture changes
2 Copyright (C) 2012-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19 /* Test if __ppc_get_timebase_freq() works and is different from zero. A read
20 failure might indicate a Linux Kernel change.
21 This test also use the frequency to compute the real elapsed time. */
22
23 #include <inttypes.h>
24 #include <stdio.h>
25 #include <stdint.h>
26
27 #include <sys/platform/ppc.h>
28
29 /* Maximum value of the Time Base Register: 2^60 - 1. */
30 #define MAX_TB 0xFFFFFFFFFFFFFFF
31
32 static int
33 do_test (void)
34 {
35 uint64_t t1, t2, f, diff;
36
37 t1 = __ppc_get_timebase ();
38 printf ("t1 = %"PRIu64"\n", t1);
39
40 f = __ppc_get_timebase_freq ();
41 printf ("Time Base frequency = %"PRIu64" Hz\n", f);
42
43 if (f == 0) {
44 printf ("Fail: The time base frequency can't be zero.\n");
45 return 1;
46 }
47
48 t2 = __ppc_get_timebase ();
49 printf ("t2 = %"PRIu64"\n", t2);
50
51 if (t2 > t1) {
52 diff = t2 - t1;
53 } else {
54 diff = (MAX_TB - t2) + t1;
55 }
56
57 printf ("Elapsed time = %1.2f usecs\n", (double) diff * 1000000 / f );
58
59 return 0;
60 }
61
62 #define TEST_FUNCTION do_test ()
63 #include "../test-skeleton.c"