FreeBSD kernel kern code
kern_cpu.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/cpu.h>
#include <sys/eventhandler.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/proc.h>
#include <sys/queue.h>
#include <sys/sbuf.h>
#include <sys/sched.h>
#include <sys/smp.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
#include <sys/sx.h>
#include <sys/timetc.h>
#include <sys/taskqueue.h>
#include "cpufreq_if.h"
Include dependency graph for kern_cpu.c:

Go to the source code of this file.

Data Structures

struct  cf_saved_freq
 
struct  cpufreq_softc
 
struct  cf_setting_array
 

Macros

#define CF_MAX_LEVELS   256
 
#define CF_MTX_INIT(x)   sx_init((x), "cpufreq lock")
 
#define CF_MTX_LOCK(x)   sx_xlock((x))
 
#define CF_MTX_UNLOCK(x)   sx_xunlock((x))
 
#define CF_MTX_ASSERT(x)   sx_assert((x), SX_XLOCKED)
 
#define CF_DEBUG(msg...)
 

Functions

 __FBSDID ("$FreeBSD$")
 
 TAILQ_HEAD (cf_setting_lst, cf_setting_array)
 
static int cpufreq_attach (device_t dev)
 
static void cpufreq_startup_task (void *ctx, int pending)
 
static int cpufreq_detach (device_t dev)
 
static int cf_set_method (device_t dev, const struct cf_level *level, int priority)
 
static int cf_get_method (device_t dev, struct cf_level *level)
 
static int cf_levels_method (device_t dev, struct cf_level *levels, int *count)
 
static int cpufreq_insert_abs (struct cpufreq_softc *sc, struct cf_setting *sets, int count)
 
static int cpufreq_expand_set (struct cpufreq_softc *sc, struct cf_setting_array *set_arr)
 
static struct cf_level * cpufreq_dup_set (struct cpufreq_softc *sc, struct cf_level *dup, struct cf_setting *set)
 
static int cpufreq_curr_sysctl (SYSCTL_HANDLER_ARGS)
 
static int cpufreq_levels_sysctl (SYSCTL_HANDLER_ARGS)
 
static int cpufreq_settings_sysctl (SYSCTL_HANDLER_ARGS)
 
 DRIVER_MODULE (cpufreq, cpu, cpufreq_driver, cpufreq_dc, 0, 0)
 
static SYSCTL_NODE (_debug, OID_AUTO, cpufreq, CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, "cpufreq debugging")
 
 SYSCTL_INT (_debug_cpufreq, OID_AUTO, lowest, CTLFLAG_RWTUN, &cf_lowest_freq, 1, "Don't provide levels below this frequency.")
 
 SYSCTL_INT (_debug_cpufreq, OID_AUTO, verbose, CTLFLAG_RWTUN, &cf_verbose, 1, "Print verbose debugging messages")
 
static int cpufreq_get_frequency (device_t dev)
 
static int cpufreq_get_level (device_t dev, struct cf_level *levels, int count)
 
static int cpufreq_add_levels (device_t cf_dev, struct cf_setting_lst *rel_sets)
 
static void cpufreq_add_freq_driver_sysctl (device_t cf_dev)
 
int cpufreq_register (device_t dev)
 
int cpufreq_unregister (device_t dev)
 
int cpufreq_settings_changed (device_t dev)
 

Variables

static device_method_t cpufreq_methods []
 
static driver_t cpufreq_driver
 
static devclass_t cpufreq_dc
 
static int cf_lowest_freq
 
static int cf_verbose
 

Macro Definition Documentation

◆ CF_DEBUG

#define CF_DEBUG (   msg...)
Value:
do { \
if (cf_verbose) \
printf("cpufreq: " msg); \
} while (0)
static int cf_verbose
Definition: kern_cpu.c:138

Definition at line 98 of file kern_cpu.c.

◆ CF_MAX_LEVELS

#define CF_MAX_LEVELS   256

Definition at line 62 of file kern_cpu.c.

◆ CF_MTX_ASSERT

#define CF_MTX_ASSERT (   x)    sx_assert((x), SX_XLOCKED)

Definition at line 96 of file kern_cpu.c.

◆ CF_MTX_INIT

#define CF_MTX_INIT (   x)    sx_init((x), "cpufreq lock")

Definition at line 93 of file kern_cpu.c.

◆ CF_MTX_LOCK

#define CF_MTX_LOCK (   x)    sx_xlock((x))

Definition at line 94 of file kern_cpu.c.

◆ CF_MTX_UNLOCK

#define CF_MTX_UNLOCK (   x)    sx_xunlock((x))

Definition at line 95 of file kern_cpu.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ cf_get_method()

static int cf_get_method ( device_t  dev,
struct cf_level *  level 
)
static

◆ cf_levels_method()

static int cf_levels_method ( device_t  dev,
struct cf_level *  levels,
int *  count 
)
static

◆ cf_set_method()

static int cf_set_method ( device_t  dev,
const struct cf_level *  level,
int  priority 
)
static

◆ cpufreq_add_freq_driver_sysctl()

static void cpufreq_add_freq_driver_sysctl ( device_t  cf_dev)
static

Definition at line 1068 of file kern_cpu.c.

References device_get_nameunit(), device_get_softc(), and device_get_sysctl_tree().

Referenced by cpufreq_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpufreq_add_levels()

static int cpufreq_add_levels ( device_t  cf_dev,
struct cf_setting_lst *  rel_sets 
)
static

Definition at line 570 of file kern_cpu.c.

References CF_DEBUG, cf_setting_array::count, cpufreq_insert_abs(), device_get_nameunit(), device_get_softc(), device_is_attached(), free(), malloc(), sets, cf_setting_array::sets, and type.

Referenced by cf_levels_method().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpufreq_attach()

◆ cpufreq_curr_sysctl()

static int cpufreq_curr_sysctl ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 936 of file kern_cpu.c.

References CF_MAX_LEVELS, count, cpufreq_dc, devclass_get_devices(), free(), levels, printf(), and sysctl_handle_int().

Referenced by cpufreq_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpufreq_detach()

static int cpufreq_detach ( device_t  dev)
static

Definition at line 213 of file kern_cpu.c.

References CF_DEBUG, device_get_nameunit(), device_get_softc(), free(), and sysctl_ctx_free().

Here is the call graph for this function:

◆ cpufreq_dup_set()

static struct cf_level * cpufreq_dup_set ( struct cpufreq_softc sc,
struct cf_level *  dup,
struct cf_setting *  set 
)
static

Definition at line 841 of file kern_cpu.c.

References CF_DEBUG, CF_MTX_ASSERT, device_get_nameunit(), free(), cpufreq_softc::lock, malloc(), and set.

Referenced by cpufreq_expand_set().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpufreq_expand_set()

static int cpufreq_expand_set ( struct cpufreq_softc sc,
struct cf_setting_array set_arr 
)
static

Definition at line 785 of file kern_cpu.c.

References CF_DEBUG, CF_MTX_ASSERT, cf_setting_array::count, cpufreq_dup_set(), cpufreq_softc::lock, set, and cf_setting_array::sets.

Referenced by cf_levels_method().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpufreq_get_frequency()

static int cpufreq_get_frequency ( device_t  dev)
static

Definition at line 423 of file kern_cpu.c.

References set.

Referenced by cpufreq_get_level().

Here is the caller graph for this function:

◆ cpufreq_get_level()

static int cpufreq_get_level ( device_t  dev,
struct cf_level *  levels,
int  count 
)
static

Definition at line 435 of file kern_cpu.c.

References count, cpufreq_get_frequency(), and levels.

Referenced by cf_get_method().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpufreq_insert_abs()

static int cpufreq_insert_abs ( struct cpufreq_softc sc,
struct cf_setting *  sets,
int  count 
)
static

Definition at line 731 of file kern_cpu.c.

References CF_DEBUG, CF_MTX_ASSERT, count, level, cpufreq_softc::lock, malloc(), and sets.

Referenced by cf_levels_method(), and cpufreq_add_levels().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpufreq_levels_sysctl()

static int cpufreq_levels_sysctl ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 991 of file kern_cpu.c.

References CF_MAX_LEVELS, count, levels, printf(), sbuf_cpy(), sbuf_data(), sbuf_delete(), sbuf_finish(), sbuf_len(), sbuf_new(), sbuf_printf(), sbuf_trim(), set, and sysctl_handle_string().

Referenced by cpufreq_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpufreq_register()

◆ cpufreq_settings_changed()

int cpufreq_settings_changed ( device_t  dev)

Definition at line 1146 of file kern_cpu.c.

References device_get_parent(), and device_get_unit().

Referenced by cpufreq_startup_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpufreq_settings_sysctl()

static int cpufreq_settings_sysctl ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 1032 of file kern_cpu.c.

References free(), malloc(), sbuf_cpy(), sbuf_data(), sbuf_delete(), sbuf_finish(), sbuf_len(), sbuf_new(), sbuf_printf(), sbuf_trim(), sets, and sysctl_handle_string().

Referenced by cpufreq_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpufreq_startup_task()

static void cpufreq_startup_task ( void *  ctx,
int  pending 
)
static

Definition at line 206 of file kern_cpu.c.

References cpufreq_settings_changed().

Referenced by cpufreq_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpufreq_unregister()

int cpufreq_unregister ( device_t  dev)

Definition at line 1122 of file kern_cpu.c.

References device_delete_child(), device_find_child(), device_get_parent(), device_get_softc(), and device_printf().

Here is the call graph for this function:

◆ DRIVER_MODULE()

DRIVER_MODULE ( cpufreq  ,
cpu  ,
cpufreq_driver  ,
cpufreq_dc  ,
,
 
)

◆ SYSCTL_INT() [1/2]

SYSCTL_INT ( _debug_cpufreq  ,
OID_AUTO  ,
lowest  ,
CTLFLAG_RWTUN  ,
cf_lowest_freq,
,
"Don't provide levels below this frequency."   
)

◆ SYSCTL_INT() [2/2]

SYSCTL_INT ( _debug_cpufreq  ,
OID_AUTO  ,
verbose  ,
CTLFLAG_RWTUN  ,
cf_verbose,
,
"Print verbose debugging messages"   
)

◆ SYSCTL_NODE()

static SYSCTL_NODE ( _debug  ,
OID_AUTO  ,
cpufreq  ,
CTLFLAG_RD|  CTLFLAG_MPSAFE,
NULL  ,
"cpufreq debugging"   
)
static

◆ TAILQ_HEAD()

TAILQ_HEAD ( cf_setting_lst  ,
cf_setting_array   
)

Variable Documentation

◆ cf_lowest_freq

int cf_lowest_freq
static

Definition at line 137 of file kern_cpu.c.

Referenced by cf_levels_method(), and cf_set_method().

◆ cf_verbose

int cf_verbose
static

Definition at line 138 of file kern_cpu.c.

◆ cpufreq_dc

devclass_t cpufreq_dc
static

Definition at line 134 of file kern_cpu.c.

Referenced by cpufreq_curr_sysctl().

◆ cpufreq_driver

driver_t cpufreq_driver
static
Initial value:
= {
"cpufreq", cpufreq_methods, sizeof(struct cpufreq_softc)
}
static device_method_t cpufreq_methods[]
Definition: kern_cpu.c:121

Definition at line 131 of file kern_cpu.c.

◆ cpufreq_methods

device_method_t cpufreq_methods[]
static
Initial value:
= {
DEVMETHOD(cpufreq_set, cf_set_method),
DEVMETHOD(cpufreq_get, cf_get_method),
DEVMETHOD(cpufreq_levels, cf_levels_method),
{0, 0}
}
static int cpufreq_detach(device_t dev)
Definition: kern_cpu.c:213
static int cpufreq_attach(device_t dev)
Definition: kern_cpu.c:152
static int cf_levels_method(device_t dev, struct cf_level *levels, int *count)
Definition: kern_cpu.c:633
static int cf_set_method(device_t dev, const struct cf_level *level, int priority)
Definition: kern_cpu.c:233
static int cf_get_method(device_t dev, struct cf_level *level)
Definition: kern_cpu.c:455
int device_probe(device_t dev)
Probe a device, and return this status.
Definition: subr_bus.c:2943
int device_detach(device_t dev)
Detach a driver from a device.
Definition: subr_bus.c:3075
int device_attach(device_t dev)
Attach a device driver to a device.
Definition: subr_bus.c:3015
int bus_generic_probe(device_t dev)
Helper function for implementing DEVICE_PROBE()
Definition: subr_bus.c:3762

Definition at line 121 of file kern_cpu.c.