eal: provide pseudo-random floating point number
[dpdk.git] / lib / eal / ppc / rte_cycles.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) IBM Corporation 2019.
3  */
4
5 #include <features.h>
6 #ifdef __GLIBC__
7 #include <sys/platform/ppc.h>
8 #elif RTE_EXEC_ENV_LINUX
9 #include <string.h>
10 #include <stdio.h>
11 #endif
12
13 #include "eal_private.h"
14
15 uint64_t
16 get_tsc_freq_arch(void)
17 {
18 #ifdef __GLIBC__
19         return __ppc_get_timebase_freq();
20 #elif RTE_EXEC_ENV_LINUX
21         static unsigned long base;
22         char buf[512];
23         ssize_t nr;
24         FILE *f;
25
26         if (base != 0)
27                 goto out;
28
29         f = fopen("/proc/cpuinfo", "rb");
30         if (f == NULL)
31                 goto out;
32
33         while (fgets(buf, sizeof(buf), f) != NULL) {
34                 char *ret = strstr(buf, "timebase");
35
36                 if (ret == NULL)
37                         continue;
38                 ret += sizeof("timebase") - 1;
39                 ret = strchr(ret, ':');
40                 if (ret == NULL)
41                         continue;
42                 base = strtoul(ret + 1, NULL, 10);
43                 break;
44         }
45         fclose(f);
46 out:
47         return (uint64_t) base;
48 #else
49         return 0;
50 #endif
51
52 }