Lines Matching +full:monitor +full:- +full:interval +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * fam15h_power.c - AMD Family 15h processor power monitoring
5 * Copyright (c) 2011-2016 Advanced Micro Devices, Inc.
11 #include <linux/hwmon-sysfs.h>
23 MODULE_DESCRIPTION("AMD Family 15h CPU processor power monitor");
41 /* set maximum interval as 1 second */
77 struct pci_dev *f4 = data->pdev; in power1_input_show()
79 pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5), in power1_input_show()
96 pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5), in power1_input_show()
109 data->base_tdp)) << running_avg_range; in power1_input_show()
110 curr_pwr_watts -= running_avg_capture; in power1_input_show()
111 curr_pwr_watts *= data->tdp_to_watts; in power1_input_show()
130 return sprintf(buf, "%u\n", data->processor_pwr_watts); in power1_crit_show()
147 rdmsrl_safe(MSR_F15H_CU_PWR_ACCUMULATOR, &data->cu_acc_power[cu]); in do_read_registers_on_cu()
148 rdmsrl_safe(MSR_F15H_PTSC, &data->cpu_sw_pwr_ptsc[cu]); in do_read_registers_on_cu()
150 data->cu_on[cu] = 1; in do_read_registers_on_cu()
165 return -ENOMEM; in read_registers()
167 memset(data->cu_on, 0, sizeof(int) * MAX_CUS); in read_registers()
177 core = -1; in read_registers()
220 prev_cu_acc_power[cu] = data->cu_acc_power[cu]; in power1_average_show()
221 prev_ptsc[cu] = data->cpu_sw_pwr_ptsc[cu]; in power1_average_show()
224 leftover = schedule_timeout_interruptible(msecs_to_jiffies(data->power_period)); in power1_average_show()
234 if (data->cu_on[cu] == 0) in power1_average_show()
237 if (data->cu_acc_power[cu] < prev_cu_acc_power[cu]) { in power1_average_show()
238 jdelta[cu] = data->max_cu_acc_power + data->cu_acc_power[cu]; in power1_average_show()
239 jdelta[cu] -= prev_cu_acc_power[cu]; in power1_average_show()
241 jdelta[cu] = data->cu_acc_power[cu] - prev_cu_acc_power[cu]; in power1_average_show()
243 tdelta = data->cpu_sw_pwr_ptsc[cu] - prev_ptsc[cu]; in power1_average_show()
244 jdelta[cu] *= data->cpu_pwr_sample_ratio * 1000; in power1_average_show()
261 return sprintf(buf, "%lu\n", data->power_period); in power1_average_interval_show()
277 return -EINVAL; in power1_average_interval_store()
279 /* the interval value should be greater than 0 */ in power1_average_interval_store()
281 return -EINVAL; in power1_average_interval_store()
283 data->power_period = temp; in power1_average_interval_store()
296 if (c->x86 == 0x15 && in fam15h_power_init_attrs()
297 (c->x86_model <= 0xf || in fam15h_power_init_attrs()
298 (c->x86_model >= 0x60 && c->x86_model <= 0x7f))) in fam15h_power_init_attrs()
305 fam15h_power_attrs = devm_kcalloc(&pdev->dev, n, in fam15h_power_init_attrs()
310 return -ENOMEM; in fam15h_power_init_attrs()
314 if (c->x86 == 0x15 && in fam15h_power_init_attrs()
315 (c->x86_model <= 0xf || in fam15h_power_init_attrs()
316 (c->x86_model >= 0x60 && c->x86_model <= 0x7f))) in fam15h_power_init_attrs()
324 data->group.attrs = fam15h_power_attrs; in fam15h_power_init_attrs()
333 pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 3), in should_load_on_this_node()
363 pci_bus_read_config_dword(pdev->bus, in tweak_runavg_range()
364 PCI_DEVFN(PCI_SLOT(pdev->devfn), 5), in tweak_runavg_range()
371 pci_bus_write_config_dword(pdev->bus, in tweak_runavg_range()
372 PCI_DEVFN(PCI_SLOT(pdev->devfn), 5), in tweak_runavg_range()
394 data->base_tdp = val >> 16; in fam15h_power_init_data()
397 pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5), in fam15h_power_init_data()
400 data->tdp_to_watts = ((val & 0x3ff) << 6) | ((val >> 10) & 0x3f); in fam15h_power_init_data()
401 tmp *= data->tdp_to_watts; in fam15h_power_init_data()
405 dev_warn(&f4->dev, in fam15h_power_init_data()
410 data->processor_pwr_watts = (tmp * 15625) >> 10; in fam15h_power_init_data()
426 data->cpu_pwr_sample_ratio = cpuid_ecx(0x80000007); in fam15h_power_init_data()
430 return -ENODEV; in fam15h_power_init_data()
433 data->max_cu_acc_power = tmp; in fam15h_power_init_data()
436 * Milliseconds are a reasonable interval for the measurement. in fam15h_power_init_data()
439 * interval as 10 ms. in fam15h_power_init_data()
441 data->power_period = 10; in fam15h_power_init_data()
450 struct device *dev = &pdev->dev; in fam15h_power_probe()
457 * are working hand-in-hand in fam15h_power_probe()
462 return -ENODEV; in fam15h_power_probe()
466 return -ENOMEM; in fam15h_power_probe()
472 data->pdev = pdev; in fam15h_power_probe()
474 data->groups[0] = &data->group; in fam15h_power_probe()
478 &data->groups[0]); in fam15h_power_probe()