tools/power/cpupower/utils/helpers/bitmask.c
Source file repositories/reference/linux-study-clean/tools/power/cpupower/utils/helpers/bitmask.c
File Facts
- System
- Linux kernel
- Corpus path
tools/power/cpupower/utils/helpers/bitmask.c- Extension
.c- Size
- 7491 bytes
- Lines
- 294
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hstring.hhelpers/bitmask.h
Detected Declarations
function bitmask_freefunction _getbitfunction _setbitfunction scan_was_okfunction bitmask_isallclearfunction bitmask_isbitsetfunction bitmask_firstfunction bitmask_lastfunction bitmask_nextfunction bitmask_parselistfunction emitfunction bitmap_parselist
Annotated Snippet
if (c1 != NULL && (c2 == NULL || c1 < c2)) {
sret = sscanf(c1, "%u%c", &b, &nextc);
if (!scan_was_ok(sret, nextc, ",:"))
goto err;
c1 = nexttoken(c1, ':');
if (c1 != NULL && (c2 == NULL || c1 < c2)) {
sret = sscanf(c1, "%u%c", &s, &nextc);
if (!scan_was_ok(sret, nextc, ","))
goto err;
}
}
if (!(a <= b))
goto err;
if (b >= bmp->size)
goto err;
while (a <= b) {
_setbit(bmp, a, 1);
a += s;
}
}
return 0;
err:
bitmask_clearall(bmp);
return -1;
}
/*
* emit(buf, buflen, rbot, rtop, len)
*
* Helper routine for bitmask_displaylist(). Write decimal number
* or range to buf+len, suppressing output past buf+buflen, with optional
* comma-prefix. Return len of what would be written to buf, if it
* all fit.
*/
static inline int emit(char *buf, int buflen, int rbot, int rtop, int len)
{
if (len > 0)
len += snprintf(buf + len, max(buflen - len, 0), ",");
if (rbot == rtop)
len += snprintf(buf + len, max(buflen - len, 0), "%d", rbot);
else
len += snprintf(buf + len, max(buflen - len, 0), "%d-%d",
rbot, rtop);
return len;
}
/*
* Write decimal list representation of bmp to buf.
*
* Output format is a comma-separated list of decimal numbers and
* ranges. Consecutively set bits are shown as two hyphen-separated
* decimal numbers, the smallest and largest bit numbers set in
* the range. Output format is compatible with the format
* accepted as input by bitmap_parselist().
*
* The return value is the number of characters which would be
* generated for the given input, excluding the trailing '\0', as
* per ISO C99.
*/
int bitmask_displaylist(char *buf, int buflen, const struct bitmask *bmp)
{
int len = 0;
/* current bit is 'cur', most recently seen range is [rbot, rtop] */
unsigned int cur, rbot, rtop;
if (buflen > 0)
*buf = 0;
rbot = cur = bitmask_first(bmp);
while (cur < bmp->size) {
rtop = cur;
cur = bitmask_next(bmp, cur+1);
if (cur >= bmp->size || cur > rtop + 1) {
len = emit(buf, buflen, rbot, rtop, len);
rbot = cur;
}
}
return len;
}
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `string.h`, `helpers/bitmask.h`.
- Detected declarations: `function bitmask_free`, `function _getbit`, `function _setbit`, `function scan_was_ok`, `function bitmask_isallclear`, `function bitmask_isbitset`, `function bitmask_first`, `function bitmask_last`, `function bitmask_next`, `function bitmask_parselist`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.