Class LinuxCentralProcessor

java.lang.Object
oshi.hardware.common.AbstractCentralProcessor
oshi.hardware.common.platform.linux.LinuxCentralProcessor
All Implemented Interfaces:
CentralProcessor
Direct Known Subclasses:
LinuxCentralProcessorNF

@ThreadSafe public abstract class LinuxCentralProcessor extends AbstractCentralProcessor
A CPU as defined in Linux /proc.
  • Constructor Details

    • LinuxCentralProcessor

      protected LinuxCentralProcessor(long hz)
      LinuxCentralProcessor.
      Parameters:
      hz - the hz
  • Method Details

    • queryProcessorId

      protected CentralProcessor.ProcessorIdentifier queryProcessorId()
      Description copied from class: AbstractCentralProcessor
      Updates logical and physical processor counts and arrays
      Specified by:
      queryProcessorId in class AbstractCentralProcessor
      Returns:
      An array of initialized Logical Processors
    • initProcessorCounts

      Description copied from class: AbstractCentralProcessor
      Initializes logical and physical processor lists and feature flags.
      Specified by:
      initProcessorCounts in class AbstractCentralProcessor
      Returns:
      Lists of initialized Logical Processors, Physical Processors, Processor Caches, and Feature Flags.
    • readTopologyWithUdev

      Reads processor topology using udev.
      Returns:
      a quartet of logical processors, caches, efficiency map, and modalias map
    • readTopologyFromSysfs

      Reads processor topology from sysfs using the default CPU path.
      Returns:
      a quartet of logical processors, caches, efficiency map, and modalias map
    • getLogicalProcessorFromSyspath

      protected static CentralProcessor.LogicalProcessor getLogicalProcessorFromSyspath(String syspath, Set<CentralProcessor.ProcessorCache> caches, String modAlias, Map<Integer,Integer> coreEfficiencyMap, Map<Integer,String> modAliasMap)
      getLogicalProcessorFromSyspath.
      Parameters:
      syspath - the syspath
      caches - the caches
      modAlias - the modAlias
      coreEfficiencyMap - the coreEfficiencyMap
      modAliasMap - the modAliasMap
      Returns:
      a LogicalProcessor for the given syspath
    • querySystemCpuLoadTicks

      public long[] querySystemCpuLoadTicks()
      Description copied from class: AbstractCentralProcessor
      Get the system CPU load ticks
      Specified by:
      querySystemCpuLoadTicks in class AbstractCentralProcessor
      Returns:
      The system CPU load ticks
    • queryCurrentFreq

      public long[] queryCurrentFreq()
      Description copied from class: AbstractCentralProcessor
      Get processor current frequency.
      Specified by:
      queryCurrentFreq in class AbstractCentralProcessor
      Returns:
      The current frequency.
    • queryCurrentFreqFromUdev

      protected abstract boolean queryCurrentFreqFromUdev(long[] freqs)
      Fills the freqs array from udev cpu-freq source. Returns true if successful (max > 0). Subclasses provide the implementation.
      Parameters:
      freqs - array to fill with per-logical-processor frequencies in Hz
      Returns:
      true if frequencies were successfully read
    • queryCurrentFreqFromSysfs

      protected static boolean queryCurrentFreqFromSysfs(long[] freqs)
      queryCurrentFreqFromSysfs.
      Parameters:
      freqs - the freqs
      Returns:
      the result
    • queryMaxFreq

      public long queryMaxFreq()
      Description copied from class: AbstractCentralProcessor
      Get processor max frequency.
      Overrides:
      queryMaxFreq in class AbstractCentralProcessor
      Returns:
      The max frequency.
    • queryMaxFreqFromUdev

      protected abstract long queryMaxFreqFromUdev()
      Queries the maximum frequency from udev.
      Returns:
      the maximum frequency in Hz
    • queryMaxFreqFromSysfs

      protected static long queryMaxFreqFromSysfs()
      Queries the maximum frequency from sysfs.
      Returns:
      the maximum frequency in Hz
    • queryMaxFreqFromCpuFreqPath

      protected static long queryMaxFreqFromCpuFreqPath(String cpuFreqPath)
      Queries the maximum frequency from a cpufreq path.
      Parameters:
      cpuFreqPath - the cpufreq directory path
      Returns:
      the maximum frequency in Hz
    • getSystemLoadAverage

      public double[] getSystemLoadAverage(int nelem)
      Description copied from interface: CentralProcessor
      Returns the system load average for the number of elements specified, up to 3, representing 1, 5, and 15 minutes. The system load average is the sum of the number of runnable entities queued to the available processors and the number of runnable entities running on the available processors averaged over a period of time.

      This method is designed to provide a hint about the system load and may be queried frequently.

      The way in which the load average is calculated is operating system specific but is typically a damped time-dependent average. Linux includes processes waiting for system resources such as disks, while macOS and Unix consider only processes waiting for CPU.

      Windows does not provide a load average. Users may set the configuration property oshi.os.windows.loadaverage to true to start a daemon thread which will provide a similar metric.

      The load average may be unavailable on some platforms (e.g., Windows without the above configuration). If the load average is not available, a negative value is returned.

      Parameters:
      nelem - Number of elements to return.
      Returns:
      an array of the system load averages for 1, 5, and 15 minutes with the size of the array specified by nelem; or negative values if not available.
    • queryProcessorCpuLoadTicks

      public long[][] queryProcessorCpuLoadTicks()
      Description copied from class: AbstractCentralProcessor
      Get the processor CPU load ticks
      Specified by:
      queryProcessorCpuLoadTicks in class AbstractCentralProcessor
      Returns:
      The processor CPU load ticks
    • queryHwcap

      protected long queryHwcap()
      Queries the hardware capabilities from the auxiliary vector. Subclasses provide platform-specific implementations using JNA or FFM native access.
      Returns:
      The hardware capabilities value, or 0 if unavailable
    • queryContextSwitches

      public long queryContextSwitches()
      Description copied from class: AbstractCentralProcessor
      Get number of context switches
      Specified by:
      queryContextSwitches in class AbstractCentralProcessor
      Returns:
      The context switches
    • queryInterrupts

      public long queryInterrupts()
      Description copied from class: AbstractCentralProcessor
      Get number of interrupts
      Specified by:
      queryInterrupts in class AbstractCentralProcessor
      Returns:
      The interrupts