A trigger on one of the /proc/pressure files has a wait queue of its
own for its poller, the cgroup pressure files use the queue of their
kernfs node through kernfs_generic_poll() and kernfs_notify(). procfs
owns the queue of its pressure files now, so use it the same way: the
poll_wait() is procfs', and a trigger that fires wakes the pollers of
its file with proc_poll_notify(). Like for the cgroup files every
poller of the file is woken when any trigger on it fires, and each
reports the state of its own trigger. psi_trigger_poll() doesn't need
the file anymore.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 include/linux/psi.h       |  3 +--
 include/linux/psi_types.h |  8 +++++---
 kernel/cgroup/cgroup.c    |  2 +-
 kernel/sched/psi.c        | 30 +++++++++++++++++-------------
 4 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/include/linux/psi.h b/include/linux/psi.h
index 7966e3ac03b9..c6f536631411 100644
--- a/include/linux/psi.h
+++ b/include/linux/psi.h
@@ -30,8 +30,7 @@ struct psi_trigger *psi_trigger_create(struct psi_group 
*group, char *buf,
 int psi_trigger_create_rtpoll_worker(struct psi_group *group);
 void psi_trigger_destroy(struct psi_trigger *t);
 
-__poll_t psi_trigger_poll(void **trigger_ptr, struct file *file,
-                       poll_table *wait);
+__poll_t psi_trigger_poll(void **trigger_ptr, poll_table *wait);
 
 #ifdef CONFIG_CGROUPS
 static inline struct psi_group *cgroup_psi(struct cgroup *cgrp)
diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h
index dd10c22299ab..ce772575c5da 100644
--- a/include/linux/psi_types.h
+++ b/include/linux/psi_types.h
@@ -8,6 +8,8 @@
 #include <linux/kref.h>
 #include <linux/wait.h>
 
+struct proc_dir_entry;
+
 #ifdef CONFIG_PSI
 
 /* Tracked task states */
@@ -132,12 +134,12 @@ struct psi_trigger {
        /* Backpointer needed during trigger destruction */
        struct psi_group *group;
 
-       /* Wait queue for polling */
-       wait_queue_head_t event_wait;
-
        /* Kernfs file for cgroup triggers */
        struct kernfs_open_file *of;
 
+       /* /proc/pressure file for system triggers, see proc_poll_notify() */
+       struct proc_dir_entry *pde;
+
        /* Pending event flag */
        int event;
 
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index a284225f8dc9..c5da33495ae3 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -4232,7 +4232,7 @@ static __poll_t cgroup_pressure_poll(struct 
kernfs_open_file *of,
 {
        struct cgroup_file_ctx *ctx = of->priv;
 
-       return psi_trigger_poll(&ctx->psi.trigger, of->file, pt);
+       return psi_trigger_poll(&ctx->psi.trigger, pt);
 }
 
 static void cgroup_pressure_release(struct kernfs_open_file *of)
diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index cdb7a832333a..97b5e2488106 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -514,7 +514,7 @@ static void update_triggers(struct psi_group *group, u64 
now,
                        if (t->of)
                                kernfs_notify(t->of->kn);
                        else
-                               wake_up_interruptible(&t->event_wait);
+                               proc_poll_notify(t->pde);
                }
                t->last_event_time = now;
                /* Reset threshold breach flag once event got generated */
@@ -1327,6 +1327,9 @@ int psi_trigger_create_rtpoll_worker(struct psi_group 
*group)
        return 0;
 }
 
+/* the /proc/pressure files, see psi_proc_init() */
+static struct proc_dir_entry *psi_proc_entry[NR_PSI_RESOURCES];
+
 struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf,
                                       enum psi_res res, struct file *file,
                                       struct kernfs_open_file *of,
@@ -1392,8 +1395,7 @@ struct psi_trigger *psi_trigger_create(struct psi_group 
*group, char *buf,
        t->event = 0;
        t->last_event_time = 0;
        t->of = of;
-       if (!of)
-               init_waitqueue_head(&t->event_wait);
+       t->pde = of ? NULL : psi_proc_entry[res];
        t->pending_event = false;
        t->aggregator = privileged ? PSI_POLL : PSI_AVGS;
 
@@ -1441,7 +1443,7 @@ void psi_trigger_destroy(struct psi_trigger *t)
        if (t->of)
                kernfs_notify(t->of->kn);
        else
-               wake_up_interruptible(&t->event_wait);
+               proc_poll_notify(t->pde);
 
        if (t->aggregator == PSI_AVGS) {
                mutex_lock(&group->avgs_lock);
@@ -1495,8 +1497,7 @@ void psi_trigger_destroy(struct psi_trigger *t)
        kfree(t);
 }
 
-__poll_t psi_trigger_poll(void **trigger_ptr,
-                               struct file *file, poll_table *wait)
+__poll_t psi_trigger_poll(void **trigger_ptr, poll_table *wait)
 {
        __poll_t ret = DEFAULT_POLLMASK;
        struct psi_trigger *t;
@@ -1508,10 +1509,9 @@ __poll_t psi_trigger_poll(void **trigger_ptr,
        if (!t)
                return DEFAULT_POLLMASK | EPOLLERR | EPOLLPRI;
 
+       /* a /proc/pressure file is polled on the queue procfs owns for it */
        if (t->of)
                kernfs_generic_poll(t->of, wait);
-       else
-               poll_wait(file, &t->event_wait, wait);
 
        if (cmpxchg(&t->event, 1, 0) == 1)
                ret |= EPOLLPRI;
@@ -1610,7 +1610,7 @@ static __poll_t psi_fop_poll(struct file *file, 
poll_table *wait)
 {
        struct seq_file *seq = file->private_data;
 
-       return psi_trigger_poll(&seq->private, file, wait);
+       return psi_trigger_poll(&seq->private, wait);
 }
 
 static int psi_fop_release(struct inode *inode, struct file *file)
@@ -1670,11 +1670,15 @@ static int __init psi_proc_init(void)
 {
        if (psi_enable) {
                proc_mkdir("pressure", NULL);
-               proc_create("pressure/io", 0666, NULL, &psi_io_proc_ops);
-               proc_create("pressure/memory", 0666, NULL, 
&psi_memory_proc_ops);
-               proc_create("pressure/cpu", 0666, NULL, &psi_cpu_proc_ops);
+               psi_proc_entry[PSI_IO] = proc_create("pressure/io", 0666, NULL,
+                                                    &psi_io_proc_ops);
+               psi_proc_entry[PSI_MEM] = proc_create("pressure/memory", 0666,
+                                                     NULL, 
&psi_memory_proc_ops);
+               psi_proc_entry[PSI_CPU] = proc_create("pressure/cpu", 0666, 
NULL,
+                                                     &psi_cpu_proc_ops);
 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
-               proc_create("pressure/irq", 0666, NULL, &psi_irq_proc_ops);
+               psi_proc_entry[PSI_IRQ] = proc_create("pressure/irq", 0666, 
NULL,
+                                                     &psi_irq_proc_ops);
 #endif
        }
        return 0;

-- 
2.53.0

Reply via email to