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.

Dependency Surface

Detected Declarations

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

Implementation Notes