All of lore.kernel.org
 help / color / mirror / Atom feed
* Subject: cell: add spu aware cpufreq governor
@ 2008-01-18 16:11 Christian Krafft
  2008-01-19 21:38 ` [Cbe-oss-dev] " Arnd Bergmann
  2008-01-21  3:09 ` [Cbe-oss-dev] Subject: cell: add spu aware cpufreq governor Akinobu Mita
  0 siblings, 2 replies; 10+ messages in thread
From: Christian Krafft @ 2008-01-18 16:11 UTC (permalink / raw)
  To: cpufreq; +Cc: Christian Krafft, cbe-oss-dev


[-- Attachment #1.1: Type: text/plain, Size: 7593 bytes --]

From: Christian Krafft <krafft@de.ibm.com>

This patch adds a cpufreq governor that takes the spu load into account.
It's very similar to the ondemand governor, but not as complex.
Instead of hacking spu load into the ondemand governor I'd like to see
cpufreq accepting multiple governors per cpu in future. Don't know if this is
the right way, but it would keep the governors simple.

This patch is also missing a correct load calculation.
It works pretty well for spu's running at full time or idling, but not so well
for mixed load (i.e. each spu running 50 percent of the time we would
switch to fullspeed instead of half speed).

Signed-off-by: Christian Krafft <krafft@de.ibm.com>

Index: linux.git/arch/powerpc/platforms/cell/Kconfig
===================================================================
--- linux.git.orig/arch/powerpc/platforms/cell/Kconfig
+++ linux.git/arch/powerpc/platforms/cell/Kconfig
@@ -87,4 +87,13 @@ config CBE_CPUFREQ_PMI
 	  processor will not only be able to run at lower speed,
 	  but also at lower core voltage.
 
+config CBE_CPUFREQ_SPU_GOVERNOR
+	tristate "CBE frequency scaling based on SPU usage"
+	depends on CBE_CPUFREQ
+	default m
+	help
+	  This governor checks for spu usage to adjust the cpu frequency.
+	  If no spu is running on a given cpu, that cpu will be throttled to
+	  the minimal possible frequency.
+
 endmenu
Index: linux.git/arch/powerpc/platforms/cell/Makefile
===================================================================
--- linux.git.orig/arch/powerpc/platforms/cell/Makefile
+++ linux.git/arch/powerpc/platforms/cell/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_CBE_THERM)			+= cbe_thermal
 obj-$(CONFIG_CBE_CPUFREQ_PMI)		+= cbe_cpufreq_pmi.o
 obj-$(CONFIG_CBE_CPUFREQ)		+= cbe-cpufreq.o
 cbe-cpufreq-y				+= cbe_cpufreq_pervasive.o cbe_cpufreq.o
+obj-$(CONFIG_CBE_CPUFREQ_SPU_GOVERNOR)	+= cbe_spu_governor.o
 
 ifeq ($(CONFIG_SMP),y)
 obj-$(CONFIG_PPC_CELL_NATIVE)		+= smp.o
Index: linux.git/arch/powerpc/platforms/cell/cbe_spu_governor.c
===================================================================
--- /dev/null
+++ linux.git/arch/powerpc/platforms/cell/cbe_spu_governor.c
@@ -0,0 +1,191 @@
+/*
+ * spu aware cpufreq governor for the cell processor
+ *
+ * (C) Copyright IBM Deutschland Entwicklung GmbH 2005-2007
+ *
+ * Author: Christian Krafft <krafft@de.ibm.com>
+ *
+ * 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, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/cpufreq.h>
+#include <linux/sched.h>
+#include <linux/timer.h>
+#include <asm/atomic.h>
+#include <asm/machdep.h>
+#include <asm/spu.h>
+
+#include "asm/cell-regs.h"
+
+#define DEBUG		1
+#define POLL_TIME	1000	/* in ms */
+
+struct spu_gov_info_struct {
+	unsigned long load;
+	unsigned long last_load;
+	struct cpufreq_policy *policy;
+	struct delayed_work work;
+	unsigned int poll_int;
+};
+static DEFINE_PER_CPU(struct spu_gov_info_struct, spu_gov_info);
+
+static struct workqueue_struct *kspugov_wq;
+
+/* parts of this function should go into spu scheduler */
+static int spu_gov_calc_load(struct spu_gov_info_struct *info)
+{
+	unsigned long active_tasks; /* fixed-point */
+	int cpu, load;
+
+	cpu = info->policy->cpu;
+	active_tasks = cbe_spu_info[cpu_to_node(cpu)].nr_active * FIXED_1;
+
+	/* this is also a bit too trivial
+	 * actually we want the max load of all spu's belonging together */
+	CALC_LOAD(info->load, EXP_1, active_tasks);
+
+	load = (info->load + FIXED_1 / 200) >> FSHIFT;
+
+	return load;
+}
+
+static void spu_gov_init_work(struct spu_gov_info_struct *info);
+
+static void spu_gov_timer(struct work_struct *work)
+{
+	struct spu_gov_info_struct *info;
+	unsigned int load_int;
+
+	info = container_of(work, struct spu_gov_info_struct, work.work);
+
+	load_int = spu_gov_calc_load(info);
+
+	if ((load_int == 0) && (info->policy->cur != info->policy->min)) {
+		pr_debug("switching low frequency\n");
+		__cpufreq_driver_target(info->policy,
+			info->policy->min,
+			CPUFREQ_RELATION_L);
+	} else if ((load_int > 0) && (info->policy->cur != info->policy->max)) {
+		pr_debug("switching to high frequency\n");
+		__cpufreq_driver_target(info->policy,
+			info->policy->max,
+			CPUFREQ_RELATION_H);
+	}
+
+	spu_gov_init_work(info);
+}
+
+static void spu_gov_init_work(struct spu_gov_info_struct *info)
+{
+	int delay = usecs_to_jiffies(info->poll_int * 1000);
+	delay -= jiffies % delay;
+	INIT_DELAYED_WORK_DEFERRABLE(&info->work, spu_gov_timer);
+	queue_delayed_work_on(info->policy->cpu, kspugov_wq, &info->work, delay);
+}
+
+static void spu_gov_cancel_work(struct spu_gov_info_struct *info)
+{
+	cancel_delayed_work(&info->work);
+}
+
+static int spu_gov_govern(struct cpufreq_policy *policy, unsigned int event)
+{
+	unsigned int cpu = policy->cpu;
+	struct spu_gov_info_struct *info, *affected_info;
+	int i;
+	int ret = 0;
+
+	info = &per_cpu(spu_gov_info, cpu);
+
+	switch (event) {
+	case CPUFREQ_GOV_START:
+		if (!cpu_online(cpu)) {
+			printk(KERN_ERR "cpu %d is not online\n", cpu);
+			ret = -EINVAL;
+			break;
+		}
+
+		if (!policy->cur) {
+			printk(KERN_ERR "no cpu specified in policy\n");
+			ret = -EINVAL;
+			break;
+		}
+
+		/* initialize spu_gov_info for all affected cpus */
+		for_each_cpu_mask(i, policy->cpus) {
+			affected_info = &per_cpu(spu_gov_info, i);
+			affected_info->policy = policy;
+		}
+
+		info->poll_int = POLL_TIME;
+
+		/* setup timer */
+		spu_gov_init_work(info);
+
+		break;
+
+	case CPUFREQ_GOV_STOP:
+		/* cancel timer */
+		spu_gov_cancel_work(info);
+
+		/* clean spu_gov_info for all affected cpus */
+		for_each_cpu_mask (i, policy->cpus) {
+			info = &per_cpu(spu_gov_info, i);
+			info->policy = NULL;
+		}
+
+		break;
+	}
+
+	return ret;
+}
+
+static struct cpufreq_governor spu_governor = {
+	.name = "spu_governor",
+	.governor = spu_gov_govern,
+	.owner = THIS_MODULE,
+};
+
+/*
+ * module init and destoy
+ */
+
+static int __init spu_gov_init(void)
+{
+	if (!machine_is(cell))
+		return -ENODEV;
+
+	kspugov_wq = create_workqueue("kspugov");
+	if (!kspugov_wq) {
+		printk(KERN_ERR "creation of kspugov failed\n");
+		return -EFAULT;
+	}
+
+	return cpufreq_register_governor(&spu_governor);
+}
+
+static void __exit spu_gov_exit(void)
+{
+	cpufreq_unregister_governor(&spu_governor);
+	destroy_workqueue(kspugov_wq);
+}
+
+
+module_init(spu_gov_init);
+module_exit(spu_gov_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>");
+


-- 
Mit freundlichen Gruessen,
kind regards,

Christian Krafft
IBM Systems & Technology Group,
Linux Kernel Development
IT Specialist


Vorsitzender des Aufsichtsrats:	Martin Jetter
Geschaeftsfuehrung:		Herbert Kircher
Sitz der Gesellschaft:		Boeblingen
Registriergericht:		Amtsgericht Stuttgart, HRB 243294

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 147 bytes --]

_______________________________________________
Cpufreq mailing list
Cpufreq@lists.linux.org.uk
http://lists.linux.org.uk/mailman/listinfo/cpufreq

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-04-16 14:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-18 16:11 Subject: cell: add spu aware cpufreq governor Christian Krafft
2008-01-19 21:38 ` [Cbe-oss-dev] " Arnd Bergmann
2008-01-28 18:03   ` Christian Krafft
2008-01-28 18:12     ` [Cbe-oss-dev] [Patch] Resending: " Christian Krafft
2008-04-14  0:21       ` Arnd Bergmann
2008-04-16 11:49         ` [Cbe-oss-dev] [Patch] Resending: cell_add_spuaware_cpufreq_governor.diff Christian Krafft
2008-04-16 12:08           ` Arnd Bergmann
2008-04-16 14:53             ` Christian Krafft
2008-01-21  3:09 ` [Cbe-oss-dev] Subject: cell: add spu aware cpufreq governor Akinobu Mita
2008-01-28 10:26   ` Christian Krafft

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.