source: branches/RWT/soft/validation/scripts/run_simus.py @ 892

Last change on this file since 892 was 843, checked in by devigne, 10 years ago

RWT Commit : Add soft directory.
Soft directory contains scripts used to validate the RWT protocol

  • Property svn:executable set to *
File size: 11.6 KB
Line 
1#!/usr/bin/python
2
3import subprocess
4import os
5import sys
6import shutil
7import random
8
9# User parameters
10use_omp = True
11nb_procs = 4
12protocol = 'dhccp'
13
14nb_max_incr = 50
15nb_max_trans = 100
16nb_ml = 7 # max number of memory lines
17nb_cl = 2 # max number of cache lines
18cache_line_size = 16
19nb_cache_lines = 256
20
21data_dir = 'data'
22test_gen_tool_dir = 'TestGenerator'
23test_gen_binary = 'generate_test'
24
25log_init_name = 'log_init_'
26log_term_name = 'log_term_'
27res_natif = 'res_natif.txt'
28
29all_protocols = [ 'dhccp', 'rwt', 'hmesi', 'wtidl' ]
30
31# Path
32top_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
33config_name = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.py")
34
35scripts_path       = os.path.join(top_path, 'scripts')
36almos_path         = os.path.join(top_path, 'almos')
37soclib_conf_name   = os.path.join(top_path, "soclib.conf")
38topcell_name       = os.path.join(top_path, "top.cpp")
39arch_info_name     = os.path.join(almos_path, "arch-info-gen.info")
40arch_info_bib_name = os.path.join(almos_path, 'arch-info.bib')
41hdd_img_file_name  = os.path.join(almos_path, "hdd-img.bin")
42shrc_file_name     = os.path.join(almos_path, "shrc")
43hard_config_name   = os.path.join(almos_path, "hard_config.h")
44app_path           = os.path.join(scripts_path, 'soft')
45
46app_name = 'gen_test'
47app_source = os.path.join(scripts_path, 'gen_test.c')
48
49# Checks
50if protocol not in all_protocols:
51    help_str = '''
52*** Error: variable protocol has an unsupported value
53'''
54    print help_str
55    sys.exit()
56
57if not os.path.isfile(config_name):
58    help_str = '''
59You should create a file named config.py in this directory with the following definitions:
60 - almos_src_dir: path to almos source directory (for kernel and bootloader binaries)
61 - hdd_img_name:  path to the hdd image to use (will be copied but not modified)
62 - tsar_dir:      path to tsar repository
63Optional definitions (necessary if you want to use alternative protocols):
64 - rwt_dir:       path to the RWT repository
65 - hmesi_dir:     path to HMESI directory
66 - wtidl_dir:     path to the ideal write-through protocol directory
67*** Stopping execution
68'''
69    print help_str
70    sys.exit()
71
72# Loading config
73exec(file(config_name))
74
75# Check that variables and paths exist
76for var in [ 'almos_src_dir', 'hdd_img_name', 'tsar_dir' ]:
77    if eval(var) == "":
78        print "*** Error: variable %s not defined in config file" % (var)
79        sys.exit()
80    if not os.path.exists(eval(var)):
81        print "*** Error: variable %s does not define a valid path" % (var)
82        sys.exit()
83
84if protocol == "rwt":
85    if rwt_dir == "":
86        print "*** Error: variable rwt_dir not defined in config file"
87        sys.exit()
88    if not os.path.exists(rwt_dir):
89        print "*** Error: variable rwt_dir does not define a valid path"
90        sys.exit()
91
92if protocol == "hmesi":
93    if hmesi_dir == "":
94        print "*** Error: variable hmesi_dir not defined in config file"
95        sys.exit()
96    if not os.path.exists(hmesi_dir):
97        print "*** Error: variable hmesi_dir does not define a valid path"
98        sys.exit()
99
100if protocol == "wtidl":
101    if wtidl_dir == "":
102        print "*** Error: variable wtidl_dir not defined in config file"
103        sys.exit()
104    if not os.path.exists(wtidl_dir):
105        print "*** Error: variable wtidl_dir does not define a valid path"
106        sys.exit()
107
108
109random.seed()
110
111
112def get_x_y(nb_procs):
113    x = 1
114    y = 1
115    to_x = True
116    while (x * y * 4 < nb_procs):
117        if to_x:
118            x = x * 2
119        else:
120            y = y * 2
121        to_x = not to_x
122    return x, y
123
124
125def gen_soclib_conf():
126
127    if os.path.isfile(soclib_conf_name):
128        print "Updating file %s" % (soclib_conf_name)
129        # First, remove lines containing "addDescPath"
130        f = open(soclib_conf_name, "r")
131        lines = f.readlines()
132        f.close()
133
134        f = open(soclib_conf_name, "w")
135
136        for line in lines:
137            if not ("addDescPath" in line):
138                f.write(line)
139        f.close()
140    else:
141        print "Creating file %s" % (soclib_conf_name)
142        f = open(soclib_conf_name, "w")
143        f.close()
144
145    # Defining common and specific modules
146    common_modules = [
147            'lib/generic_llsc_global_table',
148            'modules/dspin_router_tsar', 
149            'modules/sdmmc',
150            'modules/vci_block_device_tsar',
151            'modules/vci_ethernet_tsar',
152            'modules/vci_io_bridge',
153            'modules/vci_iox_network',
154            'modules/vci_spi',
155            'platforms/tsar_generic_xbar/tsar_xbar_cluster'
156    ]
157
158    specific_modules = [
159            'communication',
160            'lib/generic_cache_tsar',
161            'modules/vci_cc_vcache_wrapper',
162            'modules/vci_mem_cache',
163    ]
164
165    f = open(soclib_conf_name, "a")
166    # Adding common modules
167    for common_module in common_modules:
168        f.write("config.addDescPath(\"%s/%s\")\n" % (tsar_dir, common_module))
169    #f.write("\n")
170
171    if protocol == "dhccp":
172        arch_dir = tsar_dir
173    elif protocol == "rwt":
174        arch_dir = rwt_dir
175    elif protocol == "hmesi":
176        arch_dir = hmesi_dir
177    elif protocol == "wtidl":
178        arch_dir = wtidl_dir
179    else:
180        assert(False)
181
182    for specific_module in specific_modules:
183        f.write("config.addDescPath(\"%s/%s\")\n" % (arch_dir, specific_module))
184
185    #f.write("\n")
186    f.close()
187
188
189def gen_hard_config(x, y, hard_config):
190   header = '''
191/* Generated from run_simus.py */
192
193#ifndef _HD_CONFIG_H
194#define _HD_CONFIG_H
195
196#define X_SIZE              %(x)d
197#define Y_SIZE              %(y)d
198#define NB_CLUSTERS         %(nb_clus)d
199#define NB_PROCS_MAX        4
200#define NB_TASKS_MAX        8
201
202#define NB_TIM_CHANNELS     32
203#define NB_DMA_CHANNELS     1
204
205#define NB_TTY_CHANNELS     4
206#define NB_IOC_CHANNELS     1
207#define NB_NIC_CHANNELS     0
208#define NB_CMA_CHANNELS     0
209
210#define USE_XICU            1
211#define IOMMU_ACTIVE        0
212
213#define IRQ_PER_PROCESSOR   1
214''' % dict(x = x, y = y, nb_clus = x * y)
215
216   if protocol == 'wtidl':
217       header += '#define WT_IDL\n'
218
219   header += '#endif //_HD_CONFIG_H\n'
220
221   file = open(hard_config, 'w')
222   file.write(header)
223   file.close()
224
225
226
227def gen_arch_info(x, y, arch_info, arch_info_bib):
228   old_path = os.getcwd()
229   print "cd", scripts_path
230   os.chdir(scripts_path)
231   print "./gen_arch_info_large.sh", str(x), str(y), ">", arch_info
232   output = subprocess.Popen([ './gen_arch_info_large.sh', str(x), str(y) ], stdout = subprocess.PIPE).communicate()[0]
233   os.chdir(almos_path)
234   file = open(arch_info, 'w')
235   file.write(output)
236   file.close()
237   print "./info2bib -i", arch_info, "-o", arch_info_bib
238   subprocess.call([ './info2bib', '-i', arch_info, '-o', arch_info_bib ])
239   print "cd", old_path
240   os.chdir(old_path)
241
242
243def gen_sym_links():
244   old_path = os.getcwd()
245   print "cd", almos_path
246   os.chdir(almos_path)
247
248   target = os.path.join(almos_src_dir, 'tools/soclib-bootloader/bootloader-tsar-mipsel.bin')
249   link_name = 'bootloader-tsar-mipsel.bin'
250   if not os.path.isfile(link_name):
251      print "ln -s", target, link_name
252      os.symlink(target, link_name)
253
254   target = os.path.join(almos_src_dir, 'kernel/obj.tsar/almix-tsar-mipsel.bin')
255   link_name = 'kernel-soclib.bin'
256   if not os.path.isfile(link_name):
257      print "ln -s", target, link_name
258      os.symlink(target, link_name)
259
260   target = os.path.join(almos_src_dir, 'tools/bin/info2bib')
261   link_name = 'info2bib'
262   if not os.path.isfile(link_name):
263      print "ln -s", target, link_name
264      os.symlink(target, link_name)
265
266   copied_hdd = 'hdd-img.bin'
267   print "cp", hdd_img_name, copied_hdd
268   shutil.copy(hdd_img_name, copied_hdd)
269
270
271
272
273# Loop of simulation
274
275print "make -C", test_gen_tool_dir
276subprocess.call([ 'make', '-C', test_gen_tool_dir ])
277
278print "cp", os.path.join(test_gen_tool_dir, test_gen_binary), os.path.join(scripts_path, test_gen_binary)
279subprocess.call([ 'cp', os.path.join(test_gen_tool_dir, test_gen_binary), os.path.join(scripts_path, test_gen_binary)])
280
281print "mkdir -p", os.path.join(scripts_path, data_dir)
282subprocess.call([ 'mkdir', '-p', os.path.join(scripts_path, data_dir) ])
283
284gen_sym_links()
285gen_soclib_conf()
286
287while True:
288   x, y = get_x_y(nb_procs)
289   nthreads = min(4, x * y)
290   gen_hard_config(x, y, hard_config_name)
291   gen_arch_info(x, y, arch_info_name, arch_info_bib_name)
292
293   # Generating test
294   print test_gen_binary, nb_procs, nb_max_incr, nb_max_trans, nb_ml, nb_cl, cache_line_size, nb_cache_lines, app_source
295   subprocess.call([ os.path.join(scripts_path, test_gen_binary), str(nb_procs), str(nb_max_incr), str(nb_max_trans), str(nb_ml), str(nb_cl), str(cache_line_size), str(nb_cache_lines), app_source ])
296   
297   print "cd", scripts_path
298   os.chdir(scripts_path)
299
300   # Compiling and executing generated test in native
301   print "make -f Makefile.nat"
302   subprocess.call([ 'make', '-f', 'Makefile.nat' ])
303
304   print "./test_natif >", os.path.join(data_dir, res_natif)
305   output = subprocess.Popen([ './test_natif' ], stdout = subprocess.PIPE).communicate()[0]
306   file = open(os.path.join(data_dir, res_natif), 'w')
307   file.write(output)
308   file.close()
309
310   # Building simulated soft
311   print "cp", app_source, app_path
312   subprocess.call([ 'cp', app_source, app_path ])
313
314   old_path = os.getcwd()
315   print "cd", app_path
316   os.chdir(app_path)
317
318   # Compilation process is different in splash and other apps
319   print "make clean"
320   subprocess.call([ 'make', 'clean' ])
321
322   print "make TARGET=tsar"
323   subprocess.call([ 'make', 'TARGET=tsar' ])
324
325   # Creation/Modification du shrc de almos
326   shrc = "exec -p 0 /bin/gen_test\n"
327   
328   file = open(shrc_file_name, 'w')
329   file.write(shrc)
330   file.close()
331
332   # Copie du binaire et du shrc dans l'image disque
333   print "mcopy -o -i", hdd_img_file_name, shrc_file_name, "::/etc/"
334   subprocess.call([ 'mcopy', '-o', '-i', hdd_img_file_name, shrc_file_name, '::/etc/' ])
335   print "mcopy -o -i", hdd_img_file_name, app_name, "::/bin/"
336   subprocess.call([ 'mcopy', '-o', '-i', hdd_img_file_name, app_name, '::/bin/' ])
337
338   print "cd", old_path
339   os.chdir(old_path)
340
341   # Compiling topcell
342   print "cd", top_path
343   os.chdir(top_path)
344   print "touch", topcell_name
345   subprocess.call([ 'touch', topcell_name ])
346   print "make"
347   retval = subprocess.call([ 'make' ])
348   if retval != 0:
349       sys.exit()
350   
351   # Launching simulation
352   if use_omp:
353      print "./simul.x -THREADS", nthreads, ">", os.path.join(scripts_path, data_dir, log_init_name + str(nb_procs))
354      output = subprocess.Popen([ './simul.x', '-THREADS', str(nthreads) ], stdout = subprocess.PIPE).communicate()[0]
355   else:
356      print "./simul.x >" , os.path.join(scripts_path, data_dir, log_init_name + str(nb_procs))
357      output = subprocess.Popen([ './simul.x' ], stdout = subprocess.PIPE).communicate()[0]
358
359   # Writing simulation results to data directory
360   print "cd", scripts_path
361   os.chdir(scripts_path)
362   filename = os.path.join(data_dir, log_init_name + str(nb_procs))
363   file = open(filename, 'w')
364   file.write(output)
365   file.close()
366
367   term_filename = os.path.join(scripts_path, data_dir, log_term_name + str(nb_procs))
368   print "tail -n +5", os.path.join(top_path, 'term1'), ">", term_filename
369   output = subprocess.Popen([ 'tail', '-n', '+5', os.path.join(top_path, 'term1') ], stdout = subprocess.PIPE).communicate()[0]
370   file = open(term_filename, 'w')
371   file.write(output)
372   file.close()
373   
374   # Quiting if results obtained by simulation are incorrect
375   print "diff", term_filename, os.path.join(data_dir, res_natif)
376   output = subprocess.Popen([ 'diff', term_filename, os.path.join(data_dir, res_natif) ], stdout = subprocess.PIPE).communicate()[0]
377   if output != "":
378      print "*** Difference found, stopping"
379      break;
380   else:
381      print "No diff found, continuing"
382
383
384## Enf of simulations
385
386
387
388
389
390
391
392
393
Note: See TracBrowser for help on using the repository browser.