04/12 - ckrm_tasksupport
Adds logic to support adding/removing task to/from a class
Provides interface to set a task's class
--
Signed-Off-By: Chandra Seetharaman <[EMAIL PROTECTED]>
Signed-Off-By: Matt Helsley <[EMAIL PROTECTED]>
include/linux/ckrm.h | 1
include/linux/sched.h | 4 +
kernel/ckrm/Makefile | 2
kernel/ckrm/ckrm.c | 23 +++++++++
kernel/ckrm/ckrm_task.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 140 insertions(+), 1 deletion(-)
Index: linux-2.6.16/include/linux/ckrm.h
===================================================================
--- linux-2.6.16.orig/include/linux/ckrm.h
+++ linux-2.6.16/include/linux/ckrm.h
@@ -112,5 +112,6 @@ extern void ckrm_release_class(struct kr
list_for_each_entry(child, &parent->children, siblings)
extern void ckrm_teardown(void);
+extern void ckrm_setclass(struct task_struct *, struct ckrm_class *);
#endif /* CONFIG_CKRM */
#endif /* _LINUX_CKRM_H */
Index: linux-2.6.16/include/linux/sched.h
===================================================================
--- linux-2.6.16.orig/include/linux/sched.h
+++ linux-2.6.16/include/linux/sched.h
@@ -871,6 +871,10 @@ struct task_struct {
#endif
atomic_t fs_excl; /* holding fs exclusive resources */
struct rcu_head rcu;
+#ifdef CONFIG_CKRM
+ struct ckrm_class *class;
+ struct list_head member_list; /* list of tasks in class */
+#endif /* CONFIG_CKRM */
};
static inline pid_t process_group(struct task_struct *tsk)
Index: linux-2.6.16/kernel/ckrm/ckrm_task.c
===================================================================
--- /dev/null
+++ linux-2.6.16/kernel/ckrm/ckrm_task.c
@@ -0,0 +1,111 @@
+/* ckrm_task.c - Class-based Kernel Resource Management (CKRM)
+ *
+ * Copyright (C) Hubertus Franke, IBM Corp. 2003,2004
+ * (C) Shailabh Nagar, IBM Corp. 2003
+ * (C) Chandra Seetharaman, IBM Corp. 2003, 2004, 2005
+ * (C) Vivek Kashyap, IBM Corp. 2004
+ *
+ * Latest version, more details at http://ckrm.sf.net
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+#include <linux/sched.h>
+#include <linux/ckrm_rc.h>
+
+static inline struct ckrm_class *remove_from_old_class(struct task_struct *tsk)
+{
+ struct ckrm_class *class;
+
+retry:
+ class = tsk->class;
+ if (class == CKRM_NO_CLASS)
+ goto done;
+
+ spin_lock(&class->class_lock);
+ if (class != tsk->class) { /* lost the race, retry */
+ spin_unlock(&class->class_lock);
+ goto retry;
+ }
+ /* take out of old class */
+ list_del_init(&tsk->member_list);
+ tsk->class = CKRM_NO_CLASS;
+ spin_unlock(&class->class_lock);
+done:
+ return class;
+}
+
+static void move_to_new_class(struct task_struct *tsk,
+ struct ckrm_class *newclass)
+{
+ BUG_ON(!list_empty(&tsk->member_list));
+ BUG_ON(tsk->class != CKRM_NO_CLASS);
+
+ spin_lock(&newclass->class_lock);
+ tsk->class = newclass;
+ list_add(&tsk->member_list, &newclass->task_list);
+ spin_unlock(&newclass->class_lock);
+}
+
+static void notify_res_ctlrs(struct task_struct *tsk,
+ struct ckrm_class *oldclass, struct ckrm_class *newclass)
+{
+ int i;
+ struct ckrm_controller *ctlr;
+ struct ckrm_shares *old_shares, *new_shares;
+
+ for (i = 0; i < CKRM_MAX_RES_CTLRS; i++) {
+ ctlr = ckrm_get_controller_by_id(i);
+ if (ctlr == NULL)
+ continue;
+ if (ctlr->move_task) {
+ old_shares = ckrm_get_controller_shares(oldclass, ctlr);
+ new_shares = ckrm_get_controller_shares(newclass, ctlr);
+ ctlr->move_task(tsk, old_shares, new_shares);
+ }
+ ckrm_put_controller(ctlr);
+ }
+}
+
+/*
+ * Change the class of the given task to "newclass"
+ *
+ * Caller is responsible to make sure the task structure stays put
+ * through this function.
+ *
+ * This function should be called without holding class_lock of
+ * newclass and tsk->class.
+ *
+ * Called with a reference to the new class held. The reference is
+ * dropped only when the task is assigned to a different class
+ * or when the task exits.
+ */
+void ckrm_setclass(struct task_struct *tsk, struct ckrm_class *newclass)
+{
+ struct ckrm_class *oldclass;
+
+retry:
+ oldclass = remove_from_old_class(tsk);
+
+ /* The task is either exiting or is moving to a different class. */
+ if (oldclass == CKRM_NO_CLASS) {
+ /* In the exit path, must succeed */
+ if (newclass == CKRM_NO_CLASS)
+ goto retry;
+ kref_put(&newclass->ref, ckrm_release_class);
+ return;
+ }
+
+ /*
+ * notify resource controllers before we actually set the class
+ * in the task to avoid a race with notify_res_ctlrs being called
+ * from another ckrm_setclass.
+ */
+ notify_res_ctlrs(tsk, oldclass, newclass);
+ if (newclass != CKRM_NO_CLASS)
+ move_to_new_class(tsk, newclass);
+ kref_put(&oldclass->ref, ckrm_release_class);
+}
Index: linux-2.6.16/kernel/ckrm/Makefile
===================================================================
--- linux-2.6.16.orig/kernel/ckrm/Makefile
+++ linux-2.6.16/kernel/ckrm/Makefile
@@ -1 +1 @@
-obj-y = ckrm.o ckrm_shares.o
+obj-y = ckrm.o ckrm_shares.o ckrm_task.o
Index: linux-2.6.16/kernel/ckrm/ckrm.c
===================================================================
--- linux-2.6.16.orig/kernel/ckrm/ckrm.c
+++ linux-2.6.16/kernel/ckrm/ckrm.c
@@ -255,6 +255,26 @@ static int ckrm_register_controller_inte
}
/*
+ * Helper function to move all tasks in a class to/from the registering
+ * /unregistering resource controller.
+ *
+ * Assumes ctlr is valid and class is initialized with resource
+ * controller's shares.
+ */
+static void move_tasks(struct ckrm_class *class, struct ckrm_controller *ctlr,
+ struct ckrm_shares *from, struct ckrm_shares *to)
+{
+ struct task_struct *tsk;
+
+ if (!ctlr->move_task)
+ return;
+ spin_lock(&class->class_lock);
+ list_for_each_entry(tsk, &class->task_list, member_list)
+ ctlr->move_task(tsk, from, to);
+ spin_unlock(&class->class_lock);
+}
+
+/*
* Interface for registering a resource controller.
*
* Returns the 0 on success, -errno for failure.
@@ -289,6 +309,8 @@ int ckrm_register_controller(struct ckrm
kref_get(&class->ref);
read_unlock(&ckrm_class_lock);
do_alloc_shares_struct(class, ctlr);
+ move_tasks(class, ctlr, CKRM_NO_SHARE,
+ class->shares[ctlr->ctlr_id]);
if (prev_class)
kref_put(&prev_class->ref, ckrm_release_class);
prev_class = class;
@@ -323,6 +345,7 @@ int ckrm_unregister_controller(struct ck
list_for_each_entry_reverse(class, &ckrm_classes, class_list) {
kref_get(&class->ref);
read_unlock(&ckrm_class_lock);
+ move_tasks(class, ctlr, class->shares[ctlr_id], CKRM_NO_SHARE);
do_free_shares_struct(class, ctlr);
if (prev_class)
kref_put(&prev_class->ref, ckrm_release_class);
--
----------------------------------------------------------------------
Chandra Seetharaman | Be careful what you choose....
- [EMAIL PROTECTED] | .......you may get it.
----------------------------------------------------------------------
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
ckrm-tech mailing list
https://lists.sourceforge.net/lists/listinfo/ckrm-tech