レナート   TBFKAYIBYNYAAYB   ﻟﻴﻨﺎﺭﺕ

Fri, 18 Apr 2008

Finally, Secure Real-Time on the Desktop

Finally, secure real-time scheduling on the Linux desktop can be become a reality. Linux 2.6.25 gained Real-Time Group Scheduling, a feature which allows to limit the amount of CPU time real-time processes and threads may consume.

Traditionally on Linux real-time scheduling was limited to priviliged processes, because RT processes can lock up the machine if they enter a busy loop. Scheduling is effectively disabled for them -- they can do whatever they want and are (almost) never preempted by the kernel in what they are doing. In 2.6.12 RLIMIT_RTPRIO was introduced. It's a resource limit which opened up real-time scheduling for normal user processes. However the ability to lock up the machine for RT processes was not touched by this. When using /usr/security/limits.conf to raise this limit for specific users they'd gain the ability to lock up your machine.

Due to this raising this limit is a task that is left to the administrator on all current distros. Shipping a distro with the limit raised by default is shipping a distro where local users can easily freeze their machines.

It was always possible to write "watchdog" tools that could supervise RT processes by running on a higher RT priority and checking the CPU load imposed by the process on the system. However, to this point it was not possible in any way that would actually be secure (so that processes cannot escape the watchdog by forking), that wouldn't require lots of work in the watchdog (which is a bad idea since it runs at a very high RT priority, thus while it doing its stuff it will block the important RT processes from running), or that wouldn't be totally ugly.

Real-Time Group Scheduling solves the problem. It is now possible to create a cgroup for the processes to supervise. The processes cannot escape the cgroup by forking. Then, by manipulating the cpu.rt_runtime_us property of the cgroup a certain amount of RT CPU time can be assigned to the cgroup -- processes in the group cannot spend more time than this limit per one period of time. (The period length can be controlled globally via /proc/sys/kernel/sched_rt_period_us).

To demonstrate this I wrote a tool rtwatch which implements this technique in a watchdog tool that is SUID root, creates a cgroup, and forks off a user defined process inside, it with raised RLIMIT_PTPRIO but normal user priviliges. The child process can then acquire RT scheduling but never consume more CPU than allowed by the cgroup, with no option to lock up the machine anymore.

How to use this?

$ rtwatch 5 rtcpuhogger

This will start the process rtcpuhogger and grant it 5% of the available CPU time. To make sure that this is not misused by the user rtwatch will refuse to assign more than 50% CPU time to a single child. Since RT scheduling is all about determinism it is not possible to assign more than 100% CPU time (globally in sum) to all RT processes this way. Also, rtwatch will always make sure that 5% will be left for other tasks.

To work, rtwatch needs to run on Linux 2.6.25 with CONFIG_RT_GROUP_SCHED enabled. Unfortunately the Fedora kernel is not compiled this way, yet.

Why is all this so great? Those who attended my talk Practical Real-Time Programming in Userspace at Linux.conf.au 2008 (or watched the video) will know that besides the fact that I'd love to enable RT support for PulseAudio in Fedora in coming releases by default I'd also love to see RT programming more often used in desktop applications. Everywhere were the CPU time spent on a specific process should not depend on the overall system load, but solely on the time constraints of the job itself and what is process needs RT scheduling should be enabled. Examples for this are music or movie playback (the movie player should have enough time to decode one frame every 25th of a second, regardless what else is running on the system), fancy animations, quick reactions to user actions (i.e. updating the mouse cursor). All this for a machine that is snappier and more responsive with shorter latencies, regardless what else happens on the machine.

The day before yesterday, when Linux 2.6.25 was released, we came a big step closer to this goal.

posted at: 17:33 | path: /projects | permanent link to this entry | 11 comments


Posted by Jeff Schroeder at Fri Apr 18 18:00:33 2008
Finally, a sane way to tame trackerd.

Posted by Lennart at Fri Apr 18 18:20:07 2008
Jeff: No. trackerd is not a real-time process, what I describe here does not apply to trackerd.

Posted by Diego at Fri Apr 18 21:48:53 2008
cgroups is awesome :) It's a shame that there's not a lot of documentation, and integration of distros with these toys takes usually so long... :/

Posted by michal at Sat Apr 19 13:24:46 2008
@Diego

You may wish to try OptimizationKit. The latest version (0.1.2-rc2) has support for cpuset, cpu, memory, cfq cgroups subsystems.

And yes, it's really user friendly - check out the gui and documentation.

Posted by pavlinux at Sat Apr 19 20:27:11 2008
./rtwatch -v 2 ls
period=1000.00ms runtime=20.00ms max_cpu_load=2.0%
mount("rtwatch-6875", "/var/run/rtwatch/6875", "cgroup", ...): No such file or directory

Posted by Lennart at Sun Apr 20 01:04:09 2008
pavlinux: are you sure you compiled your kernel with all necessary cgroups options?

This is not a support forum. Ask questions like this by email.

If I shall help you I need a longer strace output.

Posted by pavlinux at Sun Apr 20 01:44:39 2008
1% CPU for /usr/bin/top

# ./rtwatch 1 top 


but in top window i see from 2 to 4% of CPU usage :)

Posted by Lennart at Sun Apr 20 01:57:23 2008
pavlinux: so what was your problem with the mount() failure?

rtwatch is for real-time processes. top does not use any real-time functionality.

There seems to be major confusion about this, so here again:

rtwatch is for real-time processes, for nothing else.

real-time processes are those with SCHED_FIFO or SCHED_RR scheduling enabled. See sched_setscheduler(2) for more information.

Posted by pavlinux at Sun Apr 20 16:20:31 2008
> so what was your problem with the mount() failure?

All good, just incorrect config :)

need not only  CONFIG_RT_GROUP_SCHED=y, but and

CONFIG_GROUP_SCHED=y
CONFIG_FAIR_GROUP_SCHED=y
CONFIG_CGROUP_SCHED=y

The command "mount -t cgroup -ocpu ..." did not work or you С equivalent mount(id, mnt_path, "cgroup", 0, "cpu")

Posted by kevin at Tue Jul 6 09:33:54 2010
www.iloveinwatch.com provide you the best quality replica watch,we guarantee all best  watches if any bad quality ones,customers can have this refunded.
www.iloveinwatch.com
<a href=" http://www.iloveinwatch.com/category-126-b0-Rolex+watch.html">Replica  Rolex</a>
<a href=" http://www.iloveinwatch.com/category-94-b0-Cartier+watch.html">Replica  Cartier</a>
<a href=" http://www.iloveinwatch.com/category-108-b0-Hublot+watch.html">Replica  Hublot</a>
Replica Audemars Piguet
Replica  Chanel
Replica  Graham
Replica U- boat
Replica  Roger Dubuis
Replica  Chopard
Replica  Montblanc
<a href=" http://www.iloveinwatch.com/category-126-b0-Rolex+watch.html">Replica  Rolex</a>
<a href=" http://www.iloveinwatch.com/category-94-b0-Cartier+watch.html">Replica  Cartier</a>
<a href=" http://www.iloveinwatch.com/category-108-b0-Hublot+watch.html">Replica  Hublot</a>
Replica Watches
Replica IWC  Watches
Replica  Ferrari
Replica  Omega
Replica  Panerai
Replica TAG  Heuer
IWC Big Pilot Hand
The World Lastest Watch
The World Fashion
The World Fashion Watch
The Lady Fashion

Posted by kevin at Tue Jul 6 09:34:17 2010
www.iloveinwatch.com provide you the best quality replica watch,we guarantee all best  watches if any bad quality ones,customers can have this refunded.
www.iloveinwatch.com
<a href=" http://www.iloveinwatch.com/category-126-b0-Rolex+watch.html">Replica  Rolex</a>
<a href=" http://www.iloveinwatch.com/category-94-b0-Cartier+watch.html">Replica  Cartier</a>
<a href=" http://www.iloveinwatch.com/category-108-b0-Hublot+watch.html">Replica  Hublot</a>
Replica Audemars Piguet
Replica  Chanel
Replica  Graham
Replica U- boat
Replica  Roger Dubuis
Replica  Chopard
Replica  Montblanc
<a href=" http://www.iloveinwatch.com/category-126-b0-Rolex+watch.html">Replica  Rolex</a>
<a href=" http://www.iloveinwatch.com/category-94-b0-Cartier+watch.html">Replica  Cartier</a>
<a href=" http://www.iloveinwatch.com/category-108-b0-Hublot+watch.html">Replica  Hublot</a>
Replica Watches
Replica IWC  Watches
Replica  Ferrari
Replica  Omega
Replica  Panerai
Replica TAG  Heuer
IWC Big Pilot Hand
The World Lastest Watch
The World Fashion
The World Fashion Watch
The Lady Fashion

Leave a Comment:

Your Name:


Your E-mail (optional):


Comment:


As a protection against comment spam, please type the following number into the field on the right:
Secret Number Image

Please note that this is neither a support forum nor a bug tracker! Support questions or bug reports posted here will be ignored and not responded to!


It should be obvious but in case it isn't: the opinions reflected here are my own. They are not the views of my employer, or Ronald McDonald, or anyone else.

Please note that I take the liberty to delete any comments posted here that I deem inappropriate, off-topic, or insulting. And I excercise this liberty quite agressively. So yes, if you comment here, I might censor you. If you don't want to be censored your are welcome to comment on your own blog instead.


Lennart Poettering <mzoybt (at) 0pointer (dot) net>
Syndicated on Planet GNOME, Planet Fedora, planet.freedesktop.org, Planet Debian Upstream. feed RSS 0.91, RSS 2.0
Archives: 2005, 2006, 2007, 2008, 2009, 2010

Valid XHTML 1.0 Strict!   Valid CSS!