Release 4.14 arch/powerpc/platforms/cell/cpufreq_spudemand.c
/*
* spu aware cpufreq governor for the cell processor
*
* © Copyright IBM Corporation 2006-2008
*
* 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/sched/loadavg.h>
#include <linux/module.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/atomic.h>
#include <asm/machdep.h>
#include <asm/spu.h>
#define POLL_TIME 100000
/* in µs */
#define EXP 753
/* exp(-1) in fixed-point */
struct spu_gov_info_struct {
unsigned long busy_spus; /* fixed-point */
struct cpufreq_policy *policy;
struct delayed_work work;
unsigned int poll_int; /* µs */
};
static DEFINE_PER_CPU(struct spu_gov_info_struct, spu_gov_info);
static int calc_freq(struct spu_gov_info_struct *info)
{
int cpu;
int busy_spus;
cpu = info->policy->cpu;
busy_spus = atomic_read(&cbe_spu_info[cpu_to_node(cpu)].busy_spus);
CALC_LOAD(info->busy_spus, EXP, busy_spus * FIXED_1);
pr_debug("cpu %d: busy_spus=%d, info->busy_spus=%ld\n",
cpu, busy_spus, info->busy_spus);
return info->policy->max * info->busy_spus / FIXED_1;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christian Krafft | 80 | 100.00% | 1 | 100.00% |
Total | 80 | 100.00% | 1 | 100.00% |
static void spu_gov_work(struct work_struct *work)
{
struct spu_gov_info_struct *info;
int delay;
unsigned long target_freq;
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);
target_freq = calc_freq(info);
__cpufreq_driver_target(info->policy, target_freq, CPUFREQ_RELATION_H);
delay = usecs_to_jiffies(info->poll_int);
schedule_delayed_work_on(info->policy->cpu, &info->work, delay);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christian Krafft | 89 | 98.89% | 1 | 50.00% |
Tejun Heo | 1 | 1.11% | 1 | 50.00% |
Total | 90 | 100.00% | 2 | 100.00% |
static void spu_gov_init_work(struct spu_gov_info_struct *info)
{
int delay = usecs_to_jiffies(info->poll_int);
INIT_DEFERRABLE_WORK(&info->work, spu_gov_work);
schedule_delayed_work_on(info->policy->cpu, &info->work, delay);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christian Krafft | 45 | 95.74% | 1 | 33.33% |
Tejun Heo | 2 | 4.26% | 2 | 66.67% |
Total | 47 | 100.00% | 3 | 100.00% |
static void spu_gov_cancel_work(struct spu_gov_info_struct *info)
{
cancel_delayed_work_sync(&info->work);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christian Krafft | 19 | 100.00% | 1 | 100.00% |
Total | 19 | 100.00% | 1 | 100.00% |
static int spu_gov_start(struct cpufreq_policy *policy)
{
unsigned int cpu = policy->cpu;
struct spu_gov_info_struct *info = &per_cpu(spu_gov_info, cpu);
struct spu_gov_info_struct *affected_info;
int i;
if (!cpu_online(cpu)) {
printk(KERN_ERR "cpu %d is not online\n", cpu);
return -EINVAL;
}
if (!policy->cur) {
printk(KERN_ERR "no cpu specified in policy\n");
return -EINVAL;
}
/* initialize spu_gov_info for all affected cpus */
for_each_cpu(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);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christian Krafft | 102 | 84.30% | 1 | 33.33% |
Rafael J. Wysocki | 18 | 14.88% | 1 | 33.33% |
Benjamin Herrenschmidt | 1 | 0.83% | 1 | 33.33% |
Total | 121 | 100.00% | 3 | 100.00% |
static void spu_gov_stop(struct cpufreq_policy *policy)
{
unsigned int cpu = policy->cpu;
struct spu_gov_info_struct *info = &per_cpu(spu_gov_info, cpu);
int i;
/* cancel timer */
spu_gov_cancel_work(info);
/* clean spu_gov_info for all affected cpus */
for_each_cpu (i, policy->cpus) {
info = &per_cpu(spu_gov_info, i);
info->policy = NULL;
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rafael J. Wysocki | 34 | 51.52% | 1 | 33.33% |
Christian Krafft | 31 | 46.97% | 1 | 33.33% |
Benjamin Herrenschmidt | 1 | 1.52% | 1 | 33.33% |
Total | 66 | 100.00% | 3 | 100.00% |
static struct cpufreq_governor spu_governor = {
.name = "spudemand",
.start = spu_gov_start,
.stop = spu_gov_stop,
.owner = THIS_MODULE,
};
/*
* module init and destoy
*/
static int __init spu_gov_init(void)
{
int ret;
ret = cpufreq_register_governor(&spu_governor);
if (ret)
printk(KERN_ERR "registration of governor failed\n");
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christian Krafft | 33 | 100.00% | 1 | 100.00% |
Total | 33 | 100.00% | 1 | 100.00% |
static void __exit spu_gov_exit(void)
{
cpufreq_unregister_governor(&spu_governor);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christian Krafft | 15 | 100.00% | 1 | 100.00% |
Total | 15 | 100.00% | 1 | 100.00% |
module_init(spu_gov_init);
module_exit(spu_gov_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>");
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christian Krafft | 519 | 87.97% | 1 | 12.50% |
Rafael J. Wysocki | 59 | 10.00% | 1 | 12.50% |
Tejun Heo | 3 | 0.51% | 2 | 25.00% |
Ingo Molnar | 3 | 0.51% | 1 | 12.50% |
Paul Gortmaker | 3 | 0.51% | 1 | 12.50% |
Benjamin Herrenschmidt | 2 | 0.34% | 1 | 12.50% |
Arun Sharma | 1 | 0.17% | 1 | 12.50% |
Total | 590 | 100.00% | 8 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.