aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/erl_time_sup.c
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2015-07-16 11:27:00 +0200
committerLukas Larsson <[email protected]>2016-02-02 10:45:22 +0100
commit0399f5fc547ef035c4eb5e383f30b28ae73d936e (patch)
treee4179769e6a09cc6de68f5226671fb403b5ef4e2 /erts/emulator/beam/erl_time_sup.c
parentdc1e3933e633d9d7527e6df044895d12d3845e14 (diff)
downloadotp-0399f5fc547ef035c4eb5e383f30b28ae73d936e.tar.gz
otp-0399f5fc547ef035c4eb5e383f30b28ae73d936e.tar.bz2
otp-0399f5fc547ef035c4eb5e383f30b28ae73d936e.zip
erts: Refactor perf counter internal interface
perf counter is now part of the function pointer interface and also the function returns the value instead of writing to a memory buffer.
Diffstat (limited to 'erts/emulator/beam/erl_time_sup.c')
-rw-r--r--erts/emulator/beam/erl_time_sup.c66
1 files changed, 2 insertions, 64 deletions
diff --git a/erts/emulator/beam/erl_time_sup.c b/erts/emulator/beam/erl_time_sup.c
index 6509c6a805..98159fdf72 100644
--- a/erts/emulator/beam/erl_time_sup.c
+++ b/erts/emulator/beam/erl_time_sup.c
@@ -2444,72 +2444,10 @@ BIF_RETTYPE os_system_time_1(BIF_ALIST_1)
BIF_RETTYPE
os_perf_counter_0(BIF_ALIST_0)
{
- ErtsSysHrTime pcounter;
- sys_perf_counter(&pcounter);
- BIF_RET(make_time_val(BIF_P, pcounter));
+ BIF_RET(make_time_val(BIF_P, erts_sys_perf_counter()));
}
BIF_RETTYPE erts_internal_perf_counter_unit_0(BIF_ALIST_0)
{
- BIF_RET(make_time_val(BIF_P, SYS_PERF_COUNTER_UNIT));
-}
-
-/* What resolution to spin to in micro seconds */
-#define RESOLUTION 100
-/* How many iterations to spin */
-#define ITERATIONS 1
-/* How many significant figures to round to */
-#define SIGFIGS 3
-
-static ErtsSysHrTime perf_counter_unit = 0;
-
-static ErtsSysHrTime erts_calculate_perf_counter_unit(void);
-static ErtsSysHrTime erts_calculate_perf_counter_unit() {
- int i;
- ErtsSysHrTime pre, post;
- double value = 0;
- double round_factor;
-#if defined(HAVE_GETHRTIME) && defined(GETHRTIME_WITH_CLOCK_GETTIME)
- struct timespec basetime,comparetime;
-#define __GETTIME(arg) clock_gettime(CLOCK_MONOTONIC,arg)
-#define __GETUSEC(arg) (arg.tv_nsec / 1000)
-#else
- SysTimeval basetime,comparetime;
-#define __GETTIME(arg) sys_gettimeofday(arg)
-#define __GETUSEC(arg) arg.tv_usec
-#endif
-
- for (i = 0; i < ITERATIONS; i++) {
- /* Make sure usec just flipped over at current resolution */
- __GETTIME(&basetime);
- do {
- __GETTIME(&comparetime);
- } while ((__GETUSEC(basetime) / RESOLUTION) == (__GETUSEC(comparetime) / RESOLUTION));
-
- sys_perf_counter(&pre);
-
- __GETTIME(&basetime);
- do {
- __GETTIME(&comparetime);
- } while ((__GETUSEC(basetime) / RESOLUTION) == (__GETUSEC(comparetime) / RESOLUTION));
-
- sys_perf_counter(&post);
-
- value += post - pre;
- }
- /* After this value is ticks per us */
- value /= (RESOLUTION*ITERATIONS);
-
- /* We round to 3 significant figures */
- round_factor = pow(10.0, SIGFIGS - ceil(log10(value)));
- value = ((ErtsSysHrTime)(value * round_factor + 0.5)) / round_factor;
-
- /* convert to ticks per second */
- return 1000000 * value;
-}
-
-ErtsSysHrTime erts_perf_counter_unit() {
- if (perf_counter_unit == 0)
- perf_counter_unit = erts_calculate_perf_counter_unit();
- return perf_counter_unit;
+ BIF_RET(make_time_val(BIF_P, erts_sys_perf_counter_unit()));
}