Skip to content

shellfire-dev/cpucount

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

cpucount: functions module for shellfire

This module provides utility functions for counting cpus to a shellfire application. It is deliberately separate to the core module as it is not likely to be frequently needed.

An example user is the cmake-scripted tool.

Compatibility

Overview

To find the number of hyperthreaded CPUs on a system:

local cpucount_discoveredNumberOfCpus
cpucount_findNumberOfHyperthreadedCpus
echo "Number of CPUs: $cpucount_discoveredNumberOfCpu"
local cpucount_makeJobs
local cpucount_makeLoadAverage
cpucount_computeMakeJobsAndLoadAverage 0 75
echo "Number of make jobs: $cpucount_makeJobs"
echo "Make load average: $cpucount_makeLoadAverage"

Importing

To import this module, add a git submodule to your repository. From the root of your git repository in the terminal, type:-

mkdir -p lib/shellfire
cd lib/shellfire
git submodule add "https://github.com/shellfire-dev/cpucount.git"
cd -
git submodule init --update

You may need to change the url https://github.com/shellfire-dev/cpucount.git" above if using a fork.

You will also need to add paths - include the module paths.d.

Namespace cpucount

To use in code

If calling from another shellfire module, add to your shell code the line

core_usesIn configure

in the global scope (ie outside of any functions). A good convention is to put it above any function that depends on functions in this module. If using it directly in a program, put this line inside the _program() function:-

_program()
{
	core_usesIn cpucount
	…
}

Functions


cpucount_findNumberOfHyperthreadedCpus

Parameter Value Optional

Takes no parameters.

Sets cpucount_discoveredNumberOfCpus to the number of hyperthreaded CPUs.


cpucount_computeMakeJobsAndLoadAverage

Parameter Value Optional
configuredCpuCount Integer. Set to 0 to use the value of cpucount_discoveredNumberOfCpus. Set to a negative value to use cpucount_discoveredNumberOfCpus reduced by the magnitude of the negative value. No
configuredLoadAverageCorrection Integer percentage between 0 and 100. Used to reduce the load average by this percent. No

Sets cpucount_makeJobs to the number of make jobs and cpucount_makeLoadAverage to the make load average to use.

The configuredLoadAverageCorrection is used to overcome the shell's lack of floating point maths. For instance, if the uncorrected load average would be 4.00, using a configuredLoadAverageCorrection of 75 will result in cpucount_makeLoadAverage being 3.25. If cpucount_makeLoadAverage would be 0.00 then it is forced to 0.01.

About

shellfire cpucount functions module

Resources

License

Stars

Watchers

Forks

Packages

No packages published