Copyright | Travis Whitaker 2016 |
---|---|
License | MIT |
Maintainer | pi.boy.travis@gmail.com |
Stability | Provisional |
Portability | Linux >=2.6 |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module provides information about the processors available on a system. Modern hardware provides not only multiple physical processors and physical cores, but logical cores which may not have dedicated execution resources. Intel's Hyper-Threading is an example of such a technology, capable of providing two logical cores for every physical core present on a supported physical processor.
These additional logical cores increase the performance of some, but not all workloads. Indeed, some parallel workloads may suffer a performance decrease if all logical cores presented by the operating system do not have dedicated physical resources. This is because technologies providing supernumerary logical cores typically work by scheduling multiple threads in a shared pool of execution resources, e.g. ALUs and FPUs. If threads sharing a pool of execution resources are doing the same sort of work there will be scheduling contention for a single type of execution resource on the physical core.
It is common for threaded Haskell programs to be run with +RTS -N
, causing the
RTS to simply multiplex Haskell threads or sparks over the number of logical
cores available. However, if each logical core does not have dedicated physical
resources and the thread/spark workloads are similar, then this might be slower
than multiplexing over fewer cores.
This package allows a program to use information about the physical and logical
features of the available processors as a heuristic for selecting the number of
worker OS threads to use (e.g. via setNumCapabilities
). Some workloads may
benefit from, for example, using half the number of logical cores available if
there are in fact two logical cores for each physical core. This is typically
true of numerical workloads, but as always benchmarking should be employed to
evaluate the impact of different heuristics.
In its current state this module can only collect information from Linux systems
with a kernel from the 2.6 branch or later by reading /proc/cpuinfo
. If this
module is unable to provide information on your system please file a bug
including your /proc/cpuinfo
. Help providing Windows support would be
greatly appreciated!
Synopsis
- data CPU = CPU {
- processorID :: !Word32
- vendor :: !(Maybe ByteString)
- model :: !(Maybe Word32)
- modelName :: !(Maybe ByteString)
- revision :: !(Maybe Word32)
- microcode :: !(Maybe Word32)
- freq :: !Double
- cache :: !(Maybe Word32)
- physicalID :: !Word32
- siblings :: !Word32
- coreID :: !Word32
- apicID :: !(Maybe Word32)
- fpu :: !(Maybe Bool)
- fpuExcept :: !(Maybe Bool)
- flags :: !(Maybe [ByteString])
- bogoMIPS :: !Double
- cacheAlignment :: !(Maybe Word32)
- physicalAddress :: !(Maybe Word32)
- virtualAddress :: !(Maybe Word32)
- getCPUs :: IO [CPU]
- tryGetCPUs :: IO (Maybe [CPU])
- physicalProcessors :: [CPU] -> Int
- physicalCores :: [CPU] -> Int
- logicalCores :: [CPU] -> Int
- hyperthreadingFactor :: [CPU] -> Rational
- hyperthreadingInUse :: [CPU] -> Bool
Documentation
Representation of a logical processor and its features.
CPU | |
|
Instances
Retrieving CPU Information
Read /proc/cpuinfo
and try to parse the output. If this function throws
an error on your system, please file a bug report with your
/proc/cpuinfo
contents and CPU specifications.
tryGetCPUs :: IO (Maybe [CPU]) Source #
Read /proc/cpuinfo
and try to parse the output. If this function
returns Nothing
on your system, please file a bug report with your
/proc/cpuinfo
contents and CPU specifications.
Physical Features
physicalProcessors :: [CPU] -> Int Source #
Counts the number of physical processors in the system. A physical processor corresponds to a single CPU unit in a single socket, i.e. unless you have a multi-socket motherboard, this number will be one.
physicalCores :: [CPU] -> Int Source #
Counts the number of physical cores in the system. A physical core is an independent processing unit that reads and executes instructions on its own, but potentially shares its die (and other resources) with other cores.
logicalCores :: [CPU] -> Int Source #
Counts the number of logical cores in the system. A logical core is a virtual processing unit exposed to the operating system, that may or may not directly correspond with an independent physical processing unit, e.g. a hyperthread appears as an independent processing unit to the operating system, but has no physically dedicated execution resources.
hyperthreadingFactor :: [CPU] -> Rational Source #
The hyperthreading factor is the number of logical cores divided by the number of physical cores. This quantity indicates the degree to which physical execution resources are shared among logical processors, and may be used to tune parallel applications.
hyperthreadingInUse :: [CPU] -> Bool Source #
If hyperthreading is in use, the hyperthreadingFactor
will be greater
than 1.