File: cpu_control.go

package info (click to toggle)
snapd 2.71-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 79,536 kB
  • sloc: ansic: 16,114; sh: 16,105; python: 9,941; makefile: 1,890; exp: 190; awk: 40; xml: 22
file content (108 lines) | stat: -rw-r--r-- 4,316 bytes parent folder | download
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
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
 * Copyright (C) 2018 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package builtin

const cpuControlSummary = `allows setting CPU tunables`

const cpuControlBaseDeclarationSlots = `
  cpu-control:
    allow-installation:
      slot-snap-type:
        - core
    deny-auto-connection: true
`

const cpuControlConnectedPlugAppArmor = `
# Description: This interface allows for setting CPU tunables
/sys/devices/system/cpu/**/ r,
/sys/devices/system/cpu/cpu*/online rw,
/sys/devices/system/cpu/smt/*       r,
/sys/devices/system/cpu/smt/control w,

/sys/module/cpu_boost/parameters/input_boost_freq rw,
/sys/module/cpu_boost/parameters/input_boost_ms rw,
/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_min_freq rw,
/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_max_freq rw,
/sys/devices/system/cpu/cpu[0-9]*/core_ctl/min_cpus rw,
/sys/devices/system/cpu/cpu[0-9]*/core_ctl/busy_up_thres rw,
/sys/devices/system/cpu/cpu[0-9]*/core_ctl/busy_down_thres rw,
/sys/devices/system/cpu/cpu[0-9]*/core_ctl/offline_delay_ms rw,
/sys/devices/system/cpu/cpu[0-9]*/core_ctl/task_thres rw,
/sys/devices/system/cpu/cpu[0-9]*/core_ctl/nr_prev_assist_thresh rw,
/sys/devices/system/cpu/cpu[0-9]*/core_ctl/enable rw,

# https://www.kernel.org/doc/html/latest/admin-guide/pm/cpufreq.html#policy-interface-in-sysfs
/sys/devices/system/cpu/cpufreq/{,**} r,
/sys/devices/system/cpu/cpufreq/policy*/energy_performance_preference w,
/sys/devices/system/cpu/cpufreq/policy*/scaling_governor w,
/sys/devices/system/cpu/cpufreq/policy*/scaling_max_freq w,
/sys/devices/system/cpu/cpufreq/policy*/scaling_min_freq w,
/sys/devices/system/cpu/cpufreq/policy*/scaling_setspeed w,
/sys/devices/system/cpu/cpufreq/policy*/schedutil/up_rate_limit_us rw,
/sys/devices/system/cpu/cpufreq/policy*/schedutil/down_rate_limit_us rw,
/sys/devices/system/cpu/cpufreq/policy*/schedutil/hispeed_freq rw,
/sys/devices/system/cpu/cpufreq/policy*/schedutil/pl rw,
/sys/devices/system/cpu/cpufreq/boost w,

# https://www.kernel.org/doc/html/latest/admin-guide/pm/intel_pstate.html#user-space-interface-in-sysfs
/sys/devices/system/cpu/intel_pstate/{,*} r,
/sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost w,
/sys/devices/system/cpu/intel_pstate/max_perf_pct w,
/sys/devices/system/cpu/intel_pstate/min_perf_pct w,
/sys/devices/system/cpu/intel_pstate/no_turbo w,
/sys/devices/system/cpu/intel_pstate/status w,

/proc/sys/kernel/sched_upmigrate rw,
/proc/sys/kernel/sched_downmigrate rw,
/proc/sys/kernel/sched_group_upmigrate rw,
/proc/sys/kernel/sched_group_downmigrate rw,
/proc/sys/kernel/sched_walt_rotate_big_tasks rw,
/proc/sys/kernel/sched_boost rw,

# see https://www.osadl.org/monitoring/add-on-patches/4.16.7-rt1...4.16.15-rt7/sched-add-per-cpu-load-measurement.patch.html
/proc/idleruntime/{all,cpu[0-9]*}/data r,
/proc/idleruntime/{all,cpu[0-9]*}/reset w,

# Allow control CPU C-states switching see: https://docs.kernel.org/power/pm_qos_interface.html#pm-qos-framework
/dev/cpu_dma_latency rw,

# Allow interrupt affinity settings, see https://www.kernel.org/doc/html/latest/core-api/irq/irq-affinity.html
/sys/kernel/irq{/,/[0-9]**} r,
/proc/interrupts r,
/proc/irq/[0-9]*/smp_affinity rwk,
/proc/irq/[0-9]*/smp_affinity_list rwk,
/proc/irq/default_smp_affinity rwk,
`

var cpuControlConnectedPlugUDev = []string{
	`SUBSYSTEM=="misc", KERNEL=="cpu_dma_latency"`,
}

func init() {
	registerIface(&commonInterface{
		name:                  "cpu-control",
		summary:               cpuControlSummary,
		implicitOnCore:        true,
		implicitOnClassic:     true,
		baseDeclarationSlots:  cpuControlBaseDeclarationSlots,
		connectedPlugAppArmor: cpuControlConnectedPlugAppArmor,
		connectedPlugUDev:     cpuControlConnectedPlugUDev,
	})
}