[PATCH 12/13] BC: numtasks accounting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Beautifull tasks accounting/limiting beancounter control.

Signed-off-by: Pavel Emelianov <[email protected]>
Signed-off-by: Kirill Korotaev <[email protected]>

---

 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);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux