uint64_t geopm_crc32_str(uint64_t begin, const char *key) { uint64_t result = begin; const uint64_t *ptr = (const uint64_t *)key; size_t num_word = strlen(key) / 8; for (size_t i = 0; i < num_word; ++i) { result = geopm_crc32_u64(result, ptr[i]); } size_t extra = strlen(key) - 8 * num_word; if (extra) { uint64_t last_word = 0; for (size_t i = 0; i < extra; ++i) { ((char *)(&last_word))[i] = ((char *)(ptr + num_word))[i]; } result = geopm_crc32_u64(result, last_word); } return result; }
size_t ProfileTable::hash(uint64_t key) const { size_t result = 0; if (geopm_region_id_is_mpi(key)) { result = m_mask + 1; } else if (geopm_region_id_is_epoch(key)) { result = m_mask + 2; } else { result = geopm_crc32_u64(0, key) & m_mask; } return result; }
int main(int argc, char **argv) { int err = 0; char error_msg[512]; if (argc == 2 && strncmp(argv[1], "crc32", strlen("crc32") + 1) == 0) { uint64_t result = geopm_crc32_u64(0xDEADBEEF, 0xBADFEE); if (result == 0xA347ADE3 ) { std::cout << "Platform supports crc32 intrinsic." << std::endl; } else { err = GEOPM_ERROR_PLATFORM_UNSUPPORTED; std::cerr << "Warning: <geopm_platform_supported>: Platform does not support crc32 intrinsic." << std::endl; } } else { int cpu_id = geopm_read_cpuid(); if (cpu_id != 0x63F && cpu_id != 0x63F && cpu_id != 0x63E && cpu_id != 0x62D && cpu_id != 0x64F && cpu_id != 0x657) { err = GEOPM_ERROR_PLATFORM_UNSUPPORTED; geopm_error_message(err, error_msg, 512); std::cerr << "Warning: <geopm_platform_supported>: Platform 0x" << std::hex << cpu_id << " is not a supported CPU" << " " << error_msg << "." << std::endl; } if (!err) { int fd = open("/dev/cpu/0/msr_safe", O_RDONLY); if (fd == -1) { err = GEOPM_ERROR_MSR_OPEN; geopm_error_message(err, error_msg, 512); std::cerr << "Warning: <geopm_platform_supported>: Not able to open msr_safe device. " << error_msg << "." << std::endl; } else { close(fd); } } if (!err) { std::cout << "Platform 0x" << std::hex << cpu_id << " is supported by geopm and msr_safe is available." << std::endl; } } return err; }