vsock is a socket address family for communicating into and out of virtual machines. Addresses have a port and CID. The CID is unique to each virtual machine on the computer. The VM host always has CID 2. http://man7.org/linux/man-pages/man7/vsock.7.html Inside the android guest, the adb daemon hosts a vsock server with VMADDR_CID_ANY, automatically using the guest CID. The adb server can now connect to addresses of the form vsock:cid:port, where the CID must be specified and the port defaults to 5555. This is a significant speed improvement for ADB connections in Cuttlefish, with 150-200 MB/s for `adb push` and 100-150 MB/s for `adb pull`. It also allows removing some proxying steps from Cuttlefish, simplifying the full connection path, and removes a dependency on the unstable ivshmem protocol. Commands tested against a Cuttlefish VM with CID 3: adb connect vsock:3:5555 adb -s vsock:3:5555 shell adb disconnect vsock:3:5555 Supporting "adb disconnect" and "adb -s" required modifying some of the parts that parse addresses / serials. push/pull trials with native adb vsock support in cuttlefish: 100m: 1 file pushed. 297.6 MB/s (104857600 bytes in 0.336s) 100m: 1 file pushed. 270.3 MB/s (104857600 bytes in 0.370s) 100m: 1 file pushed. 271.7 MB/s (104857600 bytes in 0.368s) 100m: 1 file pushed. 250.5 MB/s (104857600 bytes in 0.399s) 100m: 1 file pushed. 277.1 MB/s (104857600 bytes in 0.361s) 100m: 1 file pushed. 263.5 MB/s (104857600 bytes in 0.379s) 100m: 1 file pushed. 242.6 MB/s (104857600 bytes in 0.412s) 100m: 1 file pushed. 271.8 MB/s (104857600 bytes in 0.368s) 100m: 1 file pushed. 267.1 MB/s (104857600 bytes in 0.374s) /data/local/tmp/100m: 1 file pulled. 212.8 MB/s (104857600 bytes in 0.470s) /data/local/tmp/100m: 1 file pulled. 236.7 MB/s (104857600 bytes in 0.423s) /data/local/tmp/100m: 1 file pulled. 201.2 MB/s (104857600 bytes in 0.497s) /data/local/tmp/100m: 1 file pulled. 255.6 MB/s (104857600 bytes in 0.391s) /data/local/tmp/100m: 1 file pulled. 199.6 MB/s (104857600 bytes in 0.501s) /data/local/tmp/100m: 1 file pulled. 214.6 MB/s (104857600 bytes in 0.466s) /data/local/tmp/100m: 1 file pulled. 254.2 MB/s (104857600 bytes in 0.393s) /data/local/tmp/100m: 1 file pulled. 212.5 MB/s (104857600 bytes in 0.471s) /data/local/tmp/100m: 1 file pulled. 218.9 MB/s (104857600 bytes in 0.457s) /data/local/tmp/100m: 1 file pulled. 223.6 MB/s (104857600 bytes in 0.447s) Bug: 121166534 Change-Id: I50f21fb5c9acafb8daa789df4e28c9e1bbbbf2ef Test: adb connect/shell/disconnect
49 lines
1.9 KiB
C
49 lines
1.9 KiB
C
#if __BIONIC__
|
|
#include <linux/vm_sockets.h>
|
|
#else
|
|
/****************************************************************************
|
|
****************************************************************************
|
|
***
|
|
*** This header was automatically generated from a Linux kernel header
|
|
*** of the same name, to make information necessary for userspace to
|
|
*** call into the kernel available to libc. It contains only constants,
|
|
*** structures, and macros generated from the original header, and thus,
|
|
*** contains no copyrightable information.
|
|
***
|
|
*** Copied and modified from bionic/libc/kernel/uapi/linux/vm_sockets.h
|
|
***
|
|
****************************************************************************
|
|
****************************************************************************/
|
|
#ifndef _UAPI_VM_SOCKETS_H
|
|
#define _UAPI_VM_SOCKETS_H
|
|
#include <linux/socket.h>
|
|
#define SO_VM_SOCKETS_BUFFER_SIZE 0
|
|
#define SO_VM_SOCKETS_BUFFER_MIN_SIZE 1
|
|
#define SO_VM_SOCKETS_BUFFER_MAX_SIZE 2
|
|
#define SO_VM_SOCKETS_PEER_HOST_VM_ID 3
|
|
#define SO_VM_SOCKETS_TRUSTED 5
|
|
#define SO_VM_SOCKETS_CONNECT_TIMEOUT 6
|
|
#define SO_VM_SOCKETS_NONBLOCK_TXRX 7
|
|
#define VMADDR_CID_ANY -1U
|
|
#define VMADDR_PORT_ANY -1U
|
|
#define VMADDR_CID_HYPERVISOR 0
|
|
#define VMADDR_CID_RESERVED 1
|
|
#define VMADDR_CID_HOST 2
|
|
#define VM_SOCKETS_INVALID_VERSION -1U
|
|
#define VM_SOCKETS_VERSION_EPOCH(_v) (((_v)&0xFF000000) >> 24)
|
|
#define VM_SOCKETS_VERSION_MAJOR(_v) (((_v)&0x00FF0000) >> 16)
|
|
#define VM_SOCKETS_VERSION_MINOR(_v) (((_v)&0x0000FFFF))
|
|
struct sockaddr_vm {
|
|
__kernel_sa_family_t svm_family;
|
|
unsigned short svm_reserved1;
|
|
unsigned int svm_port;
|
|
unsigned int svm_cid;
|
|
unsigned char svm_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - sizeof(unsigned short) -
|
|
sizeof(unsigned int) - sizeof(unsigned int)];
|
|
};
|
|
#define IOCTL_VM_SOCKETS_GET_LOCAL_CID _IO(7, 0xb9)
|
|
#ifndef AF_VSOCK
|
|
#define AF_VSOCK 40
|
|
#endif
|
|
#endif
|
|
#endif
|