Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 have an app that communicates with up to 50 devices over serial ports. The communication takes place in threads, and the threads are throttled so that only a certain number are active at once. The threads are created as required, do their work, and terminate and free their used resources.

In some instances the serial ports are implemented with Moxa TCP/IP Ethernet ports. A Moxa driver runs on the PC which exposes the Moxa devices on the network as a COM Port.

In other cases the serial ports are implemented via USB hubs that provide 10 serial ports each.

Here's the problem. When only the Moxa serial ports are used, and (say) 8 are enabled, the CPU usage of the app wavers between 1% and 30%, depending on how many threads are active. The app behaves sensibly and the PC is responsive.

When 8 USB ports are then enabled, the CPU usage of the app peaks at 50-60% as I would expect, but the total PC CPU usage climbs to near 100% and stays there. Not surprisingly everything grinds to a halt.

I used Process Explorer and found that the bulk of the CPU usage outside of my app was in two tasks - System Idle Process/DPCs (Deferred Procedure Calls) and System Idle Process/System. The usage in these tasks peaks at around 40% each. When only Moxa ports are in use, these tasks show no significant CPU usage.

I've tried messing with the thread priority and it makes no difference. The ports run at a relatively low baudrate (2400).

Running a DPC latency checker tool shows up to 6ms latency when the USB serial ports are in use.

share|improve this question
Unfortunately, short of rewriting the drivers for the port interfaces in question or simply reducing your load, I don't really think there's much you can do. Maybe somebody a bit more knowledgeable will have some black magic, though. – Shinrai Dec 6 '11 at 21:33
See… – Moab Dec 7 '11 at 18:42
Thanks. A very thorough posting. LatencyMon needs Win7. I can't seem to get XPERF.exe installed on a Win 7 system (apparently I can then copy the EXE to the XP system and use it). I installed the Windows Performance kit on my Win7 system but XPerf is nowhere to be seen. – rossmcm Dec 7 '11 at 20:36

The high CPU usage stemmed from the fact that in the application each channel opened its serial port at the start of the session and kept it open for the duration of the application session. This was fine with ports based on the Moxa ethernet-to-COM Port adapters, or with "local" ports, but in USB ports, just having the port open causes DPC CPU usage. Having 16 USB ports open makes the PC unusable, despite there being no traffic on any port.

I changed the app so that the ports are opened whenever they are required (which is only for a few seconds every minute or so) and closed immediately afterwards.

share|improve this answer
Well, this falls under my 'reduce your load' scenario. Nicely done. – Shinrai Dec 12 '11 at 18:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .