aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam
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
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')
-rw-r--r--erts/emulator/beam/beam_emu.c4
-rw-r--r--erts/emulator/beam/erl_msacc.c14
-rw-r--r--erts/emulator/beam/erl_msacc.h8
-rw-r--r--erts/emulator/beam/erl_time.h2
-rw-r--r--erts/emulator/beam/erl_time_sup.c66
5 files changed, 16 insertions, 78 deletions
diff --git a/erts/emulator/beam/beam_emu.c b/erts/emulator/beam/beam_emu.c
index 4be311ae82..9f143c22bf 100644
--- a/erts/emulator/beam/beam_emu.c
+++ b/erts/emulator/beam/beam_emu.c
@@ -4938,10 +4938,10 @@ do { \
it has to be very very fast */
OpCase(i_perf_counter): {
BeamInstr* next;
- ErtsSysHrTime ts;
+ ErtsSysPerfCounter ts;
PreFetch(0, next);
- sys_perf_counter(&ts);
+ ts = erts_sys_perf_counter();
if (IS_SSMALL(ts)) {
r(0) = make_small((Sint)ts);
diff --git a/erts/emulator/beam/erl_msacc.c b/erts/emulator/beam/erl_msacc.c
index bf1c06dea7..71e3fd8b6e 100644
--- a/erts/emulator/beam/erl_msacc.c
+++ b/erts/emulator/beam/erl_msacc.c
@@ -117,7 +117,7 @@ void erts_msacc_init_thread(char *type, int id, int managed) {
#ifdef ERTS_MSACC_ALWAYS_ON
ERTS_MSACC_TSD_SET(msacc);
- sys_perf_counter(&msacc->perf_counter);
+ msacc->perf_counter = erts_sys_perf_counter();
msacc->state = ERTS_MSACC_STATE_OTHER;
#endif
}
@@ -278,7 +278,7 @@ reply_msacc(void *vmsaccrp)
if (msaccrp->action == ERTS_MSACC_ENABLE && !msacc) {
msacc = get_msacc();
- sys_perf_counter(&msacc->perf_counter);
+ msacc->perf_counter = erts_sys_perf_counter();
msacc->state = ERTS_MSACC_STATE_OTHER;
@@ -412,9 +412,9 @@ erts_msacc_request(Process *c_p, int action, Eterm *threads)
for (i = 0; i < unmanaged_count; i++) {
erts_mtx_lock(&unmanaged[i]->mtx);
if (unmanaged[i]->perf_counter) {
- ErtsSysHrTime perf_counter;
+ ErtsSysPerfCounter perf_counter;
/* if enabled update stats */
- sys_perf_counter(&perf_counter);
+ perf_counter = erts_sys_perf_counter();
unmanaged[i]->perf_counters[unmanaged[i]->state] +=
perf_counter - unmanaged[i]->perf_counter;
unmanaged[i]->perf_counter = perf_counter;
@@ -439,7 +439,7 @@ erts_msacc_request(Process *c_p, int action, Eterm *threads)
erts_rwmtx_rlock(&msacc_mutex);
for (msacc = msacc_unmanaged; msacc != NULL; msacc = msacc->next) {
erts_mtx_lock(&msacc->mtx);
- sys_perf_counter(&msacc->perf_counter);
+ msacc->perf_counter = erts_sys_perf_counter();
/* we assume the unmanaged thread is sleeping */
msacc->state = ERTS_MSACC_STATE_SLEEP;
erts_mtx_unlock(&msacc->mtx);
@@ -448,12 +448,12 @@ erts_msacc_request(Process *c_p, int action, Eterm *threads)
break;
}
case ERTS_MSACC_DISABLE: {
- ErtsSysHrTime perf_counter;
+ ErtsSysPerfCounter perf_counter;
erts_rwmtx_rlock(&msacc_mutex);
/* make sure to update stats with latest results */
for (msacc = msacc_unmanaged; msacc != NULL; msacc = msacc->next) {
erts_mtx_lock(&msacc->mtx);
- sys_perf_counter(&perf_counter);
+ perf_counter = erts_sys_perf_counter();
msacc->perf_counters[msacc->state] += perf_counter - msacc->perf_counter;
msacc->perf_counter = 0;
erts_mtx_unlock(&msacc->mtx);
diff --git a/erts/emulator/beam/erl_msacc.h b/erts/emulator/beam/erl_msacc.h
index 1b4b7a408a..284388f7aa 100644
--- a/erts/emulator/beam/erl_msacc.h
+++ b/erts/emulator/beam/erl_msacc.h
@@ -121,8 +121,8 @@ typedef struct erl_msacc_t_ ErtsMsAcc;
struct erl_msacc_t_ {
/* the the values below are protected by mtx iff unmanaged = 1 */
- ErtsSysHrTime perf_counter;
- ErtsSysHrTime perf_counters[ERTS_MSACC_STATE_COUNT];
+ ErtsSysPerfCounter perf_counter;
+ ErtsSysPerfCounter perf_counters[ERTS_MSACC_STATE_COUNT];
#ifdef ERTS_MSACC_STATE_COUNTERS
Uint64 state_counters[ERTS_MSACC_STATE_COUNT];
#endif
@@ -324,14 +324,14 @@ void erts_msacc_set_state_um__(ErtsMsAcc *msacc, Uint new_state, int increment)
ERTS_MSACC_INLINE
void erts_msacc_set_state_m__(ErtsMsAcc *msacc, Uint new_state, int increment) {
- ErtsSysHrTime prev_perf_counter;
+ ErtsSysPerfCounter prev_perf_counter;
Sint64 diff;
if (new_state == msacc->state)
return;
prev_perf_counter = msacc->perf_counter;
- sys_perf_counter(&msacc->perf_counter);
+ msacc->perf_counter = erts_sys_perf_counter();
diff = msacc->perf_counter - prev_perf_counter;
ASSERT(diff >= 0);
msacc->perf_counters[msacc->state] += diff;
diff --git a/erts/emulator/beam/erl_time.h b/erts/emulator/beam/erl_time.h
index 446adcf4af..5242063550 100644
--- a/erts/emulator/beam/erl_time.h
+++ b/erts/emulator/beam/erl_time.h
@@ -142,7 +142,7 @@ erts_time_unit_conversion(Uint64 value,
Uint32 from_time_unit,
Uint32 to_time_unit);
-ErtsSysHrTime erts_perf_counter_unit(void);
+ErtsSysPerfCounter erts_perf_counter_unit(void);
#if ERTS_GLB_INLINE_INCL_FUNC_DEF
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()));
}