connection-callback branch cpu usage is very high #567

Closed
opened 2023-05-25 14:20:53 -05:00 by Alvazz · 5 comments
Alvazz commented 2023-05-25 14:20:53 -05:00 (Migrated from github.com)

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);
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 commented 2023-05-25 14:25:44 -05:00 (Migrated from github.com)

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%

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%
mcuee commented 2023-05-26 20:26:28 -05:00 (Migrated from github.com)

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

Please provide more details about the device (eg: output from hidtest) and host PC configuration and OS you are using.
Youw commented 2023-05-31 12:42:41 -05:00 (Migrated from github.com)

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?

> 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_?
d3xMachina commented 2023-06-05 22:58:24 -05:00 (Migrated from github.com)

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.

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.
mcuee commented 2023-08-14 06:30:11 -05:00 (Migrated from github.com)

@Alvazz

Any updates? Thanks.

We will close the issue if there are no responses.

@Alvazz Any updates? Thanks. We will close the issue if there are no responses.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi#567
No description provided.