tools/testing/selftests/kvm/lib/lru_gen_util.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/lib/lru_gen_util.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/lib/lru_gen_util.c- Extension
.c- Size
- 10658 bytes
- Lines
- 388
- 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
time.hlru_gen_util.h
Detected Declarations
struct memcg_stats_parse_contextstruct split_iteratorfunction memcg_stats_handle_searchingfunction memcg_stats_handle_in_memcgfunction memcg_stats_handle_in_nodefunction print_memcg_statsfunction lru_gen_read_memcg_statsfunction lru_gen_sum_memcg_stats_for_genfunction lru_gen_sum_memcg_statsfunction run_aging_implfunction lru_gen_do_agingfunction lru_gen_find_generationfunction lru_gen_usable
Annotated Snippet
struct memcg_stats_parse_context {
bool consumed; /* Whether or not this line was consumed */
/* Next parse handler to invoke */
void (*next_handler)(struct memcg_stats *stats,
struct memcg_stats_parse_context *ctx,
char *line);
int current_node_idx; /* Current index in nodes array */
const char *name; /* The name of the memcg we're looking for */
};
static void memcg_stats_handle_searching(struct memcg_stats *stats,
struct memcg_stats_parse_context *ctx,
char *line);
static void memcg_stats_handle_in_memcg(struct memcg_stats *stats,
struct memcg_stats_parse_context *ctx,
char *line);
static void memcg_stats_handle_in_node(struct memcg_stats *stats,
struct memcg_stats_parse_context *ctx,
char *line);
struct split_iterator {
char *str;
char *save;
};
static char *split_next(struct split_iterator *it)
{
char *ret = strtok_r(it->str, " \t\n\r", &it->save);
it->str = NULL;
return ret;
}
static void memcg_stats_handle_searching(struct memcg_stats *stats,
struct memcg_stats_parse_context *ctx,
char *line)
{
struct split_iterator it = { .str = line };
char *prefix = split_next(&it);
char *memcg_id = split_next(&it);
char *memcg_name = split_next(&it);
char *end;
ctx->consumed = true;
if (!prefix || strcmp("memcg", prefix))
return; /* Not a memcg line (maybe empty), skip */
TEST_ASSERT(memcg_id && memcg_name,
"malformed memcg line; no memcg id or memcg_name");
if (strcmp(memcg_name + 1, ctx->name))
return; /* Wrong memcg, skip */
/* Found it! */
stats->memcg_id = strtoul(memcg_id, &end, 10);
TEST_ASSERT(*end == '\0', "malformed memcg id '%s'", memcg_id);
if (!stats->memcg_id)
return; /* Removed memcg? */
ctx->next_handler = memcg_stats_handle_in_memcg;
}
static void memcg_stats_handle_in_memcg(struct memcg_stats *stats,
struct memcg_stats_parse_context *ctx,
char *line)
{
struct split_iterator it = { .str = line };
char *prefix = split_next(&it);
char *id = split_next(&it);
long found_node_id;
char *end;
ctx->consumed = true;
ctx->current_node_idx = -1;
if (!prefix)
return; /* Skip empty lines */
if (!strcmp("memcg", prefix)) {
/* Memcg done, found next one; stop. */
ctx->next_handler = NULL;
return;
} else if (strcmp("node", prefix))
TEST_ASSERT(false, "found malformed line after 'memcg ...',"
"token: '%s'", prefix);
/* At this point we know we have a node line. Parse the ID. */
Annotation
- Immediate include surface: `time.h`, `lru_gen_util.h`.
- Detected declarations: `struct memcg_stats_parse_context`, `struct split_iterator`, `function memcg_stats_handle_searching`, `function memcg_stats_handle_in_memcg`, `function memcg_stats_handle_in_node`, `function print_memcg_stats`, `function lru_gen_read_memcg_stats`, `function lru_gen_sum_memcg_stats_for_gen`, `function lru_gen_sum_memcg_stats`, `function run_aging_impl`.
- 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.