tools/perf/arch/loongarch/util/header.c
Source file repositories/reference/linux-study-clean/tools/perf/arch/loongarch/util/header.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/arch/loongarch/util/header.c- Extension
.c- Size
- 1744 bytes
- Lines
- 97
- 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.hapi/fs/fs.herrno.hutil/debug.hutil/header.h
Detected Declarations
function get_cpuidfunction get_cpuid
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Implementation of get_cpuid().
*
* Author: Nikita Shubin <n.shubin@yadro.com>
* Bibo Mao <maobibo@loongson.cn>
* Huacai Chen <chenhuacai@loongson.cn>
*/
#include <stdio.h>
#include <stdlib.h>
#include <api/fs/fs.h>
#include <errno.h>
#include "util/debug.h"
#include "util/header.h"
/*
* Output example from /proc/cpuinfo
* CPU Family : Loongson-64bit
* Model Name : Loongson-3C5000
* CPU Revision : 0x10
* FPU Revision : 0x01
*/
#define CPUINFO_MODEL "Model Name"
#define CPUINFO "/proc/cpuinfo"
static char *_get_field(const char *line)
{
char *line2, *nl;
line2 = strrchr(line, ' ');
if (!line2)
return NULL;
line2++;
nl = strrchr(line, '\n');
if (!nl)
return NULL;
return strndup(line2, nl - line2);
}
static char *_get_cpuid(void)
{
unsigned long line_sz;
char *line, *model, *cpuid;
FILE *file;
file = fopen(CPUINFO, "r");
if (file == NULL)
return NULL;
line = model = cpuid = NULL;
while (getline(&line, &line_sz, file) != -1) {
if (strncmp(line, CPUINFO_MODEL, strlen(CPUINFO_MODEL)))
continue;
model = _get_field(line);
if (!model)
goto out_free;
break;
}
if (model && (asprintf(&cpuid, "%s", model) < 0))
cpuid = NULL;
out_free:
fclose(file);
free(model);
return cpuid;
}
int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
{
int ret = 0;
char *cpuid = _get_cpuid();
if (!cpuid)
return EINVAL;
if (sz < strlen(cpuid)) {
ret = ENOBUFS;
goto out_free;
}
scnprintf(buffer, sz, "%s", cpuid);
out_free:
free(cpuid);
return ret;
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `api/fs/fs.h`, `errno.h`, `util/debug.h`, `util/header.h`.
- Detected declarations: `function get_cpuid`, `function get_cpuid`.
- 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.