MessageData Timer and cpu usage



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/11/2010 at 18:00, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   12 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hey all,

    A user reported a rather disturbing problem.  With my plugin loaded one of the processor cores is constantly showing usage in excess of 50% with consistent spiking up to 100%.  I've traced the cause back to a timer in a MessageData class that ticks by at a rate equal to the document fps.

    The real problem is this:  The problem is strictly on windows.  Not "it's worse on windows", I mean ONLY ON WINDOWS.  On mac, the processor cores aren't even phased by this timer (or any of the code that's called as a result of the message ticking by).  With my plugin loaded the processor is 98% idle.  Without my plugin loaded the processor is 98% idle.  Not even a nick in processor usage on any particular core.

    I'm pretty sure the user is running Win7 64bit (what flavor I don't know).  I'm running Win7 64bit Home Premium.  Mine is bootcamped on a Mac Pro... I doubt the user's is the same setup; probably your standard mix n' match pc build.  I won't name him, but judging by his forum posts over the years I doubt he's running a pre-built POS Dell or anything like that.

    So, how do I even approach fixing a problem like this?

    Here's my entire MessageData class (in main.cpp) :

    class Con4DMessage : public MessageData
    {
    	
    		virtual LONG GetTimer(void)
    		{	
    			BaseDocument *doc = GetActiveDocument();
    			if (!doc) return 50;
    			LONG currentframe = doc->GetFps();
    			LONG framerate = 1000/currentframe;
    		
    			return framerate;
    		}
    	
    		virtual Bool CoreMessage(LONG id, const BaseContainer &bc)
    		{
    		
    			if (id == MSG_TIMER)
    			{
    				BaseDocument *doc = GetActiveDocument();
    	
    				BaseSceneHook *sh = doc->FindSceneHook(ID_CON4D_HOOK);
    				if (!sh) return FALSE;
    				sh->Message(ID_CON4DHOOK_MESSAGE);
    			}
    		
    			return TRUE;
    		}
    	
    };
      
    Bool RegisterCon4DMessage(void)
    {
    		return RegisterMessagePlugin(ID_CON4DHOOK_MESSAGE_DATA, String(), 0, gNew Con4DMessage);
    }
    

    The message gets passed to a scenehook btw.

    thanks,
    kvb



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/11/2010 at 07:35, xxxxxxxx wrote:

    I can confirm this. It seems it has to do with the length of the timer intervals. If you return 40ms or higher for instance Cinema runs idle again. Going under 40ms and one CPU core is busy. Strange stuff.

    I will report it to the developers.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/11/2010 at 08:39, xxxxxxxx wrote:

    Thanks Matthias:)  I see you edited your post and put everything in ms for clarification, thanks, makes my post much easier to write:D

    So I guess a fix would only occur for R12+.  Looks like I'll need to tell my pre R12 windows customers to run their animation sessions at <25fps for the time being if they don't want c4d to run wild with one of their cores while I formulate a way to tie the timer to the on/off device switch.

    thanks again,
    kvb



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 26/11/2010 at 04:14, xxxxxxxx wrote:

    Not so good news. It looks like it's an issue with the Windows timer. It simply is not as precise as the OS X timer and runs quickly into endless loops. On OS X you can go down to 1ms. I am afraid there is not much we can do about it.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 26/11/2010 at 05:41, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Not so good news. It looks like it's an issue with the Windows timer. It simply is not as precise as the OS X timer and runs quickly into endless loops. On OS X you can go down to 1ms. I am afraid there is not much we can do about it.cheers,Matthias

    To add a few infos:
    - The Windows time function has a precision of only 5 ms (or more; depending on cpu, kernel drivers, etc.). E.g. if you would use a 20 ms timer, the error would be +/- 25% (or greater). For timer intervals < 40 ms we therefore have to use a "precise mode" which creates this high cpu usage.

    - OS X has high precision timers with low overhead (which is one of the reasons why the Mac is used often for audio stuff).

    Best regards,

    Wilfried Behne



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 26/11/2010 at 06:31, xxxxxxxx wrote:

    There is a lot of example code on the web which uses QueryPerformanceCounter. It seems to be good for determining frame times in games. Couln't you use this as well?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 26/11/2010 at 10:01, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    There is a lot of example code on the web which uses QueryPerformanceCounter. It seems to be good for determining frame times in games. Couln't you use this as well?

    Looking here: http://www.virtualdub.org/blog/pivot/entry.php?id=106

    might give you an idea which pitfalls to expect when using QueryPerformanceCounter. You might use this in your plugin as an (hardware dependend) option, but don't expect it as a reliable replacement on all Windows systems.

    Also have a look at this place: http://msdn.microsoft.com/en-us/library/ms644904(VS.85).aspx

    where MS states: "On a multiprocessor computer, it should not matter which processor is called. However, you can get different results on different processors due to bugs in the basic input/output system (BIOS) or the hardware abstraction layer (HAL)."

    Best regards,

    Wilfried Behne



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 27/11/2010 at 02:18, xxxxxxxx wrote:

    Cool. Thanks for the links. QPC doesn't seem to be so good after all. I wont use it anyway. Was just curious.


Log in to reply