4 ## Copyright (c) 2020 Intel Corporation
6 ## Licensed under the Apache License, Version 2.0 (the "License");
7 ## you may not use this file except in compliance with the License.
8 ## You may obtain a copy of the License at
11 ## http://www.apache.org/licenses/LICENSE-2.0
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
20 from past.utils import old_div
24 from rapid_log import RapidLog
25 from rapid_test import RapidTest
27 class IrqTest(RapidTest):
29 Class to manage the irq testing
31 def __init__(self, test_param, runtime, testname, environment_file,
33 super().__init__(test_param, runtime, testname, environment_file)
34 self.machines = machines
37 RapidLog.info("+----------------------------------------------------------------------------------------------------------------------------+")
38 RapidLog.info("| Measuring time probably spent dealing with an interrupt. Interrupting DPDK cores for more than 50us might be problematic |")
39 RapidLog.info("| and result in packet loss. The first row shows the interrupted time buckets: first number is the bucket between 0us and |")
40 RapidLog.info("| that number expressed in us and so on. The numbers in the other rows show how many times per second, the program was |")
41 RapidLog.info("| interrupted for a time as specified by its bucket. '0' is printed when there are no interrupts in this bucket throughout |")
42 RapidLog.info("| the duration of the test. 0.00 means there were interrupts in this bucket but very few. Due to rounding this shows as 0.00 |")
43 RapidLog.info("+----------------------------------------------------------------------------------------------------------------------------+")
47 for machine in self.machines:
48 buckets=machine.socket.show_irq_buckets(machine.get_cores()[0])
49 if max_loop_duration == 0:
50 # First time we go through the loop, we need to initialize
52 result_details = {'test': self.test['testname'],
53 'environment_file': self.test['environment_file'],
55 print('Measurement ongoing ... ',end='\r')
56 machine.start() # PROX cores will be started within 0 to 1 seconds
57 # That is why we sleep a bit over 1 second to make sure all cores
60 old_irq = [[0 for x in range(len(buckets))] for y in range(len(machine.get_cores()))]
61 irq = [[0 for x in range(len(buckets))] for y in range(len(machine.get_cores()))]
63 for bucket in buckets:
64 column_names.append('<{}'.format(bucket))
65 column_names[-1] = '>{}'.format(buckets[-2])
66 for j,bucket in enumerate(buckets):
67 for i,irqcore in enumerate(machine.get_cores()):
68 old_irq[i][j] = machine.socket.irq_stats(irqcore,j)
69 # Measurements in the loop above, are updated by PROX every second
70 # This means that taking the same measurement 0.5 second later
71 # might result in the same data or data from the next 1s window
72 time.sleep(float(self.test['runtime']))
74 for i,irqcore in enumerate(machine.get_cores()):
75 row_names.append(irqcore)
76 for j,bucket in enumerate(buckets):
77 diff = machine.socket.irq_stats(irqcore,j) - old_irq[i][j]
81 irq[i][j] = str(round(old_div(diff,
82 float(self.test['runtime'])), 2))
83 if max_loop_duration < int(bucket):
84 max_loop_duration = int(bucket)
85 # Measurements in the loop above, are updated by PROX every second
86 # This means that taking the same measurement 0.5 second later
87 # might result in the same data or data from the next 1s window
88 # Conclusion: we don't know the exact window size.
89 # Real measurement windows might be wrong by 1 second
90 # This could be fixed in this script by checking this data every
91 # 0.5 seconds Not implemented since we can also run this test for
92 # a longer time and decrease the error. The absolute number of
93 # interrupts is not so important.
96 RapidLog.info('Results for PROX instance %s'%machine.name)
97 RapidLog.info('{:>12}'.format('bucket us') +
98 ''.join(['{:>12}'.format(item) for item in column_names]))
99 for j, row in enumerate(irq):
100 RapidLog.info('Core {:>7}'.format(row_names[j]) +
101 ''.join(['{:>12}'.format(item) for item in row]))
102 core_details['Core {}'.format(row_names[j])] = row
103 machine_details[machine.name] = core_details
104 result_details['machine_data'] = machine_details
105 result_details = self.post_data(result_details)
106 return (500000 - max_loop_duration, result_details)