From ac0fb38e2410e35da82308a412d99162f40505ed Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 22 Aug 2023 10:40:06 -0700 Subject: [PATCH 1/2] pre-commit: autoupdate hooks (#518) Update pre-commit hook versions Co-authored-by: adeebshihadeh --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 01148cb6f..986426503 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,11 +5,11 @@ repos: - id: check-ast - id: check-yaml - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.0 + rev: v1.5.1 hooks: - id: mypy - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.284 + rev: v0.0.285 hooks: - id: ruff - repo: local From e7c42fd11cc71f16ac762e6aed3409ce4c644b42 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Wed, 23 Aug 2023 04:08:45 +0800 Subject: [PATCH 2/2] Visionbuf: refactor ion_fd to struct IonFileHandle (#505) --- visionipc/visionbuf_ion.cc | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/visionipc/visionbuf_ion.cc b/visionipc/visionbuf_ion.cc index ed446abfb..f72e76cf7 100644 --- a/visionipc/visionbuf_ion.cc +++ b/visionipc/visionbuf_ion.cc @@ -40,30 +40,35 @@ #define DEVICE_PAGE_SIZE_CL 4096 #define PADDING_CL 0 -static int ion_fd = -1; -static void ion_init() { - if (ion_fd == -1) { - ion_fd = open("/dev/ion", O_RDWR | O_NONBLOCK); +struct IonFileHandle { + IonFileHandle() { + fd = open("/dev/ion", O_RDWR | O_NONBLOCK); + assert(fd >= 0); } + ~IonFileHandle() { + close(fd); + } + int fd = -1; +}; + +int ion_fd() { + static IonFileHandle fh; + return fh.fd; } void VisionBuf::allocate(size_t length) { - int err; - - ion_init(); - struct ion_allocation_data ion_alloc = {0}; ion_alloc.len = length + PADDING_CL + sizeof(uint64_t); ion_alloc.align = 4096; ion_alloc.heap_id_mask = 1 << ION_IOMMU_HEAP_ID; ion_alloc.flags = ION_FLAG_CACHED; - err = HANDLE_EINTR(ioctl(ion_fd, ION_IOC_ALLOC, &ion_alloc)); + int err = HANDLE_EINTR(ioctl(ion_fd(), ION_IOC_ALLOC, &ion_alloc)); assert(err == 0); struct ion_fd_data ion_fd_data = {0}; ion_fd_data.handle = ion_alloc.handle; - err = HANDLE_EINTR(ioctl(ion_fd, ION_IOC_SHARE, &ion_fd_data)); + err = HANDLE_EINTR(ioctl(ion_fd(), ION_IOC_SHARE, &ion_fd_data)); assert(err == 0); void *mmap_addr = mmap(NULL, ion_alloc.len, @@ -85,12 +90,10 @@ void VisionBuf::import(){ int err; assert(this->fd >= 0); - ion_init(); - // Get handle struct ion_fd_data fd_data = {0}; fd_data.fd = this->fd; - err = HANDLE_EINTR(ioctl(ion_fd, ION_IOC_IMPORT, &fd_data)); + err = HANDLE_EINTR(ioctl(ion_fd(), ION_IOC_IMPORT, &fd_data)); assert(err == 0); this->handle = fd_data.handle; @@ -136,7 +139,7 @@ int VisionBuf::sync(int dir) { ION_IOC_INV_CACHES : ION_IOC_CLEAN_CACHES; custom_data.arg = (unsigned long)&flush_data; - return HANDLE_EINTR(ioctl(ion_fd, ION_IOC_CUSTOM, &custom_data)); + return HANDLE_EINTR(ioctl(ion_fd(), ION_IOC_CUSTOM, &custom_data)); } int VisionBuf::free() { @@ -154,5 +157,5 @@ int VisionBuf::free() { if (err != 0) return err; struct ion_handle_data handle_data = {.handle = this->handle}; - return HANDLE_EINTR(ioctl(ion_fd, ION_IOC_FREE, &handle_data)); + return HANDLE_EINTR(ioctl(ion_fd(), ION_IOC_FREE, &handle_data)); }