Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add a simple cpufreq(9).



details:   https://anonhg.NetBSD.org/src/rev/e75a93080edc
branches:  trunk
changeset: 769967:e75a93080edc
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Wed Sep 28 10:55:46 2011 +0000

description:
Add a simple cpufreq(9).

This is slightly improved version presented on tech-kern@ with proper
locking and few additional functions, mainly required for ioctl(9)/cpuctl(8).

diffstat:

 distrib/sets/lists/comp/mi |   36 ++-
 share/man/man9/Makefile    |   14 +-
 share/man/man9/cpufreq.9   |  303 +++++++++++++++++++++++++
 sys/conf/files             |    3 +-
 sys/kern/subr_cpufreq.c    |  526 +++++++++++++++++++++++++++++++++++++++++++++
 sys/sys/cpufreq.h          |   91 +++++++
 6 files changed, 969 insertions(+), 4 deletions(-)

diffs (truncated from 1055 to 300 lines):

diff -r f4d95fd1d3c9 -r e75a93080edc distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Wed Sep 28 10:29:41 2011 +0000
+++ b/distrib/sets/lists/comp/mi        Wed Sep 28 10:55:46 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.1680 2011/09/27 00:36:49 jym Exp $
+#      $NetBSD: mi,v 1.1681 2011/09/28 10:55:46 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2354,6 +2354,7 @@
 ./usr/include/sys/conf.h                       comp-c-include
 ./usr/include/sys/core.h                       comp-c-include
 ./usr/include/sys/cpu_data.h                   comp-obsolete           obsolete
+./usr/include/sys/cpufreq.h                    comp-c-include
 ./usr/include/sys/cpuio.h                      comp-c-include
 ./usr/include/sys/ctype_bits.h                 comp-c-include
 ./usr/include/sys/ctype_inline.h               comp-c-include
@@ -9768,6 +9769,17 @@
 ./usr/share/man/cat9/cpu_switchto.0            comp-sys-catman         .cat
 ./usr/share/man/cat9/cpu_sysctl.0              comp-obsolete           obsolete
 ./usr/share/man/cat9/cpu_wait.0                        comp-obsolete           obsolete
+./usr/share/man/cat9/cpufreq.0                 comp-sys-catman         .cat
+./usr/share/man/cat9/cpufreq_register.0                comp-sys-catman         .cat
+./usr/share/man/cat9/cpufreq_deregister.0      comp-sys-catman         .cat
+./usr/share/man/cat9/cpufreq_suspend.0         comp-sys-catman         .cat
+./usr/share/man/cat9/cpufreq_resume.0          comp-sys-catman         .cat
+./usr/share/man/cat9/cpufreq_get.0             comp-sys-catman         .cat
+./usr/share/man/cat9/cpufreq_get_backend.0     comp-sys-catman         .cat
+./usr/share/man/cat9/cpufreq_get_state.0       comp-sys-catman         .cat
+./usr/share/man/cat9/cpufreq_get_state_index.0 comp-sys-catman         .cat
+./usr/share/man/cat9/cpufreq_set.0             comp-sys-catman         .cat
+./usr/share/man/cat9/cpufreq_set_all.0         comp-sys-catman         .cat
 ./usr/share/man/cat9/crcopy.0                  comp-obsolete           obsolete
 ./usr/share/man/cat9/crcvt.0                   comp-obsolete           obsolete
 ./usr/share/man/cat9/crdup.0                   comp-obsolete           obsolete
@@ -15840,6 +15852,17 @@
 ./usr/share/man/html9/cpu_swapin.html          comp-obsolete           obsolete
 ./usr/share/man/html9/cpu_swapout.html         comp-obsolete           obsolete
 ./usr/share/man/html9/cpu_switchto.html                comp-sys-htmlman        html
+./usr/share/man/html9/cpufreq.html             comp-sys-htmlman        html
+./usr/share/man/html9/cpufreq_register.html    comp-sys-htmlman        html
+./usr/share/man/html9/cpufreq_deregister.html  comp-sys-htmlman        html
+./usr/share/man/html9/cpufreq_suspend.html     comp-sys-htmlman        html
+./usr/share/man/html9/cpufreq_resume.html      comp-sys-htmlman        html
+./usr/share/man/html9/cpufreq_get.html         comp-sys-htmlman        html
+./usr/share/man/html9/cpufreq_get_backend.html comp-sys-htmlman        html
+./usr/share/man/html9/cpufreq_get_state.html   comp-sys-htmlman        html
+./usr/share/man/html9/cpufreq_get_state_index.html     comp-sys-htmlman        html
+./usr/share/man/html9/cpufreq_set.html         comp-sys-htmlman        html
+./usr/share/man/html9/cpufreq_set_all.html     comp-sys-htmlman        html
 ./usr/share/man/html9/crypto_dispatch.html     comp-sys-htmlman        html
 ./usr/share/man/html9/crypto_done.html         comp-sys-htmlman        html
 ./usr/share/man/html9/crypto_freereq.html      comp-sys-htmlman        html
@@ -22041,6 +22064,17 @@
 ./usr/share/man/man9/cpu_switchto.9            comp-sys-man            .man
 ./usr/share/man/man9/cpu_sysctl.9              comp-obsolete           obsolete
 ./usr/share/man/man9/cpu_wait.9                        comp-obsolete           obsolete
+./usr/share/man/man9/cpufreq.9                 comp-sys-man            .man
+./usr/share/man/man9/cpufreq_register.9                comp-sys-man            .man
+./usr/share/man/man9/cpufreq_deregister.9      comp-sys-man            .man
+./usr/share/man/man9/cpufreq_suspend.9         comp-sys-man            .man
+./usr/share/man/man9/cpufreq_resume.9          comp-sys-man            .man
+./usr/share/man/man9/cpufreq_get.9             comp-sys-man            .man
+./usr/share/man/man9/cpufreq_get_backend.9     comp-sys-man            .man
+./usr/share/man/man9/cpufreq_get_state.9       comp-sys-man            .man
+./usr/share/man/man9/cpufreq_get_state_index.9 comp-sys-man            .man
+./usr/share/man/man9/cpufreq_set.9             comp-sys-man            .man
+./usr/share/man/man9/cpufreq_set_all.9         comp-sys-man            .man
 ./usr/share/man/man9/crcopy.9                  comp-obsolete           obsolete
 ./usr/share/man/man9/crcvt.9                   comp-obsolete           obsolete
 ./usr/share/man/man9/crdup.9                   comp-obsolete           obsolete
diff -r f4d95fd1d3c9 -r e75a93080edc share/man/man9/Makefile
--- a/share/man/man9/Makefile   Wed Sep 28 10:29:41 2011 +0000
+++ b/share/man/man9/Makefile   Wed Sep 28 10:55:46 2011 +0000
@@ -1,4 +1,4 @@
-#       $NetBSD: Makefile,v 1.350 2011/09/27 00:36:51 jym Exp $
+#       $NetBSD: Makefile,v 1.351 2011/09/28 10:55:48 jruoho Exp $
 
 #      Makefile for section 9 (kernel function and variable) manual pages.
 
@@ -12,7 +12,7 @@
        cpu_lwp_fork.9 \
        cpu_idle.9 cpu_initclocks.9 cpu_need_resched.9 \
        cpu_number.9 cpu_reboot.9 cpu_rootconf.9 \
-       cpu_startup.9 cpu_switchto.9 \
+       cpu_startup.9 cpu_switchto.9 cpufreq.9 \
        csf.9 ctod.9 \
        curproc.9 \
        delay.9 disk.9 ddc.9 disklabel.9 dofileread.9 \
@@ -234,6 +234,16 @@
        cpu_dumpconf.9 dumpsys.9
 MLINKS+=cpu_lwp_fork.9 child_return.9 cpu_lwp_fork.9 proc_trampoline.9
 MLINKS+=cpu_rootconf.9 setroot.9
+MLINKS+=cpufreq.9 cpufreq_register.9 \
+       cpufreq.9 cpufreq_deregister.9 \
+       cpufreq.9 cpufreq_suspend.9 \
+       cpufreq.9 cpufreq_resume.9 \
+       cpufreq.9 cpufreq_get.9 \
+       cpufreq.9 cpufreq_get_backend.9 \
+       cpufreq.9 cpufreq_get_state.9 \
+       cpufreq.9 cpufreq_get_state_index.9 \
+       cpufreq.9 cpufreq_set.9 \
+       cpufreq.9 cpufreq_set_all.9
 MLINKS+=ctod.9 dtoc.9 \
        ctod.9 ctob.9 \
        ctod.9 btoc.9 \
diff -r f4d95fd1d3c9 -r e75a93080edc share/man/man9/cpufreq.9
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man9/cpufreq.9  Wed Sep 28 10:55:46 2011 +0000
@@ -0,0 +1,303 @@
+.\" $NetBSD: cpufreq.9,v 1.1 2011/09/28 10:55:48 jruoho Exp $ */
+.\"
+.\" Copyright (c) 2011 Jukka Ruohonen <jruohonen.iki.fi>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\"
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd September 23, 2011
+.Dt CPUFREQ 9
+.Os
+.Sh NAME
+.Nm cpufreq ,
+.Nm cpufreq_register ,
+.Nm cpufreq_deregister ,
+.Nm cpufreq_suspend ,
+.Nm cpufreq_resume ,
+.Nm cpufreq_get ,
+.Nm cpufreq_get_backend ,
+.Nm cpufreq_get_state ,
+.Nm cpufreq_get_state_index ,
+.Nm cpufreq_set ,
+.Nm cpufreq_set_all
+.Nd interface for CPU frequency scaling
+.Sh SYNOPSIS
+.In sys/cpufreq.h
+.Ft int
+.Fn cpufreq_register "struct cpufreq *cf"
+.Ft void
+.Fn cpufreq_deregister "void"
+.Ft void
+.Fn cpufreq_suspend "struct cpu_info *ci"
+.Ft void
+.Fn cpufreq_resume "struct cpu_info *ci"
+.Ft uint32_t
+.Fn cpufreq_get "struct cpu_info *ci"
+.Ft int
+.Fn cpufreq_get_backend "struct cpufreq *cf"
+.Ft int
+.Fn cpufreq_get_state "uint32_t freq" "struct cpufreq_state *cfs"
+.Ft int
+.Fn cpufreq_get_state_index "uint32_t index" "struct cpufreq_state *cfs"
+.Ft void
+.Fn cpufreq_set "struct cpu_info *ci" "uint32_t freq"
+.Ft void
+.Fn cpufreq_set_all "uint32_t freq"
+.\" .Ft void
+.\" .Fn cpufreq_set_higher "struct cpu_info *ci"
+.\" .Ft void
+.\" .Fn cpufreq_set_lower "struct cpu_info *ci"
+.Sh DESCRIPTION
+The machine-independent
+.Nm
+interface provides a framework for
+.Tn CPU
+frequency scaling done by a machine-dependent backend implementation.
+User space control is available via
+.Xr cpuctl 8 .
+.Pp
+The
+.Nm
+interface is a per-CPU framework.
+It is implicitly assumed that the frequency can be set
+independently for all processors in the system.
+However,
+.Nm
+does not imply any restrictions upon whether this information
+is utilized by the actual machine-dependent implementation.
+It is possible to use
+.Nm
+with frequency scaling implemented via
+.Xr pci 4 .
+In addition, it assumed that the available frequency levels are
+shared uniformly by all processors in the system,
+even when it is possible to control the frequency of individual processors.
+.Pp
+It should be noted that the
+.Nm
+interface is generally stateless.
+This implies for instance that possible caching should
+be done in the machine-dependent backend.
+The
+.Fn cpufreq_suspend
+and
+.Fn cpufreq_resume
+functions are exceptions.
+These can be integrated with
+.Xr pmf 9 .
+.Sh FUNCTIONS
+.Bl -tag -width compact
+.It Fn cpufreq_register "cf"
+The
+.Fn cpufreq_register
+function initializes the interface by associating
+a machine-dependent backend with the framework.
+Only one backend can be registered.
+Upon successful completion,
+.Fn cpufreq_register
+returns 0 and sets the frequency to the maximum available level.
+.Pp
+The following elements in
+.Vt struct cpufreq
+should be filled prior to the call:
+.Bd -literal -offset indent
+char                    cf_name[CPUFREQ_NAME_MAX];
+struct cpufreq_state     cf_state[CPUFREQ_STATE_MAX];
+uint32_t                 cf_state_count;
+bool                    cf_mp;
+void                    *cf_cookie;
+xcfunc_t                 cf_get_freq;
+xcfunc_t                 cf_set_freq;
+.Ed
+.Pp
+.Bl -bullet
+.It
+The name of the backend should be given in
+.Vt cf_name .
+.It
+The
+.Vt cpufreq_state
+structure conveys descriptive information about the frequency states.
+The following fields can be used for the registration:
+.Bd -literal -offset 2n
+uint32_t                cfs_freq;
+uint32_t                cfs_power;
+.Ed
+.Pp
+From these
+.Vt cfs_freq
+(the clock frequency in MHz) is mandatory, whereas the optional
+.Vt cfs_power
+can be filled to describe the power consumption (in mW) of each state.
+.Pp
+If the backend operates with a simple boolean switch
+without knowing the clock frequencies, the
+.Fa cfs_freq
+field should be set to
+.Dv CPUFREQ_STATE_ENABLED
+or
+.Dv CPUFREQ_STATE_DISABLED .
+.It
+The
+.Vt cf_state_count
+field defines the number of states that the backend has filled in the
+.Vt cf_state
+array.
+.It
+The
+.Vt cf_mp
+boolean should be set to false if it is known that the backend
+can not handle per-CPU frequency states;
+changes should always be propagated
+to all processors in the system.
+.It
+The
+.Vt cf_cookie
+field is an opaque pointer passed to the backend when
+.Fn cpufreq_get
+.Fn cpufreq_set ,
+or
+.Fn cpufreq_set_all
+is called.
+.It
+The
+.Vt cf_get_freq
+and
+.Vt cf_set_freq
+are function pointers that should be associated with the
+machine-dependent functions to get and set a frequency, respectively.
+The
+.Vt xcfunc_t



Home | Main Index | Thread Index | Old Index