6 from threading import Thread
7 from threading import Lock
19 __confs_unmeasured__ = []
22 """Prepare for measuring
23 Outcome is Linux image for generated configuration."""
24 print("Preparing new image.")
25 global __confs_unmeasured__
26 if len(__confs_unmeasured__) == 0:
27 dtb = database.database()
28 confs = dtb.get_unmeasured()
30 configurations.generate()
31 confs = dtb.get_unmeasured()
33 raise exceptions.NoApplicableConfiguration()
34 __confs_unmeasured__ = list(confs)
35 con = __confs_unmeasured__.pop()
36 kernel.config(con.config)
37 img = kernel.make(con.hash)
38 print("Prepared image: " + img)
41 def measure(kernelimg, con):
42 print("Measuring " + con.hash)
44 os.remove(sf(conf.jobfolder_linux_image))
45 except FileNotFoundError:
47 os.symlink(kernelimg, sf(conf.jobfolder_linux_image))
49 print("Configuration '" + con.hash + "' measured.")
55 class prepareThread(Thread):
56 def __init__(self, name='prepare'):
57 Thread.__init__(self, name=name)
59 __listlock__.acquire()
60 while not __terminate__ and len(__conflist__) <= conf.multithread_buffer:
61 __listlock__.release()
63 img, config = prepare()
64 except exceptions.NoApplicableConfiguration:
66 __listlock__.acquire()
67 __conflist__.add((img, config))
68 if not __measurethread__.isActive():
69 __measurethread__.start()
70 __listlock__.release()
72 class measureThread(Thread):
73 def __init__(self, name='measure'):
74 Thread.__init__(self, name=name)
76 __listlock__.acquire()
77 while not __terminate__ and len(__conflist__) > 0:
78 img, config = __conflist__.pop()
79 __listlock__.release()
80 if not __preparethread__.isActive():
81 __preparethread__.start()
83 __listlock__.acquire()
84 __listlock__.release()
86 __preparethread__ = prepareThread()
87 __measurethread__ = measureThread()
89 # Start and sigterm handler #
91 def sigterm_handler(_signo, _stack_frame):
95 # Main loop and single thread #
100 __preparethread__.start()
101 __measurethread__.start()
104 img, config = prepare()
107 while not __terminate__:
108 img, config = prepare()
111 #################################################################################
113 if __name__ == '__main__':
114 signal.signal(signal.SIGTERM, sigterm_handler)
115 signal.signal(signal.SIGINT, sigterm_handler)