From 0bc2bb32f6dc41b8c7ab4325f6fa673fd651add3 Mon Sep 17 00:00:00 2001 From: Rob Hoes Date: Mon, 8 Mar 2010 11:35:48 +0000 Subject: [PATCH] CP-1652: Cpuid modules gets physical and current CPU features from Xen Previously, the physical features were kept in a file in dom0 on first boot. This is not very robust, so now all physical and current CPU features come directly from Xen via a hypercall. Signed-off-by: Rob Hoes --- Makefile.in | 6 +++--- cpuid/META.in | 2 +- cpuid/Makefile | 6 +++--- cpuid/cpuid.ml | 47 +++++++++++++++++++++++++++++++++++------------ 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/Makefile.in b/Makefile.in index 62e6f03..dec3ba6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -31,7 +31,6 @@ ifeq ($(HAVE_DEVICE_MAPPER),1) endif $(MAKE) -C forking_executioner $(MAKE) -C mlvm - $(MAKE) -C cpuid $(MAKE) -C xen-utils .PHONY: allxen @@ -43,6 +42,7 @@ ifeq ($(HAVE_XEN),1) $(MAKE) -C xs $(MAKE) -C xsrpc $(MAKE) -C eventchn + $(MAKE) -C cpuid endif install: @@ -69,7 +69,6 @@ ifeq ($(HAVE_DEVICE_MAPPER),1) endif $(MAKE) -C forking_executioner install $(MAKE) -C mlvm install - $(MAKE) -C cpuid install $(MAKE) -C xen-utils install installxen: @@ -80,6 +79,7 @@ ifeq ($(HAVE_XEN),1) $(MAKE) -C xs install $(MAKE) -C xsrpc install $(MAKE) -C eventchn install + $(MAKE) -C cpuid install endif uninstall: @@ -106,7 +106,6 @@ ifeq ($(HAVE_DEVICE_MAPPER),1) endif $(MAKE) -C forking_executioner uninstall $(MAKE) -C mlvm uninstall - $(MAKE) -C cpuid uninstall $(MAKE) -C xen-utils uninstall uninstallxen: @@ -117,6 +116,7 @@ ifeq ($(HAVE_XEN),1) $(MAKE) -C xb uninstall $(MAKE) -C xc uninstall $(MAKE) -C mmap uninstall + $(MAKE) -C cpuid uninstall endif bins: diff --git a/cpuid/META.in b/cpuid/META.in index c5ced2f..7a549ec 100644 --- a/cpuid/META.in +++ b/cpuid/META.in @@ -1,5 +1,5 @@ version = "@VERSION@" description = "Cpuid extension" -requires = "" +requires = "stdext xc xen-utils" archive(byte) = "cpuid.cma" archive(native) = "cpuid.cmxa" diff --git a/cpuid/Makefile b/cpuid/Makefile index f62642f..4a4f028 100644 --- a/cpuid/Makefile +++ b/cpuid/Makefile @@ -2,7 +2,7 @@ CC = gcc CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml -I$(XEN_ROOT)/usr/include OCAMLC = ocamlc -g OCAMLOPT = ocamlopt -INCLUDES = -I ../stdext +INCLUDES = -I ../stdext -I ../xc -I ../xen-utils LDFLAGS = -cclib -L./ @@ -65,8 +65,8 @@ uninstall: .PHONY: doc doc: $(INTF) - python ../doc/doc.py $(DOCDIR) "cpuid" "package" "$(OBJS)" "." "stdext" "" + python ../doc/doc.py $(DOCDIR) "cpuid" "package" "$(OBJS)" "." "stdext xc xen-utils" "" clean: - rm -f *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot $(LIBS) $(PROGRAMS) + rm -f *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot $(LIBS) $(PROGRAMS) *~ *.rej diff --git a/cpuid/cpuid.ml b/cpuid/cpuid.ml index fe69372..8477e62 100644 --- a/cpuid/cpuid.ml +++ b/cpuid/cpuid.ml @@ -127,21 +127,44 @@ let is_maskable manufacturer family model stepping = if has_emt family then true else false -let get_physical_features features = - let features_file = "/var/xapi/features" in - try - let data = Unixext.read_whole_file_to_string features_file in - string_to_features data - with _ -> - let data = features_to_string features in - Unixext.write_string_to_file features_file data; - features - +let get_features_from_xen () = + let features = Xc.with_intf (fun xc -> Xc.get_boot_cpufeatures xc) in + match features with + | base_ecx, base_edx, ext_ecx, ext_edx, + masked_base_ecx, masked_base_edx, masked_ext_ecx, masked_ext_edx -> + { + base_ecx = masked_base_ecx; + base_edx = masked_base_edx; + ext_ecx = masked_ext_ecx; + ext_edx = masked_ext_edx + }, + { + base_ecx = base_ecx; + base_edx = base_edx; + ext_ecx = ext_ecx; + ext_edx = ext_edx + } + +let get_current_mask () = + let masks = Xen_cmdline.list_cpuid_masks () in + let get_mask m = + if List.mem_assoc m masks = false then + 0xffffffffl + else + Int32.of_string (List.assoc m masks) + in + { + base_ecx = get_mask "cpuid_mask_ecx"; + base_edx = get_mask "cpuid_mask_edx"; + ext_ecx = get_mask "cpuid_mask_ext_ecx"; + ext_edx = get_mask "cpuid_mask_ext_edx" + } + let read_cpu_info () = let manufacturer = read_manufacturer () in let family = read_family () in let model = read_model () in - let features = read_features () in + let features, phy_features = get_features_from_xen () in let stepping = read_stepping () in { manufacturer = manufacturer; @@ -149,7 +172,7 @@ let read_cpu_info () = model = model; stepping = stepping; features = features; - physical_features = get_physical_features features; + physical_features = phy_features; maskable = is_maskable manufacturer family model stepping; } -- 2.39.5