[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20a49e36e1efc99b1489d81eb7b5fe8787fcee4c.1748594840.git.libo.gcs85@bytedance.com>
Date: Fri, 30 May 2025 17:27:40 +0800
From: Bo Li <libo.gcs85@...edance.com>
To: tglx@...utronix.de,
mingo@...hat.com,
bp@...en8.de,
dave.hansen@...ux.intel.com,
x86@...nel.org,
luto@...nel.org,
kees@...nel.org,
akpm@...ux-foundation.org,
david@...hat.com,
juri.lelli@...hat.com,
vincent.guittot@...aro.org,
peterz@...radead.org
Cc: dietmar.eggemann@....com,
hpa@...or.com,
acme@...nel.org,
namhyung@...nel.org,
mark.rutland@....com,
alexander.shishkin@...ux.intel.com,
jolsa@...nel.org,
irogers@...gle.com,
adrian.hunter@...el.com,
kan.liang@...ux.intel.com,
viro@...iv.linux.org.uk,
brauner@...nel.org,
jack@...e.cz,
lorenzo.stoakes@...cle.com,
Liam.Howlett@...cle.com,
vbabka@...e.cz,
rppt@...nel.org,
surenb@...gle.com,
mhocko@...e.com,
rostedt@...dmis.org,
bsegall@...gle.com,
mgorman@...e.de,
vschneid@...hat.com,
jannh@...gle.com,
pfalcato@...e.de,
riel@...riel.com,
harry.yoo@...cle.com,
linux-kernel@...r.kernel.org,
linux-perf-users@...r.kernel.org,
linux-fsdevel@...r.kernel.org,
linux-mm@...ck.org,
duanxiongchun@...edance.com,
yinhongbo@...edance.com,
dengliang.1214@...edance.com,
xieyongji@...edance.com,
chaiwen.cc@...edance.com,
songmuchun@...edance.com,
yuanzhu@...edance.com,
chengguozhu@...edance.com,
sunjiadong.lff@...edance.com,
Bo Li <libo.gcs85@...edance.com>
Subject: [RFC v2 12/35] RPAL: enable service disable notification
When a service is disabled, all services that request this service need
to be notified.
This patch use poll functions of file to implement such notification.
When a service is disabled, it will notify all services that request it
by set bit in others services' dead_key_bitmap. And the poll function
will then issue a poll epoll event, other services can aware the service
has been disabled.
The key of disabled service can be read from the proc file.
Signed-off-by: Bo Li <libo.gcs85@...edance.com>
---
arch/x86/rpal/proc.c | 61 +++++++++++++++++++++++++++++++++++++++++
arch/x86/rpal/service.c | 37 +++++++++++++++++++++++--
include/linux/rpal.h | 10 +++++++
3 files changed, 106 insertions(+), 2 deletions(-)
diff --git a/arch/x86/rpal/proc.c b/arch/x86/rpal/proc.c
index f001afd40562..16ac9612bfc5 100644
--- a/arch/x86/rpal/proc.c
+++ b/arch/x86/rpal/proc.c
@@ -8,6 +8,7 @@
#include <linux/rpal.h>
#include <linux/proc_fs.h>
+#include <linux/poll.h>
#include "internal.h"
@@ -82,10 +83,70 @@ static long rpal_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
return ret;
}
+static ssize_t rpal_read(struct file *file, char __user *buf, size_t count,
+ loff_t *pos)
+{
+ struct rpal_service *cur = rpal_current_service();
+ struct rpal_poll_data *rpd;
+ u64 released_keys[MAX_REQUEST_SERVICE];
+ unsigned long flags;
+ int nr_key = 0;
+ int nr_byte = 0;
+ int idx;
+
+ if (!cur)
+ return -EINVAL;
+
+ rpd = &cur->rpd;
+
+ spin_lock_irqsave(&rpd->poll_lock, flags);
+ idx = find_first_bit(rpd->dead_key_bitmap, RPAL_NR_ID);
+ while (idx < RPAL_NR_ID) {
+ released_keys[nr_key++] = rpd->dead_keys[idx];
+ idx = find_next_bit(rpd->dead_key_bitmap, RPAL_NR_ID, idx + 1);
+ }
+ spin_unlock_irqrestore(&rpd->poll_lock, flags);
+ nr_byte = nr_key * sizeof(u64);
+
+ if (copy_to_user(buf, released_keys, nr_byte)) {
+ nr_byte = -EAGAIN;
+ goto out;
+ }
+out:
+ return nr_byte;
+}
+
+static __poll_t rpal_poll(struct file *filep, struct poll_table_struct *wait)
+{
+ struct rpal_service *cur = rpal_current_service();
+ struct rpal_poll_data *rpd;
+ unsigned long flags;
+ __poll_t mask = 0;
+
+ if (unlikely(!cur)) {
+ rpal_err("Not a rpal service\n");
+ goto out;
+ }
+
+ rpd = &cur->rpd;
+
+ poll_wait(filep, &rpd->rpal_waitqueue, wait);
+
+ spin_lock_irqsave(&rpd->poll_lock, flags);
+ if (find_first_bit(rpd->dead_key_bitmap, RPAL_NR_ID) < RPAL_NR_ID)
+ mask |= EPOLLIN | EPOLLRDNORM;
+ spin_unlock_irqrestore(&rpd->poll_lock, flags);
+
+out:
+ return mask;
+}
+
const struct proc_ops proc_rpal_operations = {
.proc_open = rpal_open,
+ .proc_read = rpal_read,
.proc_ioctl = rpal_ioctl,
.proc_mmap = rpal_mmap,
+ .proc_poll = rpal_poll,
};
static int __init proc_rpal_init(void)
diff --git a/arch/x86/rpal/service.c b/arch/x86/rpal/service.c
index 16a2155873a1..f490ab07301d 100644
--- a/arch/x86/rpal/service.c
+++ b/arch/x86/rpal/service.c
@@ -181,6 +181,9 @@ struct rpal_service *rpal_register_service(void)
atomic_set(&rs->req_avail_cnt, MAX_REQUEST_SERVICE);
bitmap_zero(rs->requested_service_bitmap, RPAL_NR_ID);
spin_lock_init(&rs->lock);
+ spin_lock_init(&rs->rpd.poll_lock);
+ bitmap_zero(rs->rpd.dead_key_bitmap, RPAL_NR_ID);
+ init_waitqueue_head(&rs->rpd.rpal_waitqueue);
rs->bad_service = false;
rs->base = calculate_base_address(rs->id);
@@ -296,6 +299,7 @@ static void remove_mapped_service(struct rpal_service *rs, int id, int type_bit)
clear_bit(type_bit, &node->type);
if (type_bit == RPAL_REQUEST_MAP) {
+ clear_bit(id, rs->rpd.dead_key_bitmap);
clear_requested_service_bitmap(rs, id);
atomic_inc(&rs->req_avail_cnt);
}
@@ -424,15 +428,30 @@ static int release_service(struct rpal_service *cur, struct rpal_service *tgt)
return 0;
}
+static void rpal_notify_disable(struct rpal_poll_data *rpd, u64 key, int id)
+{
+ unsigned long flags;
+ bool need_wake = false;
+
+ spin_lock_irqsave(&rpd->poll_lock, flags);
+ if (!test_bit(id, rpd->dead_key_bitmap)) {
+ need_wake = true;
+ rpd->dead_keys[id] = key;
+ set_bit(id, rpd->dead_key_bitmap);
+ }
+ spin_unlock_irqrestore(&rpd->poll_lock, flags);
+ if (need_wake)
+ wake_up_interruptible(&rpd->rpal_waitqueue);
+}
+
static void rpal_release_service_all(void)
{
struct rpal_service *cur = rpal_current_service();
struct rpal_service *tgt;
+ struct rpal_mapped_service *node;
int ret, i;
rpal_for_each_requested_service(cur, i) {
- struct rpal_mapped_service *node;
-
if (i == cur->id)
continue;
node = rpal_get_mapped_node(cur, i);
@@ -449,6 +468,20 @@ static void rpal_release_service_all(void)
}
rpal_put_service(tgt);
}
+
+ for (i = 0; i < RPAL_NR_ID; i++) {
+ if (i == cur->id)
+ continue;
+
+ node = rpal_get_mapped_node(cur, i);
+ tgt = rpal_get_service(node->rs);
+ if (!tgt)
+ continue;
+
+ if (test_bit(RPAL_REVERSE_MAP, &node->type))
+ rpal_notify_disable(&tgt->rpd, cur->key, cur->id);
+ rpal_put_service(tgt);
+ }
}
int rpal_release_service(u64 key)
diff --git a/include/linux/rpal.h b/include/linux/rpal.h
index 1fe177523a36..b9622f0235bf 100644
--- a/include/linux/rpal.h
+++ b/include/linux/rpal.h
@@ -107,6 +107,13 @@ struct rpal_mapped_service {
struct rpal_service *rs;
};
+struct rpal_poll_data {
+ spinlock_t poll_lock;
+ u64 dead_keys[RPAL_NR_ID];
+ DECLARE_BITMAP(dead_key_bitmap, RPAL_NR_ID);
+ wait_queue_head_t rpal_waitqueue;
+};
+
/*
* Each RPAL process (a.k.a RPAL service) should have a pointer to
* struct rpal_service in all its tasks' task_struct.
@@ -161,6 +168,9 @@ struct rpal_service {
struct rpal_mapped_service service_map[RPAL_NR_ID];
DECLARE_BITMAP(requested_service_bitmap, RPAL_NR_ID);
+ /* Notify service is released by others */
+ struct rpal_poll_data rpd;
+
/* delayed service put work */
struct delayed_work delayed_put_work;
--
2.20.1
Powered by blists - more mailing lists