Skip to content

Conversation

@rountree
Copy link
Collaborator

Fixes #173.

Adds polling.

README.md
Added desription of new msr_batch_op struct.
Removed example code that no longer compiles in v2.0.

examples/example.c
Modified to be working example of polling via batch.

msr-smp.c
Replaced previous read/write code with read/write/poll + timestamp

msr_batch.c
Small patch to keep allowlist functional.

msr_safe.h
New op struct.

Tested on serif.

The example code needs work and the README.md needs a cleanup pass.

rountree-alt and others added 12 commits September 12, 2024 09:54
The type of (((struct class *)0)->devnode) has changed at least
twice in the mainline kernel.  Coding based on mainline kernel
versions has repeatedly run into the problem of distros backporting
features to older kernels.

Solved here using _Generic and multiple function definitions.
Compiling under Linux 6.9.9 and gcc 10.3.1.
msr_version.h
	#defines for major, minor, and patch versions of msr-safe
	as well as helper macros to generate _u32 and string
	representation.

Makefile
	Removes CURRENT_VERSION and -DVERSION from build.
	msrsave now gets the version string from msr_version.h

msrsave_main.c
msr_entry.c
	Now #includes msr_version.h and uses MSR_SAFE_VERSION_STR

msr_safe.h
	Repurposes a bit of struct padding to hold a _u32-format
	msr-safe version number.

README.md
	Updates documentation of struct msr_batch_array to note
	the new version field.  Explains how this will remain
	unused in the 1.x.y series.  Version 2.x.y will begin
	checking this version field to make sure what the user
	compiled against is the same version as the loaded
	kernel module.  This is necessary due to anticipated
	batch API changes in version 2.0.0.

Tested on serif (Ubuntu 24.04.1 LTS, Linux 6.8.0, gcc 13.2.0)
README.md
Describes new error (ENOPROTOOP) that results from a mismatch
between the loaded kernel module and what's in the batch request.

examples/example.c
Updated to use versioning.

msr_batch.c
Checks for correct version as part of batch request parsing.

msr_version.h
Bumped version to 2.0.0.

Tested on serif.
README.md
Added desription of new msr_batch_op struct.
Removed example code that no longer compiles in v2.0.

examples/example.c
Modified to be working example of polling via batch.

msr-smp.c
Replaced previous read/write code with read/write/poll + timestamp

msr_batch.c
Small patch to keep allowlist functional.

msr_safe.h
New op struct.
@rountree rountree requested a review from slabasan as a code owner September 14, 2024 04:23
@rountree rountree added this to the v2.0.0 milestone Sep 14, 2024
@rountree rountree mentioned this pull request Sep 14, 2024
rountree and others added 12 commits September 21, 2024 16:41
Documentation not updated
Previous code only commented out, not removed.
Debugging enabled in the Makefile.  That should be turning
off in production.

TSC (maybe) and thermal (almost certainly) MSRs are Intel-
specific.  Would like the flexibility to specify which additional
MSRs to read when.  module_param() and module_param_array() may
be the way forward, but not on this branch.

Polling is working very well.
Knowing how long it took to read an MSR hasn't been useful.  Nor
has knowning both starting and ending temperatures.

This version allows for recording TSC, APERF, MPERF, THERM_STATUS,
and PACKAGE_THERM_STATUS after the read/write/poll op(s) complete.

MPERF and TSC are almost certainly indentical when the core/thread
does not leave C0, but the documentation goes out of its way to
not say that.
Massive rearrangement of msr_safe.h, including removing
"initial_*" measurements, restoring aperf, adding package
temperature, and several structs/enums/arrays for userspace.
gcc v9.0 made -Wmissing-attributes more strict, and as a result
the #defines around module_init() and cleanup_module() started
generating warnings.  The #defines were fixed around kernel 5.0.

This PR #undefs those two symbols and #defines them according to
this patch:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0b999ae3614d09d97a1575936bcee884f912b10e

Not tested for icc or clang.
Fixes llnl#188.

gcc v8+ can, during compilation, mark code as "cold" that cannot be
executed during compliant runs (e.g., executes via undefined
behavior).  Users can also add the "cold" attribute to functions
to indicate they are executed rarely, can be optimized for size
rather than speed, and may be placed together with other "cold"
functions elsewhere in the binary to improve locality of hot
functions.

The 4.18 kernel builds an objdump tool that (erroneously?) detects
code fallthrough between the write_allowlist() and
write_allowlist.cold() functions (and vice versa).  Rather than
force the use of a more recent objdump, we simple declare the
entire function as "cold" for kernels older that v5.

The warnings are not present with gcc 15.2.0 and kernel/objdump
6.14.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v2.0.0] Add timestamped polling

2 participants