System information

8 Special Implementations
Abbildung 2.2: Schema: Shared-Memory
2.3.5 buer.c
In dieser Datei befinden sich ausschließlich Routinen um mit dem Kommunikationspuer zu
arbeiten, z.B. Pakete in den Puer abzulegen oder abzuholen und die Konsistenz des Puers
sicherzustellen. Dazu stellen wir erst einmal vor, wie dieser Puer strukturiert ist:
struct chn
packet {
unsigned long l e n ;
unsigned long magic ;
char data [ 1 6 0 0 ] ;
} ;
struct c h n
b u f f e r {
unsigned long i n ;
unsigned long out ;
struct ch n
packet packet [CHN BUFFER LENGTH ] ;
} ;
struct chn
sharedmem {
unsigned long s t a t u s ;
unsigned long j i f f i e s [ 2 ] ;
struct c h n
b u f f e r b u f f e r [ 2 ] ;
} ;
Es handelt sich um einen geteilten Speicherbereich auf den beide Kommunikationspartner Zu-
gri haben. Es wird von den Kommunikationspartnern nie an dieselbe Speicheradresse geschrie-
ben, außer in die Variable status des 3-Wege-Handshakes. Dies stellt die Konsistenz sicher und
verhindert Race Conditions. Die eigentlichen Pakete (chn
packet) werden mit einem Magic
DWord versehen um eventuelle Speicherprobleme festzustellen. Die sk
buf Struktur, die uns
vom Kernel
¨
uberreicht wird, wird 1 zu 1 in dem Char-Array gespeichert, dessen L
¨
ange dann im
len Feld der chn
packet Struktur steht. Die Sende- un d Empfangspuer stellen jetzt wiederum
einen FIFO dar, implementiert durch einen Array mit in- und out-Zeigern aus chn
packets dar.
Die Rolle von Send e- und Empfangspuer sind bei den beiden Kommunikationspartnern ein-
fach wechselseitig vertauscht. Da der S chreibend e jedoch nur an das Ende schreibt (und dann
den in-Zeiger hochz
¨
ahlt), und der Lesende nur am Anfang liest (und dann den out-Zeiger
12
Figure 8.7: Layout of the shared SRAM content [3]. The left side represents the lower
addresses. The right side marks the end of the SRAM content.
behavior avoids race conditions while accessing the buffer. The buffer contains standard
Linux network packets: the sk_buf [102, 3]. The sk_buf structure is defined in the file
<linux/skbuff.h> located in the Linux kernel source code. It contains among others a times-
tamp, the device id, the destination id, the sender id, a checksum and the payload of the
network data. There is no data conversion of the network data which is sent from the
host to the CHARM card or vise versa. The CHARM-Host Network bridge operates like a
loopback device which simply copies the data of the TX buffer into the RX buffer.
Network Driver
Two Linux kernel drivers provide access to the CHARM-Host network: one for the host and
one for the CHARM card. Both drivers map the shared SRAM to the kernel space. Thereby,
the driver of the host-side maps the first PCI BAR of the CHARM card to the kernel space.
In contrast, the network driver on the CHARM side gets access to the SRAM with the aid
of the Avalon Bus address window. The layout of the shared SRAM is represented by the
next three C-structures:
struct chn_packet {
unsigned long len;
unsigned long magic;
char data[1600];
};
struct chn_buffer {
unsigned longin;
unsigned longout;
110