RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1225135 - Add built-in support for unit conversion into tuned
Summary: Add built-in support for unit conversion into tuned
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: tuned
Version: 7.2
Hardware: All
OS: Linux
urgent
urgent
Target Milestone: rc
: ---
Assignee: Jaroslav Škarvada
QA Contact: Tereza Cerna
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-05-26 16:30 UTC by Jeremy Eder
Modified: 2016-09-02 11:57 UTC (History)
6 users (show)

Fixed In Version: tuned-2.5.1-3.el7
Doc Type: Bug Fix
Doc Text:
Cause: Previously there was very limited support for units conversion in Tuned. Consequence: If user wanted to customize Tuned profiles or write their own she/he sometimes had to manually convert values between different units which sometimes wasn't straightforward (e.g. sectors vs kB). Fix: Tuned code was extended to provide built-in conversion functions. It has plug-in architecture, thus it is possible to easily add new functions. Result: The following built-in functions were implemented: exec - executes external command with arguments and substitutes its output. kb2s - converts kB to sectors s2kb - converts sectors kB cpulist2hex - converts CPU list to hexadecimal mask hex2cpulist - converts hexadecimal mask to CPU list cpus_online - checks whether CPUs from the list are online, returns only those which are online cpulist_unpack - unpacks condensed CPU list (e.g. 1-3 to 1,2,3) cpulist_invert - inverts CPU list (makes its complement) cpulist2hex_invert - converts CPU list to hexadecimal mask and inverts it Usage in Tuned profile to e.g. convert sectors to kB: [variables] secs = 10 kbs = ${f:s2kb:${secs}} Example to run external command and substitute its output: [variables] cmd = date curr_date = ${f:exec:${cmd}} The "curr_date" variable will be set to the output of the "date" command, i.e. the current date. For details and syntax description see comments in bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1225135
Clone Of:
Environment:
Last Closed: 2015-11-19 12:21:44 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2015:2375 0 normal SHIPPED_LIVE tuned bug fix and enhancement update 2015-11-19 10:51:42 UTC

Comment 3 Jaroslav Škarvada 2015-06-05 17:19:15 UTC
tuned: added support for built-in functions
   
Built-in functions has plugin architecture. They are defined in tuned/profiles/functions. Each function (plugin) is python code named function_NAME.py, where NAME is the name of the built-in function defined. It is easy to implement own functions, for example see provided functions.
    
Functions are expanded in tuned profile configuration file during profile   load. Functions are expanded after variables. The syntax for function call is  ${f:NAME:ARG1:ARG2...}. The function NAME will be called and it's result    substituted. It is possible to escape $ by \$ and : by \:. Functions are     loaded and executed on demand. Function which is once loaded during profile    application is not reloaded on multiple executions. Variables in profile arguments are supported, but function calls aren't.
    
The following functions have been implemented so far:
    
exec:ARG1:...:ARGN        - execute external command with arguments and subtitute its output.

kb2s:ARG                  - converts kbytes specified as ARG to sectors.

s2kb:ARG                  - converts sectors specified as ARG to kbytes.

cpulist2hex:ARG1:...:ARGN - converts CPU list to hexadecimal mask, takes arbitrary number of arguments, each argument can also contain "compact values", e.g.: "${f:cpulist2hex:0-3,4:5-6}"
    
hex2cpulist:ARG1 - converts hexadecimal mask to CPU list, takes one argument, the hexadecimal mask.
    
cpus_online:ARG1:...:ARGN - checks whether CPUs from the list (which is formatted the same way as with cpulist2hex) are online, returns only those which are online.
     
Example:
    
[variables]
cmd = date
curr_date = ${f:exec:${cmd}}

[variables]
cpus = ${f:hex2cpulist:0x0000001f}
online = ${f:cpus_online:${cpus}}

You cannot call function from function, but it is possible to workaround it by "helper" variable. This is for simplification of the code, otherwise it would require stack, and stack depth checking, etc.

Available in snapshot 20150605.

Comment 4 Jaroslav Škarvada 2015-06-08 11:55:00 UTC
For the 20150608 nightly also made available the cpulist_unpack built-in function. The implementation was there since 20150605 in internal API.

Usage:

[variables]
cpus = ${f:cpulist_unpack:1,2,3-5}

The 'cpus' will be set to '1,2,3,4,5'. Also the built-in function can take
arbitrary number of arguments which will be concatenated, e.g.:

[variables]
cpus = ${f:cpulist_unpack:1-3,5:6-7,9}

This means two arguments to 'cpulist_unpack' function. The first argument: '1-3,5' and the second '6-7,9'. The result: '1,2,3,5,6,7,9'.

Comment 5 Jaroslav Škarvada 2015-06-08 12:24:55 UTC
functions: added 'cpulist_invert' built-in function

Inverts list of CPUs (makes its complement). For the complement it
gets number of present CPUs from the /sys/devices/system/cpu/present,
e.g. system with 4 CPUs (0-3):

[variables]
cpus = ${f:cpulist_invert:1-3,5:6-7,9}

The 'cpus' will be set to '0'

Comment 6 Jaroslav Škarvada 2015-06-08 12:32:48 UTC
Renamed 'cpus_online' built in function to 'cpulist_online' to be consistent.

Comment 7 Jaroslav Škarvada 2015-06-08 15:20:16 UTC
commit dfdbd88e679b4735d1a62ac75114ec1c92e5c38a

functions: added autodetection of format to cpulist_unpack

Now CPUs starting with 0x are taken as hexmask. As cpulist_unpack is used as preprocessor of CPU list for other built-in functions this also works with other functions (e.g. cpulist_invert).

Example:
[variables]
cpus = ${f:cpulist_invert:1-2,0x8}

On four CPU machines (CPUs 0-3) it expands to '0'.

Comment 8 Clark Williams 2015-06-08 15:29:52 UTC
(In reply to Jaroslav Škarvada from comment #7)
> commit dfdbd88e679b4735d1a62ac75114ec1c92e5c38a
> 
> functions: added autodetection of format to cpulist_unpack
> 
> Now CPUs starting with 0x are taken as hexmask. As cpulist_unpack is used as
> preprocessor of CPU list for other built-in functions this also works with
> other functions (e.g. cpulist_invert).
> 
> Example:
> [variables]
> cpus = ${f:cpulist_invert:1-2,0x8}
> 
> On four CPU machines (CPUs 0-3) it expands to '0'.

One thing to be aware of when dealing with proc/sys bitmasks is that on systems with more than 32-cores you get comma-separated masks. E.g. on a 64-core system, the all-cpu mask is:  ffffffff,ffffffff. The cores are broken up into 32-core sections. 

If you haven't already dealt with that, I have some code you can start with. If you have dealt with it, then Never Mind(tm). :)

Comment 9 Jaroslav Škarvada 2015-06-08 15:57:39 UTC
(In reply to Clark Williams from comment #8)
> (In reply to Jaroslav Škarvada from comment #7)
> > commit dfdbd88e679b4735d1a62ac75114ec1c92e5c38a
> > 
> > functions: added autodetection of format to cpulist_unpack
> > 
> > Now CPUs starting with 0x are taken as hexmask. As cpulist_unpack is used as
> > preprocessor of CPU list for other built-in functions this also works with
> > other functions (e.g. cpulist_invert).
> > 
> > Example:
> > [variables]
> > cpus = ${f:cpulist_invert:1-2,0x8}
> > 
> > On four CPU machines (CPUs 0-3) it expands to '0'.
> 
> One thing to be aware of when dealing with proc/sys bitmasks is that on
> systems with more than 32-cores you get comma-separated masks. E.g. on a
> 64-core system, the all-cpu mask is:  ffffffff,ffffffff. The cores are
> broken up into 32-core sections. 
> 
> If you haven't already dealt with that, I have some code you can start with.
> If you have dealt with it, then Never Mind(tm). :)

Will be fixed in 20150609.

Comment 11 Jaroslav Škarvada 2015-06-10 10:29:22 UTC
(In reply to Jaroslav Škarvada from comment #9)
> (In reply to Clark Williams from comment #8)
> > (In reply to Jaroslav Škarvada from comment #7)
> > > commit dfdbd88e679b4735d1a62ac75114ec1c92e5c38a
> > > 
> > > functions: added autodetection of format to cpulist_unpack
> > > 
> > > Now CPUs starting with 0x are taken as hexmask. As cpulist_unpack is used as
> > > preprocessor of CPU list for other built-in functions this also works with
> > > other functions (e.g. cpulist_invert).
> > > 
> > > Example:
> > > [variables]
> > > cpus = ${f:cpulist_invert:1-2,0x8}
> > > 
> > > On four CPU machines (CPUs 0-3) it expands to '0'.
> > 
> > One thing to be aware of when dealing with proc/sys bitmasks is that on
> > systems with more than 32-cores you get comma-separated masks. E.g. on a
> > 64-core system, the all-cpu mask is:  ffffffff,ffffffff. The cores are
> > broken up into 32-core sections. 
> > 
> > If you haven't already dealt with that, I have some code you can start with.
> > If you have dealt with it, then Never Mind(tm). :)
> 
> Will be fixed in 20150609.

The code supported more than 32 cores, but didn't support comma separator. Currently in 20150610 it works the following way:

It's possible to combine CPU lists with hexmasks, but hexmask needs to be prefixed by "0x" (hex2cpulist function doesn't need the prefix). Hexmasks can include commas, but they are not mandatory. To separate hexmask from CPU list use double comma ',,' (there can be whitespaces between commas).

Example:
[variables]
cpus = ${f:cpulist_unpack:1-2,0x8,ffffffff,,37-39}

It's also possible to separate hexmasks and CPU list by specifying CPU list as another argument (arguments are separated by colons ':'), e.g. the following also works:

[variables]
cpus = ${f:cpulist_unpack:1-2,0x8,ffffffff:37-39}

Or separate it all by commas:

[variables]
cpus = ${f:cpulist_unpack:1-2:0x8,ffffffff:37-39}

Or without commas in hexmask:

[variables]
cpus = ${f:cpulist_unpack:1-2:0x8ffffffff:37-39}

Or any combination of the above.

Comment 12 Jaroslav Škarvada 2015-06-10 10:31:35 UTC
(In reply to Jaroslav Škarvada from comment #11)
> Or separate it all by commas:
> 
> [variables]
> cpus = ${f:cpulist_unpack:1-2:0x8,ffffffff:37-39}
> 

Typo, should be: separate it all by colons

Comment 13 Jaroslav Škarvada 2015-06-10 11:56:33 UTC
functions: added 'cpulist2hex_invert' built-in function

It converts CPU list to hexadecimal CPU mask and inverts it.

Example:

[variables]
cpus = ${f:cpulist2hex_invert:1-2}

On machine with four CPUs it returns 00000009.

Comment 18 errata-xmlrpc 2015-11-19 12:21:44 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-2375.html


Note You need to log in before you can comment on or make changes to this bug.