| Portability | non-portable (requires IA-32 processor) |
|---|---|
| Stability | provisional |
| Maintainer | [email protected] |
System.Cpuid
Contents
Description
This module provides the function cpuid for accessing the cpuid instruction on modern IA-32 processors. Additionally, some convenience functions are provided, which perform some of the (really complicated and obstruse) decoding.
As an example, you may use the following program to determine some characteristics of your machine:
module Main(main) where
import Text.Printf (printf, )
import System.Cpuid
main :: IO ()
main = do
(a, b, c, d) <- cpuid 0
_ <- printf "basic CPUID usage: EAX=0: %8x %8x %8x %8x\n\n" a b c d
_ <- printf "Vendor string: %s\n\n" =<< vendorString
_ <- printf "Brand string: %s\n\n" =<< brandString
putStrLn "Cache information:"
putStrLn . unlines .
map (\ v -> " " ++ show v) =<< cacheInfo
p <- processorInfo
_ <- printf "processor info: family: %d, model: %d, stepping: %d, processor type: %d\n"
(piFamily p) (piModel p) (piStepping p) (piType p)
return ()
- data Associativity
- data PageSize
- newtype Ways = Ways Int
- newtype Entries = Entries Int
- data CacheSize
- data CacheInfo
- = InstructionTLB (Maybe CacheSize) PageSize Associativity Entries
- | DataTLB (Maybe CacheSize) PageSize Associativity Entries
- | FirstLevelICache CacheSize Associativity LineSize
- | FirstLevelDCache CacheSize Associativity LineSize
- | NoSecondLevelCache
- | SecondLevelCache CacheSize Associativity LineSize (Maybe BytesPerSector)
- | NoThirdLevelCache
- | NoSecondOrThirdLevelCache
- | ThirdLevelCache CacheSize Associativity LineSize (Maybe BytesPerSector)
- | TraceCache MuOps Associativity
- | Prefetching Int
- newtype LineSize = LineSize Int
- newtype MuOps = MuOps Int
- newtype BytesPerSector = BytesPerSector Int
- data ProcessorInfo = ProcessorInfo {}
- cpuid :: Word32 -> IO (Word32, Word32, Word32, Word32)
- processorInfo :: IO ProcessorInfo
- vendorString :: IO String
- brandString :: IO String
- cacheInfo :: IO [CacheInfo]
Data types
data Associativity Source
Cache associativity. For some entries, this is not specified in
the manual. We report these as DirectMapped.
Constructors
| SetAssociative Ways | |
| DirectMapped |
Instances
Page size. Some entries can have alternative page sizes, therefore the complicated type.
Constructors
| PageSize Int | |
| PageSizeOr PageSize PageSize |
Associativity in a set-associative cache.
Cache size. Some entries can have alternative cache sizes, therefore the complicated type.
Constructors
| CacheSize Int | |
| CacheSizeOr CacheSize CacheSize |
Information for caches and TLBs.
Constructors
| InstructionTLB (Maybe CacheSize) PageSize Associativity Entries | Configuration of code TLB. |
| DataTLB (Maybe CacheSize) PageSize Associativity Entries | Configuration of data TLB. |
| FirstLevelICache CacheSize Associativity LineSize | First-level code cache configuration. |
| FirstLevelDCache CacheSize Associativity LineSize | First-level code cache configuration. |
| NoSecondLevelCache | No second level support. |
| SecondLevelCache CacheSize Associativity LineSize (Maybe BytesPerSector) | Second-level cache configuration. |
| NoThirdLevelCache | No third level support. |
| NoSecondOrThirdLevelCache | Internal use only. |
| ThirdLevelCache CacheSize Associativity LineSize (Maybe BytesPerSector) | Second-level cache configuration. |
| TraceCache MuOps Associativity | Trace cache (1st-level code cache) configuration. |
| Prefetching Int | Prefetching information. |
Functions
cpuid :: Word32 -> IO (Word32, Word32, Word32, Word32)Source
Execute the cpuid instructions with the given argument
in the EAX register. Return the values of the registers
EAX, EBX, ECX and EDX in that order.
processorInfo :: IO ProcessorInfoSource
Retrieve basic processor information from the processor using the
cpuid instruction.
vendorString :: IO StringSource
Execute the cpuid instruction and return the vendor
string reported by that instruction.
brandString :: IO StringSource
Execute the cpuid instruction and return the brand string
(processor name and maximum frequency) reported by that
instruction.