Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does it make sense to run OS kernel-level computations on a GPU?

I noticed a GPU can have hundreds of cores so that a parallel computation can be largely sped up with them. It seems that in an OS kernel, no parallel algorithms are used for acceleration.

People do parallel computing in users-pace with OpenMP, but why not in kernel-space? I guess there are lots of tasks inside the OS that require parallel processing, like processing multiple network connections and packets, doing cryptography operations, managing memory, searching?... Some firewalls filter and monitor network flows by matching patterns, research-oriented OSes may also analyze the program before running it, which is time-consuming and might be parallelisable.

So why OSes do not use GPUs to improve their performance and throughput? Does it make sense to run OS computations on GPU?

like image 897
W.Sun Avatar asked Mar 09 '11 06:03

W.Sun


3 Answers

GPU parallel processing applications require you to run the exact same operation hundreds of times. Moreover, you are limited in what operations you can do - branches are generally not an option, nor are traversing pointer chains.

Most kernel operations don't fit into this model; much of what the kernel is doing is managing resources via pointers, including locking. This does not fit into the GPU model at all. As for the other operations you cite:

  • Cryptography: GPUs are great for trying to crack cryptographic ciphers, but that's not the kernel's job. It usually runs a crypto operation once. In this case, the CPU is much faster, since it only needs to do it once.
  • Processing network traffic: Packets arrive at different times, and need to be processed with low latency. The GPU may be able to do stateless firewall processing, but you'd need to batch up packets and have it work on a few hundred at a time for there to be a benefit - this hurts latency and jitter, and so the job is left to the CPU. Moreover, stateful tracking requires shared, locked access to connection tracking tables, something a GPU is not capable of.
  • Managing memory: This is a pointer-heavy operation with lots of locking, and is thus not something a GPU is even remotely well suited for. Moreover, latency is critical, and sending a job to a GPU implies lots of latency.
  • Searching: Modern OS kernels don't search. That's a job for userspace - and again, it's a very pointer heavy job.

GPUs are well suited for mathematical kernels where throughput is paramount and latency is a minor issue - numerical simulations, that sort of thing. They are, in general, not well suited for data management, or where latency is critical - which is exactly the kind of stuff OS kernels do. This is why OSes typically don't make use of GPU acceleration.

There are other types of hardware acceleration that OS kernels can and do make use of - some machines have special cryptographic hardware cores specifically designed for doing one-off crypto computations quickly. These can be put to good use by the kernel, as they are better suited to the specific problems the kernel faces.

like image 148
bdonlan Avatar answered Nov 03 '22 21:11

bdonlan


Your impression that kernels don't parallelize is wrong. Modern kernels have adapted to multi-core/multi-thread CPUs quite well and deal with pretty much everything in a "parallel" way in that respect.

As for the GPUs, they are very different in terms of instructions they can process from CPUs. More adapted to vector floating point computations in particular. The Linux kernel essentially never uses that kind of operation. Exceptions whole be crypto and some raid code that can be well adapted to vector-type ops (and probably others, but still very limited).

So in general, the kernel itself doesn't actually need the kind of operations GPUs provide. For the times it needs them, you'll find modern CPU cores include specific instruction sets (like SSE, AES-NI, and such) or dedicated co-processors/offload engines (again for crypto and raid calcs, network packet checkums, etc...).

like image 38
Mat Avatar answered Nov 03 '22 21:11

Mat


Modern GPUs can be used for more than just graphics processing; they can run general-purpose programs as well. While not well-suited to all types of programs, they excel on code that can make use of their high degree of parallelism. Most uses of so-called ``General Purpose GPU'' (GPGPU) computation have been outside the realm of systems software. However, recent work on software routers and encrypted network connections has given examples of how GPGPUs can be applied to tasks more traditionally within the realm of operating systems. These uses are only scratching the surface. Other examples of system-level tasks that can take advantage of GPUs include general cryptography, pattern matching, program analysis, and acceleration of basic commonly-used algorithms.

Cited from https://code.google.com/p/kgpu/

like image 1
Ale Avatar answered Nov 03 '22 20:11

Ale