int clocks_storage(uint64_t *** aperf_val, uint64_t *** mperf_val, uint64_t *** tsc_val) { static int init = 1; static uint64_t ** aperf = NULL, ** mperf = NULL, ** tsc = NULL; static uint64_t totalThreads = 0; if (init) { totalThreads = num_devs(); aperf = (uint64_t **) libmsr_malloc(totalThreads * sizeof(uint64_t *)); mperf = (uint64_t **) libmsr_malloc(totalThreads * sizeof(uint64_t *)); tsc = (uint64_t **) libmsr_malloc(totalThreads * sizeof(uint64_t *)); allocate_batch(CLOCKS_DATA, 3UL * num_devs()); load_thread_batch(MSR_IA32_APERF, aperf, CLOCKS_DATA); load_thread_batch(MSR_IA32_MPERF, mperf, CLOCKS_DATA); load_thread_batch(IA32_TIME_STAMP_COUNTER, tsc, CLOCKS_DATA); init = 0; } if (aperf_val) { *aperf_val = aperf; } if (mperf_val) { *mperf_val = mperf; } if (tsc_val) { *tsc_val = tsc; } return 0; }
int rapl_storage(struct rapl_data **data, uint64_t **flags) { static struct rapl_data *rapl = NULL; static uint64_t *rapl_flags = NULL; static uint64_t sockets = 0; static int init = 0; #ifdef STORAGE_DEBUG fprintf(stderr, "%s %s::%d DEBUG: (rapl_storage) data pointer is %p, flags pointer is %p, data is at %p, flags are %lx at %p\n", getenv("HOSTNAME"), __FILE__, __LINE__, data, flags, rapl, (rapl_flags ? *rapl_flags : 0), rapl_flags); #endif if (!init) { init = 1; sockets = num_sockets(); rapl = (struct rapl_data *) libmsr_malloc(sockets * sizeof(struct rapl_data)); rapl_flags = (uint64_t *) libmsr_malloc(sizeof(uint64_t)); if (setflags(rapl_flags)) { return -1; } if (data != NULL) { *data = rapl; } if (flags != NULL) { *flags = rapl_flags; } #ifdef LIBMSR_DEBUG fprintf(stderr, "%s %s::%d DEBUG: (storage) initialized rapl data at %p, flags are %lx, (flags at %p, rapl_flags at %p\n", getenv("HOSTNAME"), __FILE__, __LINE__, rapl, **flags, flags, rapl_flags); fprintf(stderr, "DEBUG: socket 0 has pkg_bits at %p\n", &rapl[0].pkg_bits); #endif return 0; } /* If the data pointer is not null, it should point to the rapl array. */ if (data != NULL) { *data = rapl; } /* if the flags pointer is not null, it should point to the rapl flags. */ if (flags != NULL) { *flags = rapl_flags; } return 0; }
/// @brief Retrieve file descriptor per logical processor. /// /// @param [in] dev_idx Unique logical processor identifier. /// /// @return Unique file descriptor, else NULL. static int *core_fd(const int dev_idx) { static int init = 0; static int *file_descriptors = NULL; static uint64_t devices = 0; if (!init) { init = 1; uint64_t numDevs = num_devs();; devices = numDevs; file_descriptors = (int *) libmsr_malloc(devices * sizeof(int)); } if (dev_idx < devices) { return &(file_descriptors[dev_idx]); } libmsr_error_handler("core_fd(): Array reference out of bounds", LIBMSR_ERROR_ARRAY_BOUNDS, getenv("HOSTNAME"), __FILE__, __LINE__); return NULL; }