Next: Data Sharing
Up: System Architecture
Previous: Prefetch Thread
Synchronization
The prefetch thread and the computation thread execute independently
of each other until either of them reaches a synchronization point.
Each of the following cases represents a synchronization point:
- File Open:
The prefetch thread needs to wait until the computation thread
opens the file. The two threads are synchronized by
calling the synchronize function
with an identical synchronization_point argument. The computation thread opens a file
and calls the synchronize function to signal that the
file has been opened. The prefetch thread calls the
synchronize function, and waits until it receives the signal.
Lines C3 and P1 in Figure 2 represent the synchronization points
for the two threads. The synchronize function is
implemented using the pthread_cond_wait and
pthread_cond_signal primitives of the pthread library.
This synchronization is necessary because there may exists a conditional-branch in the original
code as to which data file will be used in the application. Having a synchronization point like
this helps avoid prefetching a wrong file that will never be used in the future.
- User Input:
The prefetch thread needs to wait for the computation thread
if the address generation computation depends on some input
from the user (stdin) or from some user-specified file. Only one of the threads
is allowed to actually perform an I/O operation and hence the other
thread needs to wait. If disk access address generation is dependent
on data from a file that is being prefetched, AASFP puts
synchronization points in both threads. This way, the prefetch
thread can proceed only after the computation thread actually reads in the
data from the file system buffer cache. For terminal input
and input from files that are not prefetched (typically
setup or configuration files), AASFP allows the prefetch thread
to perform the terminal/disk I/O instead and removes those
I/O requests from the computation thread. Thus, the prefetch thread can
still stay ahead of the computation thread. In this case, the
computation thread waits until the prefetch thread completes
its I/O, and then the computation thread resumes execution.
Figure:
Data sharing between the
computation and the prefetch thread. Both
fp and index local variables
need to be shared between the two threads.
|
- Read after Write:
If a program involves only reading from one file and writing
to a different file, or non-overlapping reads/writes on the same
file, then there is no
need for synchronization; otherwise, a synchronization is needed.
Assuming the prefetch thread is running ahead and it detects
a read request that is dependent on some previous write operation,
it then
stops and waits for the computation thread to finish the dependent write operation.
Only after the associated write is done, regardless of whether it is
a synchronous or an asynchronous write,
can the
prefetch thread proceed.
Next: Data Sharing
Up: System Architecture
Previous: Prefetch Thread
chuan-kai yang
2002-04-15