Threading vs Parallelism ?

classic Classic list List threaded Threaded
43 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: Threading vs Parallelism ?

Brian

The information about using affinity with Linux was only posted so anyone who was interested could use it , and was not intended as an addition to Free Pascal.

Regrading the previous comment about the hardware buffering the data , one still must do something with the data in user space. The choice there is to let the OS / CPU decide which core to use or dedicate a CPU core to the thread. Your choice.

Here is the code and the Linux library you must link to in order to use the functions.

{$LINKLIB libc.so}

...

function sched_getaffinity(pid : Ptruint; cpusetsize : longint; cpuset : pointer) : longint; cdecl; external;

function sched_setaffinity(pid : Ptruint; cpusetsize : longint; cpuset : pointer) : longint; cdecl; external;

function pthread_setaffinity_np(pid : Ptruint; cpusetsize : longint; cpuset : pointer) : longint; cdecl; external;
                                 
function pthread_getaffinity_np(pid : Ptruint; cpusetsize : longint; cpuset : pointer) : longint; cdecl; external;

Brian
Reply | Threaded
Open this post in threaded view
|

Re: Threading vs Parallelism ?

noreply
In reply to this post by Brian
On 2017-05-05 14:27, Brian wrote:
> Affinity
>
> If a thread is dedicated to say , polling a serial or Ethernet port
> which
> has a high input data rate , then dedicating one CPU to that
> task/thread is
> useful.
>

Isn't the speed of serial (so slow) that it would be overkill to
dedicate a Cpu to it?

Maybe usb 2 or 3, or possibly Gigabyte ethernet 1000 speed ;-)

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Threading vs Parallelism ?

Brian
I should have said "streaming" rather than "serial". True Parallelism is a long way off in the future , but a form of parallelism can be had using multiple CPU cores and hard affinity as described in the excellent article.

http://www.ibm.com/developerworks/linux/library/l-affinity/index.html#download

Consider the case of a special purpose custom design PCIe card and Linux. The classical way to interface with the card is to write an interrupt handler and accept the fact that doing so opens all your proprietary code due to the GPL. It also must wrestle with the black magic mess of BIOS PCI IRQ assignment and conflicts with other hardware.

Another approach is to memory map the PCIe card in  user space, use hard affinity and dedicate one CPU core to poll the card memory in user space. In this case the GPL does not apply and the issue of IRQ assignment is not an issue.

Another approach is to abandon the add-in (PCIe) card approach and use gigabit Ethernet with a dedicated CPU core as the I/O. This what was done on the current project.

Brian
123