I've run into some serious performance issues using the hid drivers
from my application with some specific keyboards and I'm hoping
someone can point me in the right direction.
My application is looking for consumer page button presses on
keyboards (the extra buttons for Mail, Documents, etc). It works
great on most keyboards (Apple, Logitech, etc). However, on
Microsoft keyboards I take a huge CPU hit (7-10 seconds of 100%
usage) when I open the HID driver for it, and again when I call
IORegistryEntryCreateCFProperties. That's on a 1.25 GHz Mac Mini.
Slightly faster on my dual G5, but not much. I see the hit on both
10.3.9 and 10.4.1.
I'm using the following code (edited for mail) to find devices:
ioResult = IOMasterPort(bootstrap_port, &masterPort);
NSMutableDictionary *dict = (NSMutableDictionary*)
IOServiceMatching(kIOHIDDeviceKey);
notifyPort = IONotificationPortCreate(masterPort);
CFRunLoopSourceRef runLoopSource =
IONotificationPortGetRunLoopSource(notifyPort);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource,
kCFRunLoopDefaultMode);
[dict retain];
ioResult = IOServiceAddMatchingNotification(notifyPort,
kIOFirstMatchNotification, (CFDictionaryRef) dict, DeviceAdded,
self, &deviceAddedIter);
ioResult = IOServiceAddMatchingNotification(notifyPort,
kIOTerminatedNotification, (CFDictionaryRef) dict, DeviceRemoved,
self, &deviceRemovedIter);
// Run the iterators once to arm them
...
mach_port_deallocate(mach_task_self(), masterPort);
This is the code to open a device that I have matched with: I take
a 7-10 second hit in the -> QueryInterface call.
ioResult = IOCreatePlugInInterfaceForService(ioDevice,
kIOHIDDeviceUserClientTypeID, kIOCFPlugInInterfaceID,
&plugInInterface, &score);
plugInResult = (*plugInInterface)->QueryInterface
(plugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
(void *) &deviceInterface);
(*plugInInterface)->Release (plugInInterface);
ioResult = (*deviceInterface)->open(deviceInterface, 0);
And finally, this code gets the properties of the device, which I
use to see what buttons are on the device. I take another 7-10
second hit in IORegistryEntryCreateCFProperties.
ioResult = IORegistryEntryCreateCFProperties(ioDevice,
(CFMutableDictionaryRef*) &properties, kCFAllocatorDefault,
kNilOptions);
As I said, the code only seem to run slow on Microsoft devices. I
don't see the performance hit on other brands of hardware.
Using Shark I see the following
14.3% 14.3% mach_kernel OSDictionary::setObject
(OSSymbol const*, OSMetaClassBase const*)
0.0% 14.2% mach_kernel
OSSerialize::previouslySerialized(OSMetaClassBase const*)
0.0% 14.2% mach_kernel
OSSerialize::previouslySerialized(OSMetaClassBase const*)
0.0% 13.1% mach_kernel OSNumber::serialize
(OSSerialize*) const
0.0% 13.1% mach_kernel OSDictionary::serialize
(OSSerialize*) const
0.0% 13.1% com.apple.iokit.IOHIDFamily
IOHIDElementPrivate::serialize(OSSerialize*) const
0.0% 13.1% mach_kernel OSArray::serialize
(OSSerialize*) const
0.0% 13.1% mach_kernel OSDictionary::serialize
(OSSerialize*) const
0.0% 13.0% com.apple.iokit.IOHIDFamily
IOHIDElementPrivate::serialize(OSSerialize*) const
0.0% 13.0% mach_kernel OSArray::serialize
(OSSerialize*) const
0.0% 13.0% mach_kernel OSDictionary::serialize
(OSSerialize*) const
0.0% 13.0% mach_kernel
IORegistryEntry::serializeProperties(OSSerialize*) const
0.0% 13.0% mach_kernel
is_io_registry_entry_get_properties
0.0% 13.0% mach_kernel iokit_server_routine
0.0% 13.0% mach_kernel ipc_kobject_server
0.0% 13.0% mach_kernel mach_msg_overwrite_trap
0.0% 13.0% mach_kernel shandler
0.0% 0.0% mach_kernel
IORegistryEntry::serializeProperties(OSSerialize*) const
0.0% 0.0% mach_kernel OSArray::serialize(OSSerialize*)
const
0.0% 1.1% mach_kernel OSDictionary::serialize
(OSSerialize*) const
0.0% 0.1% mach_kernel OSNumber::serialize
(OSSerialize*) const
0.0% 0.1% mach_kernel IORegistryEntry::setProperty
(OSSymbol const*, OSObject*)
29.8% 29.8% mach_kernel OSDictionary::getObject
(OSSymbol const*) const
0.0% 15.0% mach_kernel OSSerialize::addXMLStartTag
(OSMetaClassBase const*, char const*)
0.0% 14.6% mach_kernel
OSSerialize::previouslySerialized(OSMetaClassBase const*)
0.0% 0.2% mach_kernel OSMetaClass::getMetaClassWithName
(OSSymbol const*)
It looks like the driver is spending a lot of time building
dictionaries. However, the dictionary size is not terribly
different from what I get for an Apple keyboard (~200K vs ~230K).
Any thoughts?
Thanks,
Dave
---
There's an old proverb that says just about whatever you want it to.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Usb mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/usb/email@hidden
This email sent to email@hidden