Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection-callback branch cpu usage is very high #567

Open
Alvazz opened this issue May 25, 2023 · 5 comments
Open

connection-callback branch cpu usage is very high #567

Alvazz opened this issue May 25, 2023 · 5 comments
Labels
Author does not respond question Information is requested

Comments

@Alvazz
Copy link

Alvazz commented May 25, 2023

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
Copy link
Author

Alvazz commented May 25, 2023

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 mcuee added the question Information is requested label May 27, 2023
@mcuee
Copy link
Member

mcuee commented May 27, 2023

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

@Youw
Copy link
Member

Youw commented May 31, 2023

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
Copy link

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
Copy link
Member

mcuee commented Aug 14, 2023

@Alvazz

Any updates? Thanks.

We will close the issue if there are no responses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author does not respond question Information is requested
Projects
None yet
Development

No branches or pull requests

4 participants