Download LFC User Guide Version 2.0

Transcript
Chapter 5
LFC Example Application
In this section we will discuss an example application: a simplified version of the standard LFC latency
test program (file test/latency/latency simple.c in the source distribution). The application
performs an LFC latency test using two different ways to receive messages: using polling and using interrupts.
#include <stdio.h>
#include <stdlib.h>
#include <lfc.h>
#define UPCALLS_ALLOWED
static
static
static
static
static
static
1
char *progname;
unsigned nsend = 10000;
volatile unsigned nreceived;
unsigned last_nr_received;
unsigned pktsize;
unsigned msgsize = 16;
static void
usage(void)
{
fprintf(stderr, "Usage: %s <options>\n"
"\t[-nsend <nrsends>]
number roundtrips\n"
"\t[-size <msgsize>]
message size\n", progname);
exit(EXIT_FAILURE);
}
static void
command_line(int argc, char **argv)
{
unsigned i;
progname = argv[0];
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-nsend") == 0) {
if (++i >= argc) usage();
nsend = atoi(argv[i]);
} else if (strcmp(argv[i], "-size") == 0) {
if (++i >= argc) usage();
msgsize = atoi(argv[i]);
} else {
break;
}
}
if (argc - i != 0) usage();
}
Figure 5.1: Example application: argument processing
Figure 5.1 shows the include files needed by the program (in particular lfc.h), global definitions
21