From: Chandra Seetharaman <sekharan@us.ibm.com>
To: akpm@osdl.org, linux-kernel@vger.kernel.org,
ckrm-tech@lists.sourceforge.net
Cc: Chandra Seetharaman <sekharan@us.ibm.com>
Subject: [PATCH 2/6] numtasks - Add task control support
Date: Thu, 27 Apr 2006 18:35:29 -0700 [thread overview]
Message-ID: <20060428013529.27212.46309.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20060428013518.27212.954.sendpatchset@localhost.localdomain>
2/6: numtasks_tasksupport
Adds task management support by defining a function to be called from
fork() to see if the resource group is within its share allocation
Sets interface to be called from core when a task is moved to a resource
group.
--
Signed-Off-By: Chandra Seetharaman <sekharan@us.ibm.com>
include/linux/numtasks.h | 28 +++++++++++
kernel/fork.c | 7 ++
kernel/res_group/numtasks.c | 104 +++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 137 insertions(+), 2 deletions(-)
Index: linux-2617-rc3/include/linux/numtasks.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2617-rc3/include/linux/numtasks.h 2006-04-27 10:18:50.000000000 -0700
@@ -0,0 +1,28 @@
+/* numtasks.h - No. of tasks resource controller for Resource Groups
+ *
+ * Copyright (C) Chandra Seetharaman, IBM Corp. 2003, 2004, 2005
+ *
+ * Provides No. of tasks resource controller for Resource Groups
+ *
+ * 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.
+ *
+ */
+#ifndef _LINUX_NUMTASKS_H
+#define _LINUX_NUMTASKS_H
+
+#ifdef CONFIG_RES_GROUPS_NUMTASKS
+#include <linux/res_group_rc.h>
+
+extern int numtasks_allow_fork(struct resource_group *);
+
+#else /* CONFIG_RES_GROUPS_NUMTASKS */
+
+#define numtasks_allow_fork(rgroup) (0)
+
+#endif /* CONFIG_RES_GROUPS_NUMTASKS */
+#endif /* _LINUX_NUMTASKS_H */
Index: linux-2617-rc3/kernel/res_group/numtasks.c
===================================================================
--- linux-2617-rc3.orig/kernel/res_group/numtasks.c 2006-04-27 10:18:49.000000000 -0700
+++ linux-2617-rc3/kernel/res_group/numtasks.c 2006-04-27 10:18:50.000000000 -0700
@@ -21,7 +21,19 @@
static const char res_ctlr_name[] = "numtasks";
struct numtasks {
+ struct resource_group *rgroup;/* resource group i am part of... */
struct res_shares shares;
+ int cnt_min_shares; /* num_tasks min_shares in local units */
+ int cnt_unused; /* has to borrow if more than this is needed */
+ int cnt_max_shares; /* no tasks over this limit. */
+ /* Three above cnt_* fields are protected
+ * by resource group's group_lock */
+ atomic_t cnt_cur_alloc; /* current alloc from self */
+ atomic_t cnt_borrowed; /* borrowed from the parent */
+
+ /* stats */
+ int successes;
+ int failures;
};
struct res_controller numtasks_ctlr;
@@ -33,6 +45,84 @@ static struct numtasks *get_shares_numta
return NULL;
}
+static struct numtasks *get_numtasks(struct resource_group *rgroup)
+{
+ return get_shares_numtasks(get_controller_shares(rgroup,
+ &numtasks_ctlr));
+}
+
+int numtasks_allow_fork(struct resource_group *rgroup)
+{
+ struct numtasks *res;
+
+ /* controller is not registered; no resource group is given */
+ if ((numtasks_ctlr.ctlr_id == NO_RES_ID) || (rgroup == NULL))
+ return 0;
+ res = get_numtasks(rgroup);
+
+ /* numtasks not available for this resource group */
+ if (!res)
+ return 0;
+
+ if (res->cnt_max_shares == SHARE_DONT_CARE)
+ return 0;
+
+ /* Over the limit ? */
+ if (atomic_read(&res->cnt_cur_alloc) >= res->cnt_max_shares) {
+ res->failures++;
+ return -ENOSPC;
+ }
+
+ return 0;
+}
+
+static void inc_usage_count(struct numtasks *res)
+{
+ atomic_inc(&res->cnt_cur_alloc);
+
+ if (is_res_group_root(res->rgroup)) {
+ res->successes++;
+ return;
+ }
+ /* Do we need to borrow from our parent ? */
+ if ((res->cnt_unused == SHARE_DONT_CARE) ||
+ (atomic_read(&res->cnt_cur_alloc) > res->cnt_unused)) {
+ inc_usage_count(get_numtasks(res->rgroup->parent));
+ atomic_inc(&res->cnt_borrowed);
+ } else
+ res->successes++;
+}
+
+static void dec_usage_count(struct numtasks *res)
+{
+ if (atomic_read(&res->cnt_cur_alloc) == 0)
+ return;
+ atomic_dec(&res->cnt_cur_alloc);
+ if (atomic_read(&res->cnt_borrowed) > 0) {
+ atomic_dec(&res->cnt_borrowed);
+ dec_usage_count(get_numtasks(res->rgroup->parent));
+ }
+}
+
+static void numtasks_move_task(struct task_struct *task,
+ struct res_shares *old, struct res_shares *new)
+{
+ struct numtasks *oldres, *newres;
+
+ if (old == new)
+ return;
+
+ /* Decrement usage count of old resource group */
+ oldres = get_shares_numtasks(old);
+ if (oldres)
+ dec_usage_count(oldres);
+
+ /* Increment usage count of new resource group */
+ newres = get_shares_numtasks(new);
+ if (newres)
+ inc_usage_count(newres);
+}
+
/* Initialize share struct values */
static void numtasks_res_init_one(struct numtasks *numtasks_res)
{
@@ -50,6 +140,7 @@ static struct res_shares *numtasks_alloc
res = kzalloc(sizeof(struct numtasks), GFP_KERNEL);
if (!res)
return NULL;
+ res->rgroup = rgroup;
numtasks_res_init_one(res);
return &res->shares;
}
@@ -60,7 +151,17 @@ static struct res_shares *numtasks_alloc
*/
static void numtasks_free_shares_struct(struct res_shares *my_res)
{
- kfree(get_shares_numtasks(my_res));
+ struct numtasks *res, *parres;
+ int i, borrowed;
+
+ res = get_shares_numtasks(my_res);
+ if (!is_res_group_root(res->rgroup)) {
+ parres = get_numtasks(res->rgroup->parent);
+ borrowed = atomic_read(&res->cnt_borrowed);
+ for (i = 0; i < borrowed; i++)
+ dec_usage_count(parres);
+ }
+ kfree(res);
}
struct res_controller numtasks_ctlr = {
@@ -69,6 +170,7 @@ struct res_controller numtasks_ctlr = {
.ctlr_id = NO_RES_ID,
.alloc_shares_struct = numtasks_alloc_shares_struct,
.free_shares_struct = numtasks_free_shares_struct,
+ .move_task = numtasks_move_task,
};
int __init init_numtasks_res(void)
Index: linux-2617-rc3/kernel/fork.c
===================================================================
--- linux-2617-rc3.orig/kernel/fork.c 2006-04-27 10:14:38.000000000 -0700
+++ linux-2617-rc3/kernel/fork.c 2006-04-27 10:18:50.000000000 -0700
@@ -45,6 +45,7 @@
#include <linux/acct.h>
#include <linux/cn_proc.h>
#include <linux/res_group.h>
+#include <linux/numtasks.h>
#include <asm/pgtable.h>
#include <asm/pgalloc.h>
@@ -1311,7 +1312,7 @@ long do_fork(unsigned long clone_flags,
int __user *child_tidptr)
{
struct task_struct *p;
- int trace = 0;
+ int trace = 0, rc;
struct pid *pid = alloc_pid();
long nr;
@@ -1324,6 +1325,10 @@ long do_fork(unsigned long clone_flags,
clone_flags |= CLONE_PTRACE;
}
+ rc = numtasks_allow_fork(current->res_group);
+ if (rc)
+ return rc;
+
p = copy_process(clone_flags, stack_start, regs, stack_size, parent_tidptr, child_tidptr, nr);
/*
* Do this prior waking up the new thread - the thread pointer
--
----------------------------------------------------------------------
Chandra Seetharaman | Be careful what you choose....
- sekharan@us.ibm.com | .......you may get it.
----------------------------------------------------------------------
next prev parent reply other threads:[~2006-04-28 1:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-28 1:35 [PATCH 0/6] Number of Tasks Resource controller Chandra Seetharaman
2006-04-28 1:35 ` [PATCH 1/6] numtasks - Initialization routines Chandra Seetharaman
2006-04-28 1:35 ` Chandra Seetharaman [this message]
2006-04-28 1:35 ` [PATCH 3/6] numtasks - Add shares and stats support Chandra Seetharaman
2006-04-28 1:35 ` [PATCH 4/6] numtasks - Add configuration support Chandra Seetharaman
2006-04-28 1:35 ` [PATCH 5/6] numtasks - Add fork rate control support Chandra Seetharaman
2006-04-28 1:35 ` [PATCH 6/6] numtasks - Documentation for Numtasks controller Chandra Seetharaman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060428013529.27212.46309.sendpatchset@localhost.localdomain \
--to=sekharan@us.ibm.com \
--cc=akpm@osdl.org \
--cc=ckrm-tech@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.