From: Christian Krafft <krafft@de.ibm.com>
To: Christian Krafft <krafft@de.ibm.com>
Cc: parabelboi@bopserverein.de, cpufreq@lists.linux.org.uk,
cbe-oss-dev@ozlabs.org, Arnd Bergmann <arnd@arndb.de>
Subject: [Cbe-oss-dev] [Patch] Resending: cell: add spu aware cpufreq governor
Date: Mon, 28 Jan 2008 19:12:25 +0100 [thread overview]
Message-ID: <20080128191225.092a6143@de.ibm.com> (raw)
In-Reply-To: <20080128190341.21c8fc97@de.ibm.com>
[-- Attachment #1.1: Type: text/plain, Size: 7547 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,14 @@ 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 SPU_FS
+ select 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,199 @@
+/*
+ * 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 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_work(struct work_struct *work)
+{
+ struct spu_gov_info_struct *info;
+ unsigned int load_int;
+ int delay;
+
+ info = container_of(work, struct spu_gov_info_struct, work.work);
+
+ /* after cancel_delayed_work_sync we unset info->policy */
+ BUG_ON(info->policy == NULL);
+
+ load_int = spu_gov_calc_load(info);
+
+ if ((load_int == 0) && (info->policy->cur != info->policy->min)) {
+ pr_debug("switching cpu %d to low frequency\n", info->policy->cpu);
+ __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 cpu %d to high frequency\n", info->policy->cpu);
+ __cpufreq_driver_target(info->policy,
+ info->policy->max,
+ CPUFREQ_RELATION_H);
+ }
+
+ delay = msecs_to_jiffies(info->poll_int);
+ queue_delayed_work_on(info->policy->cpu, kspugov_wq, &info->work, delay);
+}
+
+static void spu_gov_init_work(struct spu_gov_info_struct *info)
+{
+ int delay = msecs_to_jiffies(info->poll_int);
+ INIT_DELAYED_WORK_DEFERRABLE(&info->work, spu_gov_work);
+ 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_sync(&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)
+{
+ int ret;
+
+ kspugov_wq = create_workqueue("kspugov");
+ if (!kspugov_wq) {
+ printk(KERN_ERR "creation of kspugov failed\n");
+ ret = -EFAULT;
+ goto out;
+ }
+
+ ret = cpufreq_register_governor(&spu_governor);
+ if (ret) {
+ printk(KERN_ERR "registration of governor failed\n");
+ destroy_workqueue(kspugov_wq);
+ goto out;;
+ }
+out:
+ return ret;
+}
+
+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>");
+
[-- 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
next prev parent reply other threads:[~2008-01-28 18:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Christian Krafft [this message]
2008-04-14 0:21 ` [Cbe-oss-dev] [Patch] Resending: " 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
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=20080128191225.092a6143@de.ibm.com \
--to=krafft@de.ibm.com \
--cc=arnd@arndb.de \
--cc=cbe-oss-dev@ozlabs.org \
--cc=cpufreq@lists.linux.org.uk \
--cc=parabelboi@bopserverein.de \
/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.