• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: Apache-2.0
2#
3# Copyright (C) 2015, ARM Limited and contributors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18import logging
19import os
20
21from test import LisaTest
22
23import trappy
24from bart.common.Analyzer import Analyzer
25
26TESTS_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
27TESTS_CONF = os.path.join(TESTS_DIRECTORY, "smoke_test_ramp.config")
28
29class STune(LisaTest):
30    """
31    Goal
32    ====
33
34    Verify that a task in a SchedTune cgroup is boosted
35
36    Detailed Description
37    ====================
38
39    The test runs a ramp task that has increasing load as time passes.
40    The load increases from 5% to 60% over 1 second.  It is run in
41    four different configurations: no boost, 15% boost, 30% boost and
42    60% boost.
43
44    Expected Behaviour
45    ==================
46
47    The margin of the task should match the formula
48
49    .. math::
50
51          (sched\_load\_scale - util) \\times boost
52
53    for all configurations
54
55    """
56
57    test_conf = TESTS_CONF
58    experiments_conf = TESTS_CONF
59
60    @classmethod
61    def setUpClass(cls, *args, **kwargs):
62        super(STune, cls).runExperiments(*args, **kwargs)
63
64    def test_boosted_utilization_signal(self):
65        """Tasks in stune groups are boosted"""
66
67        for tc in self.confs:
68            conf_id = tc["tag"]
69
70            wload_id = self.wloads.keys()[0]
71            run_dir = os.path.join(self.te.res_dir,
72                                   "rtapp:{}:{}".format(conf_id, wload_id),
73                                   "1")
74
75            ftrace_events = ["sched_boost_task"]
76            ftrace = trappy.FTrace(run_dir, scope="custom",
77                                   events=ftrace_events)
78
79            first_task_params = self.wloads[wload_id]["conf"]["params"]
80            first_task_name = first_task_params.keys()[0]
81            rta_task_name = "task_{}".format(first_task_name)
82
83            # Avoid the first period as the task starts with a very
84            # high load and it overutilizes the CPU
85            rtapp_period = first_task_params[first_task_name]["params"]["period_ms"]
86            sbt_dfr = ftrace.sched_boost_task.data_frame
87            task_start = sbt_dfr[sbt_dfr.comm == rta_task_name].index[0]
88            after_first_period = task_start + (rtapp_period / 1000.)
89
90            boost = tc["cgroups"]["conf"]["schedtune"]["/stune"]["boost"]
91            analyzer_const = {
92                "SCHED_LOAD_SCALE": 1024,
93                "BOOST": boost,
94            }
95            analyzer = Analyzer(ftrace, analyzer_const,
96                                window=(after_first_period, None),
97                                filters={"comm": rta_task_name})
98            statement = "(((SCHED_LOAD_SCALE - sched_boost_task:util) * BOOST) // 100) == sched_boost_task:margin"
99            error_msg = "task was not boosted to the expected margin: {:.2f}"\
100                        .format(boost / 100.)
101            self.assertTrue(analyzer.assertStatement(statement), msg=error_msg)
102
103# vim :set tabstop=4 shiftwidth=4 expandtab
104