Class: Jkr::Cpufreq::Config::CpuConfig
- Inherits:
-
Object
- Object
- Jkr::Cpufreq::Config::CpuConfig
- Defined in:
- lib/jkr/cpufreq.rb
Instance Attribute Summary collapse
-
#governor ⇒ Object
Returns the value of attribute governor.
-
#params ⇒ Object
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #frequency ⇒ Object
- #frequency=(freq) ⇒ Object
-
#initialize(cpu_idx, gov, params = Hash.new) ⇒ CpuConfig
constructor
cpu_idx is just a hint for gathering information.
- #to_s ⇒ Object
Constructor Details
#initialize(cpu_idx, gov, params = Hash.new) ⇒ CpuConfig
cpu_idx is just a hint for gathering information
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/jkr/cpufreq.rb', line 107 def initialize(cpu_idx, gov, params = Hash.new) @governor = gov.to_s @freq = nil @params = params @cpu_idx = cpu_idx @available_freqs = Cpufreq.available_frequency(cpu_idx) case @governor when /\Aperformance\Z/ # do nothing when /\Apowersave\Z/ # do nothing when /\Auserspace\Z/ if ! @freq = params[:frequency] raise ArgumentError.new("parameter :frequency is required for userspece governor") elsif ! @available_freqs.include?(params[:frequency]) raise ArgumentError.new("Frequency not available: #{params[:frequency]}") end when /\Aondemand\Z/ # TODO end end |
Instance Attribute Details
#governor ⇒ Object
Returns the value of attribute governor.
103 104 105 |
# File 'lib/jkr/cpufreq.rb', line 103 def governor @governor end |
#params ⇒ Object
Returns the value of attribute params.
104 105 106 |
# File 'lib/jkr/cpufreq.rb', line 104 def params @params end |
Class Method Details
.read_config(cpu_idx) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/jkr/cpufreq.rb', line 152 def self.read_config(cpu_idx) gov = `cat #{Cpufreq.cpufreqpath(cpu_idx) + "/scaling_governor"}`.strip freq = nil case gov when /\Aperformance\Z/ # do nothing when /\Aperformance\Z/ # do nothing when /\Auserspace\Z/ freq = `cat #{Cpufreq.cpufreqpath(cpu_idx) + "/scaling_cur_freq"}`.strip.to_i when /\Aondemand\Z/ # TODO: read parameters end CpuConfig.new(cpu_idx, gov, {:frequency => freq}) end |
.write_config(cpu_idx, cpuconfig) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/jkr/cpufreq.rb', line 170 def self.write_config(cpu_idx, cpuconfig) `echo #{cpuconfig.governor} > #{Cpufreq.cpufreqpath(cpu_idx) + "/scaling_governor"}` case cpuconfig.governor when /\Aperformance\Z/ # do nothing when /\Aperformance\Z/ # do nothing when /\Auserspace\Z/ `echo #{cpuconfig.frequency} > #{Cpufreq.cpufreqpath(cpu_idx) + "/scaling_setspeed"}` when /\Aondemand\Z/ if cpuconfig.params[:up_threshold] `echo #{cpuconfig.params[:up_threshold]} > #{Cpufreq.cpufreqpath(cpu_idx) + "/ondemand/up_threshold"}` end if cpuconfig.params[:sampling_rate] `echo #{cpuconfig.params[:sampling_rate]} > #{Cpufreq.cpufreqpath(cpu_idx) + "/ondemand/sampling_rate"}` end # TODO: parameters end end |
Instance Method Details
#frequency ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/jkr/cpufreq.rb', line 131 def frequency case @governor when /\Aperformance\Z/ @available_freqs.max when /\Apowersave\Z/ @available_freqs.min when /\Auserspace\Z/ @freq when /\Aondemand\Z/ `cat #{Cpufreq.cpufreqpath(@cpu_idx) + "/scaling_cur_freq"}`.strip.to_i end end |
#frequency=(freq) ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/jkr/cpufreq.rb', line 144 def frequency=(freq) if @available_freqs.include?(freq) @freq = freq else raise ArgumentError.new("Frequency not available: #{freq}") end end |
#to_s ⇒ Object
190 191 192 193 194 195 196 197 |
# File 'lib/jkr/cpufreq.rb', line 190 def to_s case self.governor when /\Auserspace\Z/ "#<CpuConfig: governor=#{self.governor}, frequency=#{self.frequency}>" else "#<CpuConfig: governor=#{self.governor}>" end end |