Class: Distem::Algorithm::CPU::Gov
- Inherits:
-
Distem::Algorithm
- Object
- Distem::Algorithm
- Distem::Algorithm::CPU::Gov
- Defined in:
- lib/distem/algorithm/cpu/gov.rb
Overview
Algorithm based on CPU throttling methods (see en.wikipedia.org/wiki/Dynamic_frequency_scaling). A core is changing his frequency periodatically between two values to reach the wished one i.e. if our physical core can change it's frequency to 1.5GHz, 2.0GHz and 2.5GHz and we want it to be set at 2.3GHz, this algorithm will make the core work 40% of the time at 2GHz and 60% at 2.5GHz.
Instance Method Summary (collapse)
-
- (Object) apply(vnode)
Apply the algorithm on a resource (virtual node) ==== Attributes *
vnode
The VNode object. -
- (Gov) initialize
constructor
Create a new Gov object.
-
- (Object) undo(vnode)
Undo the algorithm on a resource (virtual node) ==== Attributes *
vnode
The VNode object.
Constructor Details
- (Gov) initialize
Create a new Gov object
9 10 11 12 |
# File 'lib/distem/algorithm/cpu/gov.rb', line 9 def initialize() super() @ext = nil end |
Instance Method Details
- (Object) apply(vnode)
Apply the algorithm on a resource (virtual node)
Attributes
-
vnode
The VNode object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/distem/algorithm/cpu/gov.rb', line 18 def apply(vnode) super(vnode) cores = [] freqmax = nil lfreq = nil hfreq = nil wfreq = nil # wished frequency ratio = nil if vnode.vcpu and vnode.vcpu.vcores #check available frequencies table pcores = vnode.host.cpu.get_allocated_cores(vnode) cores = pcores.collect{ |core| core.physicalid.to_i } vcore = vnode.vcpu.vcores[vnode.vcpu.vcores.keys[0]] freqs = vcore.pcore.frequencies freqs.sort freqmax = vcore.pcore.frequency wfreq = vcore.frequency.to_i # if the wished frequency is one of the cpu possible frequency if freqs.index(wfreq) lfreq = wfreq hfreq = wfreq ratio = 1.0 else hfreq = freqs.select{|val| val >= wfreq}[0] if hfreq == freqs[0] lfreq = 0 else lfreq = freqs[freqs.index(hfreq) - 1] end end end unless cores.empty? @ext = CPUExtension::CPUGov.new( cores,freqmax,"#{Node::Admin::PATH_CGROUP}/#{vnode.name}" ) ratio = (wfreq.to_f - hfreq) / (lfreq - hfreq) unless ratio @ext.run(lfreq.to_i,hfreq.to_i,ratio.to_f) end end |
- (Object) undo(vnode)
Undo the algorithm on a resource (virtual node)
Attributes
-
vnode
The VNode object
63 64 65 66 67 68 69 |
# File 'lib/distem/algorithm/cpu/gov.rb', line 63 def undo(vnode) super(vnode) if @ext @ext.stop @ext = nil end end |