[PATCH 10/30] dept: Introduce split map concept and new APIs for them
Gwan-gyeong Mun
gwan-gyeong.mun at intel.com
Mon Nov 21 09:54:42 UTC 2022
From: Byungchul Park <byungchul.park at lge.com>
There is a case where total maps for its wait/event is so large in size.
For instance, struct page for PG_locked and PG_writeback is the case.
The additional memory size for the maps would be 'the # of pages *
sizeof(struct dept_map)' if each struct page keeps its map all the way,
which might be too big to accept in some systems.
It'd better have split map. One is for each instance and the other is
for what is commonly used. So split map and added new APIs for them.
Signed-off-by: Byungchul Park <byungchul.park at lge.com>
Signed-off-by: Gwan-gyeong Mun <gwan-gyeong.mun at intel.com>
---
include/linux/dept.h | 36 ++++++++++
kernel/dependency/dept.c | 148 +++++++++++++++++++++++++++++++++++++++
2 files changed, 184 insertions(+)
diff --git a/include/linux/dept.h b/include/linux/dept.h
index d58b2b9f0e6d..35be7ebd27a1 100644
--- a/include/linux/dept.h
+++ b/include/linux/dept.h
@@ -367,6 +367,30 @@ struct dept_map {
.nocheck = false, \
}
+struct dept_map_each {
+ /*
+ * wait timestamp associated to this map
+ */
+ unsigned int wgen;
+};
+
+struct dept_map_common {
+ const char *name;
+ struct dept_key *keys;
+ int sub_usr;
+
+ /*
+ * It's local copy for fast acces to the associated classes. And
+ * Also used for dept_key instance for statically defined map.
+ */
+ struct dept_key keys_local;
+
+ /*
+ * whether this map should be going to be checked or not
+ */
+ bool nocheck;
+};
+
struct dept_task {
/*
* all event contexts that have entered and before exiting
@@ -475,6 +499,11 @@ extern void dept_ecxt_enter(struct dept_map *m, unsigned long e_f, unsigned long
extern void dept_ask_event(struct dept_map *m);
extern void dept_event(struct dept_map *m, unsigned long e_f, unsigned long ip, const char *e_fn);
extern void dept_ecxt_exit(struct dept_map *m, unsigned long e_f, unsigned long ip);
+extern void dept_split_map_each_init(struct dept_map_each *me);
+extern void dept_split_map_common_init(struct dept_map_common *mc, struct dept_key *k, const char *n);
+extern void dept_wait_split_map(struct dept_map_each *me, struct dept_map_common *mc, unsigned long ip, const char *w_fn, int ne);
+extern void dept_event_split_map(struct dept_map_each *me, struct dept_map_common *mc, unsigned long ip, const char *e_fn);
+extern void dept_ask_event_split_map(struct dept_map_each *me, struct dept_map_common *mc);
static inline void dept_ecxt_enter_nokeep(struct dept_map *m)
{
@@ -497,6 +526,8 @@ extern void dept_enirq_transition(unsigned long ip);
#else /* !CONFIG_DEPT */
struct dept_key { };
struct dept_map { };
+struct dept_map_each { };
+struct dept_map_commmon { };
struct dept_task { };
#define DEPT_MAP_INITIALIZER(n) { }
@@ -521,6 +552,11 @@ struct dept_task { };
#define dept_ask_event(m) do { } while (0)
#define dept_event(m, e_f, ip, e_fn) do { (void)(e_fn); } while (0)
#define dept_ecxt_exit(m, e_f, ip) do { } while (0)
+#define dept_split_map_each_init(me) do { } while (0)
+#define dept_split_map_common_init(mc, k, n) do { (void)(n); (void)(k); } while (0)
+#define dept_wait_split_map(me, mc, ip, w_fn, ne) do { } while (0)
+#define dept_event_split_map(me, mc, ip, e_fn) do { } while (0)
+#define dept_ask_event_split_map(me, mc) do { } while (0)
#define dept_ecxt_enter_nokeep(m) do { } while (0)
#define dept_key_init(k) do { (void)(k); } while (0)
#define dept_key_destroy(k) do { (void)(k); } while (0)
diff --git a/kernel/dependency/dept.c b/kernel/dependency/dept.c
index bf315ac14e18..06281d6e5a97 100644
--- a/kernel/dependency/dept.c
+++ b/kernel/dependency/dept.c
@@ -2457,6 +2457,154 @@ void dept_ecxt_exit(struct dept_map *m, unsigned long e_f,
}
EXPORT_SYMBOL_GPL(dept_ecxt_exit);
+void dept_split_map_each_init(struct dept_map_each *me)
+{
+ unsigned long flags;
+
+ if (unlikely(!dept_working()))
+ return;
+
+ /*
+ * Allow recursive entrance.
+ */
+ flags = dept_enter_recursive();
+
+ me->wgen = 0U;
+
+ dept_exit_recursive(flags);
+}
+EXPORT_SYMBOL_GPL(dept_split_map_each_init);
+
+void dept_split_map_common_init(struct dept_map_common *mc,
+ struct dept_key *k, const char *n)
+{
+ unsigned long flags;
+
+ if (unlikely(!dept_working())) {
+ mc->nocheck = true;
+ return;
+ }
+
+ /*
+ * Allow recursive entrance.
+ */
+ flags = dept_enter_recursive();
+
+ clean_classes_cache(&mc->keys_local);
+
+ /*
+ * sub_usr is not used with split map.
+ */
+ mc->sub_usr = 0;
+ mc->keys = k;
+ mc->name = n;
+ mc->nocheck = false;
+
+ dept_exit_recursive(flags);
+}
+EXPORT_SYMBOL_GPL(dept_split_map_common_init);
+
+void dept_wait_split_map(struct dept_map_each *me,
+ struct dept_map_common *mc,
+ unsigned long ip, const char *w_fn, int ne)
+{
+ struct dept_task *dt = dept_task();
+ struct dept_class *c;
+ struct dept_key *k;
+ unsigned long flags;
+
+ if (unlikely(!dept_working()))
+ return;
+
+ if (dt->recursive)
+ return;
+
+ if (mc->nocheck)
+ return;
+
+ flags = dept_enter();
+
+ k = mc->keys ?: &mc->keys_local;
+ c = check_new_class(&mc->keys_local, k, 0, mc->name);
+ if (c)
+ add_wait(c, ip, w_fn, ne);
+
+ dept_exit(flags);
+}
+EXPORT_SYMBOL_GPL(dept_wait_split_map);
+
+void dept_ask_event_split_map(struct dept_map_each *me,
+ struct dept_map_common *mc)
+{
+ unsigned int wg;
+ unsigned long flags;
+
+ if (unlikely(!dept_working()))
+ return;
+
+ if (mc->nocheck)
+ return;
+
+ /*
+ * Allow recursive entrance.
+ */
+ flags = dept_enter_recursive();
+
+ /*
+ * Avoid zero wgen.
+ */
+ wg = atomic_inc_return(&wgen) ?: atomic_inc_return(&wgen);
+ WRITE_ONCE(me->wgen, wg);
+
+ dept_exit_recursive(flags);
+}
+EXPORT_SYMBOL_GPL(dept_ask_event_split_map);
+
+void dept_event_split_map(struct dept_map_each *me,
+ struct dept_map_common *mc,
+ unsigned long ip, const char *e_fn)
+{
+ struct dept_task *dt = dept_task();
+ struct dept_class *c;
+ struct dept_key *k;
+ unsigned long flags;
+
+ if (unlikely(!dept_working()))
+ return;
+
+ if (dt->recursive) {
+ /*
+ * Dept won't work with this map even though anyway an
+ * event has been just triggered. Don't make it confused
+ * at that time handling the next event. Disable it
+ * until the next real case.
+ */
+ WRITE_ONCE(me->wgen, 0U);
+ return;
+ }
+
+ if (mc->nocheck)
+ return;
+
+ flags = dept_enter();
+
+ k = mc->keys ?: &mc->keys_local;
+ c = check_new_class(&mc->keys_local, k, 0, mc->name);
+
+ if (c && add_ecxt((void *)me, c, 0UL, NULL, e_fn, 0)) {
+ do_event((void *)me, c, READ_ONCE(me->wgen), ip);
+ pop_ecxt((void *)me, c);
+ }
+
+ /*
+ * Keep the map diabled until the next sleep.
+ */
+ WRITE_ONCE(me->wgen, 0U);
+
+ dept_exit(flags);
+}
+EXPORT_SYMBOL_GPL(dept_event_split_map);
+
void dept_task_exit(struct task_struct *t)
{
struct dept_task *dt = &t->dept_task;
--
2.37.1
More information about the Intel-gfx-trybot
mailing list