1/6: ckrm_numtasks_init

Hooks up with CKRM core by defining the basic alloc/free functions and
registering the controller with the core.
--

Signed-Off-By: Chandra Seetharaman <[EMAIL PROTECTED]>
Signed-Off-By: Matt Helsley <[EMAIL PROTECTED]>

 init/Kconfig                |   10 ++++
 kernel/ckrm/Makefile        |    1 
 kernel/ckrm/ckrm_numtasks.c |   90 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 101 insertions(+)

Index: linux2617-rc2/kernel/ckrm/Makefile
===================================================================
--- linux2617-rc2.orig/kernel/ckrm/Makefile
+++ linux2617-rc2/kernel/ckrm/Makefile
@@ -1,2 +1,3 @@
 obj-y = ckrm.o ckrm_shares.o ckrm_task.o
+obj-$(CONFIG_CKRM_RES_NUMTASKS) += ckrm_numtasks.o
 obj-$(CONFIG_CKRM_RCFS) += ckrm_rcfs.o
Index: linux2617-rc2/kernel/ckrm/ckrm_numtasks.c
===================================================================
--- /dev/null
+++ linux2617-rc2/kernel/ckrm/ckrm_numtasks.c
@@ -0,0 +1,90 @@
+/* ckrm_numtasks.c - "Number of tasks" resource controller for CKRM
+ *
+ * Copyright (C) Chandra Seetharaman,  IBM Corp. 2003-2006
+ *           (C) Matt Helsley, IBM Corp. 2006
+ *
+ * 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.
+ *
+ */
+
+/*
+ * CKRM Resource controller for tracking number of tasks in a class.
+ */
+#include <linux/module.h>
+#include <linux/ckrm_rc.h>
+
+static const char res_ctlr_name[] = "numtasks";
+
+struct ckrm_numtasks {
+       struct ckrm_shares shares;
+};
+
+struct ckrm_controller numtasks_ctlr;
+
+static struct ckrm_numtasks *get_shares_numtasks(struct ckrm_shares *shares)
+{
+       if (shares)
+               return container_of(shares, struct ckrm_numtasks, shares);
+       return NULL;
+}
+
+/* Initialize share struct values */
+static void numtasks_res_init_one(struct ckrm_numtasks *numtasks_res)
+{
+       numtasks_res->shares.min_shares = CKRM_SHARE_DONT_CARE;
+       numtasks_res->shares.max_shares = CKRM_SHARE_DONT_CARE;
+       numtasks_res->shares.child_shares_divisor = CKRM_SHARE_DEFAULT_DIVISOR;
+       numtasks_res->shares.unused_min_shares = CKRM_SHARE_DEFAULT_DIVISOR;
+}
+
+static struct ckrm_shares *numtasks_alloc_shares_struct(
+                                               struct ckrm_class *class)
+{
+       struct ckrm_numtasks *res;
+
+       res = kzalloc(sizeof(struct ckrm_numtasks), GFP_KERNEL);
+       if (!res)
+               return NULL;
+       numtasks_res_init_one(res);
+       return &res->shares;
+}
+
+/*
+ * No locking of this resource class object necessary as we are not
+ * supposed to be assigned (or used) when/after this function is called.
+ */
+static void numtasks_free_shares_struct(struct ckrm_shares *my_res)
+{
+       kfree(get_shares_numtasks(my_res));
+}
+
+struct ckrm_controller numtasks_ctlr = {
+       .name = res_ctlr_name,
+       .depth_supported = 3,
+       .ctlr_id = CKRM_NO_RES_ID,
+       .alloc_shares_struct = numtasks_alloc_shares_struct,
+       .free_shares_struct = numtasks_free_shares_struct,
+};
+
+int __init init_ckrm_numtasks_res(void)
+{
+       if (numtasks_ctlr.ctlr_id != CKRM_NO_RES_ID)
+               return -EBUSY; /* already registered */
+       return ckrm_register_controller(&numtasks_ctlr);
+}
+
+void __exit exit_ckrm_numtasks_res(void)
+{
+       int rc;
+       do {
+               rc = ckrm_unregister_controller(&numtasks_ctlr);
+       } while (rc == -EBUSY);
+       BUG_ON(rc != 0);
+}
+module_init(init_ckrm_numtasks_res)
+module_exit(exit_ckrm_numtasks_res)
Index: linux2617-rc2/init/Kconfig
===================================================================
--- linux2617-rc2.orig/init/Kconfig
+++ linux2617-rc2/init/Kconfig
@@ -175,6 +175,16 @@ config CKRM_RCFS
          Say M if unsure, Y to save on module loading. N doesn't make sense
          when CKRM has been configured.
 
+config CKRM_RES_NUMTASKS
+       bool "Number of Tasks Resource Manager"
+       depends on CKRM
+       default y
+       help
+         Provides a Resource Controller for CKRM that allows limiting no of
+         tasks a task class can have.
+
+         Say N if unsure, Y to use the feature.
+
 endmenu
 config SYSCTL
        bool "Sysctl support"

-- 

----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [EMAIL PROTECTED]   |      .......you may get it.
----------------------------------------------------------------------


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
ckrm-tech mailing list
https://lists.sourceforge.net/lists/listinfo/ckrm-tech

Reply via email to