[2.5.32] CPUfreq core (1/4)
Subsystems (2)
PATCH 1/1 [2.5.32] CPUfreq core (1/4)
CPUFreq core for 2.5.32include/linux/cpufreq.h CPUFreq headerinclude/linux/sysctl.h /proc/sys/cpu/.../ enumeration
kernel/Makefile add cpufreq.c if necessarykernel/cpufreq.c CPUFreq corekernel/sysctl.c /proc/sys/cpu/.../ enumeration
# unfortunately no #for() preprocessor call exists...
include/linux/cpufreq.h +142 -0
@@ -0,0 +1,142 @@ +/* +* linux/include/linux/cpufreq.h +* +* Copyright (C) 2001 Russell King +* (C) 2002 Dominik Brodowski <[email protected]> +* +* +* $Id: cpufreq.h,v 1.13 2002/08/22 22:48:47 db Exp $ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ +#ifndef _LINUX_CPUFREQ_H +#define _LINUX_CPUFREQ_H + +#include <linux/config.h> +#include <linux/notifier.h> + + +/* sysctl ctl_table entries */ +#define CTL_CPU_VARS_SPEED_MAX (cpunr) { \ + ctl_name: CPU_NR_FREQ_MAX, \ + procname: "speed-max", \ + mode: 0444, \ + proc_handler: cpufreq_procctl_max, \ + extra1: (void*) (cpunr), } + +#define CTL_CPU_VARS_SPEED_MIN (cpunr) { \ + ctl_name: CPU_NR_FREQ_MIN, \ + procname: "speed-min", \ + mode: 0444, \ + proc_handler: cpufreq_procctl_min, \ + extra1: (void*) (cpunr), } + +#define CTL_CPU_VARS_SPEED (cpunr) { \ + ctl_name: CPU_NR_FREQ_MIN, \ + procname: "speed", \ + mode: 0644, \ + proc_handler: cpufreq_procctl, \ + strategy: cpufreq_sysctl, \ + extra1: (void*) (cpunr), } + +#define CTL_CPU_VARS_SPEED_SYNC { \ + ctl_name: CPU_NR_FREQ_SYNC, \ + procname: "speed-sync", \ + mode: 0444, \ + proc_handler: cpufreq_procctl_sync } + +/* speed setting interface */ + +int cpufreq_setmax (unsigned int cpu); +int cpufreq_set (unsigned int cpu,unsigned int khz); +unsigned int cpufreq_get (unsigned int cpu); + +#ifdef CONFIG_PM +int cpufreq_restore (void ); +#endif + + +/* notifier interface */ + +/* +* The max and min frequency rates that the registered device +* can tolerate. Never set any element this structure directly - +* always use cpufreq_updateminmax. +*/ +struct cpufreq_freqs { +unsigned int cpu; +unsigned int min; +unsigned int max; +unsigned int cur; +unsigned int new; +}; + +static inline +void cpufreq_updateminmax (struct cpufreq_freqs *freq, +unsigned int min, +unsigned int max) +{ +if (freq->min < min) + freq->min = min; +if (freq->max > max) + freq->max = max; +} + +/** +* cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe) +* @old: old value +* @div: divisor +* @mult: multiplier +* +* Needed for loops_per_jiffy and similar calculations. We do it +* this way to avoid math overflow on 32-bit machines. This will +* become architecture dependent once high-resolution-timer is +* merged (or any other thing that introduces sc_math.h). +* +* new = old * mult / div +*/ +static inline unsigned long cpufreq_scale (unsigned long old,u_int div,u_int mult) +{ +unsigned long val, carry; + + mult /=100 ; + div /=100 ; + val = (old / div) * mult; + carry = old % div; + carry = carry * mult / div; + +return carry + val; +} + +#define CPUFREQ_MINMAX (0) +#define CPUFREQ_PRECHANGE (1) +#define CPUFREQ_POSTCHANGE (2) + +#define CPUFREQ_ALL_CPUS (60000) + +int cpufreq_register_notifier (struct notifier_block *nb); +int cpufreq_unregister_notifier (struct notifier_block *nb); + + + +/* cpufreq driver interface */ + +typedef unsigned int (*cpufreq_verify_t ) (unsigned int cpu,unsigned int kHz); +typedef void (*cpufreq_setspeed_t ) (unsigned int cpu,unsigned int kHz); + +struct cpufreq_driver { +struct cpufreq_freqs *freq; +cpufreq_verify_t validate; +cpufreq_setspeed_t setspeed; +unsigned int sync;/* synchronized frequencies */ +}; + +#define CPUFREQ_SYNC 1/* all CPUs need to run the same frequency */ +#define CPUFREQ_ASYNC 0/* all CPUs can have different frequencies */ + +int cpufreq_register (struct cpufreq_driver *driver_data); +int cpufreq_unregister (void ); + +#endif
include/linux/sysctl.h +72 -0
78 lines not on this page · raw message
kernel/Makefile +2 -1
@@ -10,7 +10,7 @@ O_TARGET := kernel.o export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \ - printk.o platform.o suspend.o dma.o + printk.o platform.o suspend.o dma.o cpufreq.o obj-y = sched.o fork.o exec_domain.o panic.o printk.o \ module.o exit.o itimer.o time.o softirq.o resource.o \
@@ -22,6 +22,7 @@ obj-$(CONFIG_UID16) += uid16.o obj-$(CONFIG_MODULES) += ksyms.o obj-$(CONFIG_PM) += pm.o +obj-$(CONFIG_CPU_FREQ) += cpufreq.o obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend.o
kernel/cpufreq.c +709 -0
709 lines not on this page · raw message
kernel/sysctl.c +226 -0
250 lines not on this page · raw message