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')
     elif 'gbe_cnt_rst' in control_fields:
         fpga_.registers.control.write(gbe_cnt_rst='pulse')
     else:
         utils.threaded_fpga_function(fpgas, 10, 'disconnect')
         print control_fields
         raise RuntimeError('Could not find GBE debug reset field.')
Пример #2
0
 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')
     elif 'gbe_cnt_rst' in control_fields:
         fpga_.registers.control.write(gbe_cnt_rst='pulse')
     else:
         utils.threaded_fpga_function(fpgas, 10, 'disconnect')
         print control_fields
         raise RuntimeError('Could not find GBE debug reset field.')
Пример #3
0
 def request_debug_deprogram_all(self, sock):
     """
     Deprogram all the f and x roaches
     :param sock:
     :return:
     """
     try:
         from casperfpga import utils as fpgautils
         fhosts = self.instrument.fhosts
         xhosts = self.instrument.xhosts
         fpgautils.threaded_fpga_function(fhosts, 10, 'deprogram')
         fpgautils.threaded_fpga_function(xhosts, 10, 'deprogram')
     except Exception as e:
         return self._log_excep('unknown exception: %s' % e.message)
     return 'ok',
Пример #4
0
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
def exit_gracefully(_, __):
    fpgautils.threaded_fpga_function(fpgas, 10, "disconnect")
    sys.exit(0)
EXPECTED_FREQS = int(config["fengine"]["n_chans"])

# parse the hosts
if args.hosts != "":
    hosts = utils.parse_hosts(args.hosts)
else:
    hosts = utils.parse_hosts(config, section="fengine")
if len(hosts) == 0:
    raise RuntimeError("No good carrying on without hosts.")

required_snaps = ["snappfb_0_ss", "snappfb_1_ss"]

# make the FPGA objects
fpgas = fpgautils.threaded_create_fpgas_from_hosts(HOSTCLASS, hosts)
fpgautils.threaded_fpga_function(fpgas, 15, "get_system_information")
snapshot_missing = []
for fpga_ in fpgas:
    for snap in required_snaps:
        if snap not in fpga_.snapshots.names():
            snapshot_missing.append(fpga_.host)
if len(snapshot_missing) > 0:
    print "The following hosts are missing one or more of the post-pfb snapshots. Bailing."
    print snapshot_missing
    fpgautils.threaded_fpga_function(fpgas, 10, "disconnect")
    raise RuntimeError


def exit_gracefully(_, __):
    fpgautils.threaded_fpga_function(fpgas, 10, "disconnect")
    sys.exit(0)
Пример #7
0
parser.add_argument(
    '--hosts', dest='hosts', type=str, action='store', default='',
    help='comma-delimited list of hosts, or a corr2 config file')
parser.add_argument(
    '--prect', dest='prect', action='store_true', default=False,
    help='turn on or off the pre corner turn TVG')
parser.add_argument(
    '--loglevel', dest='log_level', action='store', default='',
    help='log level to use, default None, options INFO, DEBUG, ERROR')
args = parser.parse_args()

polltime = args.polltime

if args.log_level != '':
    import logging
    log_level = args.log_level.strip()
    try:
        logging.basicConfig(level=eval('logging.%s' % log_level))
    except AttributeError:
        raise RuntimeError('No such log level: %s' % log_level)

# make the fpgas
fpgas = utils.feng_script_get_fpgas(args)

# pre corner turn
fpgautils.threaded_fpga_operation(
    fpgas, 10, lambda fpga_: fpga_.registers.control.write(tvg_ct=args.prect))

fpgautils.threaded_fpga_function(fpgas, 10, 'disconnect')
# end
Пример #8
0
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
Пример #9
0
def signal_handler(sig, frame):
    print sig, frame
    fpgautils.threaded_fpga_function(fpgas, 10, 'disconnect')
    scroll.screen_teardown()
    sys.exit(0)
Пример #10
0
def exit_gracefully(sig, frame):
    print sig, frame
    scroll.screen_teardown()
    utils.threaded_fpga_function(fpgas, 10, 'disconnect')
    sys.exit(0)
Пример #11
0
    def do_for_all_f(self,
                     method,
                     block=None,
                     block_index=None,
                     args=(),
                     kwargs={},
                     timeout=3,
                     dead_count_threshold=3,
                     check_programmed=False):
        """
        Call `method` against all F-Engine instances.
        inputs:
            method (str): Method to call
            block (str or None): What block should the method call -- eg Snap2Fengine.`block`.`method`(...).
                         Use None to indicate that the call is against the Snap2Fengine instance directly
            block_index (int): Use to specify an index if the Snap2Fengine.`block` attribute is a list
            args (tuple): positional arguments to pass to the underlying method
            kwargs (dict): keyword arguments to pass to the underlying method
            timeout (float): Timeout in seconds
            dead_count_threshold (int): Number of failed connection attempts allowed before declaring an F-Engine dead. Set to None to skip error tracking
            check_programmed (bool): Set to True to call against only programmed F-Engines
        returns:
            dictionary of return values from the underlying method. Keys are f-engine hostnames.
            If *any* fengines fail to return before timeout, then this method returns None
        """
        # If all fengs are dead, leave.
        if len(self.fengs) == 0:
            return {}
        # Look for the block we're calling methods against
        # If block is None, we're calling against Snap2Fengine objects. If it's a string,
        # we're calling against some block class
        # TODO: We only check the first instance, and assume the others are the same
        if block is None:
            if not check_programmed:
                instances = self.fengs
            else:
                instances = [
                    feng for feng in self.fengs if feng.is_programmed()
                ]
        else:
            if not hasattr(self.fengs[0], block):
                return None
            if not check_programmed:
                instances = [getattr(f, block) for f in self.fengs]
            else:
                instances = [
                    getattr(f, block) for f in self.fengs if f.is_programmed()
                ]
        # If the instances are themselves lists, demand the user specify a block index
        #TODO just checking the first entry
        if isinstance(instances[0], list):
            if block_index is None:
                self.logger.error(
                    "Instances of block %s are lists, but no block_index was specified!"
                    % block)
                return None
            else:
                temp = [instance[block_index] for instance in instances]
                instances = temp

        # Check that the method is an attribute (may or may not be callable)
        if not hasattr(instances[0], method):
            return None

        rv = {}  # return value dictionary
        # Check if the method is callable. If so, call
        # if not, just get the attribute for all FEngines in a single-threaded manner
        if not callable(getattr(instances[0], method)):
            for instance in instances:
                if isinstance(instance.host, basestring):
                    rv[instance.host] = instance.__getattribute__(method)
                else:
                    rv[instance.host.host] = instance.__getattribute__(method)
        else:
            try:
                x = utils.threaded_fpga_function(instances, timeout,
                                                 (method, args, kwargs))
                for x, val in x.iteritems():
                    if not isinstance(x, basestring):
                        host = x.host
                    else:
                        host = x
                    rv[host] = val
            except RuntimeError:
                return None

        if dead_count_threshold is not None:
            # count dead engines
            for feng in self.fengs:
                if feng.host not in rv.keys():
                    feng.error_count += 1
                else:
                    feng.error_count = 0
                if feng.error_count > dead_count_threshold:
                    self.logger.warning("Declaring %s dead after %d errors" %
                                        (feng.host, feng.error_count))
                    self.declare_feng_dead(feng)
        return rv
Пример #12
0
def exit_gracefully(_, __):
    fpgautils.threaded_fpga_function(fpgas, 10, 'disconnect')
Пример #13
0
        HOSTCLASS = dcp_fpga.DcpFpga

    if 'CORR2INI' in os.environ.keys() and args.hosts == '':
        args.hosts = os.environ['CORR2INI']
    hosts = utils.parse_hosts(args.hosts)
    if len(hosts) == 0:
        raise RuntimeError('No good carrying on without hosts.')
try:
    print 'Connecting...',
    sys.stdout.flush()
    fpgas = fpgautils.threaded_create_fpgas_from_hosts(HOSTCLASS, hosts)
    print 'done.'

    print('Calculating all clocks...'),
    sys.stdout.flush()
    results = fpgautils.threaded_fpga_function(fpgas, 10, 'estimate_fpga_clock')
    print 'done.'

    for fpga_ in fpgas:
        print '%s: %.0f Mhz' % (fpga_.host, results[fpga_.host])

    fpgautils.threaded_fpga_function(fpgas, 10, 'disconnect')

except:
    raise
# except KeyboardInterrupt:
#     exit_clean()
# except:
#     exit_fail()
#
# exit_clean()
Пример #14
0
def exit_gracefully(sig, frame):
    print sig, frame
    scroll.screen_teardown()
    fpgautils.threaded_fpga_function(fpgas, 10, target_function=('disconnect',))
    sys.exit(0)
    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')
        elif 'gbe_cnt_rst' in control_fields:
            fpga_.registers.control.write(gbe_cnt_rst='pulse')
        else:
        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 args.hosts.strip() == '':
    if corr2 is None or 'CORR2INI' not in list(os.environ.keys()):
        raise RuntimeError('No hosts given and no corr2 config found. '
                           'No hosts.')
    fpgas = corr2.utils.script_get_fpgas(args)
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, 15, ('get_system_information', [], {}))

for fpga in fpgas:
    numgbes = len(fpga.gbes)
    if numgbes < 1:
        raise RuntimeWarning('Host %s has no gbe cores', fpga.host)
    print(('%s: found %i gbe core%s: %s' %
           (fpga.host, numgbes, '' if numgbes == 1 else 's',
            list(fpga.gbes.keys()))))

for fpga in fpgas:
    if args.core == 'all':
        cores = fpga.gbes.names()
    else:
        cores = [args.core]
    print((50 * '#'))
Пример #17
0
def exit_gracefully(signal, frame):
    fpgautils.threaded_fpga_function(fpgas, 10, 'disconnect')
    sys.exit(0)
Пример #18
0
        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.'
    print registers_missing
        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*'#')
    print('%s:' % fpga.host)
Пример #20
0
        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 deprogram them
fpgas = fpgautils.threaded_create_fpgas_from_hosts(HOSTCLASS, hosts)
running = fpgautils.threaded_fpga_function(fpgas, 10, 'is_running')
deprogrammed = []
already_deprogrammed = []
for fpga in fpgas:
    if running[fpga.host]:
        fpga.deprogram()
        deprogrammed.append(fpga.host)
    else:
        already_deprogrammed.append(fpga.host)
fpgautils.threaded_fpga_function(fpgas, 10, 'disconnect')
if len(deprogrammed) != 0:
    print deprogrammed, ': deprogrammed okay.'
if len(already_deprogrammed) != 0:
    print already_deprogrammed, ': already deprogrammed.'
# end
Пример #21
0
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)
Пример #22
0
    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 deprogram them
fpgas = fpgautils.threaded_create_fpgas_from_hosts(katcp_fpga.KatcpFpga, hosts)
running = fpgautils.threaded_fpga_function(fpgas, 10, "is_running")
deprogrammed = []
to_deprogram = []
already_deprogrammed = []
for fpga in fpgas:
    if running[fpga.host]:
        deprogrammed.append(fpga.host)
        to_deprogram.append(fpga)
    else:
        already_deprogrammed.append(fpga.host)
running = fpgautils.threaded_fpga_function(to_deprogram, 10, "deprogram")

if len(deprogrammed) != 0:
    print deprogrammed, ": deprogrammed okay."
if len(already_deprogrammed) != 0:
    print already_deprogrammed, ": already deprogrammed."
Пример #23
0
def exit_gracefully(sig, frame):
    print(sig)
    print(frame)
    scroll.screen_teardown()
    fpgautils.threaded_fpga_function(fpgas, 10, 'disconnect')
    sys.exit(0)
Пример #24
0
# logging.basicConfig(filename='/tmp/casperfpga_tengbe_status_curses.log',
#                     level=logging.DEBUG)
# logging.info('****************************************************')

# create the devices and connect to them
if args.hosts.strip() == '':
    if corr2 is None or 'CORR2INI' not in os.environ.keys():
        raise RuntimeError('No hosts given and no corr2 config found. '
                           'No hosts.')
    fpgas = corr2.utils.script_get_fpgas(args)
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, 15, ('get_system_information', [], {}))

for fpga in fpgas:
    numgbes = len(fpga.gbes)
    if numgbes < 1:
        raise RuntimeWarning('Host %s has no gbe cores', fpga.host)
    print('%s: found %i gbe core%s: %s' % (
        fpga.host, numgbes, '' if numgbes == 1 else 's', fpga.gbes.keys()))

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')
        elif 'gbe_cnt_rst' in control_fields:
            fpga_.registers.control.write(gbe_cnt_rst='pulse')