Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on QNX 6.5 Operating system. QNX 6.5 supports POSIX APIs. I am trying to build an application which is used to evaluate performance of hard-disks. My application will read/write/read after write a user defined data buffer of size in kB or MB continuously to the hard-disk from start sector to end sector. The operation performed (read, write, read after write) depends on the user choice. Each time, an operation is performed, application will keep track of the time using ClockCycles() and also calculate the speed of each sector read/write operation.

I am using open() call to open the device file like /dev/hd0. I am using read(), write() APIs to perform read/write operations. My problem is: I am not getting the correct speed of actual disk read/write. Actually the application is returning the speed of data read/write to cache often. The issue is more clear when I am trying to perform an immediate read after write operation. The speed of read operation just after a write operation is very high of the order of 1000-1200 MB/S; whereas a normal read is taking 50-60 MB/S. I am using open flags like O_SYNC and O_RDWR. I have also tried to change the flags to O_DSYNC and O_RSYNC. But I found the flags have no effect in the output of the application. There is no flag equivalent of O_DIRECT like in Linux.

I have also tried to disable cache in hard-disk driver during bootup. Then I got read/write speed accuracy for data sizes of the order of MBs. But even then, when lower data sizes are read after an immediate write, the read speed is again very high. I have also seen some macros like CACHE_FLUSH, CACHE_INVALIDATE for use in drivers which needs DMA transfer. But I don't know how to use these macros in an application. Can anyone please help me how to bypass caching and get the speed of read/write operation to hard-disk? My hard-disk can be either formatted or unformatted. I have tested with both cases.

share|improve this question
Look at similar programs for Linux or the BSDs. If you can't build them directly, they at least should give you and idea of how it's done. – vonbrand Feb 4 '13 at 3:34

HD Cache

Regarding your last paragraph, I believe when you are reading/writing less than 1-2M to the drive, the performance is affected by cache ON THE DRIVE, which commonly range from 2M to 16M in current day HD.

Minimize effect of HD Cache

Let assume that you successfully disabled OS level file system cache. To minimize the effect of HD cache, you should write data at least double of the HD cache.

Assume the HD has 2M cache.

To test with data write of 200kb files. Write 20 of them(individual file), and discard the result of the first 10 files and average the last 10s.

For 200kb read testing, you will need 20 files. The content can be the same, but they have to be individual file. Reading the same small file(<2M) again and again will use the HD cache.

Similar Program

You should check out Bonnie++. You may be able to compile it in QNX.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.