]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
CP-1652: Cpuid modules gets physical and current CPU features from Xen
authorRob Hoes <rob.hoes@citrix.com>
Mon, 8 Mar 2010 11:35:48 +0000 (11:35 +0000)
committerRob Hoes <rob.hoes@citrix.com>
Mon, 8 Mar 2010 11:35:48 +0000 (11:35 +0000)
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 <rob.hoes@citrix.com>
Makefile.in
cpuid/META.in
cpuid/Makefile
cpuid/cpuid.ml

index 62e6f036b4e770903ff73453d075db487329a301..dec3ba6cb16189c4f19abbe31d7f1d107f3435a5 100644 (file)
@@ -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:
index c5ced2f4a444ca4dbcc5ef945510dfffe14bda8a..7a549ec0a985987887a7d9f8d5463fdf2aa3e1cc 100644 (file)
@@ -1,5 +1,5 @@
 version = "@VERSION@"
 description = "Cpuid extension"
-requires = ""
+requires = "stdext xc xen-utils"
 archive(byte) = "cpuid.cma"
 archive(native) = "cpuid.cmxa"
index f62642f8f2ca8fd2de6ffb9761a6df10f2020beb..4a4f028c2155d99753fb824115f5ad8837ef4976 100644 (file)
@@ -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
 
index fe6937243a278b0853ac6ae8eb01a9f815676433..8477e628365fa44e263cc5e61b12534c41bb7b41 100644 (file)
@@ -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;
        }