Bitops improvements#363
Open
brenns10 wants to merge 2 commits intoosandov:mainfrom
Open
Conversation
osandov
requested changes
Oct 31, 2023
Owner
osandov
left a comment
There was a problem hiding this comment.
FWIW, this slightly less verbose version is equivalent to your cast:
cast("unsigned long *", prog["boot_cpu_data"].x86_capability)But I like these improvements anyways, modulo my endianness concerns in the comments.
The docs currently state that the bitmap must be an "unsigned long *". This is similar to the kernel API. It may not be immediately obvious "unsigned long[]" arrays are acceptable as well, so clarify that. Also, update the module documentation to reflect the fact that on little-endian architectures, the helpers work just as well with any other unsigned integer type, and update the tests to verify this. Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
The Linux API for for_each_set_bit() involves a size, but when dealing with complete array types (a relatively common case), we can default to the size of the array in bits. Add this ability to the helper. Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
606e6a3 to
40de87e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the spirit of (incrementally) reducing the verbosity of drgn, I noticed that the bitops APIs could use a bit of improvement.
First, the documentation indicated that they take an
unsigned long *, so I assumed I needed to cast my array to a pointer, which is a pretty verbose operation. But reading the code, I could see that it worked perfectly fine on arrays, and also on pointers/arrays to any unsigned integer type. (And later, I noticed even the tests use an arrray rather than pointer). So this PR updates that documentation and explicitly tests a wider range of integer types (just to be sure). That way future users would know they can provide the bitfield directly without the casting.Second, it seems like sized array types are relatively common in the kernel for bit fields (e.g.
cpuinfo_x86.x86_capabilitylink), and for these, we can infer the size parameter. So this PR makes it optional to provide that parameter.Now with the clearer documentation and optional parameter, it's a lot easier: