Port-amd64 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lapic detection at runtime for kernel modules




I'm in the process of adding support for CPUID leaf 0x40000010 in the
NVMM hypervisor.
This leaf forwards TSC and LAPIC frequency from the host machine to
the guest in order to avoid their computation and gain speed at boot
time. This is easily done in sys/dev/nvmm/x86/nvmm_x86_{svm,vmx}.c

cpudata->gprs[NVMM_X64_GPR_RAX] = curcpu()->ci_data.cpu_cc_freq / 1000;
cpudata->gprs[NVMM_X64_GPR_RBX] = lapic_per_second / 1000;

lapic_per_second is normally available when LAPIC support is enabled,
and moreover when NLAPIC > 0. When compiling nvmm as a module, which
is the standard case, it doesn't have access to "lapic.h" and then
won't be able to read NLAPIC.
One suggestion that's been given is to set NLAPIC to 1 unconditionally
for nvmm and check for lapic presence at runtime.
I came up with the following piece of code to achieve just that:

static bool
cpu_has_lapic(struct cpu_info *ci)
{
	int i;
	struct intrsource *isp;

	for (i = 0; i < MAX_INTR_SOURCES; i++) {
		isp = ci->ci_isources[i];
		if (isp == NULL)
			continue;
		if (isp->is_pic->pic_type == PIC_LAPIC)
			return true;
	}
	return false;
}

Does this seem reasonable?

------------------------------------------------------------------------
Emile `iMil' Heitor <imil@{home.imil.net,NetBSD.org}> | https://imil.net



Home | Main Index | Thread Index | Old Index