1 /* Check __ppc_get_timebase_freq() for architecture changes
2 Copyright (C) 2012-2023 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 <https://www.gnu.org/licenses/>. */
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. */
27 #include <sys/platform/ppc.h>
29 /* Maximum value of the Time Base Register: 2^60 - 1. */
30 #define MAX_TB 0xFFFFFFFFFFFFFFF
35 uint64_t t1
, t2
, f
, diff
;
37 t1
= __ppc_get_timebase ();
38 printf ("t1 = %"PRIu64
"\n", t1
);
40 f
= __ppc_get_timebase_freq ();
41 printf ("Time Base frequency = %"PRIu64
" Hz\n", f
);
44 printf ("Fail: The time base frequency can't be zero.\n");
48 t2
= __ppc_get_timebase ();
49 printf ("t2 = %"PRIu64
"\n", t2
);
54 diff
= (MAX_TB
- t2
) + t1
;
57 printf ("Elapsed time = %1.2f usecs\n", (double) diff
* 1000000 / f
);
62 #define TEST_FUNCTION do_test ()
63 #include "../test-skeleton.c"