All Projects → m-j-w → Cpuid.jl

m-j-w / Cpuid.jl

Licence: other
Ask the CPU for cache sizes, SIMD feature support, a running hypervisor, and more.

Programming Languages

julia
2034 projects

Projects that are alternatives of or similar to Cpuid.jl

Simple Pt
Simple Intel CPU processor tracing on Linux
Stars: ✭ 232 (+465.85%)
Mutual labels:  performance-tuning
powerstation
A Tool for Detecting Performance Bugs in Rails Applications
Stars: ✭ 57 (+39.02%)
Mutual labels:  performance-tuning
Netutils Linux
A suite of utilities simplilfying linux networking stack performance troubleshooting and tuning.
Stars: ✭ 664 (+1519.51%)
Mutual labels:  performance-tuning
awesome-performance
🚀 A curated list of awesome web performance stuff 🚀
Stars: ✭ 29 (-29.27%)
Mutual labels:  performance-tuning
crowdsource-experiments-using-android-devices
Android application to participate in experiment crowdsourcing (such as workload crowd-benchmarking and crowd-tuning) using Collective Knowledge Framework and open repositories of knowledge:
Stars: ✭ 23 (-43.9%)
Mutual labels:  performance-tuning
Sparklens
Qubole Sparklens tool for performance tuning Apache Spark
Stars: ✭ 345 (+741.46%)
Mutual labels:  performance-tuning
Myperf4j
High performance Java APM. Powered by ASM. Try it. Test it. If you feel its better, use it.
Stars: ✭ 2,281 (+5463.41%)
Mutual labels:  performance-tuning
Stackimpact Java
StackImpact Java Profiler - Production-Grade Performance Profiler: CPU, locks, runtime metrics, and more
Stars: ✭ 7 (-82.93%)
Mutual labels:  performance-tuning
qoopido.demand
Promise like module loader with automatic resolution of nested dependencies using XHR requests and localStorage caching to dynamically load modules, legacy JavaScript, CSS, text and bundles. Supports custom handler and plugins as well.
Stars: ✭ 36 (-12.2%)
Mutual labels:  performance-tuning
Inspectit
inspectIT is the leading Open Source APM (Application Performance Management) tool for analyzing your Java (EE) applications.
Stars: ✭ 513 (+1151.22%)
Mutual labels:  performance-tuning
AMD-APU-Tuning-Utility
Unlock the full potential of your Zen-based APU with AMD APU Tuning Utility!
Stars: ✭ 299 (+629.27%)
Mutual labels:  performance-tuning
paper-synthesizing-benchmarks
📝 "Synthesizing Benchmarks for Predictive Modeling" (🥇 CGO'17 Best Paper)
Stars: ✭ 21 (-48.78%)
Mutual labels:  performance-tuning
Processhacker
A free, powerful, multi-purpose tool that helps you monitor system resources, debug software and detect malware.
Stars: ✭ 6,285 (+15229.27%)
Mutual labels:  performance-tuning
jamonapi
Another repo for jamonapi.com which is primarily hosted on sourceforge
Stars: ✭ 57 (+39.02%)
Mutual labels:  performance-tuning
Stackimpact Python
DEPRECATED StackImpact Python Profiler - Production-Grade Performance Profiler: CPU, memory allocations, blocking calls, exceptions, metrics, and more
Stars: ✭ 671 (+1536.59%)
Mutual labels:  performance-tuning
Lightify
a reverse proxy that boosts the web app performance!
Stars: ✭ 187 (+356.1%)
Mutual labels:  performance-tuning
Stackimpact Go
DEPRECATED StackImpact Go Profiler - Production-Grade Performance Profiler: CPU, memory allocations, blocking calls, errors, metrics, and more
Stars: ✭ 276 (+573.17%)
Mutual labels:  performance-tuning
Ck Wa
Collective Knowledge workflow for ARM's workload automation tool: an open framework for gathering and sharing knowledge about system design and optimization using real-world workloads.
Stars: ✭ 24 (-41.46%)
Mutual labels:  performance-tuning
Linux Perf Examples
极客时间《Linux 性能优化实战》案例
Stars: ✭ 724 (+1665.85%)
Mutual labels:  performance-tuning
Goappmonitor
Golang application performance data monitoring.
Stars: ✭ 478 (+1065.85%)
Mutual labels:  performance-tuning

CPU, what can you do?

CpuId is a package for the Julia programming language that enables you to query the availability of specific CPU features with low run-time cost using the assembly instruction cpuid.

Status: considered a pre-beta version, ready for you to try out.

Works on Julia 0.7 or newer, on Linux, Mac and Windows with Intel CPUs; AMD CPUs partially supported respectively support is in preparation.

Motivation

Besides the obvious reason to gather information for diagnostics, the CPU provides valuable information when aiming at increasing the efficiency of code. Such use-cases could be to tailor the size of working sets of data according to the available cache sizes, to detect when the code is executed in a virtual machine (hypervisor), or to determine the size of the largest SIMD registers available to choose the best algorithm for the current hardware.

This information is obtained by directly querying the CPU through the cpuid assembly instruction which operates only using CPU registers, and provides a portable way to adapt code to specific hardware.

Same information may of course be collected from various sources, from Julia itself or from the operating system, e.g. on Linux from /proc/cpuinfo. See below for a few alternatives. However, the cpuid instruction is portable in the sense that it doesn't rely on other external dependencies.

The full documentation is found in Intel's 4670 page combined Architectures Software Devleoper Manual. A more practical and concise overview of the cpuid instruction is found at sandpile.org.

Installation and Usage

CpuId is a registered Julia package; use the package manager to install:

Julia> Pkg.add("CpuId")

Or, if you're keen to get some intermediate updates, clone from GitHub master branch:

Julia> Pkg.clone("https://github.com/m-j-w/CpuId.jl")

See the diagnostic summary on your CPU by typing

julia> using CpuId
julia> cpuinfo()

   Cpu Property         Value
  ╾───────────────────╌───────────────────────────────────────────────────────────╼
   Brand                Intel(R) Xeon(R) CPU E3-1225 v5 @ 3.30GHz
   Vendor               :Intel
   Architecture         :Skylake
   Model                Family: 6, Model: 94, Stepping: 3, Type: 0
   Cores                4 physical cores, 4 logical cores (on executing CPU)
                        No Hyperthreading detected
   Clock Frequencies    3300 / 3700 MHz (base/max), 100 MHz bus
   Data Cache           Level 1:3 : (32, 256, 8192) kbytes
                        64 byte cache line size
   Address Size         48 bits virtual, 39 bits physical
   SIMD                 256 bit = 32 byte max. SIMD vector size
   Time Stamp Counter   TSC is accessible via `rdtsc`
                        TSC runs at constant rate (invariant from clock frequency)
   Perf. Monitoring     Performance Monitoring Counters (PMC) revision 4
                        Available hardware counters per logical core:
                        3 fixed-function counters of 48 bit width
                        8 general-purpose counters of 48 bit width
   Hypervisor           No

Or get a list of the feature flags of your CPU with

julia> cpufeaturetable()

   Cpu Feature   Description
  ╾────────────╌───────────────────────────────────────────────────────────────╼
   3DNowP        3D Now PREFETCH and PREFETCHW instructions
   ACPI          Thermal monitor and software controlled clock facilities (MSR)
   ADX           Intel ADX (Multi-Precision Add-Carry Instruction Extensions)
   AES           AES encryption instruction set
   AHF64         LAHF and SAHF in PM64
   APIC          APIC on-chip (Advanced Programmable Interrupt Controller)
   AVX           256bit Advanced Vector Extensions, AVX
   AVX2          SIMD 256bit Advanced Vector Extensions 2
   BMI1          Bit Manipulation Instruction Set 1
   BMI2          Bit Manipulation Instruction Set 2
   CLFLUSH       CLFLUSHOPT Instructions
   CLFSH         CLFLUSH instruction (SSE2)
   CMOV          Conditional move CMOV and FCMOV instructions
   CX16          CMPXCHG16B instruction
   CX8           CMPXCHG8 instruction (64bit compare and exchange)
   ...

Features

This release covers a selection of fundamental and higher level functionality:

  • cpuinfo() generates the summary shown above (markdown string).
  • cpubrand(), cpumodel(), cpuvendor() allow the identification of the CPU.
  • cpuarchitecture() tries to infer the microarchitecture, currently only of Intel CPUs.
  • cpucores() and cputhreads() to determine the number of physical and logical cores on the currently executing CPU, which typically share L3 caches and main memory bandwidth. If the result of both functions is equal, then the CPU does not use of hyperthreading.
  • address_size() and physical_address_size() return the number of bits used in pointers. Useful when stealing a few bits from a pointer.
  • cachelinesize() gives the size in bytes of one cache line, which is typically 64 bytes.
  • cachesize() returns a tuple with the sizes of the data caches in bytes.
  • cpu_base_frequency(), cpu_max_frequency(), cpu_bus_frequency() give - if supported by the CPU, the base, maximum and bus clock frequencies. Use has_cpu_frequencies() to check whether this property is supported.
  • hypervised() returns true when the CPU indicates that a hypervisor is running the operating system, aka a virtual machine. In that case, hvvendor() may be invoked to get the, well, hypervisor vendor, and hvversion() returns a dictionary of additional version tags. hvinfo() generates a markdown summary of same dictionary.
  • simdbits() and simdbytes() return the size of the largest SIMD register available on the executing CPU.
  • perf_revision() to query the revision number of hardware performance monitoring counters, along with perf_fix_counters(), perf_gen_counters(), perf_fix_bits(), perf_gen_bits() to determine the number and bit width of available fixed-function and general purpose counters per logical core.
  • cpucycle() and cpucycle_id() let you directly get the CPU's time stamp counter, which is increased for every CPU clock cycle. This is a method to perform low overhead micro-benchmarking; though, technically, this uses the rdtsc and rdtscp instructions rather than cpuid.
  • cpufeature(::Symbol) permits asking for the availability of a specific feature, and cpufeaturetable() gives a complete overview of all detected features with a brief explanation, as shown above.

Background

The cpuid instruction is a generic way provided by the CPU vendor to obtain basic hardware information. It provides data in form of boolean bit fields, integer fields and strings, all packed in the returned CPU registers EAX, EBX, ECX and EDX. Which information is returned is determined by the so called leaf, which is defined by setting the input register EAX to a specific 32 bit integer value before executing the instruction. The extent and kind of information obtainable via this instruction has changed quite a lot over the past decade and still evolves with every CPU generation. Thus, not all information is available on every CPU model, and certainly everything is vendor dependent.

This Julia package also provides the cpucycle() function which allows getting the current time stamp counter (TSC) by emitting a rdtsc instruction. Similarly to cpuid, it only requires CPU registers and is usable in user-land code and facilitates an alternative approach to micro-benchmarking.

Limitations

The behaviour on non-Intel CPUs is currently unknown; though technically a crash of Julia could be expected, theoretically, a rather large list of CPUs support the cpuid instruction. Tip: Just try it and report back.

There are plenty of different CPUs, and in particular the cpuid instruction has numerous corner cases, which this package does not address, yet.

Moreover, the cpuid instruction can only provide information for the executing physical CPU, called a package. To obtain information on all packages, and all physical and logical cores, the executing program must be pinned sequentially to each and every core, and gather its properties. This is how libuv, hwloc or the operating system obtain that kind information. However, this would require additional external or operating system dependent code which is not the scope of this package.

Specific limitations

  • Why aren't all infos available that are seen e.g. in /proc/cpuinfo? Many of those features, flags and properties reside in the so called machine specific registers (MSR), which are only accessible to privileged programs running in the so called ring 0, such as the Linux kernel itself. Thus, short answer: You're not allowed to.

  • The results obtained by CpuId functions are inconsistent with my hardware! Try other programs whether they give the same information or differ. If they differ, then you found a bug. See below for some alternatives, in particular the Linux command line tool cpuid.

  • When running a hypervisor (virtual machine) the presented information is wrong! Hypervisor vendors are free to provide the cpuid information by intercepting calls to that instruction. Not all vendors comply, and some even permit the user to change what is reported. Thus, expect some surprises when a hypervisor is detected.

  • My hypervisor is not detected! Either you're not really running a hypervisor, e.g. Bash on Windows is not a virtual machine, or there is a feature missing. Raise an issue on GitHub.

  • cpucycles() invokes rdtsc; that is not cpuid! True. However, both are valuable when diagnosing performance issues and trying to perform micro benchmarks on specific hardware.

Alternatives

On Linux, most of the information may be obtained by reading from the /proc tree, in particular /proc/cpuinfo, which eventually also invokes the cpuid instruction. Type man 4 cpuid to get a brief description of this kernel driver.

On many Linux distributions, there is also the command line tool cpuid, which essentially does exactly the same. On Ubuntu, you would install it using sudo apt install cpuid, then use it to show a summary by simply typing cpuid.

Then, of course, there are a few functions in Julia Base. These are Base.Sys.cpu_info(), and Base.Sys.cpu_summary(), as well as the global variables Base.Sys.CPU_CORES, and Base.Sys.cpu_name. These are mostly provided by wrapping libuv. In particular CPU_CORES is the reason for this module: It's intrinsically unclear whether that number includes hyperthreading cores, or whether it is referring to real physical cores of the current machine.

The Julia package Hwloc.jl provides similar and more information primarily directed towards the topology of your CPUs, viz. number of CPU packages, physical & logical cores and associated caches, along with a number of features to deal with thread affinity. However, it also pulls in additional external binary dependencies in that it relies on hwloc, which also implies quite some computational overhead. Whether this is an issue in the first place depends much on your use-case.

Terms of usage

This Julia package CpuId is published as open source and licensed under the MIT "Expat" License.

Contributions welcome!

You're welcome to report successful usage or any issues via GitHub, and to open pull requests to extend the current functionality.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].