views:

247

answers:

6

Hi!

I'm working on a little rigidbody simulation. I use the Irrlicht engine for display and openMesh to work with the meshes.

Now I profiled my app using VerySleepy and noticed that most of the time is spent within the following functions (exclusive the time spent in subfunctions):

RtlCompareMemoryUlong 30% within module "ntdll" sourcefile "unknown"

KiFastSystemCallRet 21% within module "ntdll" sourcefile "unknown"

RtlFillMemoryUlong 9% within module "ntdll" sourcefile "unknown"

so 50% of the time is spent in those functions and I don't call them from somewhere in my code and i don't understand what they are doing. I doubt it's connected to the graphics, since i'm only displaying very simple meshes.

Can someone give me a hint on how to figure out why those functions are called and how to get rid of that?

Thanks!

+5  A: 

ntdll is the NT kernel functions. Chances are those are called internal to other functions to do low level operations, hence why you're seeing a lot of time spent in them - they're the sub-building-blocks of higher level functionality. Ignore them and look elsewhere (up the callstack) for performance tweaking; you're not likely to be able to get rid of the OS calls from your application. ;)

Amber
+4  A: 

The performance problem is probably that these functions are being called a lot, not in these functions themselves. You can guess from the names what they're used for. KiFastSystemCallRet in particular indicates your app went into Kernel mode.

Ignore the ntdll functions in your profile, and focus only on the functions that you wrote/control.

Terry Mahaffey
but why is my app going intno Kernel mode anyway? i think context switches are expensive so i should avoid them, no? my app is singlethreaded
genesys
A kernel transition is not a context switch - a context switch is when your thread's quantum expires, or the thread yields. You should try to minimize both; but to do system level things like drawing, or anything to do with the hardware, it's unavoidable.
Terry Mahaffey
Your app goes into kernel mode because you called a function that requires it. So as this answer says, ignore ntdll itself, and focus on your own functions. For some reason, they find it necessary to call system functions that involve a switch to kernel mode. You can't optimize the kernel, but you *can* optimize how often you call these system functions.
jalf
+3  A: 

Use a better profiler. On OS X, the CPU Instruments app that comes with Xcode gives excellent diagnostic information that makes spotting performance problems easy.

What you want to see is the callstack during all this time. That will show you which library and function is calling that OS function all the time. Once you know that, it's simply a matter of calling into that library function less often.

Frank Krueger
can you suggest a better, free profiler?
genesys
A: 

Frank Krueger is right. You need insight into the call stack as your program runs. Here's a simple explanation of why that is so. It may surprise you that you do not need special tools or a large number of samples.

Mike Dunlavey
+1  A: 

RtlCompareMemory / RtlFillMemory sound like they're probably the underlying implementations for memcmp() / memset().

Regardless, you want to change the settings of your profiler to show system call time under the calling app / library function so you can see where the calls are ultimately coming from.

Andrew Medico
A: 

You should take it as more of a symptom than part of the actual problem when you are stuck in system all the time.

Memory fragmentation and paging out is the usual suspect, but it could be a myriad of things.

In my experience performance problems are seldom something obvious like you are calling something specifically. Optimizing like commonly suggested is usually useless at a really low level. It catches things that amount to bugs that are correct but usually unintended like allocating something and deleting it over and over but for things like this you often need to have a deep understanding of everything happening to figure out exactly where the issue is (but like I said, surprisingly often it's memory management related if you are stuck in system calls a lot).

Charles Eli Cheese