Lines Matching defs:cpu
553 int get_msr(int cpu, off_t offset, unsigned long long *msr);
2100 int get_msr_sum(int cpu, off_t offset, unsigned long long *msr);
2316 char *sys_lpi_file_sysfs = "/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us";
2319 int cpu_is_not_present(int cpu)
2321 return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set);
2324 int cpu_is_not_allowed(int cpu)
2326 return !CPU_ISSET_S(cpu, cpu_allowed_setsize, cpu_allowed_set);
2384 int cpu_migrate(int cpu)
2387 CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set);
2394 int get_msr_fd(int cpu)
2399 fd = fd_percpu[cpu];
2404 sprintf(pathname, "/dev/msr%d", cpu);
2406 sprintf(pathname, "/dev/cpu/%d/msr", cpu);
2414 err(-1, "%s open failed, try chown or chmod +r /dev/cpu/*/msr, "
2417 fd_percpu[cpu] = fd;
2435 static long perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags)
2439 return syscall(__NR_perf_event_open, hw_event, pid, cpu, group_fd, flags);
2442 static long open_perf_counter(int cpu, unsigned int type, unsigned int config, int group_fd, __u64 read_format)
2459 const int fd = perf_event_open(&attr, pid, cpu, group_fd, flags);
2464 int get_instr_count_fd(int cpu)
2466 if (fd_instr_count_percpu[cpu])
2467 return fd_instr_count_percpu[cpu];
2469 fd_instr_count_percpu[cpu] = open_perf_counter(cpu, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, -1, 0);
2471 return fd_instr_count_percpu[cpu];
2474 int get_msr(int cpu, off_t offset, unsigned long long *msr)
2480 retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset);
2483 err(-1, "cpu%d: msr offset 0x%llx read failed", cpu, (unsigned long long)offset);
2488 int add_msr_counter(int cpu, off_t offset)
2499 retval = pread(get_msr_fd(cpu), &value, sizeof(value), offset);
2511 int add_rapl_msr_counter(int cpu, const struct rapl_counter_arch_info *cai)
2518 ret = add_msr_counter(cpu, cai->msr);
2537 unsigned int cpu_to_domain(const struct perf_counter_info *pc, int cpu)
2541 return cpu;
2544 return cpus[cpu].physical_core_id;
2547 return cpus[cpu].physical_package_id;
2578 " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n"
2581 " -c, --cpu cpu-set\n"
2582 " limit output to summary plus cpu-set:\n"
3167 /*if not summary line and --cpu is used */
3902 fprintf(outf, "cpu%d MPERF 0!\n", old->cpu_id);
4382 int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp, char *counter_path)
4386 if (get_msr(cpu, mp->msr_num, counterp))
4392 sprintf(path, "/sys/devices/system/cpu/cpu%d/%s", cpu, mp->sp->path);
4414 sprintf(path, "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d/current_freq_khz",
4428 int get_epb(int cpu)
4435 sprintf(path, "/sys/devices/system/cpu/cpu%d/power/energy_perf_bias", cpu);
4453 get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr);
4503 fprintf(outf, "cpu%d: BIOS BUG: apic 0x%x x2apic 0x%x\n", t->cpu_id, t->apic_id, t->x2apic_id);
4506 int get_core_throt_cnt(int cpu, unsigned long long *cnt)
4513 sprintf(path, "/sys/devices/system/cpu/cpu%d/thermal_throttle/core_throttle_count", cpu);
4707 int get_rapl_counters(int cpu, unsigned int domain, struct core_data *c, struct pkg_data *p)
4714 fprintf(stderr, "%s: cpu%d domain%d\n", __func__, cpu, domain);
4759 if (get_msr_sum(cpu, rci->msr[i], &rci->data[i]))
4762 if (get_msr(cpu, rci->msr[i], &rci->data[i]))
4801 int get_cstate_counters(unsigned int cpu, PER_THREAD_PARAMS)
4814 fprintf(stderr, "%s: cpu%d\n", __func__, cpu);
4817 assert(cpu <= ccstate_counter_info_size);
4823 cci = &ccstate_counter_info[cpu];
4893 if (get_msr(cpu, cci->msr[i], &cci->data[i]))
4905 * the counter for the current cpu is not none.
4946 int get_smi_aperf_mperf(unsigned int cpu, struct thread_data *t)
4953 fprintf(stderr, "%s: cpu%d\n", __func__, cpu);
4956 assert(cpu <= msr_counter_info_size);
4958 mci = &msr_counter_info[cpu];
4993 if (get_msr(cpu, mci->msr[i], &mci->data[i]))
5013 int perf_counter_info_read_values(struct perf_counter_info *pp, int cpu, unsigned long long *out, size_t out_size)
5020 domain = cpu_to_domain(pp, cpu);
5081 static inline int get_rapl_domain_id(int cpu)
5087 return cpus[cpu].physical_package_id;
5089 /* Compute the system-wide unique core-id for @cpu */
5090 rapl_core_id = cpus[cpu].physical_core_id;
5091 rapl_core_id += cpus[cpu].physical_package_id * nr_cores_per_package;
5098 * migrate to cpu
5099 * acquire and record local counters for that cpu
5103 int cpu = t->cpu_id;
5110 if (cpu_migrate(cpu)) {
5111 fprintf(outf, "%s: Could not migrate to CPU %d\n", __func__, cpu);
5122 get_smi_aperf_mperf(cpu, t);
5125 if (read(get_instr_count_fd(cpu), &t->instr_count, sizeof(long long)) != sizeof(long long))
5129 t->irq_count = irqs_per_cpu[cpu];
5131 t->nmi_count = nmi_per_cpu[cpu];
5133 get_cstate_counters(cpu, t, c, p);
5136 if (get_mp(cpu, mp, &t->counter[i], mp->sp->path))
5140 if (perf_counter_info_read_values(sys.perf_tp, cpu, t->perf_counter, MAX_ADDED_THREAD_COUNTERS))
5151 status = get_rapl_counters(cpu, get_rapl_domain_id(cpu), c, p);
5167 if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us))
5171 if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr))
5177 get_core_throt_cnt(cpu, &c->core_throt_cnt);
5180 if (get_mp(cpu, mp, &c->counter[i], mp->sp->path))
5184 if (perf_counter_info_read_values(sys.perf_cp, cpu, c->perf_counter, MAX_ADDED_CORE_COUNTERS))
5195 if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0))
5199 if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0))
5203 if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0))
5207 if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0))
5217 status = get_rapl_counters(cpu, get_rapl_domain_id(cpu), c, p);
5223 if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr))
5259 if (get_mp(cpu, mp, &p->counter[i], path))
5263 if (perf_counter_info_read_values(sys.perf_pp, cpu, p->perf_counter, MAX_ADDED_PACKAGE_COUNTERS))
5379 fprintf(outf, "cpu%d: MSR_PLATFORM_INFO: 0x%08llx\n", base_cpu, msr);
5396 fprintf(outf, "cpu%d: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n",
5413 fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT2: 0x%08llx\n", base_cpu, msr);
5432 fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", base_cpu, msr);
5474 fprintf(outf, "cpu%d: MSR_%sTURBO_RATIO_LIMIT: 0x%08llx\n",
5479 fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", base_cpu, core_counts);
5503 fprintf(outf, "cpu%d: MSR_ATOM_CORE_RATIOS: 0x%08llx\n", base_cpu, msr & 0xFFFFFFFF);
5518 fprintf(outf, "cpu%d: MSR_ATOM_CORE_TURBO_RATIOS: 0x%08llx\n", base_cpu, msr & 0xFFFFFFFF);
5549 fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", base_cpu, msr);
5603 fprintf(outf, "cpu%d: MSR_PKG_CST_CONFIG_CONTROL: 0x%08llx", base_cpu, msr);
5627 fprintf(outf, "cpu%d: MSR_CONFIG_TDP_NOMINAL: 0x%08llx", base_cpu, msr);
5631 fprintf(outf, "cpu%d: MSR_CONFIG_TDP_LEVEL_1: 0x%08llx (", base_cpu, msr);
5641 fprintf(outf, "cpu%d: MSR_CONFIG_TDP_LEVEL_2: 0x%08llx (", base_cpu, msr);
5651 fprintf(outf, "cpu%d: MSR_CONFIG_TDP_CONTROL: 0x%08llx (", base_cpu, msr);
5658 fprintf(outf, "cpu%d: MSR_TURBO_ACTIVATION_RATIO: 0x%08llx (", base_cpu, msr);
5675 fprintf(outf, "cpu%d: MSR_PKGC3_IRTL: 0x%08llx (", base_cpu, msr);
5682 fprintf(outf, "cpu%d: MSR_PKGC6_IRTL: 0x%08llx (", base_cpu, msr);
5689 fprintf(outf, "cpu%d: MSR_PKGC7_IRTL: 0x%08llx (", base_cpu, msr);
5696 fprintf(outf, "cpu%d: MSR_PKGC8_IRTL: 0x%08llx (", base_cpu, msr);
5703 fprintf(outf, "cpu%d: MSR_PKGC9_IRTL: 0x%08llx (", base_cpu, msr);
5710 fprintf(outf, "cpu%d: MSR_PKGC10_IRTL: 0x%08llx (", base_cpu, msr);
5771 for (int cpu = 0; cpu < topo.max_cpu_num; ++cpu) {
5772 if (msr_counter_info[cpu].fd_perf != -1)
5773 close(msr_counter_info[cpu].fd_perf);
5911 * cpu_is_first_core_in_package(cpu)
5914 int cpu_is_first_core_in_package(int cpu)
5916 return cpu == parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_siblings_list", cpu);
5919 int get_physical_package_id(int cpu)
5921 return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/physical_package_id", cpu);
5924 int get_die_id(int cpu)
5926 return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/die_id", cpu);
5929 int get_l3_id(int cpu)
5931 return parse_int_file("/sys/devices/system/cpu/cpu%d/cache/index3/id", cpu);
5934 int get_core_id(int cpu)
5936 return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_id", cpu);
5941 int pkg, node, lnode, cpu, cpux;
5945 for (cpu = 0; cpu <= topo.max_cpu_num; ++cpu)
5946 cpus[cpu].logical_node_id = -1;
5951 for (cpu = 0; cpu <= topo.max_cpu_num; ++cpu) {
5952 if (cpus[cpu].physical_package_id != pkg)
5954 /* find a cpu with an unset logical_node_id */
5955 if (cpus[cpu].logical_node_id != -1)
5957 cpus[cpu].logical_node_id = lnode;
5958 node = cpus[cpu].physical_node_id;
5964 for (cpux = cpu; cpux <= topo.max_cpu_num; cpux++) {
5984 int cpu = thiscpu->logical_cpu_id;
5987 sprintf(path, "/sys/devices/system/cpu/cpu%d/node%i/cpulist", cpu, i);
6004 if (*next == '-') /* no negative cpu numbers */
6059 int cpu = thiscpu->logical_cpu_id;
6073 sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", cpu);
6090 if ((so != cpu) && (cpus[so].thread_id < 0))
6142 * run func(cpu) on every cpu in /proc/stat
6153 retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n");
6158 retval = fscanf(fp, "cpu%u %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n", &cpu_num);
6209 err(1, "%s: cpu str malformat %s\n", PATH_EFFECTIVE_CPUS, cpu_effective_str);
6242 err(1, "cannot find calling cpu ID");
6243 sprintf(pathname, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", base_cpu);
6257 int count_cpus(int cpu)
6259 UNUSED(cpu);
6265 int mark_cpu_present(int cpu)
6267 CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set);
6271 int init_thread_id(int cpu)
6273 cpus[cpu].thread_id = -1;
6292 int set_cpu_hybrid_type(int cpu)
6294 if (cpu_migrate(cpu))
6299 cpus[cpu].type = type;
6320 /* read 1st line of /proc/interrupts to get cpu* name for each column */
6329 warn("/proc/interrupts: cpu%d: > %d", cpu_number, topo.max_cpu_num);
6338 /* read /proc/interrupt count lines and sum up irqs per cpu */
6351 /* read the count per cpu */
6410 * /sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us
6417 fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", "r");
6564 int get_msr_sum(int cpu, off_t offset, unsigned long long *msr)
6578 ret = get_msr(cpu, offset, &msr_cur);
6581 msr_last = per_cpu_msr_sum[cpu].entries[idx].last;
6583 *msr = msr_last + per_cpu_msr_sum[cpu].entries[idx].sum;
6594 int cpu = t->cpu_id;
6610 ret = get_msr(cpu, offset, &msr_cur);
6616 msr_last = per_cpu_msr_sum[cpu].entries[i].last;
6617 per_cpu_msr_sum[cpu].entries[i].last = msr_cur & 0xffffffff;
6620 per_cpu_msr_sum[cpu].entries[i].sum += msr_last;
6810 sprintf(pathname, "/dev/cpu/%d/msr", base_cpu);
6872 sprintf(pathname, "/dev/cpu/%d/msr", base_cpu);
7002 sprintf(path_base, "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d", i,
7039 if (access("/sys/devices/system/cpu/intel_uncore_frequency/uncore00/current_freq_khz", R_OK))
7044 sprintf(path_base, "/sys/devices/system/cpu/intel_uncore_frequency/uncore%02d", uncore_max_id);
7057 sprintf(path_base, "/sys/devices/system/cpu/intel_uncore_frequency/uncore%02d", i);
7116 if (access("/sys/devices/system/cpu/intel_uncore_frequency/uncore00", R_OK) == 0)
7245 if (access("/sys/devices/system/cpu/cpuidle", R_OK)) {
7250 dump_sysfs_file("/sys/devices/system/cpu/cpuidle/current_driver");
7251 dump_sysfs_file("/sys/devices/system/cpu/cpuidle/current_governor");
7252 dump_sysfs_file("/sys/devices/system/cpu/cpuidle/current_governor_ro");
7256 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", base_cpu, state);
7272 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/desc", base_cpu, state);
7279 fprintf(outf, "cpu%d: %s: %s", base_cpu, name_buf, desc);
7292 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_driver", base_cpu);
7302 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", base_cpu);
7312 fprintf(outf, "cpu%d: cpufreq driver: %s", base_cpu, driver_buf);
7313 fprintf(outf, "cpu%d: cpufreq governor: %s", base_cpu, governor_buf);
7315 sprintf(path, "/sys/devices/system/cpu/cpufreq/boost");
7324 sprintf(path, "/sys/devices/system/cpu/intel_pstate/no_turbo");
7341 int cpu, epb;
7349 cpu = t->cpu_id;
7355 if (cpu_migrate(cpu)) {
7356 fprintf(outf, "print_epb: Could not migrate to CPU %d\n", cpu);
7360 epb = get_epb(cpu);
7378 fprintf(outf, "cpu%d: EPB: %d (%s)\n", cpu, epb, epb_string);
7390 int cpu;
7401 cpu = t->cpu_id;
7407 if (cpu_migrate(cpu)) {
7408 fprintf(outf, "print_hwp: Could not migrate to CPU %d\n", cpu);
7412 if (get_msr(cpu, MSR_PM_ENABLE, &msr))
7415 fprintf(outf, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", cpu, msr, (msr & (1 << 0)) ? "" : "No-");
7421 if (get_msr(cpu, MSR_HWP_CAPABILITIES, &msr))
7424 fprintf(outf, "cpu%d: MSR_HWP_CAPABILITIES: 0x%08llx "
7426 cpu, msr,
7431 if (get_msr(cpu, MSR_HWP_REQUEST, &msr))
7434 fprintf(outf, "cpu%d: MSR_HWP_REQUEST: 0x%08llx "
7436 cpu, msr,
7444 if (get_msr(cpu, MSR_HWP_REQUEST_PKG, &msr))
7447 fprintf(outf, "cpu%d: MSR_HWP_REQUEST_PKG: 0x%08llx "
7449 cpu, msr,
7456 if (get_msr(cpu, MSR_HWP_INTERRUPT, &msr))
7459 fprintf(outf, "cpu%d: MSR_HWP_INTERRUPT: 0x%08llx "
7461 cpu, msr, ((msr) & 0x1) ? "EN" : "Dis", ((msr) & 0x2) ? "EN" : "Dis");
7463 if (get_msr(cpu, MSR_HWP_STATUS, &msr))
7466 fprintf(outf, "cpu%d: MSR_HWP_STATUS: 0x%08llx "
7468 cpu, msr, ((msr) & 0x1) ? "" : "No-", ((msr) & 0x4) ? "" : "No-");
7479 int cpu;
7487 cpu = t->cpu_id;
7493 if (cpu_migrate(cpu)) {
7494 fprintf(outf, "print_perf_limit: Could not migrate to CPU %d\n", cpu);
7499 get_msr(cpu, MSR_CORE_PERF_LIMIT_REASONS, &msr);
7500 fprintf(outf, "cpu%d: MSR_CORE_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr);
7532 get_msr(cpu, MSR_GFX_PERF_LIMIT_REASONS, &msr);
7533 fprintf(outf, "cpu%d: MSR_GFX_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr);
7552 get_msr(cpu, MSR_RING_PERF_LIMIT_REASONS, &msr);
7553 fprintf(outf, "cpu%d: MSR_RING_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr);
7687 void print_power_limit_msr(int cpu, unsigned long long msr, char *label)
7689 fprintf(outf, "cpu%d: %s: %sabled (%0.3f Watts, %f sec, clamp %sabled)\n",
7690 cpu, label,
7855 int cpu;
7867 cpu = t->cpu_id;
7868 if (cpu_migrate(cpu)) {
7869 fprintf(outf, "print_rapl: Could not migrate to CPU %d\n", cpu);
7875 if (get_msr(cpu, MSR_RAPL_PWR_UNIT, &msr))
7879 if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr))
7883 fprintf(outf, "cpu%d: %s: 0x%08llx (%f Watts, %f Joules, %f sec.)\n", cpu, msr_name, msr,
7888 if (get_msr(cpu, MSR_PKG_POWER_INFO, &msr))
7891 fprintf(outf, "cpu%d: MSR_PKG_POWER_INFO: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n",
7892 cpu, msr,
7901 if (get_msr(cpu, MSR_PKG_POWER_LIMIT, &msr))
7904 fprintf(outf, "cpu%d: MSR_PKG_POWER_LIMIT: 0x%08llx (%slocked)\n",
7905 cpu, msr, (msr >> 63) & 1 ? "" : "UN");
7907 print_power_limit_msr(cpu, msr, "PKG Limit #1");
7908 fprintf(outf, "cpu%d: PKG Limit #2: %sabled (%0.3f Watts, %f* sec, clamp %sabled)\n",
7909 cpu,
7915 if (get_msr(cpu, MSR_VR_CURRENT_CONFIG, &msr))
7918 fprintf(outf, "cpu%d: MSR_VR_CURRENT_CONFIG: 0x%08llx\n", cpu, msr);
7919 fprintf(outf, "cpu%d: PKG Limit #4: %f Watts (%slocked)\n",
7920 cpu, ((msr >> 0) & 0x1FFF) * rapl_power_units, (msr >> 31) & 1 ? "" : "UN");
7924 if (get_msr(cpu, MSR_DRAM_POWER_INFO, &msr))
7927 fprintf(outf, "cpu%d: MSR_DRAM_POWER_INFO,: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n",
7928 cpu, msr,
7935 if (get_msr(cpu, MSR_DRAM_POWER_LIMIT, &msr))
7937 fprintf(outf, "cpu%d: MSR_DRAM_POWER_LIMIT: 0x%08llx (%slocked)\n",
7938 cpu, msr, (msr >> 31) & 1 ? "" : "UN");
7940 print_power_limit_msr(cpu, msr, "DRAM Limit");
7943 if (get_msr(cpu, MSR_PP0_POLICY, &msr))
7946 fprintf(outf, "cpu%d: MSR_PP0_POLICY: %lld\n", cpu, msr & 0xF);
7949 if (get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr))
7951 fprintf(outf, "cpu%d: MSR_PP0_POWER_LIMIT: 0x%08llx (%slocked)\n",
7952 cpu, msr, (msr >> 31) & 1 ? "" : "UN");
7953 print_power_limit_msr(cpu, msr, "Cores Limit");
7956 if (get_msr(cpu, MSR_PP1_POLICY, &msr))
7959 fprintf(outf, "cpu%d: MSR_PP1_POLICY: %lld\n", cpu, msr & 0xF);
7961 if (get_msr(cpu, MSR_PP1_POWER_LIMIT, &msr))
7963 fprintf(outf, "cpu%d: MSR_PP1_POWER_LIMIT: 0x%08llx (%slocked)\n",
7964 cpu, msr, (msr >> 31) & 1 ? "" : "UN");
7965 print_power_limit_msr(cpu, msr, "GFX Limit");
8009 int cpu;
8022 cpu = t->cpu_id;
8023 if (cpu_migrate(cpu)) {
8024 fprintf(outf, "Could not migrate to CPU %d\n", cpu);
8030 fprintf(outf, "cpu%d: Using cmdline TCC Target (%d C)\n", cpu, tj_max);
8052 fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C) (%d default - %d offset)\n",
8053 cpu, msr, tcc_default - tcc_offset, tcc_default, tcc_offset);
8055 fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C)\n", cpu, msr, tcc_default);
8068 fprintf(outf, "cpu%d: Guessing tjMax %d C, Please use -T to specify\n", cpu, tj_max);
8077 int cpu;
8088 cpu = t->cpu_id;
8094 if (cpu_migrate(cpu)) {
8095 fprintf(outf, "print_thermal: Could not migrate to CPU %d\n", cpu);
8100 if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr))
8104 fprintf(outf, "cpu%d: MSR_IA32_PACKAGE_THERM_STATUS: 0x%08llx (%d C)\n", cpu, msr, tj_max - dts);
8106 if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, &msr))
8111 fprintf(outf, "cpu%d: MSR_IA32_PACKAGE_THERM_INTERRUPT: 0x%08llx (%d C, %d C)\n",
8112 cpu, msr, tj_max - dts, tj_max - dts2);
8118 if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr))
8123 fprintf(outf, "cpu%d: MSR_IA32_THERM_STATUS: 0x%08llx (%d C +/- %d)\n",
8124 cpu, msr, tj_max - dts, resolution);
8126 if (get_msr(cpu, MSR_IA32_THERM_INTERRUPT, &msr))
8131 fprintf(outf, "cpu%d: MSR_IA32_THERM_INTERRUPT: 0x%08llx (%d C, %d C)\n",
8132 cpu, msr, tj_max - dts, tj_max - dts2);
8140 if (!access("/sys/devices/system/cpu/cpu0/thermal_throttle/core_throttle_count", R_OK))
8186 fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n",
8201 fprintf(outf, "cpu%d: MSR_IA32_MISC_ENABLE: 0x%08llx (%sTCC %sEIST %sMWAIT %sPREFETCH %sTURBO)\n",
8222 "cpu%d: MSR_MISC_FEATURE_CONTROL: 0x%08llx (%sL2-Prefetch %sL2-Prefetch-pair %sL1-Prefetch %sL1-IP-Prefetch)\n",
8245 fprintf(outf, "cpu%d: MSR_MISC_PWR_MGMT: 0x%08llx (%sable-EIST_Coordination %sable-EPB %sable-OOB)\n",
8267 fprintf(outf, "cpu%d: MSR_CC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-CC6-Demotion)\n",
8271 fprintf(outf, "cpu%d: MSR_MC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-MC6-Demotion)\n",
8322 int add_rapl_perf_counter(int cpu, struct rapl_counter_info_t *rci, const struct rapl_counter_arch_info *cai,
8346 ret = open_perf_counter(cpu, rapl_type, rapl_energy_pkg_config, rci->fd_perf, PERF_FORMAT_GROUP);
8359 fprintf(stderr, "%s: %d (cpu: %d)\n", __func__, ret, cpu);
8420 for (int cpu = 0; cpu < topo.max_cpu_num + 1; ++cpu) {
8422 if (cpu_is_not_allowed(cpu))
8426 next_domain = get_rapl_domain_id(cpu);
8435 if ((cai->flags & RAPL_COUNTER_FLAG_PLATFORM_COUNTER) && (cpu != base_cpu))
8456 if (add_rapl_perf_counter(cpu, rci, cai, &scale, &unit) != -1) {
8463 } else if (add_rapl_msr_counter(cpu, cai) >= 0) {
8503 int add_cstate_perf_counter(int cpu, struct cstate_counter_info_t *cci, const struct cstate_counter_arch_info *cai)
8521 ret = open_perf_counter(cpu, type, config, *pfd_group, PERF_FORMAT_GROUP);
8532 fprintf(stderr, "%s: %d (cpu: %d)\n", __func__, ret, cpu);
8537 int add_msr_perf_counter(int cpu, struct msr_counter_info_t *cci, const struct msr_counter_arch_info *cai)
8550 ret = open_perf_counter(cpu, type, config, cci->fd_perf, PERF_FORMAT_GROUP);
8561 fprintf(stderr, "%s: %s/%s: %d (cpu: %d)\n", __func__, cai->perf_subsys, cai->perf_name, ret, cpu);
8575 for (int cpu = 0; cpu < mci_num; ++cpu)
8576 msr_counter_info[cpu].fd_perf = -1;
8584 for (int cpu = 0; cpu < mci_num; ++cpu) {
8586 struct msr_counter_info_t *const cci = &msr_counter_info[cpu];
8588 if (cpu_is_not_allowed(cpu))
8593 if (add_msr_perf_counter(cpu, cci, cai) != -1) {
8598 } else if (add_msr_counter(cpu, cai->msr) >= 0) {
8666 for (int cpu = 0; cpu < cci_num; ++cpu) {
8667 ccstate_counter_info[cpu].fd_perf_core = -1;
8668 ccstate_counter_info[cpu].fd_perf_pkg = -1;
8678 for (int cpu = 0; cpu < cci_num; ++cpu) {
8680 struct cstate_counter_info_t *const cci = &ccstate_counter_info[cpu];
8682 if (cpu_is_not_allowed(cpu))
8685 const int core_id = cpus[cpu].physical_core_id;
8686 const int pkg_id = cpus[cpu].physical_package_id;
8706 if (add_cstate_perf_counter(cpu, cci, cai) != -1) {
8712 && add_msr_counter(cpu, cai->msr) >= 0) {
8776 if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", R_OK))
9049 * in /dev/cpu/ return success for names that are numbers
9060 char *possible_file = "/sys/devices/system/cpu/possible";
9077 warnx("%s: cpu str malformat %s\n", possible_file, cpu_effective_str);
9164 err(1, "cpu%d not present", i);
9166 fprintf(stderr, "cpu%d not present\n", i);
9173 fprintf(stderr, "cpu%d not effective\n", i);
9207 fprintf(outf, "cpu%d NOT PRESENT\n", i);
9286 "cpu %d pkg %d die %d l3 %d node %d lnode %d core %d thread %d\n",
9545 for (int cpu = 0; cpu < topo.max_cpu_num + 1; ++cpu) {
9547 next_domain = cpu_to_domain(pinfo, cpu);
9551 if (cpu_is_not_allowed(cpu))
9559 * Instead of one, "/sys/bus/event_source/devices/cpu" device, there are
9565 * Code below, allow user to use the old "cpu" name, which is translated accordingly.
9569 if (strcmp(perf_device, "cpu") == 0 && perf_has_hybrid_devices()) {
9570 switch (cpus[cpu].type) {
9602 fd_perf = open_perf_counter(cpu, perf_type, perf_config, -1, 0);
9604 warnx("%s: perf/%s/%s: failed to open counter on cpu%d",
9605 __func__, perf_device, pinfo->event, cpu);
9614 fprintf(stderr, "Add perf/%s/%s cpu%d: %d\n",
9615 perf_device, pinfo->event, cpu, pinfo->fd_perf_per_domain[next_domain]);
9982 * Advance the cpu number and check if we should also advance offset to
10049 /* Otherwise, allow child to run on same cpu set as turbostat */
10398 if (!strncmp(add_command, "cpu", strlen("cpu"))) {
10624 if (sscanf(add_command + prefix_len, "cpu%u", &domain_id) == 1) {
10636 printf("%s: invalid value for scope. Expected cpu%%u, core%%u or package%%u.\n",
10855 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", base_cpu, state);
10904 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", base_cpu, state);
10992 fprintf(stderr, "\"--cpu %s\" malformed\n", optarg);
11003 { "cpu", required_argument, 0, 'c' },