energy efficient programming - uni-hamburg.de...motivation hardwarelayer oslayer applicationlayer...
Post on 11-Feb-2020
8 Views
Preview:
TRANSCRIPT
Motivation Hardware layer OS layer Application layer Conclusion Literature
Energy Efficient Programming
Merlin Steuer
Seminar Effiziente ProgrammierungArbeitsbereich Wissenschaftliches Rechnen
Fachbereich InformatikFakultät für Mathematik, Informatik und Naturwissenschaften
Universität Hamburg
24.11.2016
Merlin Steuer Energy Efficient Programming 1 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Outline
1 Motivation
2 Energy saving at hardware layer
3 Energy saving at OS layer
4 Energy saving at application layer
5 Conclusion
6 Literature
Merlin Steuer Energy Efficient Programming 2 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Motivation
Merlin Steuer Energy Efficient Programming 3 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Motivation
Power Consumption IS a deal nowadaysDKRZ: ∼ 1,2 MW⇒∼ 10,5 GWh/yr1!∼ 2800 households (3 persons)2
1[1]2[2]
Merlin Steuer Energy Efficient Programming 4 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
More power...
Top500 No. 2: National Super Computer Center in Guangzhou∼ 18 MW 3
∼ 160 GWh/yr∼ 41000 households 4
10x Reinfeld (Holst.)! 5
3[1]4[2]5[3], [4]
Merlin Steuer Energy Efficient Programming 5 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Hardware layer
Merlin Steuer Energy Efficient Programming 6 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Overview
Overview
DVFS - Dynamic voltage and frequency scalingACPI - Advanced Configuration and Power Interface
Merlin Steuer Energy Efficient Programming 7 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
DVFS
DVFS
Dynamic Frequency and Voltage Scaling
Pstatic = m · V 1
m = const.V : Core voltage
P = 12C · V 2 · f + Pstatic
6
C : capacitance of switched circuitV : Voltage of switched circuitf : Frequency
6[5]Merlin Steuer Energy Efficient Programming 8 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
DVFS
DVFS
Dynamic Frequency and Voltage ScalingPstatic = m · V 1
m = const.V : Core voltage
P = 12C · V 2 · f + Pstatic
6
C : capacitance of switched circuitV : Voltage of switched circuitf : Frequency
6[5]Merlin Steuer Energy Efficient Programming 8 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
DVFS
DVFS
Dynamic Frequency and Voltage ScalingPstatic = m · V 1
m = const.V : Core voltage
P = 12C · V 2 · f + Pstatic
6
C : capacitance of switched circuitV : Voltage of switched circuitf : Frequency
6[5]Merlin Steuer Energy Efficient Programming 8 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
DVFS
0
10
20
30
40
50
60
70
80
90
100
0 10 20 30 40 50 60 70 80 90 100% P
ow
er
Consu
mpti
on (
of
10
0%
Core
Volt
age)
% Core Voltage
Power consumption by core voltage
Power
Figure: Power vs. Voltage
0
10
20
30
40
50
60
70
80
90
100
0 10 20 30 40 50 60 70 80 90 100% P
ow
er
Consu
mpti
on (
of
10
0%
Core
Volt
age)
% Core Frequency
Power consumption by core frequency
Power
Figure: Power vs. Frequency
Merlin Steuer Energy Efficient Programming 9 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
DVFS
DVFS
Possible f is a function of VLower f ⇒ Lower execution speedGood for memory-intensive applicationsNot useful for CPU-intensive applicationsCareful! Sometimes f ↘ ⇒Memory Bandwith ↘ 7
7[6]Merlin Steuer Energy Efficient Programming 10 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
ACPI
ACPI
Advanced Configuration and Power InterfaceIndustrial standardAllows OS-directed control over voltage and frequency of asystemP(erformance)-States and C(ore)-States
Merlin Steuer Energy Efficient Programming 11 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
ACPI
P-States
P0: Normal operation, highest performance and powerconsumptionPi , i > 0: Reduced power consumption, reduced performanceExample: AMD Opteron 6128 @ 2.0 GHz 8
i Vi (V) fi (GHz)0 1.23 2.001 1.17 1.502 1.12 1.203 1.09 1.004 1.06 0.80
8[7]Merlin Steuer Energy Efficient Programming 12 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
ACPI
C-States
Core statesCannot be set by code, only by hardware⇒Conditions can be set, so the hardware sets a specificC-StateC0: Normal operationCi , i > 0: Core halted, transition time to C0 rises with higher iCan be set on core or socket level, depending on CPU
Merlin Steuer Energy Efficient Programming 13 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
ACPI
C-States
Figure: Different C-States (example)9
9[8]Merlin Steuer Energy Efficient Programming 14 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
OS layer
Merlin Steuer Energy Efficient Programming 15 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Overview
Overview
The OS manages all peripherals within a computer system⇒Can have a large impact on power consumptionCan switch different peripherals within the CPU to reduce Cin P = 1
2C · V 2 · f
Merlin Steuer Energy Efficient Programming 16 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Overview
Peripherals
Peripheral Power consumption (Watt) 10
CPU 102 - 103Graphics Card 102 - 103
HDD ∼ 10 eachOptical Drives ∼ 10
Network Interfaces ∼ 10RAM ∼ 3 - 5 per module
Mainboard 25 - 40
10[9]Merlin Steuer Energy Efficient Programming 17 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Saving energy within the OS
Energy efficient OS
Graphics cardUse lower voltage / frequencyIf present: use second low-power graphics card
HDDReduce load to HDD by cachingUse differend Power-(Spindown-)States if disc is idle
Network interfacesUse lower speeds ⇒ switch to 100MBit connection if 1GBitconnection is not needed
Merlin Steuer Energy Efficient Programming 18 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Saving energy within the OS
Energy efficient OS
CPUImproved SchedulingEnter higher P-States or even C-States when CPU is idle
Memory: Efficient layoutRAM accesses need energyGood memory layout allows better caching ⇒ less read-accesses
Mainboard peripherals can be disabled if unused to save power
Merlin Steuer Energy Efficient Programming 19 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Application layer
Merlin Steuer Energy Efficient Programming 20 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Overview
Overview
We need to know what happens under the hoodHave energy efficiency in mind when writing programsGenerally: Time-efficient programs are often energy efficient
Merlin Steuer Energy Efficient Programming 21 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Energy-aware programming techniques
Techniques
Increasing time efficiencyIncreasing data efficiencyLetting the CPU restChoosing a languageLetting the compiler help usLibraries
Merlin Steuer Energy Efficient Programming 22 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Energy-aware programming techniques
Time efficiency
Many problems may be solved fast than the trivial approachExample: Bubblesort vs. QuicksortO(n2) vs. O(n log n) (Average case)Sort a list with 106 entries
1012 vs. 6 · 106 steps
Merlin Steuer Energy Efficient Programming 23 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Energy-aware programming techniques
Algorithms
Another example: Sub-String searchingTrivial aproach: O(n ·m)Boyer-Moore: O(n + m)
Algorithms allowing the CPU to Idle are betterRecursive algorithms are nice, but usually energy-inefficient(Cache misses)
Merlin Steuer Energy Efficient Programming 24 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Energy-aware programming techniques
Data efficiency
Data efficiency causes less memory operations ⇒more energyefficientMore cache hits ⇒ less execution timeTime efficiency vs. Data efficiencyChoose your data structures wisely!
Merlin Steuer Energy Efficient Programming 25 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Energy-aware programming techniques
Example: Lists11
Linked List vs. ArrayLinked lists (SE I) seem great, but:
Read in O( n2 ) vs. O(1)
Each container-object is located at different memory locations⇒Cache miss for nearly every step
Use linked lists only if you append a lot and have no need tooften traverse the whole listImagine a bubble sort in a linked list with 106 entries
11[10]Merlin Steuer Energy Efficient Programming 26 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Energy-aware programming techniques
Logging12
Logging is great during developementLogging to the hard disc is causing the drive to spin up veryoftenReduce logging to the minimum needed, maintaining theinformationCache messages
12[11]Merlin Steuer Energy Efficient Programming 27 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Energy-aware programming techniques
Letting the CPU rest
A sleeping CPU is a good CPUExample: Network communications
Merlin Steuer Energy Efficient Programming 28 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Energy-aware programming techniques
Example13: Network communication: Don’t
1 while (true)2 {3 // Read data4 result = recv( serverSocket , buffer , bufferLen , 0);56 // Handle data7 if( result != 0)8 {9 HandleData ( buffer );
10 }1112 // Sleep and repeat13 Sleep (1000) ;14 }
13[8]Merlin Steuer Energy Efficient Programming 29 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Energy-aware programming techniques
Example: Network communication: Do
1 WSANETWORKEVENTS NetworkEvents ;2 WSAEVENT wsaSocketEvent ;3 wsaSocketEvent = WSACreateEvent ();4 WSAEventSelect ( serverSocket , wsaSocketEvent ,
↪→ FD_READ | FD_CLOSE );5 while (true)6 {7 // Wait until data will be available in the socket8 WaitForSingleObject ( wsaSocketEvent , INFINITE );9 // Read data
10 result = recv( serverSocket , buffer , bufferLen , 0);1112 // Handle data13 if( result != 0)14 {15 HandleData ( buffer );16 }17 }Merlin Steuer Energy Efficient Programming 30 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Energy-aware programming techniques
When talking about communication14
Network communication needs energyKeep your protocols slimreduce overhead to a minimumSend big messages less frequent than small ones very often⇒ less CPU-wake-ups
14[11]Merlin Steuer Energy Efficient Programming 31 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Considerations
Choosing a language15
Lower level languages like C, C++ are better for energyefficiencyMore control over memory and program flowHigh-Level languages (C#, Java) are convenient, but coder hasless controlPrefer compiled languages over interpreted ones
15[10]Merlin Steuer Energy Efficient Programming 32 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Considerations
Letting the compiler help us16
If possible, let the compiler use architecture-specific instructionsetsHardware acceleration gives a huge boost in efficiencyLet the compiler optimize the code (-Ox)Less instructions per task ⇒ better efficiency
16[10]Merlin Steuer Energy Efficient Programming 33 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Considerations
Libraries
A Lot of tasks have been solved alreadyLibraries save time and moneyMultithreading/Parallel computing may give a goodperformance improvement:
OpenMPMPI
Search for Libraries before inventing the wheel over and overagain
Merlin Steuer Energy Efficient Programming 34 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Conclusion
Merlin Steuer Energy Efficient Programming 35 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Conclusion
To make a program energy-efficient, it’s good to know whathappens in hardwareKnow what the OS does to make a system energy efficientSimple rules make programs more efficientThink about your problem - The trivial approach is the best inrare cases only
Merlin Steuer Energy Efficient Programming 36 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Thank you.Questions?
Merlin Steuer Energy Efficient Programming 37 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Literature
Merlin Steuer Energy Efficient Programming 38 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Literature I
[1] Top500.org. Top500 list november 2016. Accessed: 15.11.2016.[Online]. Available: https://www.top500.org/list/2016/11/
[2] Die-Stromsparinitiative.de. Stromverbrauch im haushalt:Durchschnitt und spartipps. Accessed: 15.11.2016. [Online].Available: http://www.die-stromsparinitiative.de/stromkosten/stromverbrauch-pro-haushalt/
[3] B. für politische Bildung. Bevölkerung und haushalte. Accessed:15.11.2016. [Online]. Available:http://www.bpb.de/nachschlagen/zahlen-und-fakten/soziale-situation-in-deutschland/61584/bevoelkerung-und-haushalte
Merlin Steuer Energy Efficient Programming 39 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Literature II
[4] Reinfeld.de. Starting page. Accessed: 15.11.2016. [Online].Available: http://www.reinfeld.de/
[5] M. Travers, “CPU Power Consumption Experiments andResults Analysis of Intel i7-4820K,” p. 5, 2015. [Online].Available: http://async.org.uk/tech-reports/NCL-EEE-MICRO-TR-2015-197.pdf
[6] D. M. Robert Schone, Daniel Hackenberg, “Memoryperformance at reduced cpu clock speeds: An analysis ofcurrent x86 64 processors,” p. 3, 2014. [Online]. Available:https://pdfs.semanticscholar.org/8668/5044b78aed871688f4c7e8d95b4b62538570.pdf
Merlin Steuer Energy Efficient Programming 40 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Literature III
[7] M. Dolz, “Paving the way towards energy-awarehigh-performance-computing,” p. 18, 2014. [Online]. Available:https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2014_2015/eep-1415-eehpc.pdf
[8] Cprogramming. Green code developement. Accessed:15.11.2016. [Online]. Available:http://www.cprogramming.com/appup6.html
[9] buildcomputers. Power consumption of pc components inwatts. Accessed: 15.11.2016. [Online]. Available:http://www.buildcomputers.net/power-consumption-of-pc-components.html
Merlin Steuer Energy Efficient Programming 41 / 42
Motivation Hardware layer OS layer Application layer Conclusion Literature
Literature IV
[10] D. Lohmann, “Energy-aware programming techniques,” 2014.[Online]. Available: https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2014_2015/eep-1415-lohmann-programming-techniques.pdf
[11] C. Weekly. 8 ways to make your software applications moreenergy efficient. Accessed: 15.11.2016. [Online]. Available:http://www.computerweekly.com/blog/Green-Tech/8-ways-to-make-your-software-applications-more-energy-efficient
Merlin Steuer Energy Efficient Programming 42 / 42
top related