Class: AmdgpuFan::Service
- Inherits:
-
Object
- Object
- AmdgpuFan::Service
- Defined in:
- lib/amdgpu_fan/service.rb
Overview
AmdgpuService
A service class for reading and interacting with AMD radeon graphics cards through the amdgpu Linux kernel driver.
Defined Under Namespace
Classes: Error
Constant Summary collapse
- BASE_FOLDER =
'/sys/class/drm'- FAN_MODES =
{ '1' => 'manual', '2' => 'auto' }.freeze
Instance Attribute Summary collapse
-
#card_num ⇒ Object
readonly
Returns the value of attribute card_num.
Instance Method Summary collapse
- #busy_percent ⇒ Object
- #connectors ⇒ Object
- #core_clock ⇒ Object
- #display_names ⇒ Object
- #fan_mode ⇒ Object
- #fan_mode=(mode) ⇒ Object
- #fan_speed=(value) ⇒ Object
- #fan_speed_percent ⇒ Object
- #fan_speed_rpm ⇒ Object
-
#initialize(card_num: 0) ⇒ Service
constructor
A new instance of Service.
- #memory_clock ⇒ Object
- #memory_total ⇒ Object
- #name ⇒ Object
- #power_dpm_state ⇒ Object
- #power_draw ⇒ Object
- #power_draw_percent ⇒ Object
- #power_max ⇒ Object
- #profile_auto ⇒ Object
- #profile_force=(state) ⇒ Object
- #profile_mode ⇒ Object
- #profile_summary ⇒ Object
- #temperature ⇒ Object
- #vbios_version ⇒ Object
Constructor Details
#initialize(card_num: 0) ⇒ Service
Returns a new instance of Service.
24 25 26 |
# File 'lib/amdgpu_fan/service.rb', line 24 def initialize(card_num: 0) @card_num = card_num end |
Instance Attribute Details
#card_num ⇒ Object (readonly)
Returns the value of attribute card_num.
20 21 22 |
# File 'lib/amdgpu_fan/service.rb', line 20 def card_num @card_num end |
Instance Method Details
#busy_percent ⇒ Object
28 29 30 |
# File 'lib/amdgpu_fan/service.rb', line 28 def busy_percent File.read("#{base_card_dir}/gpu_busy_percent").strip end |
#connectors ⇒ Object
32 33 34 |
# File 'lib/amdgpu_fan/service.rb', line 32 def connectors @connectors ||= Connector.where card_num: card_num end |
#core_clock ⇒ Object
36 37 38 |
# File 'lib/amdgpu_fan/service.rb', line 36 def core_clock clock_from_pp_file "#{base_card_dir}/pp_dpm_sclk" end |
#display_names ⇒ Object
40 41 42 |
# File 'lib/amdgpu_fan/service.rb', line 40 def display_names connectors.map(&:display_name).compact end |
#fan_mode ⇒ Object
44 45 46 |
# File 'lib/amdgpu_fan/service.rb', line 44 def fan_mode FAN_MODES[File.read(fan_mode_file).strip] || 'unknown' end |
#fan_mode=(mode) ⇒ Object
48 49 50 |
# File 'lib/amdgpu_fan/service.rb', line 48 def fan_mode=(mode) sudo_write fan_mode_file, FAN_MODES.key(mode.to_s) end |
#fan_speed=(value) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/amdgpu_fan/service.rb', line 52 def fan_speed=(value) if valid_fan_percent_speed?(value) new_raw = (value.to_f / 100 * fan_raw_speeds(:max).to_i).round elsif valid_fan_raw_speed?(value) new_raw = value end raise(self.class::Error, 'Invalid fan speed provided') if new_raw.to_s.empty? self.fan_mode = :manual unless fan_mode == 'manual' sudo_write fan_power_file, new_raw end |
#fan_speed_percent ⇒ Object
66 67 68 |
# File 'lib/amdgpu_fan/service.rb', line 66 def fan_speed_percent (fan_speed_raw.to_f / fan_raw_speeds(:max).to_i * 100).round end |
#fan_speed_rpm ⇒ Object
70 71 72 |
# File 'lib/amdgpu_fan/service.rb', line 70 def fan_speed_rpm File.read(fan_file(:input)).strip end |
#memory_clock ⇒ Object
74 75 76 |
# File 'lib/amdgpu_fan/service.rb', line 74 def memory_clock clock_from_pp_file "#{base_card_dir}/pp_dpm_mclk" end |
#memory_total ⇒ Object
78 79 80 |
# File 'lib/amdgpu_fan/service.rb', line 78 def memory_total File.read("#{base_card_dir}/mem_info_vram_total").to_i end |
#name ⇒ Object
82 83 84 |
# File 'lib/amdgpu_fan/service.rb', line 82 def name lspci_subsystem.split(': ')[1].strip end |
#power_dpm_state ⇒ Object
86 87 88 |
# File 'lib/amdgpu_fan/service.rb', line 86 def power_dpm_state File.read("#{base_card_dir}/power_dpm_state").strip end |
#power_draw ⇒ Object
90 91 92 |
# File 'lib/amdgpu_fan/service.rb', line 90 def power_draw power_raw_to_watts File.read(power_avg_file) end |
#power_draw_percent ⇒ Object
94 95 96 |
# File 'lib/amdgpu_fan/service.rb', line 94 def power_draw_percent (power_draw.to_f / power_max.to_i * 100).round end |
#power_max ⇒ Object
98 99 100 |
# File 'lib/amdgpu_fan/service.rb', line 98 def power_max @power_max ||= power_raw_to_watts File.read("#{base_hwmon_dir}/power1_cap") end |
#profile_auto ⇒ Object
102 103 104 |
# File 'lib/amdgpu_fan/service.rb', line 102 def profile_auto sudo_write "#{base_card_dir}/power_dpm_force_performance_level", 'auto' end |
#profile_force=(state) ⇒ Object
106 107 108 109 |
# File 'lib/amdgpu_fan/service.rb', line 106 def profile_force=(state) sudo_write "#{base_card_dir}/power_dpm_force_performance_level", 'manual' sudo_write "#{base_card_dir}/pp_power_profile_mode", state end |
#profile_mode ⇒ Object
111 112 113 |
# File 'lib/amdgpu_fan/service.rb', line 111 def profile_mode File.read("#{base_card_dir}/pp_power_profile_mode").slice(/\w+\s*+\*/).delete('*').strip end |
#profile_summary ⇒ Object
115 116 117 |
# File 'lib/amdgpu_fan/service.rb', line 115 def profile_summary File.read("#{base_card_dir}/pp_power_profile_mode") end |
#temperature ⇒ Object
119 120 121 |
# File 'lib/amdgpu_fan/service.rb', line 119 def temperature (File.read(temperature_file).to_f / 1000).round(1) end |
#vbios_version ⇒ Object
123 124 125 |
# File 'lib/amdgpu_fan/service.rb', line 123 def vbios_version @vbios_version ||= File.read("#{base_card_dir}/vbios_version").strip end |