tools/testing/selftests/powerpc/cache_shape/cache_shape.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/cache_shape/cache_shape.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/cache_shape/cache_shape.c- Extension
.c- Size
- 2380 bytes
- Lines
- 122
- 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.
Dependency Surface
elf.herrno.hfcntl.hlink.hstdio.hstdlib.hstring.hsys/stat.hsys/types.hsys/wait.hunistd.hutils.h
Detected Declarations
function print_sizefunction print_geofunction test_cache_shapefunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright 2017, Michael Ellerman, IBM Corp.
*/
#include <elf.h>
#include <errno.h>
#include <fcntl.h>
#include <link.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "utils.h"
#ifndef AT_L1I_CACHESIZE
#define AT_L1I_CACHESIZE 40
#define AT_L1I_CACHEGEOMETRY 41
#define AT_L1D_CACHESIZE 42
#define AT_L1D_CACHEGEOMETRY 43
#define AT_L2_CACHESIZE 44
#define AT_L2_CACHEGEOMETRY 45
#define AT_L3_CACHESIZE 46
#define AT_L3_CACHEGEOMETRY 47
#endif
static void print_size(const char *label, uint32_t val)
{
printf("%s cache size: %#10x %10dB %10dK\n", label, val, val, val / 1024);
}
static void print_geo(const char *label, uint32_t val)
{
uint16_t assoc;
printf("%s line size: %#10x ", label, val & 0xFFFF);
assoc = val >> 16;
if (assoc)
printf("%u-way", assoc);
else
printf("fully");
printf(" associative\n");
}
static int test_cache_shape()
{
static char buffer[4096];
ElfW(auxv_t) *p;
int found;
FAIL_IF(read_auxv(buffer, sizeof(buffer)));
found = 0;
p = find_auxv_entry(AT_L1I_CACHESIZE, buffer);
if (p) {
found++;
print_size("L1I ", (uint32_t)p->a_un.a_val);
}
p = find_auxv_entry(AT_L1I_CACHEGEOMETRY, buffer);
if (p) {
found++;
print_geo("L1I ", (uint32_t)p->a_un.a_val);
}
p = find_auxv_entry(AT_L1D_CACHESIZE, buffer);
if (p) {
found++;
print_size("L1D ", (uint32_t)p->a_un.a_val);
}
p = find_auxv_entry(AT_L1D_CACHEGEOMETRY, buffer);
if (p) {
found++;
print_geo("L1D ", (uint32_t)p->a_un.a_val);
}
p = find_auxv_entry(AT_L2_CACHESIZE, buffer);
if (p) {
found++;
print_size("L2 ", (uint32_t)p->a_un.a_val);
}
Annotation
- Immediate include surface: `elf.h`, `errno.h`, `fcntl.h`, `link.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/stat.h`.
- Detected declarations: `function print_size`, `function print_geo`, `function test_cache_shape`, `function main`.
- 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.