[PATCH] Filesystem: Remove per file descriptor semaphore

sebastian.huber at embedded-brains.de sebastian.huber at embedded-brains.de
Thu Apr 26 14:14:00 UTC 2012


From: Sebastian Huber <sebastian.huber at embedded-brains.de>

The per file descriptor semaphore (field of rtems_libio_t) is unused in
RTEMS.  There is a considerable memory overhead due to that.  A
semaphore needs roughly 124 bytes which is huge compared to the
approximately 72 bytes for the file descriptor structure itself.  Device
drivers can create their own synchronization primitives in the open
handler on demand.
---
 cpukit/libcsupport/include/rtems/libio.h |    1 -
 cpukit/libcsupport/src/libio.c           |   28 ++++------------------------
 cpukit/sapi/include/confdefs.h           |    6 ++----
 testsuites/sptests/spfatal14/Makefile.am |    1 -
 testsuites/sptests/spfatal14/testcase.h  |    3 +--
 testsuites/sptests/spfatal15/Makefile.am |    1 -
 testsuites/sptests/spfatal15/testcase.h  |    3 +--
 testsuites/sptests/spfatal16/testcase.h  |    4 +++-
 testsuites/sptests/spfatal17/Makefile.am |    2 +-
 testsuites/sptests/spfatal18/Makefile.am |    2 +-
 testsuites/sptests/spfatal19/Makefile.am |    2 +-
 testsuites/sptests/spfatal20/testcase.h  |    4 ----
 testsuites/sptests/spfifo02/init.c       |    4 ----
 13 files changed, 14 insertions(+), 47 deletions(-)

diff --git a/cpukit/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h
index f1908f7..04ca52c 100644
--- a/cpukit/libcsupport/include/rtems/libio.h
+++ b/cpukit/libcsupport/include/rtems/libio.h
@@ -1165,7 +1165,6 @@ struct rtems_libio_tt {
   off_t                                   offset;    /* current offset into file */
   uint32_t                                flags;
   rtems_filesystem_location_info_t        pathinfo;
-  rtems_id                                sem;
   uint32_t                                data0;     /* private to "driver" */
   void                                   *data1;     /* ... */
 };
diff --git a/cpukit/libcsupport/src/libio.c b/cpukit/libcsupport/src/libio.c
index 985ad8b..e75b66b 100644
--- a/cpukit/libcsupport/src/libio.c
+++ b/cpukit/libcsupport/src/libio.c
@@ -131,36 +131,19 @@ int rtems_libio_to_fcntl_flags( uint32_t flags )
 
 rtems_libio_t *rtems_libio_allocate( void )
 {
-  rtems_libio_t *iop, *next;
-  rtems_status_code rc;
-  rtems_id sema;
+  rtems_libio_t *iop = NULL;
 
   rtems_libio_lock();
 
   if (rtems_libio_iop_freelist) {
-    rc = rtems_semaphore_create(
-      RTEMS_LIBIO_IOP_SEM(rtems_libio_iop_freelist - rtems_libio_iops),
-      1,
-      RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
-      0,
-      &sema
-    );
-    if (rc != RTEMS_SUCCESSFUL)
-      goto failed;
     iop = rtems_libio_iop_freelist;
-    next = iop->data1;
-    (void) memset( iop, 0, sizeof(rtems_libio_t) );
+    rtems_libio_iop_freelist = iop->data1;
+    memset( iop, 0, sizeof(*iop) );
     iop->flags = LIBIO_FLAGS_OPEN;
-    iop->sem = sema;
-    rtems_libio_iop_freelist = next;
-    goto done;
   }
 
-failed:
-  iop = 0;
-
-done:
   rtems_libio_unlock();
+
   return iop;
 }
 
@@ -179,9 +162,6 @@ void rtems_libio_free(
 
   rtems_libio_lock();
 
-    if (iop->sem)
-      rtems_semaphore_delete(iop->sem);
-
     iop->flags &= ~LIBIO_FLAGS_OPEN;
     iop->data1 = rtems_libio_iop_freelist;
     rtems_libio_iop_freelist = iop;
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index d896c59..3e4cb90 100644
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -119,11 +119,9 @@ rtems_fs_init_functions_t    rtems_fs_init_helper =
 #endif
 
 /**
- *  From the number of file descriptors, we can determine how many
- *  semaphores the implementation will require.
+ *  Semaphore count used by the IO library.
  */
-#define CONFIGURE_LIBIO_SEMAPHORES \
-  (CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS + 1)
+#define CONFIGURE_LIBIO_SEMAPHORES 1
 
 #ifdef CONFIGURE_INIT
   /**
diff --git a/testsuites/sptests/spfatal14/Makefile.am b/testsuites/sptests/spfatal14/Makefile.am
index 7f72c19..b8dad5f 100644
--- a/testsuites/sptests/spfatal14/Makefile.am
+++ b/testsuites/sptests/spfatal14/Makefile.am
@@ -16,7 +16,6 @@ include $(top_srcdir)/../automake/compile.am
 include $(top_srcdir)/../automake/leaf.am
 
 AM_CPPFLAGS += -I$(top_srcdir)/../support/include
-AM_CPPFLAGS += -DSEMAPHORES_REMAINING=5
 
 LINK_OBJS = $(spfatal14_OBJECTS)
 LINK_LIBS = $(spfatal14_LDLIBS)
diff --git a/testsuites/sptests/spfatal14/testcase.h b/testsuites/sptests/spfatal14/testcase.h
index e9e95b6..a63541b 100644
--- a/testsuites/sptests/spfatal14/testcase.h
+++ b/testsuites/sptests/spfatal14/testcase.h
@@ -17,8 +17,7 @@
 #define FATAL_ERROR_EXPECTED_IS_INTERNAL FALSE
 #define FATAL_ERROR_EXPECTED_ERROR       0x55544431
 
-#define CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS \
-  CONSUME_SEMAPHORE_DRIVERS
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 1
 
 void force_error()
 {
diff --git a/testsuites/sptests/spfatal15/Makefile.am b/testsuites/sptests/spfatal15/Makefile.am
index d5356ad..63006e6 100644
--- a/testsuites/sptests/spfatal15/Makefile.am
+++ b/testsuites/sptests/spfatal15/Makefile.am
@@ -16,7 +16,6 @@ include $(top_srcdir)/../automake/compile.am
 include $(top_srcdir)/../automake/leaf.am
 
 AM_CPPFLAGS += -I$(top_srcdir)/../support/include
-AM_CPPFLAGS += -DSEMAPHORES_REMAINING=6
 
 LINK_OBJS = $(spfatal15_OBJECTS)
 LINK_LIBS = $(spfatal15_LDLIBS)
diff --git a/testsuites/sptests/spfatal15/testcase.h b/testsuites/sptests/spfatal15/testcase.h
index 66ca243..7570e4e 100644
--- a/testsuites/sptests/spfatal15/testcase.h
+++ b/testsuites/sptests/spfatal15/testcase.h
@@ -16,8 +16,7 @@
 #define FATAL_ERROR_EXPECTED_IS_INTERNAL FALSE
 #define FATAL_ERROR_EXPECTED_ERROR       0x55544432
 
-#define CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS \
-  { consume_semaphores_initialize, NULL, NULL, NULL, NULL, NULL }
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 2
 
 void force_error()
 {
diff --git a/testsuites/sptests/spfatal16/testcase.h b/testsuites/sptests/spfatal16/testcase.h
index 6a22838..fed0d4a 100644
--- a/testsuites/sptests/spfatal16/testcase.h
+++ b/testsuites/sptests/spfatal16/testcase.h
@@ -24,5 +24,7 @@
 
 void force_error()
 {
-  /* we will not run this far */
+  /* This fatal error depends on the Termios device configuration */
+  printk( "*** END OF TEST FATAL " FATAL_ERROR_TEST_NAME " ***\n" );
+  rtems_test_exit(0);
 }
diff --git a/testsuites/sptests/spfatal17/Makefile.am b/testsuites/sptests/spfatal17/Makefile.am
index d47e19b..d1d00f7 100644
--- a/testsuites/sptests/spfatal17/Makefile.am
+++ b/testsuites/sptests/spfatal17/Makefile.am
@@ -16,7 +16,7 @@ include $(top_srcdir)/../automake/compile.am
 include $(top_srcdir)/../automake/leaf.am
 
 AM_CPPFLAGS += -I$(top_srcdir)/../support/include
-AM_CPPFLAGS += -DSEMAPHORES_REMAINING=4
+AM_CPPFLAGS += -DSEMAPHORES_REMAINING=3
 
 LINK_OBJS = $(spfatal17_OBJECTS)
 LINK_LIBS = $(spfatal17_LDLIBS)
diff --git a/testsuites/sptests/spfatal18/Makefile.am b/testsuites/sptests/spfatal18/Makefile.am
index 24f8b80..15a095b 100644
--- a/testsuites/sptests/spfatal18/Makefile.am
+++ b/testsuites/sptests/spfatal18/Makefile.am
@@ -16,7 +16,7 @@ include $(top_srcdir)/../automake/compile.am
 include $(top_srcdir)/../automake/leaf.am
 
 AM_CPPFLAGS += -I$(top_srcdir)/../support/include
-AM_CPPFLAGS += -DSEMAPHORES_REMAINING=3
+AM_CPPFLAGS += -DSEMAPHORES_REMAINING=2
 
 LINK_OBJS = $(spfatal18_OBJECTS)
 LINK_LIBS = $(spfatal18_LDLIBS)
diff --git a/testsuites/sptests/spfatal19/Makefile.am b/testsuites/sptests/spfatal19/Makefile.am
index 679b052..9c6b266 100644
--- a/testsuites/sptests/spfatal19/Makefile.am
+++ b/testsuites/sptests/spfatal19/Makefile.am
@@ -16,7 +16,7 @@ include $(top_srcdir)/../automake/compile.am
 include $(top_srcdir)/../automake/leaf.am
 
 AM_CPPFLAGS += -I$(top_srcdir)/../support/include
-AM_CPPFLAGS += -DSEMAPHORES_REMAINING=2
+AM_CPPFLAGS += -DSEMAPHORES_REMAINING=1
 
 LINK_OBJS = $(spfatal19_OBJECTS)
 LINK_LIBS = $(spfatal19_LDLIBS)
diff --git a/testsuites/sptests/spfatal20/testcase.h b/testsuites/sptests/spfatal20/testcase.h
index 566c4bf..08721a0 100644
--- a/testsuites/sptests/spfatal20/testcase.h
+++ b/testsuites/sptests/spfatal20/testcase.h
@@ -9,10 +9,6 @@
  *  $Id$
  */
 
-/* generate fatal errors in termios.c 
- *    rtems_semaphore_create( rtems_build_name ('T', 'R', 'r', c),...);
- */
-
 #define FATAL_ERROR_TEST_NAME            "20"
 #define FATAL_ERROR_DESCRIPTION  \
   "rtems_termios_initialize cannot create semaphore"
diff --git a/testsuites/sptests/spfifo02/init.c b/testsuites/sptests/spfifo02/init.c
index 8526d0c..2725a50 100644
--- a/testsuites/sptests/spfifo02/init.c
+++ b/testsuites/sptests/spfifo02/init.c
@@ -145,11 +145,7 @@ rtems_task Init(
 
   puts( "Creating FIFO" );
   create_fifo();
-  
-  puts( "Opening FIFO.. expect ENFILE (semaphore @ open could not be created)" );
-  open_fifo(ENFILE, O_RDWR);
 
-  delete_semaphore();
   puts( "Opening FIFO.. expect ENOMEM (semaphore for pipe could not be created)" );
   open_fifo(ENOMEM, O_RDWR);
 
-- 
1.6.4.2




More information about the devel mailing list