Opened 15 years ago

Last modified 7 years ago

#201 new enhancement

fflush() should be cheap if output buffer is empty

Reported by: Jiri Svoboda Owned by:
Priority: major Milestone:
Component: helenos/unspecified Version: mainline
Keywords: Cc:
Blocker for: Depends on:
See also:

Description

Currently a non-standard synchronization scheme is used for the console. The console/fb drivers assume that they can delay screen update until an explicit sync operation. This sync operation is achieved via fsync(). fflush() calls fsync() every time.

In POSIX fflush() only writes out (flushes) the output buffer (if it is non-empty). But it does not sync the file descriptor, fsync() is a stronger operation. Terminal output in POSIX is updated immediately when data is written to the file descriptor.

The big problem in HelenOS is that fflush() is expensive (does fsync(), which results in IPC) even when there is no data in the output buffer. This contributes to the slowness of operations such as fgetc() which try to flush output streams (and currently do it always, not just when we are reading from stdin).

Another question is, whether it would be better to make the console behavior more standard, so that an fsync() is not necessary.

Change History (7)

comment:1 by Jiri Svoboda, 15 years ago

See also #200 and #202.

comment:2 by Jiri Svoboda, 15 years ago

I have alleviated the problem. FILE structures now have a boolean field need_sync. It is set when data is written to the file descriptor and cleared when the fd is synced. fflush() only syncs the fd if need_sync is set.

This makes the fflush() operation cheap when no data has been written. However, I still think we rather need to re-define console behavior and not to require a sync to propagate data. Therefore I am not considering this ticked resolved yet.

comment:3 by Jakub Jermář, 14 years ago

Milestone: 0.4.30.5.0

comment:4 by Jakub Jermář, 14 years ago

Type: defectenhancement

comment:5 by Jakub Jermář, 13 years ago

Milestone: 0.5.00.5.1

comment:6 by Jakub Jermář, 10 years ago

Milestone: 0.5.10.7.1

comment:7 by Jakub Jermář, 7 years ago

Milestone: 0.7.1
Note: See TracTickets for help on using tickets.