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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
--- indicator-cpufreq/bin/indicator-cpufreq-selector 2014-12-27 02:48:58.330816000 +0900
+++ indicator-cpufreq/bin/indicator-cpufreq-selector 2014-12-27 02:25:45.903998358 +0900
@@ -21,6 +21,8 @@
import dbus.service
import dbus.mainloop.glib
+import subprocess
+
from indicator_cpufreq import cpufreq
class PermissionDeniedByPolicy(dbus.DBusException):
@@ -42,6 +44,15 @@
self._package_operation_in_progress = False
@dbus.service.method(dbus_interface='com.ubuntu.IndicatorCpufreqSelector',
+ in_signature='as',
+ out_signature='',
+ sender_keyword='sender',
+ connection_keyword='conn')
+ def SetThrottle(self, throttle, sender=None, conn=None):
+ self._check_polkit_privilege(sender, conn, 'com.ubuntu.indicatorcpufreqselector.setthrottle')
+ error = subprocess.Popen(["/bin/sh", "throttle", throttle])
+
+ @dbus.service.method(dbus_interface='com.ubuntu.IndicatorCpufreqSelector',
in_signature='auu',
out_signature='',
sender_keyword='sender',
@@ -61,6 +72,33 @@
for cpu in cpus:
error = cpufreq.modify_policy_governor(cpu, governor)
+ @dbus.service.method(dbus_interface='com.ubuntu.IndicatorCpufreqSelector',
+ in_signature='as',
+ out_signature='',
+ sender_keyword='sender',
+ connection_keyword='conn')
+ def SetPSTurbo(self, psturbo, sender=None, conn=None):
+ self._check_polkit_privilege(sender, conn, 'com.ubuntu.indicatorcpufreqselector.setpsturbo')
+ error = subprocess.Popen(["/bin/sh", "throttle", psturbo])
+
+ @dbus.service.method(dbus_interface='com.ubuntu.IndicatorCpufreqSelector',
+ in_signature='as',
+ out_signature='',
+ sender_keyword='sender',
+ connection_keyword='conn')
+ def SetHyperthreads(self, hyperthreads, sender=None, conn=None):
+ self._check_polkit_privilege(sender, conn, 'com.ubuntu.indicatorcpufreqselector.sethyperthreads')
+ error = subprocess.Popen(["/bin/sh", "throttle", hyperthreads])
+
+ @dbus.service.method(dbus_interface='com.ubuntu.IndicatorCpufreqSelector',
+ in_signature='as',
+ out_signature='',
+ sender_keyword='sender',
+ connection_keyword='conn')
+ def SetGPUThrottle(self, gputhrottle, sender=None, conn=None):
+ self._check_polkit_privilege(sender, conn, 'com.ubuntu.indicatorcpufreqselector.setgputhrottle')
+ error = subprocess.Popen(["/bin/sh", "throttle", gputhrottle])
+
def _check_polkit_privilege(self, sender, conn, privilege):
'''Verify that sender has a given PolicyKit privilege.
--- indicator-cpufreq/indicator_cpufreq/com.ubuntu.indicatorcpufreq.policy.in 2014-12-27 02:48:58.330816000 +0900
+++ indicator-cpufreq/indicator_cpufreq/com.ubuntu.indicatorcpufreq.policy.in 2014-12-27 02:29:19.809678757 +0900
@@ -13,13 +13,55 @@
<vendor_url>https://launchpad.net/indicator-cpufreq</vendor_url>
<icon_name>indicator-cpufreq</icon_name>
+ <action id="com.ubuntu.indicatorcpufreqselector.setthrottle">
+ <_description>Change device powersaving settings</_description>
+ <_message>System policy prevents you from changing system throttle.</_message>
+
+ <defaults>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>yes</allow_active>
+ </defaults>
+ </action>
+
<action id="com.ubuntu.indicatorcpufreqselector.setfrequencyscaling">
<_description>Change CPU frequency scaling</_description>
<_message>System policy prevents you from changing CPU frequency scaling.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
- <allow_active>auth_admin_keep</allow_active>
+ <allow_active>yes</allow_active>
+ </defaults>
+ </action>
+
+ <action id="com.ubuntu.indicatorcpufreqselector.setpsturbo">
+ <_description>Change Intel P-State Turbo settings</_description>
+ <_message>System policy prevents you from changing P-State Turbo.</_message>
+
+ <defaults>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>yes</allow_active>
+ </defaults>
+ </action>
+
+ <action id="com.ubuntu.indicatorcpufreqselector.sethyperthreads">
+ <_description>Change hyperthreading settings</_description>
+ <_message>System policy prevents you from changing hyperthreading.</_message>
+
+ <defaults>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>yes</allow_active>
</defaults>
</action>
+
+ <action id="com.ubuntu.indicatorcpufreqselector.setgputhrottle">
+ <_description>Change GPU throttle settings</_description>
+ <_message>System policy prevents you from changing GPU throttle.</_message>
+
+ <defaults>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>yes</allow_active>
+ </defaults>
+ </action>
+
+
</policyconfig>
--- indicator-cpufreq/indicator_cpufreq/indicator.py.orig 2015-09-10 14:46:45.814511000 +0900
+++ indicator-cpufreq/indicator_cpufreq/indicator.py 2015-09-10 14:46:45.989929097 +0900
@@ -29,6 +29,10 @@
from gettext import gettext as _
#gettext.textdomain('indicator-cpufreq')
+
+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)
@@ -50,6 +54,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
@@ -71,28 +84,90 @@
maxcpu += 1
self.cpus = range(maxcpu)
+ # 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()
+ 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())
+
# frequency menu items
#freqs = cpufreq.get_available_frequencies(self.cpus[0])
freqs = reversed(sorted(set(cpufreq.get_available_frequencies(self.cpus[0]))))
+ freqmenu = Gtk.Menu()
+ freqm = Gtk.MenuItem("CPU Frequency")
+ freqm.set_submenu(freqmenu)
for freq in freqs:
menu_item = Gtk.RadioMenuItem.new_with_label(group, readable_frequency(freq))
group = menu_item.get_group()
- menu.append(menu_item)
+ freqmenu.append(menu_item)
menu_item.connect("activate", self.select_activated, 'frequency', freq)
self.select_items[freq] = menu_item
-
- menu.append(Gtk.SeparatorMenuItem())
+ menu.append(freqm)
# governor menu items
governors = cpufreq.get_available_governors(self.cpus[0])
+ govmenu = Gtk.Menu()
+ govm = Gtk.MenuItem("CPU Governor")
+ govm.set_submenu(govmenu)
for governor in governors:
if governor == 'userspace':
continue
menu_item = Gtk.RadioMenuItem.new_with_label(group, readable_governor(governor))
group = menu_item.get_group()
- menu.append(menu_item)
+ govmenu.append(menu_item)
menu_item.connect('activate', self.select_activated, 'governor', governor)
self.select_items[governor] = menu_item
+ menu.append(govm)
+
+ # 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)
@@ -134,9 +209,21 @@
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':
+ if select == 'throttle':
+ proxy.SetThrottle(value,
+ dbus_interface='com.ubuntu.IndicatorCpufreqSelector')
+ elif select == 'frequency':
proxy.SetFrequency(cpus, dbus.UInt32(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,
dbus_interface='com.ubuntu.IndicatorCpufreqSelector')
|