#define pr_fmt(fmt) …
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/cpu.h>
#include <linux/thermal.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/idle_inject.h>
#include <asm/msr.h>
#include <asm/mwait.h>
#include <asm/cpu_device_id.h>
#define MAX_TARGET_RATIO …
#define CONFIDENCE_OK …
#define DEFAULT_DURATION_JIFFIES …
static struct dentry *debug_dir;
static bool poll_pkg_cstate_enable;
static unsigned int current_ratio;
static bool should_skip;
struct powerclamp_data { … };
static struct powerclamp_data powerclamp_data;
static struct thermal_cooling_device *cooling_dev;
static DEFINE_MUTEX(powerclamp_lock);
static unsigned int duration;
static unsigned int pkg_cstate_ratio_cur;
static unsigned int window_size;
static int duration_set(const char *arg, const struct kernel_param *kp)
{ … }
static int duration_get(char *buf, const struct kernel_param *kp)
{ … }
static const struct kernel_param_ops duration_ops = …;
module_param_cb(…);
MODULE_PARM_DESC(…) …;
#define DEFAULT_MAX_IDLE …
#define MAX_ALL_CPU_IDLE …
static u8 max_idle = …;
static cpumask_var_t idle_injection_cpu_mask;
static int allocate_copy_idle_injection_mask(const struct cpumask *copy_mask)
{ … }
static bool check_invalid(cpumask_var_t mask, u8 idle)
{ … }
static int cpumask_set(const char *arg, const struct kernel_param *kp)
{ … }
static int cpumask_get(char *buf, const struct kernel_param *kp)
{ … }
static const struct kernel_param_ops cpumask_ops = …;
module_param_cb(…);
MODULE_PARM_DESC(…) …;
static int max_idle_set(const char *arg, const struct kernel_param *kp)
{ … }
static const struct kernel_param_ops max_idle_ops = …;
module_param_cb(…);
MODULE_PARM_DESC(…) …;
struct powerclamp_calibration_data { … };
static struct powerclamp_calibration_data cal_data[MAX_TARGET_RATIO];
static int window_size_set(const char *arg, const struct kernel_param *kp)
{ … }
static const struct kernel_param_ops window_size_ops = …;
module_param_cb(…);
MODULE_PARM_DESC(…) …;
struct pkg_cstate_info { … };
#define PKG_CSTATE_INIT(id) …
static struct pkg_cstate_info pkg_cstates[] = …;
static bool has_pkg_state_counter(void)
{ … }
static u64 pkg_state_counter(void)
{ … }
static unsigned int get_compensation(int ratio)
{ … }
static void adjust_compensation(int target_ratio, unsigned int win)
{ … }
static bool powerclamp_adjust_controls(unsigned int target_ratio,
unsigned int guard, unsigned int win)
{ … }
static unsigned int get_run_time(void)
{ … }
static void poll_pkg_cstate(struct work_struct *dummy);
static DECLARE_DELAYED_WORK(poll_pkg_cstate_work, poll_pkg_cstate);
static void poll_pkg_cstate(struct work_struct *dummy)
{ … }
static struct idle_inject_device *ii_dev;
static bool idle_inject_update(void)
{ … }
static void trigger_idle_injection(void)
{ … }
static int powerclamp_idle_injection_register(void)
{ … }
static void remove_idle_injection(void)
{ … }
static int start_power_clamp(void)
{ … }
static void end_power_clamp(void)
{ … }
static int powerclamp_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{ … }
static int powerclamp_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{ … }
static int powerclamp_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long new_target_ratio)
{ … }
static const struct thermal_cooling_device_ops powerclamp_cooling_ops = …;
static const struct x86_cpu_id __initconst intel_powerclamp_ids[] = …;
MODULE_DEVICE_TABLE(x86cpu, intel_powerclamp_ids);
static int __init powerclamp_probe(void)
{ … }
static int powerclamp_debug_show(struct seq_file *m, void *unused)
{ … }
DEFINE_SHOW_ATTRIBUTE(…);
static inline void powerclamp_create_debug_files(void)
{ … }
static int __init powerclamp_init(void)
{ … }
module_init(…) …;
static void __exit powerclamp_exit(void)
{ … }
module_exit(powerclamp_exit);
MODULE_IMPORT_NS(…);
MODULE_LICENSE(…) …;
MODULE_AUTHOR(…) …;
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;