Path: blob/master/tools/power/x86/intel-speed-select/isst.h
26295 views
/* SPDX-License-Identifier: GPL-2.0 */1/*2* Intel Speed Select -- Enumerate and control features3* Copyright (c) 2019 Intel Corporation.4*/56#ifndef _ISST_H_7#define _ISST_H_89#include <stdio.h>10#include <unistd.h>11#include <sys/types.h>12#include <sched.h>13#include <sys/stat.h>14#include <sys/resource.h>15#include <getopt.h>16#include <err.h>17#include <fcntl.h>18#include <signal.h>19#include <sys/time.h>20#include <limits.h>21#include <stdlib.h>22#include <string.h>23#include <cpuid.h>24#include <dirent.h>25#include <errno.h>2627#include <stdarg.h>28#include <sys/ioctl.h>2930#include <linux/isst_if.h>3132#define BIT(x) (1 << (x))33#define BIT_ULL(nr) (1ULL << (nr))34#define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (sizeof(long) * 8 - 1 - (h))))35#define GENMASK_ULL(h, l) \36(((~0ULL) << (l)) & (~0ULL >> (sizeof(long long) * 8 - 1 - (h))))3738#define CONFIG_TDP 0x7f39#define CONFIG_TDP_GET_LEVELS_INFO 0x0040#define CONFIG_TDP_GET_TDP_CONTROL 0x0141#define CONFIG_TDP_SET_TDP_CONTROL 0x0242#define CONFIG_TDP_GET_TDP_INFO 0x0343#define CONFIG_TDP_GET_PWR_INFO 0x0444#define CONFIG_TDP_GET_TJMAX_INFO 0x0545#define CONFIG_TDP_GET_CORE_MASK 0x0646#define CONFIG_TDP_GET_TURBO_LIMIT_RATIOS 0x0747#define CONFIG_TDP_SET_LEVEL 0x0848#define CONFIG_TDP_GET_UNCORE_P0_P1_INFO 0X0949#define CONFIG_TDP_GET_P1_INFO 0x0a50#define CONFIG_TDP_GET_MEM_FREQ 0x0b51#define CONFIG_TDP_GET_RATIO_INFO 0x0c5253#define CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES 0x1054#define CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS 0x1155#define CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO 0x125657#define CONFIG_TDP_PBF_GET_CORE_MASK_INFO 0x2058#define CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO 0x2159#define CONFIG_TDP_PBF_GET_TJ_MAX_INFO 0x2260#define CONFIG_TDP_PBF_GET_TDP_INFO 0X236162#define CONFIG_CLOS 0xd063#define CLOS_PQR_ASSOC 0x0064#define CLOS_PM_CLOS 0x0165#define CLOS_PM_QOS_CONFIG 0x0266#define CLOS_STATUS 0x036768#define MBOX_CMD_WRITE_BIT 0x086970#define PM_QOS_INFO_OFFSET 0x0071#define PM_QOS_CONFIG_OFFSET 0x0472#define PM_CLOS_OFFSET 0x0873#define PQR_ASSOC_OFFSET 0x207475#define READ_PM_CONFIG 0x9476#define WRITE_PM_CONFIG 0x9577#define PM_FEATURE 0x037879#define DISP_FREQ_MULTIPLIER 1008081#define MAX_PACKAGE_COUNT 3282#define MAX_DIE_PER_PACKAGE 1683#define MAX_PUNIT_PER_DIE 88485/* Unified structure to specific a CPU or a Power Domain */86struct isst_id {87int cpu;88int pkg;89int die;90int punit;91};9293struct isst_clos_config {94unsigned int clos_min;95unsigned int clos_max;96unsigned char epp;97unsigned char clos_prop_prio;98unsigned char clos_desired;99};100101struct isst_fact_bucket_info {102int hp_cores;103int hp_ratios[TRL_MAX_LEVELS];104};105106struct isst_pbf_info {107int pbf_acticated;108int pbf_available;109size_t core_cpumask_size;110cpu_set_t *core_cpumask;111int p1_high;112int p1_low;113int t_control;114int t_prochot;115int tdp;116};117118#define ISST_TRL_MAX_ACTIVE_CORES 8119#define ISST_FACT_MAX_BUCKETS 8120struct isst_fact_info {121int lp_ratios[TRL_MAX_LEVELS];122struct isst_fact_bucket_info bucket_info[ISST_FACT_MAX_BUCKETS];123};124125struct isst_pkg_ctdp_level_info {126int processed;127int control_cpu;128int pkg_id;129int die_id;130int level;131int fact_support;132int pbf_support;133int fact_enabled;134int pbf_enabled;135int sst_cp_support;136int sst_cp_enabled;137int tdp_ratio;138int active;139int tdp_control;140int pkg_tdp;141int pkg_min_power;142int pkg_max_power;143int fact;144int t_proc_hot;145int cooling_type;146int uncore_p0;147int uncore_p1;148int uncore_pm;149int uncore1_p0;150int uncore1_p1;151int uncore1_pm;152int sse_p1;153int avx2_p1;154int avx512_p1;155int amx_p1;156int mem_freq;157size_t core_cpumask_size;158cpu_set_t *core_cpumask;159int cpu_count;160unsigned long long trl_cores; /* Buckets info */161int trl_ratios[TRL_MAX_LEVELS][ISST_TRL_MAX_ACTIVE_CORES];162int kobj_bucket_index;163int active_bucket;164int fact_max_index;165int fact_max_config;166int pbf_found;167int pbf_active;168struct isst_pbf_info pbf_info;169struct isst_fact_info fact_info;170};171172#define ISST_MAX_TDP_LEVELS (4 + 1) /* +1 for base config */173struct isst_pkg_ctdp {174int locked;175int version;176int processed;177int levels;178int current_level;179int enabled;180struct isst_pkg_ctdp_level_info ctdp_level[ISST_MAX_TDP_LEVELS];181};182183enum isst_platform_param {184ISST_PARAM_MBOX_DELAY,185ISST_PARAM_MBOX_RETRIES,186};187188struct isst_platform_ops {189int (*get_disp_freq_multiplier)(void);190int (*get_trl_max_levels)(void);191char *(*get_trl_level_name)(int level);192void (*update_platform_param)(enum isst_platform_param param, int value);193int (*is_punit_valid)(struct isst_id *id);194int (*read_pm_config)(struct isst_id *id, int *cp_state, int *cp_cap);195int (*get_config_levels)(struct isst_id *id, struct isst_pkg_ctdp *pkg_ctdp);196int (*get_ctdp_control)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);197int (*get_tdp_info)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);198int (*get_pwr_info)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);199int (*get_coremask_info)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);200int (*get_get_trl)(struct isst_id *id, int level, int avx_level, int *trl);201int (*get_get_trls)(struct isst_id *id, int level, struct isst_pkg_ctdp_level_info *ctdp_level);202int (*get_trl_bucket_info)(struct isst_id *id, int level, unsigned long long *buckets_info);203int (*set_tdp_level)(struct isst_id *id, int tdp_level);204int (*get_pbf_info)(struct isst_id *id, int level, struct isst_pbf_info *pbf_info);205int (*set_pbf_fact_status)(struct isst_id *id, int pbf, int enable);206int (*get_fact_info)(struct isst_id *id, int level, int fact_bucket, struct isst_fact_info *fact_info);207void (*adjust_uncore_freq)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);208int (*get_clos_information)(struct isst_id *id, int *enable, int *type);209int (*pm_qos_config)(struct isst_id *id, int enable_clos, int priority_type);210int (*pm_get_clos)(struct isst_id *id, int clos, struct isst_clos_config *clos_config);211int (*set_clos)(struct isst_id *id, int clos, struct isst_clos_config *clos_config);212int (*clos_get_assoc_status)(struct isst_id *id, int *clos_id);213int (*clos_associate)(struct isst_id *id, int clos_id);214};215216extern int is_cpu_in_power_domain(int cpu, struct isst_id *id);217extern int get_topo_max_cpus(void);218extern int get_cpu_count(struct isst_id *id);219extern int get_max_punit_core_id(struct isst_id *id);220extern int api_version(void);221222/* Common interfaces */223FILE *get_output_file(void);224extern int is_debug_enabled(void);225extern void debug_printf(const char *format, ...);226extern int out_format_is_json(void);227extern void set_isst_id(struct isst_id *id, int cpu);228extern size_t alloc_cpu_set(cpu_set_t **cpu_set);229extern void free_cpu_set(cpu_set_t *cpu_set);230extern int find_phy_core_num(int logical_cpu);231extern void set_cpu_mask_from_punit_coremask(struct isst_id *id,232unsigned long long core_mask,233size_t core_cpumask_size,234cpu_set_t *core_cpumask,235int *cpu_cnt);236extern int isst_send_msr_command(unsigned int cpu, unsigned int command,237int write, unsigned long long *req_resp);238239extern int isst_set_platform_ops(int api_version);240extern void isst_update_platform_param(enum isst_platform_param, int vale);241extern int isst_get_disp_freq_multiplier(void);242extern int isst_get_trl_max_levels(void);243extern char *isst_get_trl_level_name(int level);244extern int isst_is_punit_valid(struct isst_id *id);245246extern int isst_get_ctdp_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev);247extern int isst_get_ctdp_control(struct isst_id *id, int config_index,248struct isst_pkg_ctdp_level_info *ctdp_level);249extern int isst_get_coremask_info(struct isst_id *id, int config_index,250struct isst_pkg_ctdp_level_info *ctdp_level);251extern void isst_adjust_uncore_freq(struct isst_id *id, int config_index,252struct isst_pkg_ctdp_level_info *ctdp_level);253extern int isst_get_process_ctdp(struct isst_id *id, int tdp_level,254struct isst_pkg_ctdp *pkg_dev);255extern void isst_get_process_ctdp_complete(struct isst_id *id,256struct isst_pkg_ctdp *pkg_dev);257extern void isst_ctdp_display_information(struct isst_id *id, FILE *outf, int tdp_level,258struct isst_pkg_ctdp *pkg_dev);259extern void isst_ctdp_display_core_info(struct isst_id *id, FILE *outf, char *prefix,260unsigned int val, char *str0, char *str1);261extern void isst_ctdp_display_information_start(FILE *outf);262extern void isst_ctdp_display_information_end(FILE *outf);263extern void isst_pbf_display_information(struct isst_id *id, FILE *outf, int level,264struct isst_pbf_info *info);265extern int isst_set_tdp_level(struct isst_id *id, int tdp_level);266extern int isst_set_pbf_fact_status(struct isst_id *id, int pbf, int enable);267extern int isst_get_pbf_info(struct isst_id *id, int level,268struct isst_pbf_info *pbf_info);269extern int isst_get_fact_info(struct isst_id *id, int level, int fact_bucket,270struct isst_fact_info *fact_info);271extern void isst_fact_display_information(struct isst_id *id, FILE *outf, int level,272int fact_bucket, int fact_avx,273struct isst_fact_info *fact_info);274extern int isst_set_trl(struct isst_id *id, unsigned long long trl);275extern int isst_get_trl(struct isst_id *id, unsigned long long *trl);276extern int isst_set_trl_from_current_tdp(struct isst_id *id, unsigned long long trl);277extern int isst_get_config_tdp_lock_status(struct isst_id *id);278279extern int isst_pm_qos_config(struct isst_id *id, int enable_clos, int priority_type);280extern int isst_pm_get_clos(struct isst_id *id, int clos,281struct isst_clos_config *clos_config);282extern int isst_set_clos(struct isst_id *id, int clos,283struct isst_clos_config *clos_config);284extern int isst_clos_associate(struct isst_id *id, int clos);285extern int isst_clos_get_assoc_status(struct isst_id *id, int *clos_id);286extern void isst_clos_display_information(struct isst_id *id, FILE *outf, int clos,287struct isst_clos_config *clos_config);288extern void isst_clos_display_assoc_information(struct isst_id *id, FILE *outf, int clos);289290extern void isst_display_result(struct isst_id *id, FILE *outf, char *feature, char *cmd,291int result);292293extern int isst_clos_get_clos_information(struct isst_id *id, int *enable, int *type);294extern void isst_clos_display_clos_information(struct isst_id *id, FILE *outf,295int clos_enable, int type,296int state, int cap);297extern int is_clx_n_platform(void);298extern int get_cpufreq_base_freq(int cpu);299extern int isst_read_pm_config(struct isst_id *id, int *cp_state, int *cp_cap);300extern void isst_display_error_info_message(int error, char *msg, int arg_valid, int arg);301extern int is_skx_based_platform(void);302extern int is_spr_platform(void);303extern int is_emr_platform(void);304extern int is_icx_platform(void);305extern void isst_trl_display_information(struct isst_id *id, FILE *outf, unsigned long long trl);306307extern void set_cpu_online_offline(int cpu, int state);308extern void for_each_online_power_domain_in_set(void (*callback)(struct isst_id *, void *, void *,309void *, void *),310void *arg1, void *arg2, void *arg3,311void *arg4);312extern int isst_daemon(int debug_mode, int poll_interval, int no_daemon);313extern void process_level_change(struct isst_id *id);314extern int hfi_main(void);315extern void hfi_exit(void);316317/* Interface specific callbacks */318extern struct isst_platform_ops *mbox_get_platform_ops(void);319extern struct isst_platform_ops *tpmi_get_platform_ops(void);320321/* Cgroup related interface */322extern int enable_cpuset_controller(void);323extern int isolate_cpus(struct isst_id *id, int mask_size, cpu_set_t *cpu_mask,324int level, int cpu_0_only);325extern int use_cgroupv2(void);326327#endif328329330