cpuinfo-0.1.0.0: Haskell Library for Checking CPU Information

CopyrightTravis Whitaker 2016
LicenseMIT
Maintainerpi.boy.travis@gmail.com
StabilityProvisional
PortabilityLinux >=2.6
Safe HaskellSafe
LanguageHaskell2010

System.CPU

Contents

Description

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

Documentation

data CPU Source

Representation of a logical processor and its features.

Constructors

CPU 

Fields

processorID :: !Word32

Logical Processor Index

vendor :: !(Maybe ByteString)

CPU Vendor

model :: !(Maybe Word32)

CPU Model Number

modelName :: !(Maybe ByteString)

CPU Model Name

revision :: !(Maybe Word32)

CPU Model Revision

microcode :: !(Maybe Word32)

CPU Microcode Revision

freq :: !Double

Processor Frequency

cache :: !(Maybe Word32)

CPU Cache Size. (TODO figure out how to get the cache topology)

physicalID :: !Word32

Physical Processor Index

siblings :: !Word32

Number of Physical Cores on this Physical Processor.

coreID :: !Word32

Physical Core Index

apicID :: !(Maybe Word32)

CPU APIC Index

fpu :: !(Maybe Bool)

Whether or not the Physical Core provides a floating point unit.

fpuExcept :: !(Maybe Bool)

Whether or not the Physical Core provides a floating point exception unit.

flags :: !(Maybe [ByteString])

Vendor-specific CPU flags.

bogoMIPS :: !Double

MIPS approximation computed by the Linux kernel on boot.

cacheAlignment :: !(Maybe Word32)

Cache line size in bytes.

physicalAddress :: !(Maybe Word32)

Physical address width.

virtualAddress :: !(Maybe Word32)

Virtual address width.

Retrieving CPU Information

getCPUs :: IO [CPU] Source

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.