1919#include <linux/sched.h>
2020#include <linux/cpumask.h>
2121#include <linux/cpuset.h>
22+ #include <linux/debugfs.h>
2223#include <linux/mutex.h>
2324#include <linux/sysctl.h>
2425#include <linux/nodemask.h>
@@ -34,50 +35,38 @@ static bool __read_mostly sched_itmt_capable;
3435 * of higher turbo frequency for cpus supporting Intel Turbo Boost Max
3536 * Technology 3.0.
3637 *
37- * It can be set via /proc/ sys/kernel/sched_itmt_enabled
38+ * It can be set via /sys/kernel/debug/x86 /sched_itmt_enabled
3839 */
39- unsigned int __read_mostly sysctl_sched_itmt_enabled ;
40+ bool __read_mostly sysctl_sched_itmt_enabled ;
4041
41- static int sched_itmt_update_handler (struct ctl_table * table , int write ,
42- void * buffer , size_t * lenp , loff_t * ppos )
42+ static ssize_t sched_itmt_enabled_write (struct file * filp ,
43+ const char __user * ubuf ,
44+ size_t cnt , loff_t * ppos )
4345{
44- unsigned int old_sysctl ;
45- int ret ;
46+ ssize_t result ;
47+ bool orig ;
4648
47- mutex_lock (& itmt_update_mutex );
49+ guard ( mutex ) (& itmt_update_mutex );
4850
49- if (!sched_itmt_capable ) {
50- mutex_unlock (& itmt_update_mutex );
51- return - EINVAL ;
52- }
53-
54- old_sysctl = sysctl_sched_itmt_enabled ;
55- ret = proc_dointvec_minmax (table , write , buffer , lenp , ppos );
51+ orig = sysctl_sched_itmt_enabled ;
52+ result = debugfs_write_file_bool (filp , ubuf , cnt , ppos );
5653
57- if (! ret && write && old_sysctl != sysctl_sched_itmt_enabled ) {
54+ if (sysctl_sched_itmt_enabled != orig ) {
5855 x86_topology_update = true;
5956 rebuild_sched_domains ();
6057 }
6158
62- mutex_unlock (& itmt_update_mutex );
63-
64- return ret ;
59+ return result ;
6560}
6661
67- static struct ctl_table itmt_kern_table [] = {
68- {
69- .procname = "sched_itmt_enabled" ,
70- .data = & sysctl_sched_itmt_enabled ,
71- .maxlen = sizeof (unsigned int ),
72- .mode = 0644 ,
73- .proc_handler = sched_itmt_update_handler ,
74- .extra1 = SYSCTL_ZERO ,
75- .extra2 = SYSCTL_ONE ,
76- },
77- {}
62+ static const struct file_operations dfs_sched_itmt_fops = {
63+ .read = debugfs_read_file_bool ,
64+ .write = sched_itmt_enabled_write ,
65+ .open = simple_open ,
66+ .llseek = default_llseek ,
7867};
7968
80- static struct ctl_table_header * itmt_sysctl_header ;
69+ static struct dentry * dfs_sched_itmt ;
8170
8271/**
8372 * sched_set_itmt_support() - Indicate platform supports ITMT
@@ -98,16 +87,18 @@ static struct ctl_table_header *itmt_sysctl_header;
9887 */
9988int sched_set_itmt_support (void )
10089{
101- mutex_lock (& itmt_update_mutex );
90+ guard ( mutex ) (& itmt_update_mutex );
10291
103- if (sched_itmt_capable ) {
104- mutex_unlock (& itmt_update_mutex );
92+ if (sched_itmt_capable )
10593 return 0 ;
106- }
10794
108- itmt_sysctl_header = register_sysctl ("kernel" , itmt_kern_table );
109- if (!itmt_sysctl_header ) {
110- mutex_unlock (& itmt_update_mutex );
95+ dfs_sched_itmt = debugfs_create_file_unsafe ("sched_itmt_enabled" ,
96+ 0644 ,
97+ arch_debugfs_dir ,
98+ & sysctl_sched_itmt_enabled ,
99+ & dfs_sched_itmt_fops );
100+ if (IS_ERR_OR_NULL (dfs_sched_itmt )) {
101+ dfs_sched_itmt = NULL ;
111102 return - ENOMEM ;
112103 }
113104
@@ -118,8 +109,6 @@ int sched_set_itmt_support(void)
118109 x86_topology_update = true;
119110 rebuild_sched_domains ();
120111
121- mutex_unlock (& itmt_update_mutex );
122-
123112 return 0 ;
124113}
125114
@@ -135,27 +124,22 @@ int sched_set_itmt_support(void)
135124 */
136125void sched_clear_itmt_support (void )
137126{
138- mutex_lock (& itmt_update_mutex );
127+ guard ( mutex ) (& itmt_update_mutex );
139128
140- if (!sched_itmt_capable ) {
141- mutex_unlock (& itmt_update_mutex );
129+ if (!sched_itmt_capable )
142130 return ;
143- }
131+
144132 sched_itmt_capable = false;
145133
146- if (itmt_sysctl_header ) {
147- unregister_sysctl_table (itmt_sysctl_header );
148- itmt_sysctl_header = NULL ;
149- }
134+ debugfs_remove (dfs_sched_itmt );
135+ dfs_sched_itmt = NULL ;
150136
151137 if (sysctl_sched_itmt_enabled ) {
152138 /* disable sched_itmt if we are no longer ITMT capable */
153139 sysctl_sched_itmt_enabled = 0 ;
154140 x86_topology_update = true;
155141 rebuild_sched_domains ();
156142 }
157-
158- mutex_unlock (& itmt_update_mutex );
159143}
160144
161145int arch_asym_cpu_priority (int cpu )
0 commit comments