1 (* Memory info command for virtual domains.
2 (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 Common & utility functions.
24 let ( +^ ) = Int64.add
25 let ( -^ ) = Int64.sub
26 let ( *^ ) = Int64.mul
27 let ( /^ ) = Int64.div
28 let ( &^ ) = Int64.logand
29 let ( |^ ) = Int64.logor
32 | I386 | X86_64 | IA64 | PPC | PPC64 | SPARC | SPARC64
34 let string_of_architecture = function
41 | SPARC64 -> "sparc64"
43 let architecture_of_string = function
45 String.length str = 4 &&
46 (str.[0] = 'i' || str.[0] = 'I') &&
47 (str.[1] >= '3' && str.[1] <= '6') &&
48 str.[2] = '8' && str.[3] = '6' -> I386
49 | "x86_64" | "X86_64" | "x86-64" | "X86-64" -> X86_64
50 | "ia64" | "IA64" -> IA64
51 | "ppc" | "PPC" | "ppc32" | "PPC32" -> PPC
52 | "ppc64" | "PPC64" -> PPC64
53 | "sparc" | "SPARC" | "sparc32" | "SPARC32" -> SPARC
54 | "sparc64" | "SPARC64" -> SPARC64
56 failwith (sprintf "architecture_of_string: %s: unknown architecture"
59 let endian_of_architecture = function
60 | I386 | X86_64 -> Bitmatch.LittleEndian
61 | IA64 -> Bitmatch.LittleEndian (* XXX usually? *)
62 | PPC | PPC64 | SPARC | SPARC64 -> Bitmatch.BigEndian
67 let wordsize_of_architecture = function
76 let bits_of_wordsize = function
77 | W32 -> 32 | W64 -> 64
78 let bytes_of_wordsize = function
81 (* Returns (count, value) in order of highest frequency occurring in the
85 let xs = List.sort compare xs in
86 let rec loop = function
89 | x :: y :: xs when x = y ->
90 let rest = loop (y :: xs) in
91 let (count, _), rest = List.hd rest, List.tl rest in
97 List.rev (List.sort compare xs)