4

I have a program running two threads - they communicate using message queues.

In one thread, I call ioctl() to access the hardware decryptor. The code goes like:

void Decrypt
{

...
..
...

if(<condition 1>)
{.
...
...
retVal = ioctl(...);
comesInHere1++;
}

if(<condition 2>)
{
...
...
retVal = ioctl(...);
comesInHere2++;
}

comesInHere1 and comesInHere2 are used to count the number of times it goes in that particular if loop.

The entire program takes 80 ms to execute. But if I comment out the test variables (comesInHere1, comesInHere2 within the if loops), the execution time increases by 8 ms to 88 ms!

How is that possible? I cant comment out the variables now since it increases the time taken, cant keep them either - will get killed in code review :)

Kindly let me know

Thanks

sje397
  • 41,293
  • 8
  • 87
  • 103
James
  • 71
  • 1
  • 3
  • How many test runs have you done? It might be an observational error. If not, you have to look at assembler code generated by the compiler to figure out what is wrong. In any case, post-increment is not needed here, use pre-increment to avoid copying. –  Sep 20 '10 at 12:18
  • I had run it around 20 times to make sure the observation is correct. Does the "delay" added in excuting an extra line of code help the ioctl call somehow? Doesnt sound logical ... but the timing measurement is puzzling – James Sep 20 '10 at 12:35
  • btw i am using a hardware registry read call to calculate time. I tried making the variable as volatile - still no luck – James Sep 20 '10 at 12:52
  • Are you compiling with optimization? I guess you aren't ... turn it on and measure again. – pmg Sep 20 '10 at 13:16
  • I tried with O2 and O3 - no luck, takes more time – James Sep 20 '10 at 13:25
  • FYI, a (maybe) related post: http://stackoverflow.com/questions/2735245/compiler-optimization-causing-the-performance-to-slow-down – pmg Sep 20 '10 at 13:55

1 Answers1

1

Cache? It's possible that by adding a bit more data you're moving code to different cache lines that would somehow be placed together, causing thrashing. You could experiment by running on different systems and by adding padding data between variables that are used exclusively in each thread.

What happens if you serialize the processing onto a single core?

Paul Rubel
  • 26,632
  • 7
  • 60
  • 80