tools/perf/tests/topology.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/topology.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/topology.c- Extension
.c- Size
- 7104 bytes
- Lines
- 233
- 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
string.hstdlib.hstdio.hperf/cpumap.hcpumap.htests.hsession.hevlist.hdebug.hpmus.htarget.hlinux/err.h
Detected Declarations
function get_tempfunction session_write_headerfunction check_cpu_topologyfunction test__session_topology
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <perf/cpumap.h>
#include "cpumap.h"
#include "tests.h"
#include "session.h"
#include "evlist.h"
#include "debug.h"
#include "pmus.h"
#include "target.h"
#include <linux/err.h>
#define TEMPL "/tmp/perf-test-XXXXXX"
#define DATA_SIZE 10
static int get_temp(char *path)
{
int fd;
strcpy(path, TEMPL);
fd = mkstemp(path);
if (fd < 0) {
perror("mkstemp failed");
return -1;
}
close(fd);
return 0;
}
static int session_write_header(char *path)
{
struct perf_session *session;
struct perf_data data = {
.path = path,
.mode = PERF_DATA_MODE_WRITE,
};
struct target target = {};
session = perf_session__new(&data, NULL);
TEST_ASSERT_VAL("can't get session", !IS_ERR(session));
session->evlist = evlist__new_default(&target, /*sample_callchains=*/false);
TEST_ASSERT_VAL("can't get evlist", session->evlist);
session->evlist->session = session;
perf_header__set_feat(&session->header, HEADER_CPU_TOPOLOGY);
perf_header__set_feat(&session->header, HEADER_NRCPUS);
perf_header__set_feat(&session->header, HEADER_ARCH);
session->header.data_size += DATA_SIZE;
TEST_ASSERT_VAL("failed to write header",
!perf_session__write_header(session, session->evlist,
perf_data__fd(&data), true));
evlist__delete(session->evlist);
perf_session__delete(session);
return 0;
}
static int check_cpu_topology(char *path, struct perf_cpu_map *map)
{
struct perf_session *session;
struct perf_data data = {
.path = path,
.mode = PERF_DATA_MODE_READ,
};
unsigned int i;
struct aggr_cpu_id id;
struct perf_cpu cpu;
struct perf_env *env;
session = perf_session__new(&data, NULL);
TEST_ASSERT_VAL("can't get session", !IS_ERR(session));
env = perf_session__env(session);
cpu__setup_cpunode_map();
/* On platforms with large numbers of CPUs process_cpu_topology()
* might issue an error while reading the perf.data file section
* HEADER_CPU_TOPOLOGY and the cpu_topology_map pointed to by member
* cpu is a NULL pointer.
* Example: On s390
* CPU 0 is on core_id 0 and physical_package_id 6
* CPU 1 is on core_id 1 and physical_package_id 3
*
Annotation
- Immediate include surface: `string.h`, `stdlib.h`, `stdio.h`, `perf/cpumap.h`, `cpumap.h`, `tests.h`, `session.h`, `evlist.h`.
- Detected declarations: `function get_temp`, `function session_write_header`, `function check_cpu_topology`, `function test__session_topology`.
- 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.