amdgpu_fan 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f57ebc2011d08efe82baa67964bf75a17dfe7c85a518249a93c7b6eeadf207e
4
- data.tar.gz: 1e1fa6d5af4f3cecc5346003949eb4a1edeb1c1ef943e60478f09cd8e3600099
3
+ metadata.gz: a499ce52639612b25843b04c3497c7c36f23f3a960d0946b7dc2e249e9a18874
4
+ data.tar.gz: fa87ca342988d97a91773b1272829a3b825b88dbd65420d6abd26fed8d97ac92
5
5
  SHA512:
6
- metadata.gz: a185688066129ae01860f6dcf15fa75d84b5441f0cf3fbf23df812986c8da194eb6ed00557afe607299d6d3640beed3b5dc60483b1e6155d09d4e40180865793
7
- data.tar.gz: 2ef75cd3c949fd579eaf855c63ca985a1ddff172e41fceb46dd10b5f1177e0ddaf7f74427e3ce64c26a86ac15da473806f400014abaf428fb7275f075cd79069
6
+ metadata.gz: 06b3bd73191b39da57ac9c14e7ada8fa2cf1a069e8401f45af10eab6ede0bf79a5ebd2f80ba5c464e60f960e24d11783cf20d698c640a38e36c80846b305772e
7
+ data.tar.gz: 794e28fd6ae71a898b1e897a0fd612add4585e901ece8bc3928e62de9d8245107767848352fe7203d4aa5b6ec60c4e78b28523cc0c893d4d0bcb2f67fdd52044
data/README.md CHANGED
@@ -93,7 +93,7 @@ And now the watch is ended.
93
93
 
94
94
  - [Ruby](https://www.ruby-lang.org) with [Bundler](https://bundler.io)
95
95
  - [Thor](http://whatisthor.com/) (installed with `bundle install`)
96
- - [`lspci`](https://linux.die.net/man/8/lspci) (included with most Linux distributions)
96
+ - Internet connection - Device info is retrieved from https://pci-ids.ucw.cz/
97
97
 
98
98
  ## Building a binary
99
99
 
@@ -10,5 +10,6 @@ require_relative '../lib/amdgpu_fan/mixin/sys_write'
10
10
 
11
11
  require_relative '../lib/amdgpu_fan/service'
12
12
  require_relative '../lib/amdgpu_fan/cli'
13
+ require_relative '../lib/amdgpu_fan/pci'
13
14
  require_relative '../lib/amdgpu_fan/stat_set'
14
15
  require_relative '../lib/amdgpu_fan/watcher'
@@ -7,7 +7,7 @@ module AmdgpuFan
7
7
  class Cli < Thor
8
8
  include CliOutputFormat
9
9
 
10
- ICONS = YAML.load(File.read(File.join(__dir__, '../../config/icons.yml')))
10
+ ICONS = YAML.safe_load(File.read(File.join(__dir__, '../../config/icons.yml')))
11
11
  .transform_keys(&:to_sym).freeze
12
12
  WATCH_FIELD_SEPARATOR = ' | '
13
13
 
@@ -57,13 +57,13 @@ module AmdgpuFan
57
57
  def status(option = nil)
58
58
  puts radeon_logo if option == '--logo'
59
59
  puts ICONS[:gpu] + ' GPU:'.ljust(9) + amdgpu_service.name,
60
- ICONS[:vbios]+ ' vBIOS:'.ljust(9) + amdgpu_service.vbios_version,
61
- ICONS[:display] + ' Displays:' + amdgpu_service.display_names.join(', '),
60
+ ICONS[:vbios] + ' vBIOS:'.ljust(9) + amdgpu_service.vbios_version,
61
+ ICONS[:display] + ' Displays:' + amdgpu_service.display_names.join(', '),
62
62
  ICONS[:clock] + ' Clocks:'.ljust(9) + clock_status,
63
63
  ICONS[:memory] + ' Memory:'.ljust(9) + mem_total_mibibyes,
64
64
  ICONS[:fan] + ' Fan:'.ljust(9) + fan_status,
65
65
  ICONS[:temp] + ' Temp:'.ljust(9) + "#{amdgpu_service.temperature}°C",
66
- ICONS[:power] + ' Power:'.ljust(9) + "#{amdgpu_service.profile_mode} profile in " \
66
+ ICONS[:power] + ' Power:'.ljust(9) + "#{amdgpu_service.profile_mode} profile in " \
67
67
  "#{amdgpu_service.power_dpm_state} mode using " \
68
68
  "#{amdgpu_service.power_draw} / #{amdgpu_service.power_max} Watts "\
69
69
  "(#{amdgpu_service.power_draw_percent}%)",
@@ -11,7 +11,6 @@ module AmdgpuFan
11
11
  index_range: (54..125)
12
12
  }.freeze
13
13
 
14
-
15
14
  attr_reader :card_num, :dir_path, :index, :type
16
15
 
17
16
  class << self
@@ -4,7 +4,6 @@ module AmdgpuFan
4
4
  ##
5
5
  # A mixin to read fan details and validate input
6
6
  module Fan
7
-
8
7
  private
9
8
 
10
9
  def fan_file(type)
@@ -3,11 +3,10 @@
3
3
  module AmdgpuFan
4
4
  # A mixin to help with writing to system files
5
5
  module SysWrite
6
-
7
6
  private
8
7
 
9
8
  ##
10
- # Write to a system file with elevated priviledges.
9
+ # Write to a system file with elevated priviledges.
11
10
  def sudo_write(file_path, value)
12
11
  `echo "#{value}" | sudo tee #{file_path}`
13
12
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+
5
+ module AmdgpuFan
6
+ ## PCI
7
+ #
8
+ # Retrieve device information from PCI IDs.
9
+ # https://pci-ids.ucw.cz/
10
+ #
11
+ class PCI
12
+ TMP_FILE = '/tmp/pci.ids.txt'
13
+ URL = 'https://pci-ids.ucw.cz/v2.2/pci.ids'
14
+
15
+ ##
16
+ # Return the device name if available
17
+ #
18
+ def self.device_name(vendor_id, device_id, subdevice_id)
19
+ device = info.dig vendor_id, :devices, device_id
20
+
21
+ device.dig(subdevice_id, :name) || device[:name]
22
+ end
23
+
24
+ def self.vendor_name(vendor_id)
25
+ info.dig vendor_id, :name
26
+ end
27
+
28
+ def self.info
29
+ current_vendor_id = nil
30
+ current_device_id = nil
31
+
32
+ @info = raw.each_line.with_object({}) do |line, hash|
33
+ next if line.empty? || line.start_with?('#')
34
+
35
+ if line[0] =~ /(\d|[a-z])/
36
+ # Vendor line
37
+ current_vendor_id = line.split(' ').first.to_i(16)
38
+ vendor_name = line.split(' ').last.strip
39
+ hash[current_vendor_id] = { name: vendor_name, devices: {} }
40
+ elsif line[0..1] =~ /\t\w/
41
+ # Device line
42
+ current_device_id = line.split(' ').first.to_i(16)
43
+ device_name = line.split(' ').last.strip
44
+ hash[current_vendor_id][:devices][current_device_id] = { name: device_name }
45
+ elsif line[0..2] =~ /\t\t\w/
46
+ # Subvendor line
47
+ subvendor_id = line.split(' ').first.to_i(16)
48
+ subdevice_id = line.split(' ')[1].to_i(16)
49
+ subdevice_name = line.split(' ')[1].strip
50
+ hash[current_vendor_id][:devices][current_device_id][subdevice_id] =
51
+ { name: subdevice_name }
52
+ end
53
+ end
54
+ end
55
+
56
+ def self.raw
57
+ File.write(TMP_FILE, Net::HTTP.get(URI(URL))) unless File.exist?(TMP_FILE)
58
+
59
+ @raw ||= File.read(TMP_FILE)
60
+ end
61
+ end
62
+ end
@@ -4,6 +4,7 @@ require_relative 'mixin/fan'
4
4
  require_relative 'mixin/sys_write'
5
5
 
6
6
  require_relative 'connector'
7
+ require_relative 'pci'
7
8
 
8
9
  module AmdgpuFan
9
10
  ## AmdgpuService
@@ -45,10 +46,16 @@ module AmdgpuFan
45
46
  FAN_MODES[File.read(fan_mode_file).strip] || 'unknown'
46
47
  end
47
48
 
49
+ ##
50
+ # Set the fan mode to auto or manual.
51
+ #
48
52
  def fan_mode=(mode)
49
53
  sudo_write fan_mode_file, FAN_MODES.key(mode.to_s)
50
54
  end
51
55
 
56
+ ##
57
+ # Set the fan speed to a percentage if <= 100 or a raw value
58
+ #
52
59
  def fan_speed=(value)
53
60
  if valid_fan_percent_speed?(value)
54
61
  new_raw = (value.to_f / 100 * fan_raw_speeds(:max).to_i).round
@@ -67,20 +74,37 @@ module AmdgpuFan
67
74
  (fan_speed_raw.to_f / fan_raw_speeds(:max).to_i * 100).round
68
75
  end
69
76
 
77
+ ##
78
+ # Return the fan speed in revolutions per minute
79
+ #
70
80
  def fan_speed_rpm
71
81
  File.read(fan_file(:input)).strip
72
82
  end
73
83
 
84
+ ##
85
+ # Return the current memory clock speed.
86
+ #
74
87
  def memory_clock
75
88
  clock_from_pp_file "#{base_card_dir}/pp_dpm_mclk"
76
89
  end
77
90
 
91
+ ##
92
+ # Return the total memory on the card in bytes
93
+ #
78
94
  def memory_total
79
95
  File.read("#{base_card_dir}/mem_info_vram_total").to_i
80
96
  end
81
97
 
98
+ def model_id
99
+ @model_id ||= File.read(File.join(base_card_dir, '/subsystem_device')).gsub(/\A0x/, '').upcase
100
+ end
101
+
82
102
  def name
83
- lspci_subsystem.split(': ')[1].strip
103
+ return 'Unknown' unless PCI.vendor_name(vendor_id)
104
+
105
+ [PCI.vendor_name(vendor_id),
106
+ PCI.device_name(vendor_id, device_id, subdevice_id) || 'unknown']
107
+ .join(' ')
84
108
  end
85
109
 
86
110
  def power_dpm_state
@@ -138,12 +162,8 @@ module AmdgpuFan
138
162
  File.read(file).slice(/\w+(?= \*)/)
139
163
  end
140
164
 
141
- def gpu_pci_id
142
- @gpu_pci_id ||= `lspci -v | grep VGA`.split(' ').first
143
- end
144
-
145
- def lspci_subsystem
146
- @lspci_subsystem ||= `lspci -v -s #{gpu_pci_id} | grep "Subsystem:"`
165
+ def device_id
166
+ @device_id ||= File.read(File.join(base_card_dir, 'device')).to_i(16)
147
167
  end
148
168
 
149
169
  def power_avg_file
@@ -154,8 +174,16 @@ module AmdgpuFan
154
174
  (raw_string.strip.to_f / 1_000_000).round(2)
155
175
  end
156
176
 
177
+ def subdevice_id
178
+ @subdevice_id ||= File.read(File.join(base_card_dir, 'subsystem_device')).to_i(16)
179
+ end
180
+
157
181
  def temperature_file
158
182
  @temperature_file ||= Dir.glob("#{base_card_dir}/**/temp1_input").first
159
183
  end
184
+
185
+ def vendor_id
186
+ @vendor_id ||= File.read(File.join(base_card_dir, 'vendor')).to_i(16)
187
+ end
160
188
  end
161
189
  end
@@ -18,7 +18,7 @@ module AmdgpuFan
18
18
  # Return a string containing all the stats with units.
19
19
  #
20
20
  def to_s
21
- stats.map { |k,v| "#{k}: #{v.to_s.rjust(6)} #{unit.ljust(3)} " }.join
21
+ stats.map { |k, v| "#{k}: #{v.to_s.rjust(6)} #{unit.ljust(3)} " }.join
22
22
  end
23
23
  end
24
24
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module AmdgpuFan
4
4
  # Current version of RSpec Core, in semantic versioning format.
5
- VERSION = '0.6.0'
5
+ VERSION = '0.7.0'
6
6
  end
@@ -47,8 +47,8 @@ module AmdgpuFan
47
47
 
48
48
  stat_set.min = stat_set.now if stat_set.now < stat_set.min
49
49
  stat_set.avg =
50
- ((stat_set.now + stat_set.avg * (num_measurements - 1)) / num_measurements.to_f)
51
- .round(1)
50
+ ((stat_set.now + stat_set.avg * (num_measurements - 1)) / num_measurements.to_f)
51
+ .round(1)
52
52
  stat_set.max = stat_set.now if stat_set.now > stat_set.max
53
53
  end
54
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amdgpu_fan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McCormack
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-03 00:00:00.000000000 Z
11
+ date: 2020-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -69,6 +69,7 @@ files:
69
69
  - lib/amdgpu_fan/mixin/cli_output_format.rb
70
70
  - lib/amdgpu_fan/mixin/fan.rb
71
71
  - lib/amdgpu_fan/mixin/sys_write.rb
72
+ - lib/amdgpu_fan/pci.rb
72
73
  - lib/amdgpu_fan/service.rb
73
74
  - lib/amdgpu_fan/stat_set.rb
74
75
  - lib/amdgpu_fan/version.rb
@@ -77,7 +78,7 @@ homepage: https://github.com/HarlemSquirrel/amdgpu-fan-rb
77
78
  licenses:
78
79
  - MIT
79
80
  metadata: {}
80
- post_install_message:
81
+ post_install_message:
81
82
  rdoc_options: []
82
83
  require_paths:
83
84
  - lib
@@ -93,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
94
  version: '0'
94
95
  requirements: []
95
96
  rubygems_version: 3.1.2
96
- signing_key:
97
+ signing_key:
97
98
  specification_version: 4
98
99
  summary: A CLI to view and set fan speeds for AMD graphics cards running on the open
99
100
  source amdgpu Linux driver