326 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * Intel Speed Select -- Enumerate and control features4 * Copyright (c) 2019 Intel Corporation.5 */6 7#ifndef _ISST_H_8#define _ISST_H_9 10#include <stdio.h>11#include <unistd.h>12#include <sys/types.h>13#include <sched.h>14#include <sys/stat.h>15#include <sys/resource.h>16#include <getopt.h>17#include <err.h>18#include <fcntl.h>19#include <signal.h>20#include <sys/time.h>21#include <limits.h>22#include <stdlib.h>23#include <string.h>24#include <cpuid.h>25#include <dirent.h>26#include <errno.h>27 28#include <stdarg.h>29#include <sys/ioctl.h>30 31#include <linux/isst_if.h>32 33#define BIT(x) (1 << (x))34#define BIT_ULL(nr) (1ULL << (nr))35#define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (sizeof(long) * 8 - 1 - (h))))36#define GENMASK_ULL(h, l) \37 (((~0ULL) << (l)) & (~0ULL >> (sizeof(long long) * 8 - 1 - (h))))38 39#define CONFIG_TDP 0x7f40#define CONFIG_TDP_GET_LEVELS_INFO 0x0041#define CONFIG_TDP_GET_TDP_CONTROL 0x0142#define CONFIG_TDP_SET_TDP_CONTROL 0x0243#define CONFIG_TDP_GET_TDP_INFO 0x0344#define CONFIG_TDP_GET_PWR_INFO 0x0445#define CONFIG_TDP_GET_TJMAX_INFO 0x0546#define CONFIG_TDP_GET_CORE_MASK 0x0647#define CONFIG_TDP_GET_TURBO_LIMIT_RATIOS 0x0748#define CONFIG_TDP_SET_LEVEL 0x0849#define CONFIG_TDP_GET_UNCORE_P0_P1_INFO 0X0950#define CONFIG_TDP_GET_P1_INFO 0x0a51#define CONFIG_TDP_GET_MEM_FREQ 0x0b52#define CONFIG_TDP_GET_RATIO_INFO 0x0c53 54#define CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES 0x1055#define CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS 0x1156#define CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO 0x1257 58#define CONFIG_TDP_PBF_GET_CORE_MASK_INFO 0x2059#define CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO 0x2160#define CONFIG_TDP_PBF_GET_TJ_MAX_INFO 0x2261#define CONFIG_TDP_PBF_GET_TDP_INFO 0X2362 63#define CONFIG_CLOS 0xd064#define CLOS_PQR_ASSOC 0x0065#define CLOS_PM_CLOS 0x0166#define CLOS_PM_QOS_CONFIG 0x0267#define CLOS_STATUS 0x0368 69#define MBOX_CMD_WRITE_BIT 0x0870 71#define PM_QOS_INFO_OFFSET 0x0072#define PM_QOS_CONFIG_OFFSET 0x0473#define PM_CLOS_OFFSET 0x0874#define PQR_ASSOC_OFFSET 0x2075 76#define READ_PM_CONFIG 0x9477#define WRITE_PM_CONFIG 0x9578#define PM_FEATURE 0x0379 80#define DISP_FREQ_MULTIPLIER 10081 82#define MAX_PACKAGE_COUNT 3283#define MAX_DIE_PER_PACKAGE 1684#define MAX_PUNIT_PER_DIE 885 86/* Unified structure to specific a CPU or a Power Domain */87struct isst_id {88 int cpu;89 int pkg;90 int die;91 int punit;92};93 94struct isst_clos_config {95 unsigned int clos_min;96 unsigned int clos_max;97 unsigned char epp;98 unsigned char clos_prop_prio;99 unsigned char clos_desired;100};101 102struct isst_fact_bucket_info {103 int hp_cores;104 int hp_ratios[TRL_MAX_LEVELS];105};106 107struct isst_pbf_info {108 int pbf_acticated;109 int pbf_available;110 size_t core_cpumask_size;111 cpu_set_t *core_cpumask;112 int p1_high;113 int p1_low;114 int t_control;115 int t_prochot;116 int tdp;117};118 119#define ISST_TRL_MAX_ACTIVE_CORES 8120#define ISST_FACT_MAX_BUCKETS 8121struct isst_fact_info {122 int lp_ratios[TRL_MAX_LEVELS];123 struct isst_fact_bucket_info bucket_info[ISST_FACT_MAX_BUCKETS];124};125 126struct isst_pkg_ctdp_level_info {127 int processed;128 int control_cpu;129 int pkg_id;130 int die_id;131 int level;132 int fact_support;133 int pbf_support;134 int fact_enabled;135 int pbf_enabled;136 int sst_cp_support;137 int sst_cp_enabled;138 int tdp_ratio;139 int active;140 int tdp_control;141 int pkg_tdp;142 int pkg_min_power;143 int pkg_max_power;144 int fact;145 int t_proc_hot;146 int cooling_type;147 int uncore_p0;148 int uncore_p1;149 int uncore_pm;150 int sse_p1;151 int avx2_p1;152 int avx512_p1;153 int amx_p1;154 int mem_freq;155 size_t core_cpumask_size;156 cpu_set_t *core_cpumask;157 int cpu_count;158 unsigned long long trl_cores; /* Buckets info */159 int trl_ratios[TRL_MAX_LEVELS][ISST_TRL_MAX_ACTIVE_CORES];160 int kobj_bucket_index;161 int active_bucket;162 int fact_max_index;163 int fact_max_config;164 int pbf_found;165 int pbf_active;166 struct isst_pbf_info pbf_info;167 struct isst_fact_info fact_info;168};169 170#define ISST_MAX_TDP_LEVELS (4 + 1) /* +1 for base config */171struct isst_pkg_ctdp {172 int locked;173 int version;174 int processed;175 int levels;176 int current_level;177 int enabled;178 struct isst_pkg_ctdp_level_info ctdp_level[ISST_MAX_TDP_LEVELS];179};180 181enum isst_platform_param {182 ISST_PARAM_MBOX_DELAY,183 ISST_PARAM_MBOX_RETRIES,184};185 186struct isst_platform_ops {187 int (*get_disp_freq_multiplier)(void);188 int (*get_trl_max_levels)(void);189 char *(*get_trl_level_name)(int level);190 void (*update_platform_param)(enum isst_platform_param param, int value);191 int (*is_punit_valid)(struct isst_id *id);192 int (*read_pm_config)(struct isst_id *id, int *cp_state, int *cp_cap);193 int (*get_config_levels)(struct isst_id *id, struct isst_pkg_ctdp *pkg_ctdp);194 int (*get_ctdp_control)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);195 int (*get_tdp_info)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);196 int (*get_pwr_info)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);197 int (*get_coremask_info)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);198 int (*get_get_trl)(struct isst_id *id, int level, int avx_level, int *trl);199 int (*get_get_trls)(struct isst_id *id, int level, struct isst_pkg_ctdp_level_info *ctdp_level);200 int (*get_trl_bucket_info)(struct isst_id *id, int level, unsigned long long *buckets_info);201 int (*set_tdp_level)(struct isst_id *id, int tdp_level);202 int (*get_pbf_info)(struct isst_id *id, int level, struct isst_pbf_info *pbf_info);203 int (*set_pbf_fact_status)(struct isst_id *id, int pbf, int enable);204 int (*get_fact_info)(struct isst_id *id, int level, int fact_bucket, struct isst_fact_info *fact_info);205 void (*adjust_uncore_freq)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);206 int (*get_clos_information)(struct isst_id *id, int *enable, int *type);207 int (*pm_qos_config)(struct isst_id *id, int enable_clos, int priority_type);208 int (*pm_get_clos)(struct isst_id *id, int clos, struct isst_clos_config *clos_config);209 int (*set_clos)(struct isst_id *id, int clos, struct isst_clos_config *clos_config);210 int (*clos_get_assoc_status)(struct isst_id *id, int *clos_id);211 int (*clos_associate)(struct isst_id *id, int clos_id);212};213 214extern int is_cpu_in_power_domain(int cpu, struct isst_id *id);215extern int get_topo_max_cpus(void);216extern int get_cpu_count(struct isst_id *id);217extern int get_max_punit_core_id(struct isst_id *id);218extern int api_version(void);219 220/* Common interfaces */221FILE *get_output_file(void);222extern int is_debug_enabled(void);223extern void debug_printf(const char *format, ...);224extern int out_format_is_json(void);225extern void set_isst_id(struct isst_id *id, int cpu);226extern size_t alloc_cpu_set(cpu_set_t **cpu_set);227extern void free_cpu_set(cpu_set_t *cpu_set);228extern int find_phy_core_num(int logical_cpu);229extern void set_cpu_mask_from_punit_coremask(struct isst_id *id,230 unsigned long long core_mask,231 size_t core_cpumask_size,232 cpu_set_t *core_cpumask,233 int *cpu_cnt);234extern int isst_send_msr_command(unsigned int cpu, unsigned int command,235 int write, unsigned long long *req_resp);236 237extern int isst_set_platform_ops(int api_version);238extern void isst_update_platform_param(enum isst_platform_param, int vale);239extern int isst_get_disp_freq_multiplier(void);240extern int isst_get_trl_max_levels(void);241extern char *isst_get_trl_level_name(int level);242extern int isst_is_punit_valid(struct isst_id *id);243 244extern int isst_get_ctdp_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev);245extern int isst_get_ctdp_control(struct isst_id *id, int config_index,246 struct isst_pkg_ctdp_level_info *ctdp_level);247extern int isst_get_coremask_info(struct isst_id *id, int config_index,248 struct isst_pkg_ctdp_level_info *ctdp_level);249extern void isst_adjust_uncore_freq(struct isst_id *id, int config_index,250 struct isst_pkg_ctdp_level_info *ctdp_level);251extern int isst_get_process_ctdp(struct isst_id *id, int tdp_level,252 struct isst_pkg_ctdp *pkg_dev);253extern void isst_get_process_ctdp_complete(struct isst_id *id,254 struct isst_pkg_ctdp *pkg_dev);255extern void isst_ctdp_display_information(struct isst_id *id, FILE *outf, int tdp_level,256 struct isst_pkg_ctdp *pkg_dev);257extern void isst_ctdp_display_core_info(struct isst_id *id, FILE *outf, char *prefix,258 unsigned int val, char *str0, char *str1);259extern void isst_ctdp_display_information_start(FILE *outf);260extern void isst_ctdp_display_information_end(FILE *outf);261extern void isst_pbf_display_information(struct isst_id *id, FILE *outf, int level,262 struct isst_pbf_info *info);263extern int isst_set_tdp_level(struct isst_id *id, int tdp_level);264extern int isst_set_pbf_fact_status(struct isst_id *id, int pbf, int enable);265extern int isst_get_pbf_info(struct isst_id *id, int level,266 struct isst_pbf_info *pbf_info);267extern int isst_get_fact_info(struct isst_id *id, int level, int fact_bucket,268 struct isst_fact_info *fact_info);269extern void isst_fact_display_information(struct isst_id *id, FILE *outf, int level,270 int fact_bucket, int fact_avx,271 struct isst_fact_info *fact_info);272extern int isst_set_trl(struct isst_id *id, unsigned long long trl);273extern int isst_get_trl(struct isst_id *id, unsigned long long *trl);274extern int isst_set_trl_from_current_tdp(struct isst_id *id, unsigned long long trl);275extern int isst_get_config_tdp_lock_status(struct isst_id *id);276 277extern int isst_pm_qos_config(struct isst_id *id, int enable_clos, int priority_type);278extern int isst_pm_get_clos(struct isst_id *id, int clos,279 struct isst_clos_config *clos_config);280extern int isst_set_clos(struct isst_id *id, int clos,281 struct isst_clos_config *clos_config);282extern int isst_clos_associate(struct isst_id *id, int clos);283extern int isst_clos_get_assoc_status(struct isst_id *id, int *clos_id);284extern void isst_clos_display_information(struct isst_id *id, FILE *outf, int clos,285 struct isst_clos_config *clos_config);286extern void isst_clos_display_assoc_information(struct isst_id *id, FILE *outf, int clos);287 288extern void isst_display_result(struct isst_id *id, FILE *outf, char *feature, char *cmd,289 int result);290 291extern int isst_clos_get_clos_information(struct isst_id *id, int *enable, int *type);292extern void isst_clos_display_clos_information(struct isst_id *id, FILE *outf,293 int clos_enable, int type,294 int state, int cap);295extern int is_clx_n_platform(void);296extern int get_cpufreq_base_freq(int cpu);297extern int isst_read_pm_config(struct isst_id *id, int *cp_state, int *cp_cap);298extern void isst_display_error_info_message(int error, char *msg, int arg_valid, int arg);299extern int is_skx_based_platform(void);300extern int is_spr_platform(void);301extern int is_emr_platform(void);302extern int is_icx_platform(void);303extern void isst_trl_display_information(struct isst_id *id, FILE *outf, unsigned long long trl);304 305extern void set_cpu_online_offline(int cpu, int state);306extern void for_each_online_power_domain_in_set(void (*callback)(struct isst_id *, void *, void *,307 void *, void *),308 void *arg1, void *arg2, void *arg3,309 void *arg4);310extern int isst_daemon(int debug_mode, int poll_interval, int no_daemon);311extern void process_level_change(struct isst_id *id);312extern int hfi_main(void);313extern void hfi_exit(void);314 315/* Interface specific callbacks */316extern struct isst_platform_ops *mbox_get_platform_ops(void);317extern struct isst_platform_ops *tpmi_get_platform_ops(void);318 319/* Cgroup related interface */320extern int enable_cpuset_controller(void);321extern int isolate_cpus(struct isst_id *id, int mask_size, cpu_set_t *cpu_mask,322 int level, int cpu_0_only);323extern int use_cgroupv2(void);324 325#endif326