summaryrefslogtreecommitdiff
path: root/kernel/delayacct.c
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2021-05-10 14:01:00 +0200
committerPeter Zijlstra <peterz@infradead.org>2021-05-12 11:43:25 +0200
commit0cd7c741f01de13dc1eecf22557593b3514639bb (patch)
tree9d1031e2a5e08dc9d45a6670f4d8e6171be8864c /kernel/delayacct.c
parente4042ad492357fa995921376462b04a025dd53b6 (diff)
delayacct: Add sysctl to enable at runtime
Just like sched_schedstats, allow runtime enabling (and disabling) of delayacct. This is useful if one forgot to add the delayacct boot time option. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/YJkhebGJAywaZowX@hirez.programming.kicks-ass.net
Diffstat (limited to 'kernel/delayacct.c')
-rw-r--r--kernel/delayacct.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/kernel/delayacct.c b/kernel/delayacct.c
index 3f086903b295..51530d5b15a8 100644
--- a/kernel/delayacct.c
+++ b/kernel/delayacct.c
@@ -18,6 +18,17 @@ DEFINE_STATIC_KEY_FALSE(delayacct_key);
int delayacct_on __read_mostly; /* Delay accounting turned on/off */
struct kmem_cache *delayacct_cache;
+static void set_delayacct(bool enabled)
+{
+ if (enabled) {
+ static_branch_enable(&delayacct_key);
+ delayacct_on = 1;
+ } else {
+ delayacct_on = 0;
+ static_branch_disable(&delayacct_key);
+ }
+}
+
static int __init delayacct_setup_enable(char *str)
{
delayacct_on = 1;
@@ -29,9 +40,30 @@ void delayacct_init(void)
{
delayacct_cache = KMEM_CACHE(task_delay_info, SLAB_PANIC|SLAB_ACCOUNT);
delayacct_tsk_init(&init_task);
- if (delayacct_on)
- static_branch_enable(&delayacct_key);
+ set_delayacct(delayacct_on);
+}
+
+#ifdef CONFIG_PROC_SYSCTL
+int sysctl_delayacct(struct ctl_table *table, int write, void *buffer,
+ size_t *lenp, loff_t *ppos)
+{
+ int state = delayacct_on;
+ struct ctl_table t;
+ int err;
+
+ if (write && !capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ t = *table;
+ t.data = &state;
+ err = proc_dointvec_minmax(&t, write, buffer, lenp, ppos);
+ if (err < 0)
+ return err;
+ if (write)
+ set_delayacct(state);
+ return err;
}
+#endif
void __delayacct_tsk_init(struct task_struct *tsk)
{