This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix for unbuffered reads causing one roundtrip per byte tounderlying fs


This is a strange one.

I wonder if there is some other factor that normally causes large
unbuffered reads to only require a single roundtrip to the underlying
fs.




Øyvind



Index: ecos/packages/language/c/libc/stdio/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdio/current/ChangeLog,v
retrieving revision 1.24
diff -a -w -u -r1.24 ChangeLog
--- ecos/packages/language/c/libc/stdio/current/ChangeLog	3 Sep 2003 15:37:55 -0000	1.24
+++ ecos/packages/language/c/libc/stdio/current/ChangeLog	27 Feb 2004 09:42:24 -0000
@@ -1,3 +1,9 @@
+2004-02-27  Oyvind Harboe <oyvind.harboe@zylin.com>
+
+	* fixed performance problem with unbuffered reads. Long unbuffered
+	i/o read requests would cause one roundtrip to the underlying file
+	system for each byte, instead of a single trip as intended.
+
 2003-09-03  Thomas Koeller <thomas.koeller@baslerweb.com>
 
 	* cdl/stdio.cdl: only require "/dev/haldiag" if actually using it.
Index: ecos/packages/language/c/libc/stdio/current/src/common/stream.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdio/current/src/common/stream.cxx,v
retrieving revision 1.5
diff -a -w -u -r1.5 stream.cxx
--- ecos/packages/language/c/libc/stdio/current/src/common/stream.cxx	23 May 2002 23:07:18 -0000	1.5
+++ ecos/packages/language/c/libc/stdio/current/src/common/stream.cxx	27 Feb 2004 09:42:24 -0000
@@ -323,6 +323,7 @@
 Cyg_StdioStream::read( cyg_uint8 *user_buffer, cyg_ucount32 buffer_length,
                        cyg_ucount32 *bytes_read )
 {
+    Cyg_ErrNo read_err=ENOERR;
     CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
     
     *bytes_read = 0;
@@ -386,9 +387,22 @@
 
     position += *bytes_read;
     
+
+    // if we are unbuffered, we read as much as we can directly from the 
+    // file system at this point.
+    //
+    // unless we do this, we could end up reading byte-by-byte from the filing system
+    // due to the readbuf_char scheme.
+    if ((*bytes_read<buffer_length) && !flags.buffering) {
+        cyg_uint32 len;
+        len=buffer_length-*bytes_read;
+        read_err = cyg_stdio_read(my_device, user_buffer + *bytes_read, &len);      
+        *bytes_read+=len;
+    }
+    
     unlock_me();
 
-    return ENOERR;
+    return read_err;
 } // read()
 
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]