6 from threading import Thread
7 from threading import Lock
8 from threading import Event
20 __confs_unmeasured__ = []
21 __confs_prepared__ = []
24 """Prepare for measuring
25 Outcome is Linux image for generated configuration."""
27 confs = dtb.get_unmeasured()
28 for pr in __confs_prepared__:
29 for cn in confs.copy():
34 print("Preparing new image.")
35 global __confs_unmeasured__
36 if len(__confs_unmeasured__) == 0:
37 dtb = database.database()
40 configurations.generate()
43 raise exceptions.NoApplicableConfiguration()
44 __confs_unmeasured__ = list(confs)
45 con = __confs_unmeasured__.pop()
46 kernel.config(con.config)
47 img = kernel.make(con.hash)
48 print("Prepared image: " + img)
49 __confs_prepared__.append(con.hash)
52 def measure(kernelimg, con):
53 print("Measuring " + con.hash)
55 os.remove(sf(conf.jobfolder_linux_image))
56 except FileNotFoundError:
58 os.symlink(kernelimg, sf(conf.jobfolder_linux_image))
60 print("Configuration '" + con.hash + "' measured.")
61 os.remove(sf(conf.build_folder) + '/' + kernelimg)
62 __confs_prepared__.remove(con.hash)
67 __preparethreadEvent__ = Event()
68 __measurethreadEvent__ = Event()
70 class prepareThread(Thread):
71 global __preparethread__
72 global __measurethread__
73 def __init__(self, name='prepare'):
74 Thread.__init__(self, name=name)
76 print('Prepare thread start')
77 while not __terminate__:
79 img, config = prepare()
80 except exceptions.NoApplicableConfiguration:
82 __listlock__.acquire()
83 __conflist__.append((img, config))
84 __preparethreadEvent__.set()
85 if len(__conflist__) > conf.multithread_buffer:
86 __listlock__.release()
87 print('Prepare thread suspended')
88 __measurethreadEvent__.wait()
89 print('Prepare thread waken')
91 __listlock__.release()
92 __measurethreadEvent__.clear()
93 print('Prepare thread stop')
95 class measureThread(Thread):
96 global __preparethread__
97 global __measurethread__
98 def __init__(self, name='measure'):
99 Thread.__init__(self, name=name)
101 print('Measure thread start')
102 while not __terminate__:
103 __listlock__.acquire()
104 if len(__conflist__) <= 0:
105 __listlock__.release()
106 print('Measure thread suspended')
107 __preparethreadEvent__.wait()
108 print('Measure thread waken')
109 __listlock__.acquire()
110 __preparethreadEvent__.clear()
111 img, config = __conflist__.pop()
112 __listlock__.release()
113 __measurethreadEvent__.set()
115 print('Measure thread stop')
117 __preparethread__ = prepareThread()
118 __measurethread__ = measureThread()
120 # Start and sigterm handler #
121 def sigterm_handler(_signo, _stack_frame):
125 __measurethreadEvent__.set()
126 __preparethreadEvent__.set()
128 # Main loop and single thread #
129 __terminate__ = False
134 __preparethread__.start()
135 __measurethread__.start()
138 img, config = prepare()
141 while not __terminate__:
142 img, config = prepare()
145 #################################################################################
147 if __name__ == '__main__':
148 signal.signal(signal.SIGTERM, sigterm_handler)
149 signal.signal(signal.SIGINT, sigterm_handler)