1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
17 class Optimize(object):
21 def bind_cpu(self, cpu_range, thread):
22 flag, num = commands.getstatusoutput('taskset -pc %s %s' % (cpu_range, thread))
25 def catch_thread_info(self):
26 thread_info = {'fwd_vhost': None, 'src_recv_irq': None, 'dst_send_irq': None}
27 # top -H get the usage info
28 flag, threads_usages = commands.getstatusoutput('top -bH -n1 -c -w 2000')
29 line_array = threads_usages.split('\n')
30 # get highest vhost line
31 for line in line_array:
32 if re.search('vhost-', line) and self._check_thread_usage(line):
33 thread_info['fwd_vhost'] = line.split()[0]
35 # get highest irq thread as src_recv_irq thread
36 for line in line_array:
37 if re.search('irq/', line) and self._check_thread_usage(line):
38 thread_info['src_recv_irq'] = line.split()[0]
39 line_array.remove(line)
41 # get the second highest irq thread as dst_send_irq
42 for line in line_array:
43 if re.search('irq/', line) and self._check_thread_usage(line):
44 thread_info['dst_send_irq'] = line.split()[0]
46 # check the data valid
48 for key in thread_info.keys():
49 if thread_info[key] is None:
50 return False, str(thread_info)
51 return True, str(thread_info)
53 def _check_thread_usage(self, line):
55 usage = line.split()[8]
56 if float(usage) >= 3.0:
59 print("[ERROR]The highest thread %s is less than 0.05" % usage)
62 print("[ERROR]The thread usage get failed.")