summary in July <test Nahanni Interrupt>

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");
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值