Test interrupt
Get vm id on vm A
xzl@xzl-test-first-vm:~/Nahanni/tests/uio/tests/Interrupts/VM$ sudo ./getident /dev/uio0
[sudo] password for xzl:
ID is 0
exiting
Wait for reading on vm A (read is blocked)
xzl@xzl-test-first-vm:~/Nahanni/tests/uio/tests/Interrupts/VM$ sudo ./uio_read /dev/uio0 10
[UIO] opening file /dev/uio0
[UIO] reading
Send Interrupt on vm B
xzl@xzl-test-second-vm:~/Nahanni/tests/uio/tests/Interrupts/VM$ sudo ./uio_send /dev/uio0 10 SEMA_IRQ 0
[UIO] opening file /dev/uio0
[UIO] count is 10
[UIO] writing 0
[UIO] ping #0
[UIO] ping #1
[UIO] ping #2
[UIO] ping #3
[UIO] ping #4
[UIO] ping #5
[UIO] ping #6
[UIO] ping #7
[UIO] ping #8
[UIO] ping #9
[UIO] Exiting...
Then received the Interrupts on vm A (read is unblocked)
[UIO] buf is 1
[UIO] buf is 2
[UIO] buf is 3
[UIO] buf is 4
[UIO] buf is 5
[UIO] buf is 6
[UIO] buf is 7
[UIO] buf is 8
[UIO] buf is 9
[UIO] buf is 10
[UIO] Exiting...
uio_read.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <openssl/sha.h>
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
#include "ivshmem.h"
int main(int argc, char ** argv){
int i, count, rv, fd , buf;
if (argc != 3) {
printf("USAGE: uio_read <filename> <count>\n");
exit(-1);
}
fd = open(argv[1], O_RDWR);
count = atoi(argv[2]);
printf("[UIO] opening file %s\n", argv[1]);
printf("[UIO] reading\n");
for (i = 0; i < count; i++) {
rv = read(fd, &buf,sizeof(buf));
printf("[UIO] rv is %d buf is %d\n", rv,buf);
}
close(fd);
printf("[UIO] Exiting...\n");
}
uio_send.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <openssl/sha.h>
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
#include "ivshmem.h"
enum ivshmem_registers {
IntrMask = 0,
IntrStatus = 4,
IVPosition = 8,
Doorbell = 12,
IVLiveList = 16
};
int main(int argc, char ** argv){
void * memptr;
unsigned int * map_array;
int i, fd;
int count;
int msg, cmd, dest;
if (argc != 5) {
printf("USAGE: uio_ioctl <filename> <count> <cmd> <dest>\n");
exit(-1);
}
fd=open(argv[1], O_RDWR);
printf("[UIO] opening file %s\n", argv[1]);
count = atol(argv[2]);
cmd = (unsigned short) atoi(argv[3]);
dest = (unsigned short) atoi(argv[4]);
printf("[UIO] count is %d\n", count);
if ((memptr = mmap(NULL, 256, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (void *) -1){
printf("mmap failed (0x%p)\n", memptr);
close (fd);
exit (-1);
}
map_array = (unsigned int *)memptr;
msg = ((dest & 0xffff) << 16) + (cmd & 0xffff);
// msg = cmd;
printf("[UIO] writing %u\n", msg);
for (i = 0; i < count; i++) {
printf("[UIO] ping #%d\n", i);
map_array[Doorbell/sizeof(int)] = msg;
sleep(1);
}
munmap(memptr, 256);
close(fd);
printf("[UIO] Exiting...\n");
}