I'm wondering if you have any good advice to me.
I'm writing a program for a Linux-computer which should read data from 12 USB-CAN channels (2x PCAN-USB FDx6).
I'm ready with my code and it works perfect.
BUT,, I have coded using threads in C .
That has resulted in 100% loaded CPU-cores (all six of them.)
Is there a better way to catch data from several can-busses?
Next for me is to test with separate processes. Not sure if it helps.
But I guess somebody out there has got it working.
The Select command sit there and waits for data.Is there a memory queue in the drivers?
Or is it possible to check several channels within on select command? Probably not since it require a handle.
What does Linux-computer mean in your case?
Can you give us some hardware-specs to see if you might some ceiling in terms of whats possible?
Furthermore, which API are you using?
PEAK Basic API 4.4.0 .
Ubuntu 20.04.1 LTS 64-Bit
The computer is an Intel i5. with 6 cores.
8MB of memory. 480GB MM2 drive.
Two PCAN-USB x 6 IPEH-004064.
Is there any input cache in the PCAN-USBx6 Device?
Does the drivers have any cache? or queue?
Thank you for the information.
Yes, the driver does use a queue, those queues are also referenced quite a few times in the PCAN-Linux Driver Documentation:
Most likely you are reading constantly, which of course will drive CPU usage up.
A recommendation here is to use event-driven reading instead of a constant call of read within a loop.
For this you can take a look at the example "pcaneventread" to see how events can be used to initiate a read. You can find this example in.
Code: Select all
Thanks for a quick answer.
I based my code on your program example pcan event read.
Anyways I tested threads. One thread-process for each can-interface.
Every thread would occupy one core to almost 100% cpu.
I don't think select and treads works together well.
Anyways, I have now changed the code using fork() to make 6 extra processes.
All cpu-cores are now resting at 1 - 10%.