tools/perf/arch/x86/util/tsc.c
Source file repositories/reference/linux-study-clean/tools/perf/arch/x86/util/tsc.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/arch/x86/util/tsc.c- Extension
.c- Size
- 1787 bytes
- Lines
- 94
- 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
linux/types.hmath.hstring.hstdlib.h../../../util/debug.h../../../util/tsc.hcpuid.h
Detected Declarations
function rdtscfunction cpuinfo_tsc_freqfunction arch_get_tsc_freq
Annotated Snippet
if (!strncmp(line, "model name", 10)) {
char *pos = strstr(line + 11, " @ ");
double float_result;
if (pos && sscanf(pos, " @ %lfGHz", &float_result) == 1) {
float_result *= 1000000000;
result = (u64)float_result;
goto out;
}
}
}
out:
if (result == 0)
pr_err("Failed to find TSC frequency in /proc/cpuinfo\n");
free(line);
fclose(cpuinfo);
return result;
}
u64 arch_get_tsc_freq(void)
{
unsigned int a, b, c, d, lvl;
static bool cached;
static double tsc;
char vendor[16];
if (cached)
return tsc;
cached = true;
get_cpuid_0(vendor, &lvl);
if (!strstr(vendor, "Intel"))
return 0;
/*
* Don't support Time Stamp Counter and
* Nominal Core Crystal Clock Information Leaf.
*/
if (lvl < 0x15) {
tsc = cpuinfo_tsc_freq();
return tsc;
}
cpuid(0x15, 0, &a, &b, &c, &d);
/* TSC frequency is not enumerated */
if (!a || !b || !c) {
tsc = cpuinfo_tsc_freq();
return tsc;
}
tsc = (u64)c * (u64)b / (u64)a;
return tsc;
}
Annotation
- Immediate include surface: `linux/types.h`, `math.h`, `string.h`, `stdlib.h`, `../../../util/debug.h`, `../../../util/tsc.h`, `cpuid.h`.
- Detected declarations: `function rdtsc`, `function cpuinfo_tsc_freq`, `function arch_get_tsc_freq`.
- 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.