hidapi icon indicating copy to clipboard operation
hidapi copied to clipboard

connection-callback branch cpu usage is very high

Open Alvazz opened this issue 2 years ago • 5 comments

pls check it!

if (hid_init())
		return;

	hid_hotplug_register_callback(0x0213, 0xA22C,
				      HID_API_HOTPLUG_EVENT_DEVICE_ARRIVED |
					      HID_API_HOTPLUG_EVENT_DEVICE_LEFT,
				      HID_API_HOTPLUG_ENUMERATE,
				      device_callback, NULL, &token2);

Alvazz avatar May 25 '23 19:05 Alvazz

Let me describe it more clearly, when I don't plug in the device (0x0213, 0xA22C), the CPU usage is not high, but when I plug in the device, the CPU instantly rises to 9%~11%

Alvazz avatar May 25 '23 19:05 Alvazz

Please provide more details about the device (eg: output from hidtest) and host PC configuration and OS you are using.

mcuee avatar May 27 '23 01:05 mcuee

Please provide more details

And the source for your device_callback function.

Can you confirm that you're trying out the https://github.com/libusb/hidapi/tree/connection-callback branch on Windows?

I don't think anything abnormal is happening.

And BTW: what is the CPU usage when you plug your device, when your application isn't running at all?

Youw avatar May 31 '23 17:05 Youw

On my end I only have 0.05% cpu usage when a device gets connected with the connection-callback branch and my application does a number of things at the same time. My config is Windows 11 and a 13600k cpu.

Make sure you keep your code in the callback as concise as possible. You can use a producer-consumer pattern with a FIFO to process those connections/disconnections in another thread.

d3xMachina avatar Jun 06 '23 03:06 d3xMachina

@Alvazz

Any updates? Thanks.

We will close the issue if there are no responses.

mcuee avatar Aug 14 '23 11:08 mcuee