2016-06-14 01:19:17 +02:00
|
|
|
/** VILLASfpga utility for tests and benchmarks
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
|
|
|
* @copyright 2015-2016, Steffen Vogel
|
|
|
|
* This file is part of VILLASnode. All Rights Reserved. Proprietary and confidential.
|
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
|
|
|
**********************************************************************************/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2016-06-15 20:05:09 +02:00
|
|
|
#include <string.h>
|
2016-06-14 01:19:17 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <sched.h>
|
|
|
|
|
|
|
|
#include <villas/log.h>
|
|
|
|
#include <villas/timing.h>
|
|
|
|
#include <villas/utils.h>
|
|
|
|
#include <villas/nodes/vfpga.h>
|
|
|
|
#include <villas/kernel/pci.h>
|
|
|
|
#include <villas/kernel/kernel.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "config-fpga.h"
|
|
|
|
|
2016-06-15 20:05:09 +02:00
|
|
|
/* Declarations */
|
|
|
|
int fpga_bench(struct vfpga *f);
|
|
|
|
int fpga_tests(struct vfpga *f);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
|
|
|
void usage(char *name)
|
|
|
|
{
|
2016-06-15 20:05:09 +02:00
|
|
|
printf("Usage: %s CONFIGFILE CMD [OPTIONS]\n", name);
|
|
|
|
printf(" Commands:\n");
|
|
|
|
printf(" tests Test functionality of VILLASfpga card\n");
|
|
|
|
printf(" bench Do benchmarks\n\n");
|
|
|
|
printf(" Options:\n");
|
|
|
|
printf(" -d Set log level\n\n");
|
|
|
|
|
|
|
|
print_copyright();
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
2016-06-14 01:19:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int ret;
|
2016-06-15 20:05:09 +02:00
|
|
|
struct vfpga *fpga;
|
|
|
|
enum {
|
|
|
|
FPGA_TESTS,
|
|
|
|
FPGA_BENCH
|
|
|
|
} subcommand;
|
|
|
|
config_t config;
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-15 20:05:09 +02:00
|
|
|
if (argc < 3)
|
|
|
|
usage(argv[0]);
|
|
|
|
|
|
|
|
if (strcmp(argv[2], "tests") == 0)
|
|
|
|
subcommand = FPGA_TESTS;
|
|
|
|
else if (strcmp(argv[2], "bench") == 0)
|
|
|
|
subcommand = FPGA_BENCH;
|
|
|
|
else
|
|
|
|
usage(argv[0]);
|
|
|
|
|
|
|
|
/* Setup libconfig */
|
|
|
|
config_init(&config);
|
|
|
|
ret = config_read_file(&config, argv[1]);
|
|
|
|
if (ret != CONFIG_TRUE) {
|
|
|
|
error("Failed to parse configuration: %s in %s:%d",
|
|
|
|
config_error_text(&config),
|
|
|
|
config_error_file(&config) ? config_error_file(&config) : argv[1],
|
|
|
|
config_error_line(&config)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-14 01:19:17 +02:00
|
|
|
/* Parse arguments */
|
|
|
|
char c, *endptr;
|
2016-06-15 20:05:09 +02:00
|
|
|
while ((c = getopt (argc-1, argv+1, "d:")) != -1) {
|
2016-06-14 01:19:17 +02:00
|
|
|
switch (c) {
|
|
|
|
case 'd':
|
|
|
|
log_setlevel(strtoul(optarg, &endptr, 10), ~0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage(argv[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 20:05:09 +02:00
|
|
|
/* Initialize VILLASfpga card */
|
|
|
|
config_setting_t *cfg_root = config_root_setting(&config);
|
|
|
|
ret = vfpga_init(argc, argv, cfg_root);
|
2016-06-14 01:19:17 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to initialize fpga card");
|
2016-06-15 20:05:09 +02:00
|
|
|
|
|
|
|
fpga = vfpga_get();
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-15 20:05:09 +02:00
|
|
|
vfpga_dump(fpga);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
|
|
|
/* Setup scheduler */
|
|
|
|
cpu_set_t set = integer_to_cpuset(AFFINITY);
|
|
|
|
|
|
|
|
ret = sched_setaffinity(0, sizeof(set), &set);
|
|
|
|
if (ret)
|
|
|
|
serror("Failed to pin thread");
|
|
|
|
|
|
|
|
ret = sched_setscheduler(0, SCHED_FIFO, &(struct sched_param) { .sched_priority = PRIORITY });
|
|
|
|
if (ret)
|
|
|
|
serror("Failed to change scheduler");
|
|
|
|
|
2016-06-15 20:05:09 +02:00
|
|
|
for (int i = 0; i < fpga->vd.irqs[VFIO_PCI_MSI_IRQ_INDEX].count; i++) {
|
|
|
|
ret = kernel_irq_setaffinity(fpga->vd.msi_irqs[i], AFFINITY, NULL);
|
2016-06-14 01:19:17 +02:00
|
|
|
if (ret)
|
|
|
|
serror("Failed to change affinity of VFIO-MSI interrupt");
|
|
|
|
}
|
|
|
|
|
2016-06-15 20:05:09 +02:00
|
|
|
/* Start subcommand */
|
|
|
|
switch (subcommand) {
|
|
|
|
case FPGA_TESTS: fpga_tests(fpga); break;
|
|
|
|
case FPGA_BENCH: /*fpga_bench(fpga);*/ break;
|
|
|
|
}
|
2016-06-14 01:19:17 +02:00
|
|
|
|
|
|
|
/* Shutdown */
|
2016-06-15 20:05:09 +02:00
|
|
|
ret = vfpga_deinit(&fpga);
|
2016-06-14 01:19:17 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to de-initialize fpga card");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|