functions: added cpulist_unpack built-in function
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'.
Also renamed internal function 'unpack_cpulist' to 'cpulist_unpack' to be
more consistent.
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
parent
a6f4fca71d
commit
b7981e7b5e
2 changed files with 22 additions and 3 deletions
19
tuned/profiles/functions/function_cpulist_unpack.py
Normal file
19
tuned/profiles/functions/function_cpulist_unpack.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import os
|
||||
import tuned.logs
|
||||
import base
|
||||
from tuned.utils.commands import commands
|
||||
|
||||
log = tuned.logs.get()
|
||||
|
||||
class cpulist_unpack(base.Function):
|
||||
"""
|
||||
Conversion function: unpacks CPU list in form 1-3,4 to 1,2,3,4
|
||||
"""
|
||||
def __init__(self):
|
||||
# arbitrary number of arguments
|
||||
super(self.__class__, self).__init__("cpulist_unpack", 0)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(self.__class__, self).execute(args):
|
||||
return None
|
||||
return ",".join(str(v) for v in self._cmd.cpulist_unpack(",".join(args)))
|
||||
|
|
@ -136,7 +136,7 @@ class commands:
|
|||
return cpus
|
||||
|
||||
# Unpacks CPU list, i.e. 1-3 will be converted to 1, 2, 3
|
||||
def unpack_cpulist(self, l):
|
||||
def cpulist_unpack(self, l):
|
||||
rl = []
|
||||
if l is None:
|
||||
return l
|
||||
|
|
@ -157,10 +157,10 @@ class commands:
|
|||
if l is None:
|
||||
return None
|
||||
m = 0
|
||||
ul = self.unpack_cpulist(l)
|
||||
ul = self.cpulist_unpack(l)
|
||||
if ul is None:
|
||||
return None
|
||||
for v in self.unpack_cpulist(l):
|
||||
for v in ul:
|
||||
m |= pow(2, v)
|
||||
return "0x%08x" % m
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue