Check whether userfaultfd is available
2016-05-07 22:15
621 查看
I have been focusing on linux for several years, most time I read articles blogged by others and found they were great helpful. Now it's my turn.
Started from April, I found great interest in qemu/KVM. Qemu is a big project with a sophisticated architecture. A great amount of knowledge to learn. OMG!
Userfaultfd system call is the key component of qemu/KVM postcopy live migration. It requires linux kernel 4.3 or above and userfaultfd feature enabled in kernel configuration. This little app checks whether this feature is available.
Started from April, I found great interest in qemu/KVM. Qemu is a big project with a sophisticated architecture. A great amount of knowledge to learn. OMG!
Userfaultfd system call is the key component of qemu/KVM postcopy live migration. It requires linux kernel 4.3 or above and userfaultfd feature enabled in kernel configuration. This little app checks whether this feature is available.
/* * Check whether USERFAULFD is available. * CPU architecture related preprocessor macros can be found here: * https://sourceforge.net/p/predef/wiki/Architectures/ * * references: * [1] https://www.kernel.org/doc/Documentation/vm/userfaultfd.txt * [2] https://lists.gnu.org/archive/html/qemu-devel/2016-04/msg04137.html * [3] http://xiaogr.com/?p=96 */ #include<stdio.h> #include<sys/ioctl.h> #include<unistd.h> #include<fcntl.h> #include<string.h> #include<errno.h> #if defined(__LP64__) || defined(_LP64) #define __NR_userfaultfd 323 #else #define __NR_userfaultfd 374 #endif #if !defined(__linux__) int check(void){ printf("Must be run in linux!\n"); return -1; } #else /* * where do you locate userfaultfd.h? */ #include"userfaultfd.h" int check(void){ struct uffdio_api userfaultapi; int tmp=syscall(__NR_userfaultfd,O_CLOEXEC); if (tmp<0){ printf("1:Check failed:%s\n",strerror(errno)); return -1; } userfaultapi.api=UFFD_API; userfaultapi.features=0; tmp=ioctl(tmp,UFFDIO_API,&userfaultapi); if (tmp<0){ printf("2:Check failed:%s\n",strerror(errno)); return -1; } printf("Success:ioctls bitmask:%llx\n",userfaultapi.ioctls); return 0; } #endif int main(void){ #if !defined(__i386__) && !defined(__x86_64__) printf("Must be run in i386 or x86_64 arch!\n"); return -1; #endif return(check()); }
相关文章推荐
- Ubuntu配置Open BlockChain
- details标签
- traits简单认识
- failed to create process
- 217. Contains Duplicate
- 在ubuntu更新时,出现错误E: Some index files failed to download, they have been ignored, or old ones used inst
- sleep() 和 wait() 有什么区别?
- Codeforces 635D Factory Repairs (树状数组)
- HDU5029 Relief grain(树链剖分+线段树)
- poj,1273Drainage Ditches
- 1090. Highest Price in Supply Chain (25)
- keychain service钥匙串服务
- HDU 4251-The Famous ICPC Team Again(划分树-区间中位数)
- 理解notify()/notifyall()/interupt()对于线程里面wait方法的影响
- 服务器TIME_WAIT和CLOSE_WAIT详解
- 11周1--2以Point为基类,派生出一个Circle(圆)类,增加数据成员r(半径),以及求面积的成员函数area,实现其他需要的成员函数,设计main函数完成测试;
- 进入BrowsermainRunner::Run处理消息
- windows安装Apache,注册服务出现“(OS 5)拒绝访问。 : AH00369: Failed to open the WinNT service manager..."错误
- 【模拟】HDU1302The Snail
- Too many classes in --main-dex-list