diff options
author | 2023-02-21 18:24:12 -0800 | |
---|---|---|
committer | 2023-02-21 18:24:12 -0800 | |
commit | 5b7c4cabbb65f5c469464da6c5f614cbd7f730f2 (patch) | |
tree | cc5c2d0a898769fd59549594fedb3ee6f84e59a0 /tools/power/cpupower/debug | |
download | linux-5b7c4cabbb65f5c469464da6c5f614cbd7f730f2.tar.gz linux-5b7c4cabbb65f5c469464da6c5f614cbd7f730f2.zip |
Merge tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-nextgrafted
Pull networking updates from Jakub Kicinski:
"Core:
- Add dedicated kmem_cache for typical/small skb->head, avoid having
to access struct page at kfree time, and improve memory use.
- Introduce sysctl to set default RPS configuration for new netdevs.
- Define Netlink protocol specification format which can be used to
describe messages used by each family and auto-generate parsers.
Add tools for generating kernel data structures and uAPI headers.
- Expose all net/core sysctls inside netns.
- Remove 4s sleep in netpoll if carrier is instantly detected on
boot.
- Add configurable limit of MDB entries per port, and port-vlan.
- Continue populating drop reasons throughout the stack.
- Retire a handful of legacy Qdiscs and classifiers.
Protocols:
- Support IPv4 big TCP (TSO frames larger than 64kB).
- Add IP_LOCAL_PORT_RANGE socket option, to control local port range
on socket by socket basis.
- Track and report in procfs number of MPTCP sockets used.
- Support mixing IPv4 and IPv6 flows in the in-kernel MPTCP path
manager.
- IPv6: don't check net.ipv6.route.max_size and rely on garbage
collection to free memory (similarly to IPv4).
- Support Penultimate Segment Pop (PSP) flavor in SRv6 (RFC8986).
- ICMP: add per-rate limit counters.
- Add support for user scanning requests in ieee802154.
- Remove static WEP support.
- Support minimal Wi-Fi 7 Extremely High Throughput (EHT) rate
reporting.
- WiFi 7 EHT channel puncturing support (client & AP).
BPF:
- Add a rbtree data structure following the "next-gen data structure"
precedent set by recently added linked list, that is, by using
kfunc + kptr instead of adding a new BPF map type.
- Expose XDP hints via kfuncs with initial support for RX hash and
timestamp metadata.
- Add BPF_F_NO_TUNNEL_KEY extension to bpf_skb_set_tunnel_key to
better support decap on GRE tunnel devices not operating in collect
metadata.
- Improve x86 JIT's codegen for PROBE_MEM runtime error checks.
- Remove the need for trace_printk_lock for bpf_trace_printk and
bpf_trace_vprintk helpers.
- Extend libbpf's bpf_tracing.h support for tracing arguments of
kprobes/uprobes and syscall as a special case.
- Significantly reduce the search time for module symbols by
livepatch and BPF.
- Enable cpumasks to be used as kptrs, which is useful for tracing
programs tracking which tasks end up running on which CPUs in
different time intervals.
- Add support for BPF trampoline on s390x and riscv64.
- Add capability to export the XDP features supported by the NIC.
- Add __bpf_kfunc tag for marking kernel functions as kfuncs.
- Add cgroup.memory=nobpf kernel parameter option to disable BPF
memory accounting for container environments.
Netfilter:
- Remove the CLUSTERIP target. It has been marked as obsolete for
years, and we still have WARN splats wrt races of the out-of-band
/proc interface installed by this target.
- Add 'destroy' commands to nf_tables. They are identical to the
existing 'delete' commands, but do not return an error if the
referenced object (set, chain, rule...) did not exist.
Driver API:
- Improve cpumask_local_spread() locality to help NICs set the right
IRQ affinity on AMD platforms.
- Separate C22 and C45 MDIO bus transactions more clearly.
- Introduce new DCB table to control DSCP rewrite on egress.
- Support configuration of Physical Layer Collision Avoidance (PLCA)
Reconciliation Sublayer (RS) (802.3cg-2019). Modern version of
shared medium Ethernet.
- Support for MAC Merge layer (IEEE 802.3-2018 clause 99). Allowing
preemption of low priority frames by high priority frames.
- Add support for controlling MACSec offload using netlink SET.
- Rework devlink instance refcounts to allow registration and
de-registration under the instance lock. Split the code into
multiple files, drop some of the unnecessarily granular locks and
factor out common parts of netlink operation handling.
- Add TX frame aggregation parameters (for USB drivers).
- Add a new attr TCA_EXT_WARN_MSG to report TC (offload) warning
messages with notifications for debug.
- Allow offloading of UDP NEW connections via act_ct.
- Add support for per action HW stats in TC.
- Support hardware miss to TC action (continue processing in SW from
a specific point in the action chain).
- Warn if old Wireless Extension user space interface is used with
modern cfg80211/mac80211 drivers. Do not support Wireless
Extensions for Wi-Fi 7 devices at all. Everyone should switch to
using nl80211 interface instead.
- Improve the CAN bit timing configuration. Use extack to return
error messages directly to user space, update the SJW handling,
including the definition of a new default value that will benefit
CAN-FD controllers, by increasing their oscillator tolerance.
New hardware / drivers:
- Ethernet:
- nVidia BlueField-3 support (control traffic driver)
- Ethernet support for imx93 SoCs
- Motorcomm yt8531 gigabit Ethernet PHY
- onsemi NCN26000 10BASE-T1S PHY (with support for PLCA)
- Microchip LAN8841 PHY (incl. cable diagnostics and PTP)
- Amlogic gxl MDIO mux
- WiFi:
- RealTek RTL8188EU (rtl8xxxu)
- Qualcomm Wi-Fi 7 devices (ath12k)
- CAN:
- Renesas R-Car V4H
Drivers:
- Bluetooth:
- Set Per Platform Antenna Gain (PPAG) for Intel controllers.
- Ethernet NICs:
- Intel (1G, igc):
- support TSN / Qbv / packet scheduling features of i226 model
- Intel (100G, ice):
- use GNSS subsystem instead of TTY
- multi-buffer XDP support
- extend support for GPIO pins to E823 devices
- nVidia/Mellanox:
- update the shared buffer configuration on PFC commands
- implement PTP adjphase function for HW offset control
- TC support for Geneve and GRE with VF tunnel offload
- more efficient crypto key management method
- multi-port eswitch support
- Netronome/Corigine:
- add DCB IEEE support
- support IPsec offloading for NFP3800
- Freescale/NXP (enetc):
- support XDP_REDIRECT for XDP non-linear buffers
- improve reconfig, avoid link flap and waiting for idle
- support MAC Merge layer
- Other NICs:
- sfc/ef100: add basic devlink support for ef100
- ionic: rx_push mode operation (writing descriptors via MMIO)
- bnxt: use the auxiliary bus abstraction for RDMA
- r8169: disable ASPM and reset bus in case of tx timeout
- cpsw: support QSGMII mode for J721e CPSW9G
- cpts: support pulse-per-second output
- ngbe: add an mdio bus driver
- usbnet: optimize usbnet_bh() by avoiding unnecessary queuing
- r8152: handle devices with FW with NCM support
- amd-xgbe: support 10Mbps, 2.5GbE speeds and rx-adaptation
- virtio-net: support multi buffer XDP
- virtio/vsock: replace virtio_vsock_pkt with sk_buff
- tsnep: XDP support
- Ethernet high-speed switches:
- nVidia/Mellanox (mlxsw):
- add support for latency TLV (in FW control messages)
- Microchip (sparx5):
- separate explicit and implicit traffic forwarding rules, make
the implicit rules always active
- add support for egress DSCP rewrite
- IS0 VCAP support (Ingress Classification)
- IS2 VCAP filters (protos, L3 addrs, L4 ports, flags, ToS
etc.)
- ES2 VCAP support (Egress Access Control)
- support for Per-Stream Filtering and Policing (802.1Q,
8.6.5.1)
- Ethernet embedded switches:
- Marvell (mv88e6xxx):
- add MAB (port auth) offload support
- enable PTP receive for mv88e6390
- NXP (ocelot):
- support MAC Merge layer
- support for the the vsc7512 internal copper phys
- Microchip:
- lan9303: convert to PHYLINK
- lan966x: support TC flower filter statistics
- lan937x: PTP support for KSZ9563/KSZ8563 and LAN937x
- lan937x: support Credit Based Shaper configuration
- ksz9477: support Energy Efficient Ethernet
- other:
- qca8k: convert to regmap read/write API, use bulk operations
- rswitch: Improve TX timestamp accuracy
- Intel WiFi (iwlwifi):
- EHT (Wi-Fi 7) rate reporting
- STEP equalizer support: transfer some STEP (connection to radio
on platforms with integrated wifi) related parameters from the
BIOS to the firmware.
- Qualcomm 802.11ax WiFi (ath11k):
- IPQ5018 support
- Fine Timing Measurement (FTM) responder role support
- channel 177 support
- MediaTek WiFi (mt76):
- per-PHY LED support
- mt7996: EHT (Wi-Fi 7) support
- Wireless Ethernet Dispatch (WED) reset support
- switch to using page pool allocator
- RealTek WiFi (rtw89):
- support new version of Bluetooth co-existance
- Mobile:
- rmnet: support TX aggregation"
* tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next: (1872 commits)
page_pool: add a comment explaining the fragment counter usage
net: ethtool: fix __ethtool_dev_mm_supported() implementation
ethtool: pse-pd: Fix double word in comments
xsk: add linux/vmalloc.h to xsk.c
sefltests: netdevsim: wait for devlink instance after netns removal
selftest: fib_tests: Always cleanup before exit
net/mlx5e: Align IPsec ASO result memory to be as required by hardware
net/mlx5e: TC, Set CT miss to the specific ct action instance
net/mlx5e: Rename CHAIN_TO_REG to MAPPED_OBJ_TO_REG
net/mlx5: Refactor tc miss handling to a single function
net/mlx5: Kconfig: Make tc offload depend on tc skb extension
net/sched: flower: Support hardware miss to tc action
net/sched: flower: Move filter handle initialization earlier
net/sched: cls_api: Support hardware miss to tc action
net/sched: Rename user cookie and act cookie
sfc: fix builds without CONFIG_RTC_LIB
sfc: clean up some inconsistent indentings
net/mlx4_en: Introduce flexible array to silence overflow warning
net: lan966x: Fix possible deadlock inside PTP
net/ulp: Remove redundant ->clone() test in inet_clone_ulp().
...
Diffstat (limited to 'tools/power/cpupower/debug')
-rw-r--r-- | tools/power/cpupower/debug/i386/Makefile | 42 | ||||
-rw-r--r-- | tools/power/cpupower/debug/i386/centrino-decode.c | 112 | ||||
-rw-r--r-- | tools/power/cpupower/debug/i386/dump_psb.c | 194 | ||||
-rw-r--r-- | tools/power/cpupower/debug/i386/intel_gsic.c | 77 | ||||
-rw-r--r-- | tools/power/cpupower/debug/i386/powernow-k8-decode.c | 95 | ||||
-rw-r--r-- | tools/power/cpupower/debug/kernel/Makefile | 23 | ||||
-rw-r--r-- | tools/power/cpupower/debug/kernel/cpufreq-test_tsc.c | 111 | ||||
-rw-r--r-- | tools/power/cpupower/debug/x86_64/Makefile | 31 |
8 files changed, 685 insertions, 0 deletions
diff --git a/tools/power/cpupower/debug/i386/Makefile b/tools/power/cpupower/debug/i386/Makefile new file mode 100644 index 000000000..b3f771039 --- /dev/null +++ b/tools/power/cpupower/debug/i386/Makefile @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: GPL-2.0 +OUTPUT=./ +ifeq ("$(origin O)", "command line") + OUTPUT := $(O)/ +endif + +DESTDIR = +bindir = /usr/bin + +INSTALL = /usr/bin/install + + +default: all + +$(OUTPUT)centrino-decode: centrino-decode.c + $(CC) $(CFLAGS) -o $@ centrino-decode.c + +$(OUTPUT)dump_psb: dump_psb.c + $(CC) $(CFLAGS) -o $@ dump_psb.c + +$(OUTPUT)intel_gsic: intel_gsic.c + $(CC) $(CFLAGS) -o $@ -llrmi intel_gsic.c + +$(OUTPUT)powernow-k8-decode: powernow-k8-decode.c + $(CC) $(CFLAGS) -o $@ powernow-k8-decode.c + +all: $(OUTPUT)centrino-decode $(OUTPUT)dump_psb $(OUTPUT)intel_gsic $(OUTPUT)powernow-k8-decode + +clean: + rm -rf $(OUTPUT)centrino-decode + rm -rf $(OUTPUT)dump_psb + rm -rf $(OUTPUT)intel_gsic + rm -rf $(OUTPUT)powernow-k8-decode + +install: + $(INSTALL) -d $(DESTDIR)${bindir} + $(INSTALL) $(OUTPUT)centrino-decode $(DESTDIR)${bindir} + $(INSTALL) $(OUTPUT)powernow-k8-decode $(DESTDIR)${bindir} + $(INSTALL) $(OUTPUT)dump_psb $(DESTDIR)${bindir} + $(INSTALL) $(OUTPUT)intel_gsic $(DESTDIR)${bindir} + +.PHONY: all default clean install diff --git a/tools/power/cpupower/debug/i386/centrino-decode.c b/tools/power/cpupower/debug/i386/centrino-decode.c new file mode 100644 index 000000000..700cd31a7 --- /dev/null +++ b/tools/power/cpupower/debug/i386/centrino-decode.c @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * (C) 2003 - 2004 Dominik Brodowski <linux@dominikbrodowski.de> + * + * Based on code found in + * linux/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c + * and originally developed by Jeremy Fitzhardinge. + * + * USAGE: simply run it to decode the current settings on CPU 0, + * or pass the CPU number as argument, or pass the MSR content + * as argument. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <unistd.h> +#include <errno.h> +#include <fcntl.h> + +#include <sys/types.h> +#include <sys/stat.h> + +#define MCPU 32 + +#define MSR_IA32_PERF_STATUS 0x198 + +static int rdmsr(unsigned int cpu, unsigned int msr, + unsigned int *lo, unsigned int *hi) +{ + int fd; + char file[20]; + unsigned long long val; + int retval = -1; + + *lo = *hi = 0; + + if (cpu > MCPU) + goto err1; + + sprintf(file, "/dev/cpu/%d/msr", cpu); + fd = open(file, O_RDONLY); + + if (fd < 0) + goto err1; + + if (lseek(fd, msr, SEEK_CUR) == -1) + goto err2; + + if (read(fd, &val, 8) != 8) + goto err2; + + *lo = (uint32_t )(val & 0xffffffffull); + *hi = (uint32_t )(val>>32 & 0xffffffffull); + + retval = 0; +err2: + close(fd); +err1: + return retval; +} + +static void decode (unsigned int msr) +{ + unsigned int multiplier; + unsigned int mv; + + multiplier = ((msr >> 8) & 0xFF); + + mv = (((msr & 0xFF) * 16) + 700); + + printf("0x%x means multiplier %d @ %d mV\n", msr, multiplier, mv); +} + +static int decode_live(unsigned int cpu) +{ + unsigned int lo, hi; + int err; + + err = rdmsr(cpu, MSR_IA32_PERF_STATUS, &lo, &hi); + + if (err) { + printf("can't get MSR_IA32_PERF_STATUS for cpu %d\n", cpu); + printf("Possible trouble: you don't run an Enhanced SpeedStep capable cpu\n"); + printf("or you are not root, or the msr driver is not present\n"); + return 1; + } + + decode(lo); + + return 0; +} + +int main (int argc, char **argv) +{ + unsigned int cpu, mode = 0; + + if (argc < 2) + cpu = 0; + else { + cpu = strtoul(argv[1], NULL, 0); + if (cpu >= MCPU) + mode = 1; + } + + if (mode) + decode(cpu); + else + decode_live(cpu); + + return 0; +} diff --git a/tools/power/cpupower/debug/i386/dump_psb.c b/tools/power/cpupower/debug/i386/dump_psb.c new file mode 100644 index 000000000..6fb81b42e --- /dev/null +++ b/tools/power/cpupower/debug/i386/dump_psb.c @@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-2.0-only +// dump_psb. (c) 2004, Dave Jones, Red Hat Inc. + +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#define _GNU_SOURCE +#include <getopt.h> + +#include <sys/mman.h> + +#define LEN (0x100000 - 0xc0000) +#define OFFSET (0xc0000) + +#ifndef __packed +#define __packed __attribute((packed)) +#endif + +static long relevant; + +static const int fid_to_mult[32] = { + 110, 115, 120, 125, 50, 55, 60, 65, + 70, 75, 80, 85, 90, 95, 100, 105, + 30, 190, 40, 200, 130, 135, 140, 210, + 150, 225, 160, 165, 170, 180, -1, -1, +}; + +static const int vid_to_voltage[32] = { + 2000, 1950, 1900, 1850, 1800, 1750, 1700, 1650, + 1600, 1550, 1500, 1450, 1400, 1350, 1300, 0, + 1275, 1250, 1225, 1200, 1175, 1150, 1125, 1100, + 1075, 1050, 1024, 1000, 975, 950, 925, 0, +}; + +struct psb_header { + char signature[10]; + u_char version; + u_char flags; + u_short settlingtime; + u_char res1; + u_char numpst; +} __packed; + +struct pst_header { + u_int32_t cpuid; + u_char fsb; + u_char maxfid; + u_char startvid; + u_char numpstates; +} __packed; + +static u_int fsb; +static u_int sgtc; + +static int +decode_pst(char *p, int npstates) +{ + int i; + int freq, fid, vid; + + for (i = 0; i < npstates; ++i) { + fid = *p++; + vid = *p++; + freq = 100 * fid_to_mult[fid] * fsb; + + printf(" %2d %8dkHz FID %02x (%2d.%01d) VID %02x (%4dmV)\n", + i, + freq, + fid, fid_to_mult[fid]/10, fid_to_mult[fid]%10, + vid, vid_to_voltage[vid]); + } + + return 0; +} + +static +void decode_psb(char *p, int numpst) +{ + int i; + struct psb_header *psb; + struct pst_header *pst; + + psb = (struct psb_header*) p; + + if (psb->version != 0x12) + return; + + printf("PSB version: %hhx flags: %hhx settling time %hhuus res1 %hhx num pst %hhu\n", + psb->version, + psb->flags, + psb->settlingtime, + psb->res1, + psb->numpst); + sgtc = psb->settlingtime * 100; + + if (sgtc < 10000) + sgtc = 10000; + + p = ((char *) psb) + sizeof(struct psb_header); + + if (numpst < 0) + numpst = psb->numpst; + else + printf("Overriding number of pst :%d\n", numpst); + + for (i = 0; i < numpst; i++) { + pst = (struct pst_header*) p; + + if (relevant != 0) { + if (relevant!= pst->cpuid) + goto next_one; + } + + printf(" PST %d cpuid %.3x fsb %hhu mfid %hhx svid %hhx numberstates %hhu\n", + i+1, + pst->cpuid, + pst->fsb, + pst->maxfid, + pst->startvid, + pst->numpstates); + + fsb = pst->fsb; + decode_pst(p + sizeof(struct pst_header), pst->numpstates); + +next_one: + p += sizeof(struct pst_header) + 2*pst->numpstates; + } + +} + +static struct option info_opts[] = { + {"numpst", no_argument, NULL, 'n'}, +}; + +void print_help(void) +{ + printf ("Usage: dump_psb [options]\n"); + printf ("Options:\n"); + printf (" -n, --numpst Set number of PST tables to scan\n"); + printf (" -r, --relevant Only display PSTs relevant to cpuid N\n"); +} + +int +main(int argc, char *argv[]) +{ + int fd; + int numpst=-1; + int ret=0, cont=1; + char *mem = NULL; + char *p; + + do { + ret = getopt_long(argc, argv, "hr:n:", info_opts, NULL); + switch (ret){ + case '?': + case 'h': + print_help(); + cont = 0; + break; + case 'r': + relevant = strtol(optarg, NULL, 16); + break; + case 'n': + numpst = strtol(optarg, NULL, 10); + break; + case -1: + cont = 0; + break; + } + + } while(cont); + + fd = open("/dev/mem", O_RDONLY); + if (fd < 0) { + printf ("Couldn't open /dev/mem. Are you root?\n"); + exit(1); + } + + mem = mmap(mem, 0x100000 - 0xc0000, PROT_READ, MAP_SHARED, fd, 0xc0000); + close(fd); + + for (p = mem; p - mem < LEN; p+=16) { + if (memcmp(p, "AMDK7PNOW!", 10) == 0) { + decode_psb(p, numpst); + break; + } + } + + munmap(mem, LEN); + return 0; +} diff --git a/tools/power/cpupower/debug/i386/intel_gsic.c b/tools/power/cpupower/debug/i386/intel_gsic.c new file mode 100644 index 000000000..befd837f0 --- /dev/null +++ b/tools/power/cpupower/debug/i386/intel_gsic.c @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * (C) 2003 Bruno Ducrot + * (C) 2004 Dominik Brodowski <linux@dominikbrodowski.de> + * + * Based on code found in + * linux/include/asm-i386/ist.h and linux/arch/i386/kernel/setup.c + * and originally developed by Andy Grover <andrew.grover@intel.com> + */ + +#include <stdio.h> +#include <string.h> +#include <lrmi.h> + +int main (void) +{ + struct LRMI_regs r; + int retval; + + if (!LRMI_init()) + return 0; + + memset(&r, 0, sizeof(r)); + + r.eax = 0x0000E980; + r.edx = 0x47534943; + + retval = LRMI_int(0x15, &r); + + if (!retval) { + printf("Failed!\n"); + return 0; + } + if (r.eax == 0x47534943) { + printf("BIOS supports GSIC call:\n"); + printf("\tsignature: %c%c%c%c\n", + (r.eax >> 24) & 0xff, + (r.eax >> 16) & 0xff, + (r.eax >> 8) & 0xff, + (r.eax) & 0xff); + printf("\tcommand port = 0x%.4x\n", + r.ebx & 0xffff); + printf("\tcommand = 0x%.4x\n", + (r.ebx >> 16) & 0xffff); + printf("\tevent port = 0x%.8x\n", r.ecx); + printf("\tflags = 0x%.8x\n", r.edx); + if (((r.ebx >> 16) & 0xffff) != 0x82) { + printf("non-default command value. If speedstep-smi " + "doesn't work out of the box,\nyou may want to " + "try out the default value by passing " + "smi_cmd=0x82 to the module\n ON YOUR OWN " + "RISK.\n"); + } + if ((r.ebx & 0xffff) != 0xb2) { + printf("non-default command port. If speedstep-smi " + "doesn't work out of the box,\nyou may want to " + "try out the default value by passing " + "smi_port=0x82 to the module\n ON YOUR OWN " + "RISK.\n"); + } + } else { + printf("BIOS DOES NOT support GSIC call. Dumping registers anyway:\n"); + printf("eax = 0x%.8x\n", r.eax); + printf("ebx = 0x%.8x\n", r.ebx); + printf("ecx = 0x%.8x\n", r.ecx); + printf("edx = 0x%.8x\n", r.edx); + printf("Note also that some BIOS do not support the initial " + "GSIC call, but the newer\nspeedstep-smi driver may " + "work.\nFor this, you need to pass some arguments to " + "the speedstep-smi driver:\n"); + printf("\tsmi_cmd=0x?? smi_port=0x?? smi_sig=1\n"); + printf("\nUnfortunately, you have to know what exactly are " + "smi_cmd and smi_port, and this\nis system " + "dependent.\n"); + } + return 1; +} diff --git a/tools/power/cpupower/debug/i386/powernow-k8-decode.c b/tools/power/cpupower/debug/i386/powernow-k8-decode.c new file mode 100644 index 000000000..735dca1e2 --- /dev/null +++ b/tools/power/cpupower/debug/i386/powernow-k8-decode.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * (C) 2004 Bruno Ducrot <ducrot@poupinou.org> + * + * Based on code found in + * linux/arch/i386/kernel/cpu/cpufreq/powernow-k8.c + * and originally developed by Paul Devriendt + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <unistd.h> +#include <errno.h> +#include <fcntl.h> + +#include <sys/types.h> +#include <sys/stat.h> + +#define MCPU 32 + +#define MSR_FIDVID_STATUS 0xc0010042 + +#define MSR_S_HI_CURRENT_VID 0x0000001f +#define MSR_S_LO_CURRENT_FID 0x0000003f + +static int get_fidvid(uint32_t cpu, uint32_t *fid, uint32_t *vid) +{ + int err = 1; + uint64_t msr = 0; + int fd; + char file[20]; + + if (cpu > MCPU) + goto out; + + sprintf(file, "/dev/cpu/%d/msr", cpu); + + fd = open(file, O_RDONLY); + if (fd < 0) + goto out; + lseek(fd, MSR_FIDVID_STATUS, SEEK_CUR); + if (read(fd, &msr, 8) != 8) + goto err1; + + *fid = ((uint32_t )(msr & 0xffffffffull)) & MSR_S_LO_CURRENT_FID; + *vid = ((uint32_t )(msr>>32 & 0xffffffffull)) & MSR_S_HI_CURRENT_VID; + err = 0; +err1: + close(fd); +out: + return err; +} + + +/* Return a frequency in MHz, given an input fid */ +static uint32_t find_freq_from_fid(uint32_t fid) +{ + return 800 + (fid * 100); +} + +/* Return a voltage in miliVolts, given an input vid */ +static uint32_t find_millivolts_from_vid(uint32_t vid) +{ + return 1550-vid*25; +} + +int main (int argc, char *argv[]) +{ + int err; + int cpu; + uint32_t fid, vid; + + if (argc < 2) + cpu = 0; + else + cpu = strtoul(argv[1], NULL, 0); + + err = get_fidvid(cpu, &fid, &vid); + + if (err) { + printf("can't get fid, vid from MSR\n"); + printf("Possible trouble: you don't run a powernow-k8 capable cpu\n"); + printf("or you are not root, or the msr driver is not present\n"); + exit(1); + } + + + printf("cpu %d currently at %d MHz and %d mV\n", + cpu, + find_freq_from_fid(fid), + find_millivolts_from_vid(vid)); + + return 0; +} diff --git a/tools/power/cpupower/debug/kernel/Makefile b/tools/power/cpupower/debug/kernel/Makefile new file mode 100644 index 000000000..7b5c43684 --- /dev/null +++ b/tools/power/cpupower/debug/kernel/Makefile @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-m := + +KDIR := /lib/modules/$(shell uname -r)/build +KMISC := /lib/modules/$(shell uname -r)/cpufrequtils/ + +ifeq ("$(CONFIG_X86_TSC)", "y") + obj-m += cpufreq-test_tsc.o +endif + +default: + $(MAKE) -C $(KDIR) M=$(CURDIR) + +clean: + - rm -rf *.o *.ko .*.cmd .*.mod.* *.mod.c + - rm -rf Module.symvers modules.order + +install: default + install -d $(KMISC) + install -m 644 -c *.ko $(KMISC) + /sbin/depmod -a + +all: default diff --git a/tools/power/cpupower/debug/kernel/cpufreq-test_tsc.c b/tools/power/cpupower/debug/kernel/cpufreq-test_tsc.c new file mode 100644 index 000000000..e364b170b --- /dev/null +++ b/tools/power/cpupower/debug/kernel/cpufreq-test_tsc.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * test module to check whether the TSC-based delay routine continues + * to work properly after cpufreq transitions. Needs ACPI to work + * properly. + * + * Based partly on the Power Management Timer (PMTMR) code to be found + * in arch/i386/kernel/timers/timer_pm.c on recent 2.6. kernels, especially + * code written by John Stultz. The read_pmtmr function was copied verbatim + * from that file. + * + * (C) 2004 Dominik Brodowski + * + * To use: + * 1.) pass clock=tsc to the kernel on your bootloader + * 2.) modprobe this module (it'll fail) + * 3.) change CPU frequency + * 4.) modprobe this module again + * 5.) if the third value, "diff_pmtmr", changes between 2. and 4., the + * TSC-based delay routine on the Linux kernel does not correctly + * handle the cpufreq transition. Please report this to + * linux-pm@vger.kernel.org + */ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/delay.h> +#include <linux/acpi.h> +#include <asm/io.h> + +static int pm_tmr_ioport = 0; + +/*helper function to safely read acpi pm timesource*/ +static u32 read_pmtmr(void) +{ + u32 v1=0,v2=0,v3=0; + /* It has been reported that because of various broken + * chipsets (ICH4, PIIX4 and PIIX4E) where the ACPI PM time + * source is not latched, so you must read it multiple + * times to insure a safe value is read. + */ + do { + v1 = inl(pm_tmr_ioport); + v2 = inl(pm_tmr_ioport); + v3 = inl(pm_tmr_ioport); + } while ((v1 > v2 && v1 < v3) || (v2 > v3 && v2 < v1) + || (v3 > v1 && v3 < v2)); + + /* mask the output to 24 bits */ + return (v2 & 0xFFFFFF); +} + +static int __init cpufreq_test_tsc(void) +{ + u32 now, then, diff; + u64 now_tsc, then_tsc, diff_tsc; + int i; + + /* the following code snipped is copied from arch/x86/kernel/acpi/boot.c + of Linux v2.6.25. */ + + /* detect the location of the ACPI PM Timer */ + if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) { + /* FADT rev. 2 */ + if (acpi_gbl_FADT.xpm_timer_block.space_id != + ACPI_ADR_SPACE_SYSTEM_IO) + return 0; + + pm_tmr_ioport = acpi_gbl_FADT.xpm_timer_block.address; + /* + * "X" fields are optional extensions to the original V1.0 + * fields, so we must selectively expand V1.0 fields if the + * corresponding X field is zero. + */ + if (!pm_tmr_ioport) + pm_tmr_ioport = acpi_gbl_FADT.pm_timer_block; + } else { + /* FADT rev. 1 */ + pm_tmr_ioport = acpi_gbl_FADT.pm_timer_block; + } + + printk(KERN_DEBUG "start--> \n"); + then = read_pmtmr(); + then_tsc = rdtsc(); + for (i=0;i<20;i++) { + mdelay(100); + now = read_pmtmr(); + now_tsc = rdtsc(); + diff = (now - then) & 0xFFFFFF; + diff_tsc = now_tsc - then_tsc; + printk(KERN_DEBUG "t1: %08u t2: %08u diff_pmtmr: %08u diff_tsc: %016llu\n", then, now, diff, diff_tsc); + then = now; + then_tsc = now_tsc; + } + printk(KERN_DEBUG "<-- end \n"); + return -ENODEV; +} + +static void __exit cpufreq_none(void) +{ + return; +} + +module_init(cpufreq_test_tsc) +module_exit(cpufreq_none) + + +MODULE_AUTHOR("Dominik Brodowski"); +MODULE_DESCRIPTION("Verify the TSC cpufreq notifier working correctly -- needs ACPI-enabled system"); +MODULE_LICENSE ("GPL"); diff --git a/tools/power/cpupower/debug/x86_64/Makefile b/tools/power/cpupower/debug/x86_64/Makefile new file mode 100644 index 000000000..b1b6c4364 --- /dev/null +++ b/tools/power/cpupower/debug/x86_64/Makefile @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: GPL-2.0 +OUTPUT=./ +ifeq ("$(origin O)", "command line") + OUTPUT := $(O)/ +endif + +DESTDIR = +bindir = /usr/bin + +INSTALL = /usr/bin/install + + +default: all + +$(OUTPUT)centrino-decode: ../i386/centrino-decode.c + $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $< + +$(OUTPUT)powernow-k8-decode: ../i386/powernow-k8-decode.c + $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $< + +all: $(OUTPUT)centrino-decode $(OUTPUT)powernow-k8-decode + +clean: + rm -rf $(OUTPUT)centrino-decode $(OUTPUT)powernow-k8-decode + +install: + $(INSTALL) -d $(DESTDIR)${bindir} + $(INSTALL) $(OUTPUT)centrino-decode $(DESTDIR)${bindir} + $(INSTALL) $(OUTPUT)powernow-k8-decode $(DESTDIR)${bindir} + +.PHONY: all default clean install |