Fine-grained Energy and Thermal Management using Real-time Power Sensors