summarylogtreecommitdiffstats
path: root/indicator.py.patch
blob: bdc27a50b2506c0ff6a79ec3d2453f0e4ebb4c45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
=== modified file 'indicator_cpufreq/indicator.py'
--- indicator_cpufreq/indicator.py	2013-02-20 03:47:48 +0000
+++ indicator_cpufreq/indicator.py	2017-04-04 16:49:04 +0000
@@ -23,12 +23,15 @@
 import locale
 import dbus
 
-from indicator_cpufreq import cpufreq
-
 import gettext
 from gettext import gettext as _
 #gettext.textdomain('indicator-cpufreq')
 
+import glob
+
+def readable_throttle(t):
+        return t
+
 def readable_frequency(f):
     # temp hack for properly displaying intel turbo mode (actual freq + 1000kHz)
     label = _("%s GHz") % locale.format(_("%.2f"), f / 1.0e6)
@@ -37,9 +40,9 @@
     return label
 
 governor_names = {
+    'schedutil': _("Scheduler"),
     'conservative': _("Conservative"),
     'ondemand': _("Ondemand"),
-    #'userspace': _("Userspace"),
     'powersave': _("Powersave"),
     'performance': _("Performance"),
 }
@@ -50,6 +53,15 @@
     else:
         return g
 
+def readable_psturbo(t):
+        return t
+
+def readable_hyperthreads(h):
+        return h
+
+def readable_gputhrottles(gt):
+        return gt
+
 class MyIndicator(object):
     def __init__(self, show_frequency=False):
         self.show_frequency = show_frequency
@@ -66,33 +78,81 @@
         self.select_items = {}
         group = []
         
-        maxcpu = 0
-        while cpufreq.cpu_exists(maxcpu) == 0:
-            maxcpu += 1
-        self.cpus = range(maxcpu)
-        
-        # frequency menu items
-        #freqs = cpufreq.get_available_frequencies(self.cpus[0])
-        freqs = reversed(sorted(set(cpufreq.get_available_frequencies(self.cpus[0]))))
-        for freq in freqs:
-            menu_item = Gtk.RadioMenuItem.new_with_label(group, readable_frequency(freq))
+        # throttle menu items
+        throttles = ['full', 'cut']
+        throtmenu = Gtk.Menu()
+        throtm = Gtk.MenuItem("System Throttle")
+        throtm.set_submenu(throtmenu)
+        for toggle in throttles:
+            menu_item = Gtk.RadioMenuItem.new_with_label(group, readable_throttle(toggle))
             group = menu_item.get_group()
-            menu.append(menu_item)
-            menu_item.connect("activate", self.select_activated, 'frequency', freq)
-            self.select_items[freq] = menu_item
+            throtmenu.append(menu_item)
+            menu_item.connect('activate', self.select_activated, 'throttle', toggle)
+            self.select_items[toggle] = menu_item
+        menu.append(throtm)
 
         menu.append(Gtk.SeparatorMenuItem())
 
         # governor menu items
-        governors = cpufreq.get_available_governors(self.cpus[0])
-        for governor in governors:
-            if governor == 'userspace':
-                continue
+        govFile = open("/sys/devices/system/cpu/cpufreq/policy0/scaling_available_governors")
+        governors = govFile.readline().strip("\n")
+        govList = governors.split(" ")
+        govmenu = Gtk.Menu()
+        govm = Gtk.MenuItem("CPU Governor")
+        govm.set_submenu(govmenu)
+        for governor in govList:
+            if governor == 'performance':
+                toggle = 'full'
+            else:
+                toggle = 'cut'
             menu_item = Gtk.RadioMenuItem.new_with_label(group, readable_governor(governor))
             group = menu_item.get_group()
-            menu.append(menu_item)
-            menu_item.connect('activate', self.select_activated, 'governor', governor)
+            govmenu.append(menu_item)
+            menu_item.connect('activate', self.select_activated, 'governor', toggle)
             self.select_items[governor] = menu_item
+        menu.append(govm)
+        govFile.close
+
+        # p-state turbo menu items
+        psturbo = ['on', 'off']
+        pstmenu = Gtk.Menu()
+        pstm = Gtk.MenuItem("P-State Turbo")
+        pstm.set_submenu(pstmenu)
+        for toggle in psturbo:
+            menu_item = Gtk.RadioMenuItem.new_with_label(group, readable_psturbo(toggle))
+            group = menu_item.get_group()
+            pstmenu.append(menu_item)
+            menu_item.connect('activate', self.select_activated, 'psturbo', toggle)
+            self.select_items[toggle] = menu_item
+        menu.append(pstm)
+
+        # hyperthreading menu items
+        hyperthreads = ['on', 'off']
+        htmenu = Gtk.Menu()
+        htm = Gtk.MenuItem("Hyperthreads")
+        htm.set_submenu(htmenu)
+        for toggle in hyperthreads:
+            menu_item = Gtk.RadioMenuItem.new_with_label(group, readable_hyperthreads(toggle))
+            group = menu_item.get_group()
+            htmenu.append(menu_item)
+            menu_item.connect('activate', self.select_activated, 'hyperthreads', toggle)
+            self.select_items[toggle] = menu_item
+        menu.append(htm)
+
+        menu.append(Gtk.SeparatorMenuItem())
+
+        # gpu runtime pm menu items
+        gputhrottles = ['full', 'cut']
+        gpumenu = Gtk.Menu()
+        gpum = Gtk.MenuItem("GPU Throttle")
+        gpum.set_submenu(gpumenu)
+        for toggle in gputhrottles:
+            menu_item = Gtk.RadioMenuItem.new_with_label(group, readable_gputhrottles(toggle))
+            group = menu_item.get_group()
+            gpumenu.append(menu_item)
+            menu_item.connect('activate', self.select_activated, 'gputhrottle', toggle)
+            self.select_items[toggle] = menu_item
+        menu.append(gpum)
 
         menu.show_all()        
         self.ind.set_menu(menu)
@@ -107,13 +167,29 @@
         for i in self.select_items.values():
             i.handler_block_by_func(self.select_activated)
         
-        fmin, fmax, governor = cpufreq.get_policy(self.cpus[0])
+        govFile = open("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor", 'r')
+        governor = govFile.readline().strip("\n")
+        fmnFile = open("/sys/devices/system/cpu/cpufreq/policy0/cpuinfo_min_freq", 'r')
+        fmin = int(fmnFile.readline().strip("\n"))
+        fmxFile = open("/sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq", 'r')
+        fmax = int(fmxFile.readline().strip("\n"))
         # use the highest freq among cores for display
-        freq = max([cpufreq.get_freq_kernel(cpu) for cpu in self.cpus])
+        freq_list = glob.glob('/sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq')
+        freqs = []
+        for cur_freq in freq_list:
+            f = open(cur_freq, 'r')
+            freqs.append(int(f.readline().strip("\n")))
+            f.close
+
+        freq = max(freqs)
         
         ratio = min([25, 50, 75, 100], key=lambda x: abs((fmax - fmin) * x / 100.0 - (freq - fmin)))
         if freq < fmax and ratio == 100:
             ratio = 75
+
+        govFile.close
+        fmnFile.close
+        fmxFile.close
         
         #self.set_icon(get_data_file('media', 'indicator-cpufreq-%d.png' % ratio))
         self.ind.set_icon('indicator-cpufreq-%d' % ratio)
@@ -133,12 +209,21 @@
         if menuitem.get_active():
             bus = dbus.SystemBus()
             proxy = bus.get_object("com.ubuntu.IndicatorCpufreqSelector", "/Selector", introspect=False)
-            cpus = [dbus.UInt32(cpu) for cpu in self.cpus]
-            if select == 'frequency':
-                proxy.SetFrequency(cpus, dbus.UInt32(value),
+            #cpus = [dbus.UInt32(cpu) for cpu in self.cpus]
+            if select == 'throttle':
+                proxy.SetThrottle(value,
+                    dbus_interface='com.ubuntu.IndicatorCpufreqSelector')
+            elif select == 'psturbo':
+                proxy.SetPSTurbo("turbo-" + value,
+                    dbus_interface='com.ubuntu.IndicatorCpufreqSelector')
+            elif select == 'hyperthreads':
+                proxy.SetHyperthreads("ht-" + value,
+                    dbus_interface='com.ubuntu.IndicatorCpufreqSelector')
+            elif select == 'gputhrottle':
+                proxy.SetGPUThrottle("gpu-" + value,
                     dbus_interface='com.ubuntu.IndicatorCpufreqSelector')
             else:
-                proxy.SetGovernor(cpus, value,
+                proxy.SetGovernor("gov-" + value,
                     dbus_interface='com.ubuntu.IndicatorCpufreqSelector')
     
     def can_set(self):