linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: KUROSAWA Takahiro <kurosawa@valinux.co.jp>
To: Paul Jackson <pj@sgi.com>
Cc: taka@valinux.co.jp, magnus.damm@gmail.com, dino@in.ibm.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] CPUMETER: connect the CPU resource controller to CPUMETER
Date: Mon, 26 Sep 2005 18:34:12 +0900	[thread overview]
Message-ID: <20050926093433.2394770045@sv1.valinux.co.jp> (raw)
In-Reply-To: <20050910015209.4f581b8a.pj@sgi.com>

This patch puts the CPU resource controller into CPUMETER framework.
With this patch, we can control the CPU resource from the cpuset
filesystem.

Signed-off-by: KUROSAWA Takahiro <kurosawa@valinux.co.jp>

--- from-0003/init/Kconfig
+++ to-work/init/Kconfig	2005-09-26 17:31:40.247109876 +0900
@@ -249,6 +249,7 @@ config CPUMETER
 
 config CPU_RC
 	bool "CPU resource controller"
+	depends on CPUMETER
 	help
 	  This options will let you control the CPU resource by scaling 
 	  the timeslice allocated for each tasks.
--- from-0003/kernel/cpu_rc.c
+++ to-work/kernel/cpu_rc.c	2005-09-22 11:51:57.000000000 +0900
@@ -228,6 +228,124 @@ void cpu_rc_collect_hunger(task_t *tsk)
 	tsk->last_activated = 0;
 }
 
+/*
+ * interface functions for cpumeter
+ */
+static void *cpu_rc_create_rcdomain(struct cpuset *cs,
+				    cpumask_t cpus, nodemask_t mems)
+{
+	struct cpu_rc_domain *rcd;
+
+	if (cpus_empty(cpus)) {
+		return NULL;
+	}
+
+	rcd = kmalloc(sizeof(*rcd), GFP_KERNEL);
+	if (rcd == NULL) {
+		return NULL;
+	}
+
+	rcd->cpus = cpus;
+	spin_lock_init(&rcd->lock);
+	rcd->hungry_groups = 0;
+
+	rcd->numcpus = cpus_weight(cpus);
+
+	return rcd;
+}
+
+static void cpu_rc_destroy_rcdomain(void *rcd)
+{
+	kfree(rcd);
+}
+
+static void *cpu_rc_create(void *rcd, struct cpuset *cs)
+{
+	struct cpu_rc *cr;
+
+	cr = kmalloc(sizeof(*cr), GFP_KERNEL);
+	if (cr == NULL) {
+		return NULL;
+	}
+
+	memset(cr, 0, sizeof(*cr));
+	cr->rcd = rcd;
+	cr->ts_factor = CPU_RC_TSFACTOR_MAX;
+	
+	return cr;
+}
+
+static void cpu_rc_destroy(void *p)
+{
+	struct cpu_rc *cr = p;
+
+	cpu_rc_lock(cr);
+	cpu_rc_set_satisfied(cr);
+	cpu_rc_unlock(cr);
+
+	kfree(p);
+}
+
+static int cpu_rc_set_guar(void *ctldata, unsigned long val)
+{
+	struct cpu_rc *cr = ctldata;
+
+	if (cr == NULL) {
+		return -EINVAL;
+	}
+
+	cpu_rc_lock(cr);
+	cr->guarantee = val;
+	cpu_rc_unlock(cr);
+
+	return 0;
+}
+
+static int cpu_rc_get_cur(void *ctldata, unsigned long *valp)
+{
+	struct cpu_rc *cr = ctldata;
+	unsigned int load;
+	int i, n;
+
+	if (cr == NULL) {
+		return -EINVAL;
+	}
+
+	load = 0;
+	n = 0;
+
+	/* Just displaying the value, so no locking... */
+	for_each_cpu_mask(i, cr->rcd->cpus) {
+		load += cr->stat[i].load;
+		n++;
+	}
+
+	*valp = load / n * CPU_RC_GUAR_SCALE / CPU_RC_LOAD_SCALE;
+
+	return 0;
+}
+
+static struct cpumeter_ctlr cpu_rc_ctlr = {
+	.name = "cpu",
+	.create_rcdomain = cpu_rc_create_rcdomain,
+	.destroy_rcdomain = cpu_rc_destroy_rcdomain,
+	.create = cpu_rc_create,
+	.destroy = cpu_rc_destroy,
+	.set_lim = NULL,
+	.set_guar = cpu_rc_set_guar,
+	.get_cur = cpu_rc_get_cur,
+};
+
 void cpu_rc_init(void)
 {
+	int err;
+	err = cpumeter_register_controller(&cpu_rc_ctlr);
+	if (err) {
+		printk(KERN_ERR "cpu_rc: register to cpumeter failed\n");
+	}
+}
+
+static struct cpu_rc *cpu_rc_get(task_t *tsk)
+{
+	return cpumeter_get_controller_data(tsk->cpuset, &cpu_rc_ctlr);
 }

  parent reply	other threads:[~2005-09-26  9:34 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-08  5:39 [PATCH 0/5] SUBCPUSETS: a resource control functionality using CPUSETS KUROSAWA Takahiro
2005-09-08  7:23 ` Paul Jackson
2005-09-08  8:18   ` KUROSAWA Takahiro
2005-09-08 12:02     ` Paul Jackson
2005-09-09  1:38       ` KUROSAWA Takahiro
2005-09-09  4:12         ` Magnus Damm
2005-09-09  5:55           ` Paul Jackson
2005-09-09  7:52             ` Magnus Damm
2005-09-09  8:39               ` Paul Jackson
2005-09-09 11:38             ` Hirokazu Takahashi
2005-09-09 13:31               ` Paul Jackson
2005-09-10  7:11                 ` Hirokazu Takahashi
2005-09-10  8:52                   ` Paul Jackson
2005-09-11 16:02                     ` Hirokazu Takahashi
2005-09-26  9:33                     ` [PATCH 0/3] CPUMETER (Re: [PATCH 0/5] SUBCPUSETS: a resource control functionality using CPUSETS) KUROSAWA Takahiro
2005-10-02  4:20                       ` Paul Jackson
2005-10-04  2:49                         ` KUROSAWA Takahiro
2005-09-26  9:34                     ` [PATCH 1/3] CPUMETER: add cpumeter framework to the CPUSETS KUROSAWA Takahiro
2005-09-27  8:37                       ` Paul Jackson
2005-09-27  9:22                         ` Nick Piggin
2005-09-27 15:53                           ` [ckrm-tech] " Paul Jackson
2005-09-27 21:45                           ` Chandra Seetharaman
2005-09-28  6:35                           ` KUROSAWA Takahiro
2005-09-28 10:08                             ` Hirokazu Takahashi
2005-09-28 10:32                               ` KUROSAWA Takahiro
2005-09-27 11:39                         ` KUROSAWA Takahiro
2005-09-27 15:49                           ` [ckrm-tech] " Paul Jackson
2005-09-28  6:21                             ` KUROSAWA Takahiro
2005-09-28  6:43                               ` Paul Jackson
2005-09-28  7:08                               ` Paul Jackson
2005-09-28  7:53                                 ` KUROSAWA Takahiro
2005-09-28 16:49                                   ` Paul Jackson
2005-09-29  2:53                                     ` KUROSAWA Takahiro
2005-09-29  2:58                                       ` Paul Jackson
2005-09-30  9:39                                       ` Simon Derr
2005-09-30 14:21                                         ` Paul Jackson
2005-10-02  7:01                             ` Ok to change cpuset flags for sched domains? (was [PATCH 1/3] CPUMETER ...) Paul Jackson
2005-10-03 14:00                               ` Dinakar Guniguntala
2005-10-03 23:36                                 ` [ckrm-tech] " Paul Jackson
2005-09-28  9:25                           ` [PATCH][BUG] fix memory leak on reading cpuset files after seeking beyond eof KUROSAWA Takahiro
2005-09-28 13:42                             ` Paul Jackson
2005-09-28 13:42                             ` [PATCH] cpuset read past eof memory leak fix Paul Jackson
2005-09-28 15:01                               ` Linus Torvalds
2005-09-28 17:53                                 ` Paul Jackson
2005-09-28 18:03                                   ` Linus Torvalds
2005-09-28 18:03                                   ` Randy.Dunlap
2005-09-28 19:04                                     ` [ckrm-tech] " Paul Jackson
2005-09-28 14:29                           ` [PATCH 1/3] CPUMETER: add cpumeter framework to the CPUSETS Paul Jackson
2005-09-26  9:34                     ` [PATCH 2/3] CPUMETER: CPU resource controller KUROSAWA Takahiro
2005-09-26  9:34                     ` KUROSAWA Takahiro [this message]
2005-09-09 22:26           ` [PATCH 0/5] SUBCPUSETS: a resource control functionality using CPUSETS Matthew Helsley
2005-09-08 13:14   ` Dinakar Guniguntala
2005-09-08 14:11     ` Dipankar Sarma
2005-09-08 14:55       ` Paul Jackson
2005-09-08 14:59     ` Paul Jackson
2005-09-08 22:51     ` [ckrm-tech] " 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=20050926093433.2394770045@sv1.valinux.co.jp \
    --to=kurosawa@valinux.co.jp \
    --cc=dino@in.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=pj@sgi.com \
    --cc=taka@valinux.co.jp \
    /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;
as well as URLs for NNTP newsgroup(s).