def script_get_fpgas(cmdline_args, host_type=None, fpga_class=CasperFpga, *args, **kwargs): """ Given command line arguments, return CASPER FPGA objects :param cmdline_args: the parsed args object from the script :param host_type: 'fengine', 'xengine', etc :param fpga_class: a specific CasperFpga (sub)class, if required :return: a list of CasperFpga objects """ config, host_details = _script_get_hosts(cmdline_args, host_type) fpgas = [] for val in host_details: fhosts = fpgautils.threaded_create_fpgas_from_hosts(val[1], fpga_class, *args, **kwargs) if hasattr(fhosts[0].transport, 'katcprequest'): gsi_args = [] else: gsi_args = [val[2]] fpgautils.threaded_fpga_function( fpga_list=fhosts, timeout=15, target_function=('get_system_information', gsi_args, {})) fpgas.extend(fhosts) return fpgas
except AttributeError: raise RuntimeError('No such log level: %s' % log_level) if args.comms == 'katcp': HOSTCLASS = katcp_fpga.KatcpFpga else: HOSTCLASS = dcp_fpga.DcpFpga if 'CORR2INI' in os.environ.keys() and args.hosts == '': args.hosts = os.environ['CORR2INI'] hosts = utils.parse_hosts(args.hosts, section='fengine') if len(hosts) == 0: raise RuntimeError('No good carrying on without hosts.') # create the devices and connect to them fpgas = fpgautils.threaded_create_fpgas_from_hosts(HOSTCLASS, hosts) fpgautils.threaded_fpga_function(fpgas, 15, 'get_system_information') registers_missing = [] max_hostname = -1 for fpga_ in fpgas: max_hostname = max(len(fpga_.host), max_hostname) freg_error = False for necreg in ['ct_errcnt', 'ct_cnt', 'wintime_error']: if necreg not in fpga_.registers.names(): freg_error = True continue if freg_error: registers_missing.append(fpga_.host) continue if len(registers_missing) > 0: print 'The following hosts are missing necessary registers. Bailing.'
import logging from casperfpga import utils as casperutils logging.basicConfig(level=logging.INFO) some_skarabs = ['10.99.49.171', '10.99.51.170', '10.99.53.170', '10.99.57.170'] a_fpg = '/home/paulp/bofs/sbram_test_2017-6-14_1312.fpg' program = False fpgas = casperutils.threaded_create_fpgas_from_hosts(some_skarabs) # a func that exists on the fpga object if program: casperutils.threaded_fpga_function( fpgas, timeout=120, target_function=('upload_to_ram_and_program', [a_fpg], {})) else: casperutils.threaded_fpga_function( fpgas, timeout=120, target_function=('get_system_information', [a_fpg], {})) print(50*'%') # another func that exists on the fpga object print(casperutils.threaded_fpga_function( fpgas, timeout=120, target_function=('listdev', [], {}))) print(50*'%') def some_func(fpga, an_arg, a_kwarg): return fpga.host + '_' + str(an_arg) + '_' + str(a_kwarg)
try: logging.basicConfig(level=eval('logging.%s' % log_level)) except AttributeError: raise RuntimeError('No such log level: %s' % log_level) # create the devices and connect to them if corr2 is not None: import os if 'CORR2INI' in os.environ.keys() and args.hosts == '': args.hosts = os.environ['CORR2INI'] hosts = corr2.utils.parse_hosts(args.hosts) else: hosts = args.hosts.strip().replace(' ', '').split(',') if len(hosts) == 0: raise RuntimeError('No good carrying on without hosts.') fpgas = utils.threaded_create_fpgas_from_hosts(hosts) utils.threaded_fpga_function(fpgas, 10, 'test_connection') utils.threaded_fpga_function(fpgas, 15, 'get_system_information') for fpga in fpgas: numgbes = len(fpga.tengbes) if numgbes < 1: raise RuntimeWarning('Host %s has no 10gbe cores', fpga.host) print('%s: found %i 10gbe core%s.' % ( fpga.host, numgbes, '' if numgbes == 1 else 's')) for fpga in fpgas: if args.core == 'all': cores = fpga.tengbes.names() else: cores = [args.core] print(50*'#')
if args.dnsmasq: hosts, lease_filename = utils.hosts_from_dhcp_leases() print 'Found %i roaches in %s.' % (len(hosts), lease_filename) for host in hosts: print '\t', host else: # are we doing it by class? if 'CORR2INI' in os.environ.keys() and args.hosts == '': args.hosts = os.environ['CORR2INI'] if args.hclass != '': if args.hclass == 'fengine': hosts = utils.parse_hosts(args.hosts, section='fengine') elif args.hclass == 'xengine': hosts = utils.parse_hosts(args.hosts, section='xengine') else: raise RuntimeError('No such host class: %s' % args.hclass) else: hosts = utils.parse_hosts(args.hosts) if len(hosts) == 0: raise RuntimeError('No good carrying on without hosts.') # create the devices and program them fpgas = fpgautils.threaded_create_fpgas_from_hosts(katcp_fpga.KatcpFpga, hosts) running = fpgautils.threaded_fpga_function(fpgas, 10, 'is_running') fpgautils.threaded_fpga_function(fpgas, 10, 'upload_to_ram_and_program', args.fpg) fpgautils.threaded_fpga_function(fpgas, 10, 'disconnect') # end
# if args.comms == 'katcp': # HOSTCLASS = katcp_fpga.KatcpFpga # else: # HOSTCLASS = dcp_fpga.DcpFpga if 'CORR2INI' in os.environ.keys() and args.hosts == '': args.hosts = os.environ['CORR2INI'] hosts = utils.parse_hosts(args.hosts, section='xengine') if len(hosts) == 0: raise RuntimeError('No good carrying on without hosts.') #TODO - sort out getting sys info from the config file # create the devices and connect to them fpgas = fpgautils.threaded_create_fpgas_from_hosts(xhost_fpga.FpgaXHost, hosts) fpgautils.threaded_fpga_function(fpgas, 15, 'get_system_information') if args.rstcnt: fpgautils.threaded_fpga_operation(fpgas, 10, lambda fpga_: fpga_.registers.control.write(cnt_rst='pulse')) def get_fpga_data(fpga): vaccstats = fpga.vacc_get_status() _data = {} for _ctr in range(0, 4): _data['err%i' % _ctr] = vaccstats[_ctr]['errors'] _data['cnt%i' % _ctr] = vaccstats[_ctr]['count'] _data['armcnt%i' % _ctr] = vaccstats[_ctr]['armcount'] _data['ldcnt%i' % _ctr] = vaccstats[_ctr]['loadcount']
if args.comms == 'katcp': HOSTCLASS = katcp_fpga.KatcpFpga else: HOSTCLASS = dcp_fpga.DcpFpga # create the devices and connect to them if corr2 is not None: import os if 'CORR2INI' in os.environ.keys() and args.hosts == '': args.hosts = os.environ['CORR2INI'] hosts = corr2.utils.parse_hosts(args.hosts) else: hosts = args.hosts.strip().replace(' ', '').split(',') if len(hosts) == 0: raise RuntimeError('No good carrying on without hosts.') fpgas = utils.threaded_create_fpgas_from_hosts(HOSTCLASS, hosts) utils.threaded_fpga_function(fpgas, 10, 'test_connection') utils.threaded_fpga_function(fpgas, 15, 'get_system_information') for fpga in fpgas: numgbes = len(fpga.tengbes) if numgbes < 1: raise RuntimeWarning('Host %s has no 10gbe cores', fpga.host) print '%s: found %i 10gbe core%s.' % (fpga.host, numgbes, '' if numgbes == 1 else 's') if args.resetctrs: def reset_gbe_debug(fpga_): control_fields = fpga_.registers.control.field_names() if 'gbe_debug_rst' in control_fields: fpga_.registers.control.write(gbe_debug_rst='pulse')
spead_pkts += spead_data['rx_cnt%i' % ctr] data['spd_rx'] = spead_pkts return data def signal_handler(sig, frame): print sig, frame fpgautils.threaded_fpga_function(fpgas, 10, 'disconnect') scroll.screen_teardown() sys.exit(0) import signal signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGHUP, signal_handler) # make the FPGA objects fpgas = fpgautils.threaded_create_fpgas_from_hosts(fhost_fpga.DigitiserDataReceiver, hosts) fpgautils.threaded_fpga_function(fpgas, 15, 'get_system_information') registers_missing = [] max_hostname = -1 for fpga_ in fpgas: max_hostname = max(len(fpga_.host), max_hostname) freg_error = False for necreg in ['reorder_ctrs']: if necreg not in fpga_.registers.names(): freg_error = True continue if freg_error: registers_missing.append(fpga_.host) continue if len(registers_missing) > 0: print 'The following hosts are missing necessary registers. Bailing.'
hosts = utils.parse_hosts(args.hosts) if len(hosts) == 0: raise RuntimeError('No good carrying on without hosts.') if args.listhosts: print(hosts) import sys sys.exit(0) if not (args.disable or args.enable): print('Cowardly refusing to do nothing!') import sys sys.exit(0) # create the devices and enable/disable tx fpgas = fpgautils.threaded_create_fpgas_from_hosts(hosts) fpgautils.threaded_fpga_function(fpgas, 10, 'get_system_information') def enable_disable(endisable): print('%s tx on all hosts' % ('Enabling' if endisable else 'Disabling')) if fpgas[0].registers.names().count('control') > 0: if fpgas[0].registers.control.field_names().count('gbe_out_en') > 0: print('\tProduction control registers found.') fpgautils.threaded_fpga_operation( fpgas, 10, lambda fpga: fpga.registers.control.write( gbe_out_en=endisable)) elif fpgas[0].registers.control.field_names().count('gbe_txen') > 0: print('\tSim-style control registers found.') fpgautils.threaded_fpga_operation(