Add validation for performance tuning option
[ta/cm-plugins.git] / recuserconfighandlers / recperformanceprofileshandler / recperformanceprofileshandler.py
1 #! /usr/bin/python
2 # Copyright 2019 Nokia
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 from cmframework.apis import cmuserconfig
17 from cmframework.apis import cmerror
18 from cmdatahandlers.api import configerror
19
20 """
21 This plugin is used to handle REC specific performance profiles configs.
22 """
23
24
25 class recperformanceprofileshandler(cmuserconfig.CMUserConfigPlugin):
26     low_latency_options = [
27         'intel_idle.max_cstate=5',
28         'processor.max_cstate=5',
29     ]
30
31     def __init__(self):
32         super(recperformanceprofileshandler, self).__init__()
33
34     def handle(self, confman):
35         try:
36             self._set_low_latency_options(confman)
37         except configerror.ConfigError as exp:
38             raise cmerror.CMError(str(exp))
39
40     def _set_low_latency_options(self, confman):
41         perfprofconf = confman.get_performance_profiles_config_handler()
42         for profile in perfprofconf.get_performance_profiles():
43             perfprofconf.set_low_latency_kcmd_options(profile, self.low_latency_options)