[Devel] [PATCH 12/13] BC: numtasks accounting

Kirill Korotaev dev at sw.ru
Thu Nov 9 09:09:22 PST 2006


Beautifull tasks accounting/limiting beancounter control.

Signed-off-by: Pavel Emelianov <xemul at sw.ru>
Signed-off-by: Kirill Korotaev <dev at sw.ru>

---

 include/linux/sched.h |    1 +
 kernel/bc/misc.c      |   31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

--- ./include/linux/sched.h.bctasks	2006-11-03 17:47:38.000000000 +0300
+++ ./include/linux/sched.h	2006-11-03 17:51:57.000000000 +0300
@@ -1068,6 +1068,7 @@ int copy_beancounter(struct task_struct 
 #endif
 #ifdef CONFIG_BEANCOUNTERS
 	struct beancounter *exec_bc;
+	struct beancounter *task_bc;
 #endif
 };
 
--- ./kernel/bc/misc.c.bctasks	2006-11-03 17:47:38.000000000 +0300
+++ ./kernel/bc/misc.c	2006-11-03 17:51:57.000000000 +0300
@@ -17,6 +17,10 @@ int copy_beancounter(struct task_struct 
 	struct beancounter *bc;
 
 	bc = parent->exec_bc;
+	if (bc_charge(bc, BC_NUMTASKS, 1, BC_LIMIT))
+		return -ENOMEM;
+
+	tsk->task_bc = bc_get(bc);
 	tsk->exec_bc = bc_get(bc);
 	return 0;
 }
@@ -25,6 +29,10 @@ void free_beancounter(struct task_struct
 {
 	struct beancounter *bc;
 
+	bc = tsk->task_bc;
+	bc_uncharge(bc, BC_NUMTASKS, 1);
+	bc_put(bc);
+
 	bc = tsk->exec_bc;
 	bc_put(bc);
 }
@@ -86,3 +94,26 @@ int bc_task_move(struct task_struct *tsk
 	return err;
 }
 EXPORT_SYMBOL(bc_task_move);
+
+#define BC_NUMTASKS_BARRIER	128
+#define BC_NUMTASKS_LIMIT	128
+
+static int bc_task_init(struct beancounter *bc, int i)
+{
+	bc_init_resource(&bc->bc_parms[BC_NUMTASKS],
+			BC_NUMTASKS_BARRIER, BC_NUMTASKS_LIMIT);
+	return 0;
+}
+
+static struct bc_resource bc_task_resource = {
+	.bcr_name = "numtasks",
+	.bcr_init = bc_task_init,
+};
+
+static int __init bc_misc_init_resource(void)
+{
+	bc_register_resource(BC_NUMTASKS, &bc_task_resource);
+	return 0;
+}
+
+__initcall(bc_misc_init_resource);




More information about the Devel mailing list