FreeBSD FBFS live DVD image is available now

The FBFS live DVD

Important note !

The published live dvd image freezes when starting the gnome desktop environment if you run it on real hardware. It works, however if you try to run it from vmware player. I do not have enough time now to explore the issue so if you really want to try the FBFS scheduler with the X desktop environment, you need to follow the tutorial on the second half of this page and compile the FBFS into the kernel manually.

End of important note !

I have published on internet a bootable live dvd image of FreeBSD with the FBFS scheduler. So now you can easily try it:-) The FreeBSD image on this dvd contains an X environment. It is a slightly stripped down version of the GNOME desktop environment. The compressed image can be downloaded from here. Just download it, uncompress and burn the iso image.

I have created there a user with unprotected root access. The username is fbfs and the password is also fbfs.

This dvd image image contains a slightly lighter version of FreeBSD. I removed the locales and many gnome applications to make it lighter and thus easier for me to publish and for you to download.

The downloaded iso image is a live dvd, that means you can boot your computer from this image and run the supplied operating system without the need to install it on your disk. This makes it easy for you to try my new scheduler.

Manually compiling the FBFS

Firstly a quick warning. Here I write a quick guide how to compile the FBFS scheduler into the FreeBSD. Although I have tried to do my best, it is possible that the following procedure could make your system unstable or even unbootable. So use common sense, do not apply it to production systems:-) The scheduler is still under development.

Now I assume you are running the 8.2-RELEASE version of the FreeBSD operating system. It is the latest version available for download from the official FreeBSD web page. You can get it from here.

The first thing you need to do is to download the FreeBSD sources for the version RELENG_8_2. One possible way how to do it is using the csup utility. Make sure you have enough free space in the /usr filesystem and download this supfile. You should now edit this file and change the first line

*default host=cvsup.cz.FreeBSD.org

to specify a host name that is near your geographic location. The list of available hosts is here. So after editing, the first line could look like this if you are from France.

*default host=cvsup.fr.FreeBSD.org

Now execute the following command as root:

# csup src-supfile

where the src-supfile is the name of the downloaded supfile. This will download for you the required sources. Wait until the download ends, it will take a while.

Now you need to download the FBFS patch to the FreeBSD kernel from here. Download it to the /usr/src location. You should apply the patch with the following commands as root:

# cd /usr/src
# patch -p1 < fbfs_midterm.patch

where fbfs_midterm.patch is the name of the downloaded patch file.

The next thing you need to do is to configure your kernel to use the FBFS scheduler. Edit your kernel configuration file. (for example /usr/src/sys/i386/conf/GENERIC) Now locate this line:

options SCHED_ULE # ULE scheduler

and change it to this:

options SCHED_FBFS # FBFS scheduler

Now you need to compile and install the patched kernel. For this, you should read this carefully. To build and install the new kernel, you need to issue these commands as root (Replace the GENERIC with the kernel config file name that you use):

# cd /usr/src
# make buildkernel KERNCONF=GENERIC
# make installkernel KERNCONF=GENERIC

Now reboot and try the FBFS scheduler.

What is still missing

If you run my scheduler, you may notice that there is some functionality missing that you are used to. Now, there is no process cpu accounting information delivered to the user space. So when you run the top command, all processes will show 0% cpu utilization. The current FBFS implementation also lacks the cpuset functionality. I will add the implementation for these features next time.

Feedback is welcome

Any feedback is welcome:-)

This entry was posted in Uncategorized. Bookmark the permalink.

19 Responses to FreeBSD FBFS live DVD image is available now

  1. fidaj says:

    Hi!
    Is it possible to adapt the code for CURRENT?
    Thank you!

    • Rudo Tomori says:

      Hi.
      there are some differences in the relevant struct declarations and some preprocessor macros. While it probably would not be much effort to make changes to the code so that it compiles when applied to the CURRENT branch, I could create new bugs by doing so. And I do not want to maintain 2 separate branches of the FBFS. So I do not plan to release the code for the CURRENT branch now.

      rudo

      • fidaj says:

        Simply, in my opinion, it would be logical to test innovations in KURRENT just for the fact that they had a right to exist in the future …
        But in any case, thanks for the work!

  2. subbsd says:

    > So I do not plan to release the code for the CURRENT branch now.

    +1 to fidaj.
    Yea, Really – it is no necessity support code in two branches. But.. Usually development is carried on in CURRENT and there is expected to test something new. It is not a pity to me that in HEAD I can test your code

  3. Arne Meyer says:

    Hi
    I applied your patch to my 8-STABLE system. I had to change the code somewhat as P_NOLOAD doesn’t exist anymore. As a test I just recompiled my kernel while watching a Futurama episode and everything seems fine. The system feels a bit snappier but that could just be my imagination.
    Anyway, great work!

  4. Arne Meyer says:

    Not sure waht happend to my post. so, again:
    applied patch to my 8-STABLE machine but had to edit it a bit since P_NOLOAD is gone. works good so far. system feels a bit snappier but that could be my imagination.

    • Rudo Tomori says:

      Hi,
      thanks for the notice about the P_NOLOAD. As to your previous post – the spam filter of this blog is probably over-intelligent – it flagged it as spam. I try to check the posts regularly but during weekends I am sometimes offline and then there is some delay with the posts. This was also the case last week.

  5. Rudo Tomori says:

    Hi,
    thanks for the idea about doing the work under the CURRENT branch. I was also thinking before the start of the project about which branch to use for my development. And I chose the 8.2-STABLE – I chose stable because I have not had experience with running the CURRENT and I did not know how stable or unstable it is. I was afraid that doing the development under the CURRENT branch would slow me down. I mean that when I get some kernel panics or so I will not be sure if the error is my code or some other code.
    I do this as a summer of code project. And there is allocated a 3 months period for it. In this 3 months period (of which 2 months are already gone) I will probably not switch or try to modify the code for the CURRENT branch.
    But I am not planning to give up the project after the 3 months period. I think I would work on it later as a university project. I might then switch to the CURRENT branch.

    again,
    thanks for the constructive comments

  6. Hi,

    I’ve tested the patch on 8.2-RELEASE amd64 box. I have a problem with it: when I start audio player (beep media player), it plays music fine. But as soon as I start firefox, sound becomes distortioned. Any ideas what could be wrong with that?

    • Arne Meyer says:

      I’ve been running my laptop with fbfs since saturday. And I’ve experienced similar problems. Audio will sometimes become jittery when I use “big” programs like chromium.

    • Rudo Tomori says:

      Hi,
      you said you have tested the patch on amd64 box. This is interesting because I have tried lately the FBFS on 2 different amd64 machines (I do the development on i386) and I even could not boot the FreeBSD. The kernel panics. You have not observed this behaviour? I will now try to find out why it panics.

      • I didn’t notice any panics, but I didn’t run it for long though, ’cause not being able to listen to music is quite disappointing. :-)

        Let me know if I can help you with testing.

  7. fidaj says:

    Hi all.
    I have tried to adapt source code this scheduler to him build the kernel CURRENT…
    Here is a patch to be applied after the original patch
    [code]
    --- sched_fbfs.c 2011-07-20 01:30:16.000000000 +0300
    +++ sched_fbfs_my.c 2011-07-20 20:47:31.000000000 +0300
    @@ -130,6 +130,10 @@
    */
    static struct runq runq;

    +#ifdef SMP
    +static cpuset_t idle_cpus_mask;
    +#endif
    +
    /*
    * Priority ratios for virtual deadline per nice value calculations.
    */
    @@ -303,7 +307,7 @@
    thread_lock(td);
    thread_unlock(td);
    mtx_lock_spin(&sched_lock);
    - if ((child->td_proc->p_flag & P_NOLOAD) == 0)
    + if ((child->td_proc->p_flag & P_FOLLOWFORK) == 0)
    sched_load_rem();
    mtx_unlock_spin(&sched_lock);
    }
    @@ -436,7 +440,7 @@
    {
    THREAD_LOCK_ASSERT(td, MA_OWNED);
    td->td_base_user_pri = prio;
    - if (td->td_flags & TDF_UBORROWING && td->td_user_pri td_flags & TDF_UNUSED09 && td->td_user_pri td_user_pri = prio;
    }
    @@ -447,25 +451,25 @@
    u_char oldprio;

    THREAD_LOCK_ASSERT(td, MA_OWNED);
    - td->td_flags |= TDF_UBORROWING;
    + td->td_flags |= TDF_UNUSED09;
    oldprio = td->td_user_pri;
    td->td_user_pri = prio;
    }

    -void
    -sched_unlend_user_prio(struct thread *td, u_char prio)
    -{
    - u_char base_pri;
    -
    - THREAD_LOCK_ASSERT(td, MA_OWNED);
    - base_pri = td->td_base_user_pri;
    - if (prio >= base_pri) {
    - td->td_flags &= ~TDF_UBORROWING;
    - sched_user_prio(td, base_pri);
    - } else {
    - sched_lend_user_prio(td, prio);
    - }
    -}
    +//void
    +//sched_unlend_user_prio(struct thread *td, u_char prio)
    +//{
    +// u_char base_pri;
    +
    +// THREAD_LOCK_ASSERT(td, MA_OWNED);
    +// base_pri = td->td_base_user_pri;
    +// if (prio >= base_pri) {
    +// td->td_flags &= ~TDF_UNUSED09;
    +// sched_user_prio(td, base_pri);
    +// } else {
    +// sched_lend_user_prio(td, prio);
    +// }
    +//}

    void
    sched_sleep(struct thread *td, int pri)
    @@ -503,7 +507,7 @@
    tmtx = thread_lock_block(td);
    }

    - if ((p->p_flag & P_NOLOAD) == 0)
    + if ((p->p_flag & P_FOLLOWFORK) == 0)
    sched_load_rem();

    if (newtd) {
    @@ -525,7 +529,7 @@
    if (td->td_flags & TDF_IDLETD) {
    TD_SET_CAN_RUN(td);
    #ifdef SMP
    - idle_cpus_mask &= ~PCPU_GET(cpumask);
    + CPU_CLR(PCPU_GET(cpuid), &idle_cpus_mask);
    #endif
    } else {
    if (TD_IS_RUNNING(td)) {
    @@ -548,7 +552,7 @@
    ("trying to run inhibited thread"));
    newtd->td_flags |= TDF_DIDRUN;
    TD_SET_RUNNING(newtd);
    - if ((newtd->td_proc->p_flag & P_NOLOAD) == 0)
    + if ((newtd->td_proc->p_flag & P_FOLLOWFORK) == 0)
    sched_load_add();
    } else {
    newtd = choosethread();
    @@ -599,7 +603,7 @@

    #ifdef SMP
    if (td->td_flags & TDF_IDLETD)
    - idle_cpus_mask |= PCPU_GET(cpumask);
    + CPU_SET(PCPU_GET(cpuid), &idle_cpus_mask);
    #endif
    sched_lock.mtx_lock = (uintptr_t)td;
    td->td_oncpu = PCPU_GET(cpuid);
    @@ -665,7 +669,8 @@
    max_thread = curthread;
    max_prio = max_thread->td_priority;
    ts = max_thread->td_sched;
    - SLIST_FOREACH(pc, &cpuhead, pc_allcpu) {
    +// SLIST_FOREACH(pc, &cpuhead, pc_allcpu) {
    + STAILQ_FOREACH(pc, &cpuhead, pc_allcpu) {
    cthr = pc->pc_curthread;
    if (max_prio td_priority) {
    max_thread = cthr;
    @@ -689,7 +694,9 @@
    struct td_sched *ts;
    struct thread *thr_worst;
    struct cpu_group *cg;
    - cpumask_t dontuse, map, me;
    +// cpumask_t dontuse, map, me;
    + cpuset_t dontuse, map, map_oth;
    + u_int me;
    u_char c;

    THREAD_LOCK_ASSERT(td, MA_OWNED);
    @@ -699,28 +706,39 @@
    ts->ts_slptime = 0;
    sched_add(td, SRQ_BORING);

    - me = PCPU_GET(cpumask);
    - dontuse = me | stopped_cpus | hlt_cpus_mask;
    - map = idle_cpus_mask & ~dontuse;
    +// me = PCPU_GET(cpumask);
    + me = PCPU_GET(cpuid);
    +// dontuse = me | stopped_cpus | hlt_cpus_mask;
    +// map = idle_cpus_mask & ~dontuse;
    +
    + CPU_SETOF(me, &dontuse);
    + CPU_OR(&dontuse, &stopped_cpus);
    + CPU_OR(&dontuse, &hlt_cpus_mask);
    + map = idle_cpus_mask;
    + CPU_NAND(&map, &dontuse);

    /*
    * Firstly check if we should reschedule the last cpu the thread
    * run on.
    */
    if (preempt_lastcpu(td)) {
    - if (map)
    + if (!CPU_EMPTY(&map))
    ipi_selected(map, IPI_AST);
    return;
    }
    /*
    * Is there any idle cpu ?
    */
    - if (map) {
    + if (!CPU_EMPTY(&map)) {
    cg = cpu_topology[td->td_lastcpu];
    - while ((cg != NULL) && ((map & cg->cg_mask) == 0))
    + map_oth = map;
    + CPU_AND(&map_oth, &cg->cg_mask);
    + while ((cg != NULL) && (CPU_EMPTY(&map_oth)))
    cg = cg->cg_parent;
    - if (map & cg->cg_mask) {
    - ipi_selected(map & cg->cg_mask, IPI_AST);
    + map_oth = map;
    + CPU_AND(&map_oth, &cg->cg_mask);
    + if (!CPU_EMPTY(&map_oth)) {
    + ipi_selected(map_oth, IPI_AST);
    return;
    }
    ipi_selected(map, IPI_AST);
    @@ -780,7 +798,7 @@
    CTR2(KTR_RUNQ, "sched_add: adding td_sched:%p (td:%p) to runq", ts, td);
    ts->ts_runq = &runq;

    - if ((td->td_proc->p_flag & P_NOLOAD) == 0)
    + if ((td->td_proc->p_flag & P_FOLLOWFORK) == 0)
    sched_load_add();
    runq_add(ts->ts_runq, td, flags);
    }
    @@ -800,7 +818,7 @@
    "prio:%d", td->td_priority, KTR_ATTR_LINKED,
    sched_tdname(curthread));

    - if ((td->td_proc->p_flag & P_NOLOAD) == 0)
    + if ((td->td_proc->p_flag & P_FOLLOWFORK) == 0)
    sched_load_rem();
    runq_remove(ts->ts_runq, td);
    TD_SET_CAN_RUN(td);
    @@ -990,7 +1008,7 @@
    }

    void
    -sched_tick(void)
    +sched_tick(int cnt)
    {
    }
    [/code]
    but this is the kernel at boot panic on some modules…
    can someone say – where the errors in my change?

    Can still make a joint effort to test a version of CURRENT? ;)
    Thanks!
    P.S. sorry for my english :(

    • nestor says:

      hi, rudo posted latest patch, could you please look at it and see if it can be ported to current? furthermore, could you please post it as a file and not straight here? I tried your approach and it did not wantd to patch… dunno why…

  8. Do you have a Facebook page or Twitter? Would love to follow you there, I’m on my iPhone and love reading your stuff!

  9. ipod touch says:

    Great review! You actually covered some great news on your blog. I came across it by using Google and I’ve got to admit that I already subscribed to the site, will be following you on my iphone :)

  10. nestor says:

    hi, I’m about to recompile the kernel without drivers to have em load from loader.conf, it’s a laptop and I’m trying to pimp it as much as possible to get the most out of its features, but I am missing the most important part, BFS scheduler on 9.0 current, please … perhaps it’s not ready but I’m willing to test it…

Leave a Reply