From dfed5e982329076d918354de7742eff0eefb7acb Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 19 Aug 2022 22:22:26 -0700 Subject: [PATCH 1/4] bugfix: fix Intel DRAM overflow issue Need to check if difference in DRAM bits is negative, not the joule value --- src/variorum/Intel/intel_power_features.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/variorum/Intel/intel_power_features.c b/src/variorum/Intel/intel_power_features.c index 4620d98d2..994309f4a 100644 --- a/src/variorum/Intel/intel_power_features.c +++ b/src/variorum/Intel/intel_power_features.c @@ -1052,18 +1052,33 @@ int delta_rapl_data(off_t msr_rapl_unit) /* This case should not happen. */ if (rapl->pkg_delta_joules[i] < 0) { - variorum_error_handler("Energy used since last same is negative", + variorum_error_handler("PKG energy used since last same is negative", VARIORUM_ERROR_INVAL, getenv("HOSTNAME"), __FILE__, __FUNCTION__, __LINE__); } - if (rapl->dram_joules[i] - rapl->old_dram_joules[i] < 0) + + /* Check to see if there was wraparound and use corresponding translation. */ + if ((double)*rapl->dram_bits[i] - (double)rapl->dram_pkg_bits[i] < 0) { - rapl->dram_delta_joules[i] = (rapl->dram_joules[i] + max_joules) - - rapl->old_dram_joules[i]; + rapl->dram_delta_bits[i] = (uint64_t)((*rapl->dram_bits[i] + + (uint64_t)max_joules) - rapl->old_dram_bits[i]); + translate(i, &rapl->dram_delta_bits[i], &rapl->dram_delta_joules[i], + BITS_TO_JOULES, msr_rapl_unit); +#ifdef VARIORUM_DEBUG + fprintf(stderr, "OVF dram%d new=0x%lx old=0x%lx -> %lf\n", i, *rapl->dram_bits[i], + rapl->old_dram_bits[i], rapl->dram_delta_joules[i]); +#endif } else { rapl->dram_delta_joules[i] = rapl->dram_joules[i] - rapl->old_dram_joules[i]; } + /* This case should not happen. */ + if (rapl->dram_delta_joules[i] < 0) + { + variorum_error_handler("DRAM energy used since last same is negative", + VARIORUM_ERROR_INVAL, getenv("HOSTNAME"), __FILE__, __FUNCTION__, __LINE__); + } + /* Get watts. */ if (rapl->elapsed > 0.0L) { From c582ac20878d5d072193d569b8c6e16b450f90c5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 25 Aug 2022 11:43:27 -0700 Subject: [PATCH 2/4] fixes --- src/variorum/Intel/intel_power_features.c | 7 ++++--- src/variorum/Intel/intel_power_features.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/variorum/Intel/intel_power_features.c b/src/variorum/Intel/intel_power_features.c index 994309f4a..6b9efafe8 100644 --- a/src/variorum/Intel/intel_power_features.c +++ b/src/variorum/Intel/intel_power_features.c @@ -324,15 +324,16 @@ static void create_rapl_data_batch(struct rapl_data *rapl, rapl->old_pkg_bits = (uint64_t *) calloc(nsockets, sizeof(uint64_t)); rapl->old_pkg_joules = (double *) calloc(nsockets, sizeof(double)); rapl->pkg_delta_joules = (double *) calloc(nsockets, sizeof(double)); - rapl->pkg_delta_bits = (uint64_t *) calloc(nsockets, sizeof(double)); + rapl->pkg_delta_bits = (uint64_t *) calloc(nsockets, sizeof(uint64_t)); rapl->pkg_watts = (double *) calloc(nsockets, sizeof(double)); load_socket_batch(msr_pkg_energy_status, rapl->pkg_bits, RAPL_DATA); rapl->dram_bits = (uint64_t **) calloc(nsockets, sizeof(uint64_t *)); - rapl->old_dram_bits = (uint64_t *) calloc(nsockets, sizeof(uint64_t)); rapl->dram_joules = (double *) calloc(nsockets, sizeof(double)); + rapl->old_dram_bits = (uint64_t *) calloc(nsockets, sizeof(uint64_t)); rapl->old_dram_joules = (double *) calloc(nsockets, sizeof(double)); rapl->dram_delta_joules = (double *) calloc(nsockets, sizeof(double)); + rapl->dram_delta_bits = (uint64_t *) calloc(nsockets, sizeof(uint64_t)); rapl->dram_watts = (double *) calloc(nsockets, sizeof(double)); load_socket_batch(msr_dram_energy_status, rapl->dram_bits, RAPL_DATA); @@ -1057,7 +1058,7 @@ int delta_rapl_data(off_t msr_rapl_unit) } /* Check to see if there was wraparound and use corresponding translation. */ - if ((double)*rapl->dram_bits[i] - (double)rapl->dram_pkg_bits[i] < 0) + if ((double)*rapl->dram_bits[i] - (double)rapl->old_dram_bits[i] < 0) { rapl->dram_delta_bits[i] = (uint64_t)((*rapl->dram_bits[i] + (uint64_t)max_joules) - rapl->old_dram_bits[i]); diff --git a/src/variorum/Intel/intel_power_features.h b/src/variorum/Intel/intel_power_features.h index d0878d9e2..399b6dcbc 100644 --- a/src/variorum/Intel/intel_power_features.h +++ b/src/variorum/Intel/intel_power_features.h @@ -159,6 +159,7 @@ struct rapl_data double *old_dram_joules; /// @brief Difference in DRAM energy usage between two data measurements. double *dram_delta_joules; + uint64_t *dram_delta_bits; /// @brief DRAM power consumption (in Watts) derived by dividing difference /// in DRAM energy usage by time elapsed between data measurements. double *dram_watts; From a09a8038c76d3173e0f0fd90f820770f2683fb4d Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Thu, 11 May 2023 15:28:00 -0700 Subject: [PATCH 3/4] fix formatting --- src/variorum/Intel/intel_power_features.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/variorum/Intel/intel_power_features.c b/src/variorum/Intel/intel_power_features.c index 6b9efafe8..b839e3532 100644 --- a/src/variorum/Intel/intel_power_features.c +++ b/src/variorum/Intel/intel_power_features.c @@ -1061,12 +1061,13 @@ int delta_rapl_data(off_t msr_rapl_unit) if ((double)*rapl->dram_bits[i] - (double)rapl->old_dram_bits[i] < 0) { rapl->dram_delta_bits[i] = (uint64_t)((*rapl->dram_bits[i] + - (uint64_t)max_joules) - rapl->old_dram_bits[i]); + (uint64_t)max_joules) - rapl->old_dram_bits[i]); translate(i, &rapl->dram_delta_bits[i], &rapl->dram_delta_joules[i], BITS_TO_JOULES, msr_rapl_unit); #ifdef VARIORUM_DEBUG - fprintf(stderr, "OVF dram%d new=0x%lx old=0x%lx -> %lf\n", i, *rapl->dram_bits[i], - rapl->old_dram_bits[i], rapl->dram_delta_joules[i]); + fprintf(stderr, "OVF dram%d new=0x%lx old=0x%lx -> %lf\n", i, + *rapl->dram_bits[i], rapl->old_dram_bits[i], + rapl->dram_delta_joules[i]); #endif } else From fa414ac6fae2dda5c50cd70882bbc558c9958dde Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Mon, 11 Mar 2024 22:30:23 -0700 Subject: [PATCH 4/4] fix missing parameter to translate --- src/variorum/Intel/intel_power_features.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/variorum/Intel/intel_power_features.c b/src/variorum/Intel/intel_power_features.c index b839e3532..492e195d1 100644 --- a/src/variorum/Intel/intel_power_features.c +++ b/src/variorum/Intel/intel_power_features.c @@ -1062,8 +1062,10 @@ int delta_rapl_data(off_t msr_rapl_unit) { rapl->dram_delta_bits[i] = (uint64_t)((*rapl->dram_bits[i] + (uint64_t)max_joules) - rapl->old_dram_bits[i]); +#ifdef VARIORUM_WITH_INTEL_CPU translate(i, &rapl->dram_delta_bits[i], &rapl->dram_delta_joules[i], - BITS_TO_JOULES, msr_rapl_unit); + BITS_TO_JOULES, msr_rapl_unit, P_INTEL_CPU_IDX); +#endif #ifdef VARIORUM_DEBUG fprintf(stderr, "OVF dram%d new=0x%lx old=0x%lx -> %lf\n", i, *rapl->dram_bits[i], rapl->old_dram_bits[i],