summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-07-26 10:15:47 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-07-26 11:43:17 +0100
commitd19e435ff9a4716e890d2653af6a1231d8961e37 (patch)
tree3ee41245f3d50a9253e50ed735e4ae3f27b04640 /src/lib/eina
parent24a49c893886d4fa8cd81f727c465f717c3a0629 (diff)
reduce syscalls on opening files - roll CLOEXEC into open
on linux open supports() O_CLOEXEC. add test case for this in meson build and ifdef. this rolls 3 syscalls into 1 as we were doing open, then fnctl to get and fcntl to set flags. less syscalls is a good thing as syscalls are not cheap on some architectures or systems. I've seen a syscall on 1 system take 2-3x as long as another and another syscall in the same 2 system comparison take 10x as long. depending on the syscall you may only have a budget of something like 5000 syscalls "per frame" (60fps) before you spend all of your frame time just in syscalls not doing any processing, so we should keep these down if possible and that is what this does.
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_file.c21
-rw-r--r--src/lib/eina/eina_mmap.c6
2 files changed, 21 insertions, 6 deletions
diff --git a/src/lib/eina/eina_file.c b/src/lib/eina/eina_file.c
index cc53f65..068aa12 100644
--- a/src/lib/eina/eina_file.c
+++ b/src/lib/eina/eina_file.c
@@ -802,19 +802,28 @@ eina_file_open(const char *path, Eina_Bool shared)
802 if (!filename) return NULL; 802 if (!filename) return NULL;
803 803
804 if (shared) 804 if (shared)
805 {
805#ifdef HAVE_SHM_OPEN 806#ifdef HAVE_SHM_OPEN
806 fd = shm_open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO); 807 fd = shm_open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
808 if ((fd != -1) && (!eina_file_close_on_exec(fd, EINA_TRUE)))
809 goto on_error;
807#else 810#else
808 goto on_error; 811 goto on_error;
809#endif 812#endif
813 }
810 else 814 else
811 fd = open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO); 815 {
816#ifdef HAVE_OPEN_CLOEXEC
817 fd = open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO | O_CLOEXEC);
818#else
819 fd = open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
820 if ((fd != -1) && (!eina_file_close_on_exec(fd, EINA_TRUE)))
821 goto on_error;
822#endif
823 }
812 824
813 if (fd < 0) goto on_error; 825 if (fd < 0) goto on_error;
814 826
815 if (!eina_file_close_on_exec(fd, EINA_TRUE))
816 goto on_error;
817
818 if (fstat(fd, &file_stat)) 827 if (fstat(fd, &file_stat))
819 goto on_error; 828 goto on_error;
820 829
diff --git a/src/lib/eina/eina_mmap.c b/src/lib/eina/eina_mmap.c
index 11d8804..23386da 100644
--- a/src/lib/eina/eina_mmap.c
+++ b/src/lib/eina/eina_mmap.c
@@ -198,10 +198,16 @@ eina_mmap_safety_enabled_set(Eina_Bool enabled)
198 /* no zero page device - open it */ 198 /* no zero page device - open it */
199 if (_eina_mmap_zero_fd < 0) 199 if (_eina_mmap_zero_fd < 0)
200 { 200 {
201#ifdef HAVE_OPEN_CLOEXEC
202 _eina_mmap_zero_fd = open("/dev/zero", O_RDWR | O_CLOEXEC);
203 /* if we don;'t have one - fail to set up mmap safety */
204 if (_eina_mmap_zero_fd < 0) return EINA_FALSE;
205#else
201 _eina_mmap_zero_fd = open("/dev/zero", O_RDWR); 206 _eina_mmap_zero_fd = open("/dev/zero", O_RDWR);
202 /* if we don;'t have one - fail to set up mmap safety */ 207 /* if we don;'t have one - fail to set up mmap safety */
203 if (_eina_mmap_zero_fd < 0) return EINA_FALSE; 208 if (_eina_mmap_zero_fd < 0) return EINA_FALSE;
204 eina_file_close_on_exec(_eina_mmap_zero_fd, EINA_TRUE); 209 eina_file_close_on_exec(_eina_mmap_zero_fd, EINA_TRUE);
210#endif
205 } 211 }
206 /* set up signal handler for SIGBUS */ 212 /* set up signal handler for SIGBUS */
207 sa.sa_sigaction = _eina_mmap_safe_sigbus; 213 sa.sa_sigaction = _eina_mmap_safe_sigbus;