Built-in functions for profile customization
You can use the built-in functions in TuneD profiles to dynamically expand at runtime when a profile is activated. Use built-in functions with TuneD variables to modify and process values dynamically within a profile.
You can extend TuneD with custom functions by creating and integrating custom Python functions as plugins.
- Syntax to start a built-in function
-
${f:function_name:argument_1:argument_2}To retrieve the directory path where the profile and the
tuned.conffile are located, use thePROFILE_DIRvariable. It uses the following syntax:${i:PROFILE_DIR} - Example of isolating CPU cores by using a built-in function
-
[variables] non_isolated_cores=0,3-5 [bootloader] cmdline=isolcpus=${f:cpulist_invert:${non_isolated_cores}}In this example, the
${non_isolated_cores}variable expands to0,3-5. Thecpulist_invertfunction inverts the CPU list. On a system with 6 CPUs,0,3-5inverts to1,2, resulting in the kernel booting with theisolcpus=1,2option.Table 1. Available built-in functions: Function name Description assertion
Compare two arguments. If they do not match, the function logs text from the first argument and cancels profile loading.
assertion_non_equal
Compare two arguments. If they match, the function logs text from the first argument and cancels profile loading.
calc_isolated_cores
Calculates and returns isolated cores. The argument specifies how many cores per socket to reserve for housekeeping. If not specified, one core per socket is reserved for housekeeping and the rest are isolated.
check_net_queue_count
Checks whether the user has specified a queue count for net devices. If not, it returns the number of housekeeping CPUs.
cpuinfo_check
Checks regular expressions against /proc/cpuinfo. Accepts arguments in the form: REGEX1, STR1, REGEX2, STR2, …[, STR_FALLBACK]. If REGEX1 matches something in /proc/cpuinfo, it expands to STR1; if REGEX2 matches, it expands to STR2. It stops on the first match. If no regular expression matches, it expands to STR_FALLBACK or an empty string if no fallback is provided.
cpulist2devs
Converts a CPU list to device strings.
cpulist2hex
Converts a CPU list to a hexadecimal CPU mask.
cpulist2hex_invert
Converts a CPU list to a hexadecimal CPU mask and inverts it.
cpulist_invert
Inverts a list of CPUs to make its complement. For example, on a system with 4 CPUs (0-3), the inversion of the list 0,2,3 is 1.
cpulist_online
Checks whether the CPUs from the list are online. Returns the list containing only online CPUs.
cpulist_pack
Packs a CPU list in the form of 1,2,3,5 to 1-3,5.
cpulist_present
Checks whether the CPUs from the list are present. Returns the list containing only present CPUs.
cpulist_unpack
Unpacks a CPU list in the form of 1-3,4 to 1,2,3,4.
exec
Runs a process and returns its output.
hex2cpulist
Converts a hexadecimal CPU mask to a CPU list.
intel_recommended_pstate
Checks the processor code name and returns the recommended
intel_pstateCPUFreq driver mode. "Active" is returned for newer generation processors not in thePROCESSOR_NAMElist.iscpu_check
Checks regular expressions against the output of
iscpu. Accepts arguments in the form: REGEX1, STR1, REGEX2, STR2, …[, STR_FALLBACK]. If REGEX1 matches something in the output, it expands to STR1; if REGEX2 matches, it expands to STR2. It stops on the first match. If no regular expression matches, it expands toSTR_FALLBACKor an empty string if no fallback is provided.package2cpus
Provides a CPU device list for a package (socket).
package2uncores
Provides an uncore device list for a package (socket).
regex_search_ternary
Ternary regular expression operator. Takes arguments in the form: STR1, REGEX, STR2, STR3. If REGEX matches STR1 (
re.searchis used), STR2 is returned; otherwise, STR3 is returned.log
Expands to the concatenation of arguments and logs the result, useful for debugging.
kb2s
Converts KB to disk sectors.
s2kb
Converts disk sectors to KB.
strip
Creates a string from all passed arguments and deletes both leading and trailing white spaces.
virt_check
Checks whether TuneD is running inside a virtual machine (VM) or on bare metal. Inside a VM, the function returns the first argument. On bare metal, the function returns the second argument, even in case of an error.