mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: MAEDA Naoaki <maeda.naoaki@jp.fujitsu.com>
To: akpm@osdl.org, linux-kernel@vger.kernel.org,
	ckrm-tech@lists.sourceforge.net
Cc: MAEDA Naoaki <maeda.naoaki@jp.fujitsu.com>
Subject: [PATCH 7/9] CPU controller - Add routines to change share values and show stat
Date: Fri, 28 Apr 2006 10:38:06 +0900	[thread overview]
Message-ID: <20060428013806.9582.46781.sendpatchset@moscone.dvs.cs.fujitsu.co.jp> (raw)
In-Reply-To: <20060428013730.9582.9351.sendpatchset@moscone.dvs.cs.fujitsu.co.jp>

7/9: cpu_shares_n_stats

Adds routine to change share values and show statistics.

Signed-off-by: MAEDA Naoaki <maeda.naoaki@jp.fujitsu.com>
Signed-off-by: Kurosawa Takahiro <kurosawa@valinux.co.jp>

 kernel/res_group/cpu.c |  120 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 120 insertions(+)

Index: linux-2.6.17-rc3/kernel/res_group/cpu.c
===================================================================
--- linux-2.6.17-rc3.orig/kernel/res_group/cpu.c
+++ linux-2.6.17-rc3/kernel/res_group/cpu.c
@@ -113,12 +113,132 @@ static void cpu_free_shares_struct(struc
 	kfree(res);
 }
 
+static int recalc_shares(int self_shares, int parent_shares, int parent_divisor)
+{
+	u64 numerator;
+
+	if (parent_divisor == 0)
+		return 0;
+	numerator = (u64) self_shares * parent_shares;
+	do_div(numerator, parent_divisor);
+	return numerator;
+}
+
+static int recalc_unused_shares(int self_cnt_min_shares,
+				int self_unused_min_shares, int self_divisor)
+{
+	u64 numerator;
+
+	if (self_divisor == 0)
+		return 0;
+	numerator = (u64) self_unused_min_shares * self_cnt_min_shares;
+	do_div(numerator, self_divisor);
+	return numerator;
+}
+
+static void recalc_self(struct cpu_res *res, struct cpu_res *parres)
+{
+	struct res_shares *par = &parres->shares;
+	struct res_shares *self = &res->shares;
+	u64 cnt_total, cnt_min_shares;
+
+	/* calculate total and current min_shares */
+	cnt_total = recalc_shares(self->min_shares,
+					parres->cnt_total_min_shares,
+					par->child_shares_divisor);
+	cnt_min_shares = recalc_unused_shares(self->unused_min_shares,
+					cnt_total,
+					par->child_shares_divisor);
+	cpu_rc_set_share(&res->cpu_rc, (int) cnt_min_shares);
+	res->cnt_total_min_shares = (int) cnt_total;
+}
+
+static void
+recalc_and_propagate(struct cpu_res *res)
+{
+	struct resource_group *child = NULL;
+	struct cpu_res *parres, *childres;
+
+	parres = get_res_group_cpu(res->rgroup->parent);
+
+	if (parres)
+		recalc_self(res, parres);
+
+	/* propagate to children */
+	spin_lock(&res->rgroup->group_lock);
+	for_each_child(child, res->rgroup) {
+		childres = get_res_group_cpu(child);
+		if (childres)
+			recalc_and_propagate(childres);
+	}
+	spin_unlock(&res->rgroup->group_lock);
+	return;
+}
+
+static void cpu_shares_changed(struct res_shares *my_res)
+{
+	struct cpu_res *parres, *res;
+	struct res_shares *cur, *par;
+	u64    temp = 0;
+
+	res = get_shares_cpu(my_res);
+	if (!res)
+		return;
+	cur = &res->shares;
+
+	if (!is_res_group_root(res->rgroup)) {
+		spin_lock(&res->rgroup->parent->group_lock);
+		parres = get_res_group_cpu(res->rgroup->parent);
+		par = &parres->shares;
+	} else {
+		par = NULL;
+		parres = NULL;
+	}
+
+	if (parres) {
+		/* adjust parent's unused min_shares */
+		temp = recalc_unused_shares(parres->cnt_total_min_shares,
+					par->unused_min_shares,
+					par->child_shares_divisor);
+		cpu_rc_set_share(&parres->cpu_rc, temp);
+	} else {
+		/* adjust root resouce group's unused min_shares */
+		temp = recalc_unused_shares(SHARE_DEFAULT_DIVISOR,
+					cur->unused_min_shares,
+					cur->child_shares_divisor);
+		cpu_rc_set_share(&res->cpu_rc, temp);
+	}
+	recalc_and_propagate(res);
+
+	if (!is_res_group_root(res->rgroup))
+		spin_unlock(&res->rgroup->parent->group_lock);
+}
+
+static ssize_t cpu_show_stats(struct res_shares *my_res, char *buf,
+							size_t buf_size)
+{
+	struct cpu_res *res;
+	unsigned int load = 0;
+	ssize_t	i;
+
+	res = get_shares_cpu(my_res);
+	if (!res)
+		return -EINVAL;
+
+	load = cpu_rc_load(&res->cpu_rc);
+	i = snprintf(buf, buf_size, "%s:effective_min_shares=%d, load=%d\n",
+				res_ctlr_name, res->cpu_rc.share, load);
+	return i;
+}
+
 struct res_controller cpu_ctlr = {
 	.name = res_ctlr_name,
 	.depth_supported = 3,
 	.ctlr_id = NO_RES_ID,
 	.alloc_shares_struct = cpu_alloc_shares_struct,
 	.free_shares_struct = cpu_free_shares_struct,
+	.shares_changed = cpu_shares_changed,
+	.show_stats = cpu_show_stats,
 };
 
 int __init init_cpu_res(void)

  parent reply	other threads:[~2006-04-28  1:39 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-28  1:37 [PATCH 0/9] CPU controller MAEDA Naoaki
2006-04-28  1:37 ` [PATCH 1/9] CPU controller - Add class load estimation support MAEDA Naoaki
2006-04-28  1:37 ` [PATCH 2/9] CPU controller - Add class hungry detection support MAEDA Naoaki
2006-04-28  1:37 ` [PATCH 3/9] CPU controller - Add timeslice scaling support MAEDA Naoaki
2006-04-28  1:37 ` [PATCH 4/9] CPU controller - Add interface functions MAEDA Naoaki
2006-04-28  1:37 ` [PATCH 5/9] CPU controller - Documentation how the controller works MAEDA Naoaki
2006-04-28  1:38 ` [PATCH 6/9] CPU controller - Add basic functions and registering the controller MAEDA Naoaki
2006-04-28  1:38 ` MAEDA Naoaki [this message]
2006-04-28  1:38 ` [PATCH 8/9] CPU controller - Add cpu hotplug support MAEDA Naoaki
2006-04-28  1:38 ` [PATCH 9/9] CPU controller - Documentation how to use the controller MAEDA Naoaki
2006-04-28  5:25 ` [PATCH 0/9] CPU controller Mike Galbraith
2006-04-28  5:48   ` MAEDA Naoaki
2006-04-28  6:59     ` Mike Galbraith
2006-04-28  7:26       ` MAEDA Naoaki
2006-04-28  7:41         ` Mike Galbraith
2006-04-28  7:56           ` [ckrm-tech] " MAEDA Naoaki
2006-04-28  9:29             ` Mike Galbraith
2006-04-28 10:01               ` Mike Galbraith
2006-04-28 10:11               ` Con Kolivas
2006-04-28 12:07                 ` MAEDA Naoaki
2006-04-28 13:09                   ` Con Kolivas
2006-04-28 13:55                     ` Hirokazu Takahashi
2006-04-28 14:55                       ` Con Kolivas
2006-04-28 15:39                       ` Mike Galbraith
2006-04-28  5:56   ` Kirill Korotaev
2006-04-28  7:11     ` Mike Galbraith
2006-04-28  7:46       ` Mike Galbraith
2006-04-28  8:13         ` Kirill Korotaev
2006-04-28  9:35           ` Mike Galbraith
2006-04-28 10:09         ` Con Kolivas
2006-04-28 10:16           ` Mike Galbraith
2006-04-28 10:26             ` Con Kolivas
2006-04-28 10:42               ` Mike Galbraith
2006-04-28  8:28     ` MAEDA Naoaki

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=20060428013806.9582.46781.sendpatchset@moscone.dvs.cs.fujitsu.co.jp \
    --to=maeda.naoaki@jp.fujitsu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®