1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2020 Intel Corporation 4 */ 5 6 #include <asm/msr.h> 7 8 #include "librapl.h" 9 librapl_energy_uJ(void)10u64 librapl_energy_uJ(void) 11 { 12 unsigned long long power; 13 u32 units; 14 15 if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power)) 16 return 0; 17 18 units = (power & 0x1f00) >> 8; 19 20 if (rdmsrl_safe(MSR_PP1_ENERGY_STATUS, &power)) 21 return 0; 22 23 return (1000000 * power) >> units; /* convert to uJ */ 24 } 25