tools/perf/util/header.c
Source file repositories/reference/linux-study-clean/tools/perf/util/header.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/header.c- Extension
.c- Size
- 118153 bytes
- Lines
- 5241
- 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
errno.hinttypes.hstring2.hsys/param.hsys/types.hbyteswap.hunistd.hregex.hstdio.hstdlib.hlinux/compiler.hlinux/list.hlinux/kernel.hlinux/bitops.hlinux/string.hlinux/stringify.hlinux/zalloc.hsys/stat.hsys/utsname.hlinux/time64.hdirent.hbpf/libbpf.hperf/cpumap.htools/libc_compat.hdso.hevlist.hevsel.hutil/evsel_fprintf.hheader.hmemswap.htrace-event.hsession.h
Detected Declarations
struct perf_file_attrstruct group_descstruct header_print_datastruct header_fwfunction perf_header__set_featfunction perf_header__clear_featfunction perf_header__has_featfunction __do_write_fdfunction __do_write_buffunction do_writefunction do_write_bitmapfunction write_paddedfunction do_write_stringfunction __do_read_fdfunction __do_read_buffunction __do_readfunction do_read_u32function do_read_u64function do_read_bitmapfunction write_tracing_datafunction write_build_idfunction write_hostnamefunction write_osreleasefunction write_archfunction write_e_machinefunction write_versionfunction __write_cpudescfunction write_cpudescfunction write_nrcpusfunction write_event_descfunction evlist__for_each_entryfunction write_cmdlinefunction write_cpu_topologyfunction write_total_memfunction write_numa_topologyfunction write_pmu_mappingsfunction write_group_descfunction evlist__for_each_entryfunction get_cpuid_strfunction strcmp_cpuid_strfunction get_cpuidfunction write_cpuidfunction write_branch_stackfunction write_auxtracefunction write_clockidfunction write_clock_datafunction write_hybrid_topologyfunction write_dir_format
Annotated Snippet
struct perf_file_attr {
struct perf_event_attr attr;
struct perf_file_section ids;
};
void perf_header__set_feat(struct perf_header *header, int feat)
{
__set_bit(feat, header->adds_features);
}
void perf_header__clear_feat(struct perf_header *header, int feat)
{
__clear_bit(feat, header->adds_features);
}
bool perf_header__has_feat(const struct perf_header *header, int feat)
{
return test_bit(feat, header->adds_features);
}
static int __do_write_fd(struct feat_fd *ff, const void *buf, size_t size)
{
ssize_t ret = writen(ff->fd, buf, size);
if (ret != (ssize_t)size)
return ret < 0 ? (int)ret : -1;
return 0;
}
static int __do_write_buf(struct feat_fd *ff, const void *buf, size_t size)
{
/* struct perf_event_header::size is u16 */
const size_t max_size = 0xffff - sizeof(struct perf_event_header);
size_t new_size = ff->size;
void *addr;
if (size + ff->offset > max_size)
return -E2BIG;
while (size > (new_size - ff->offset))
new_size <<= 1;
new_size = min(max_size, new_size);
if (ff->size < new_size) {
addr = realloc(ff->buf, new_size);
if (!addr)
return -ENOMEM;
ff->buf = addr;
ff->size = new_size;
}
memcpy(ff->buf + ff->offset, buf, size);
ff->offset += size;
return 0;
}
/* Return: 0 if succeeded, -ERR if failed. */
int do_write(struct feat_fd *ff, const void *buf, size_t size)
{
if (!ff->buf)
return __do_write_fd(ff, buf, size);
return __do_write_buf(ff, buf, size);
}
/* Return: 0 if succeeded, -ERR if failed. */
static int do_write_bitmap(struct feat_fd *ff, unsigned long *set, u64 size)
{
u64 *p = (u64 *) set;
int i, ret;
ret = do_write(ff, &size, sizeof(size));
if (ret < 0)
return ret;
for (i = 0; (u64) i < BITS_TO_U64(size); i++) {
ret = do_write(ff, p + i, sizeof(*p));
if (ret < 0)
return ret;
}
return 0;
}
/* Return: 0 if succeeded, -ERR if failed. */
int write_padded(struct feat_fd *ff, const void *bf,
size_t count, size_t count_aligned)
{
static const char zero_buf[NAME_ALIGN];
int err = do_write(ff, bf, count);
Annotation
- Immediate include surface: `errno.h`, `inttypes.h`, `string2.h`, `sys/param.h`, `sys/types.h`, `byteswap.h`, `unistd.h`, `regex.h`.
- Detected declarations: `struct perf_file_attr`, `struct group_desc`, `struct header_print_data`, `struct header_fw`, `function perf_header__set_feat`, `function perf_header__clear_feat`, `function perf_header__has_feat`, `function __do_write_fd`, `function __do_write_buf`, `function do_write`.
- 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.