Skip to content

Change to 250hz and voluntary preemption #1216

Closed

Description

@robingroppe

Please change the kernel to 250hz and voluntary preemption.

In everyday use my Pi with the modified kernel can take more work while still being responsive to all other running tasks. For example when i run the MumbleRubyPluginbot, with the stock kernel, which needs to be fed with data every 20ms or so and start an apt upgrade of some packets it quickly starts to lag.
With the modified kernel everything is fine.
You said you would need some evidence. I ran UnixBench on both kernels.
I cant tell much about starting graphical apps, because my pi is running headless but i guess you guys are having crosscompilers set up and can easily build a modified kernel.
By the way these two things i am mentioning are also used in almost every stockkernel in most distributions (Debian, Ubuntu...). And in my opinion there is a reason for that.

Unixbench Stock Kernel: https://robingroppe.de/media/rpi2/orig.txt
Unixbench Modified Kernel: https://robingroppe.de/media/rpi2/mod.txt

Activity

  1. P33M commented on Dec 7, 2015

    @P33M
    Contributor

    Preemption is enabled by default.

    https://github.com/raspberrypi/linux/blob/rpi-4.1.y/arch/arm/configs/bcmrpi_defconfig#L42

    We don't set CONFIG_HZ in the defconfig so the default of 100Hz is used - this in theory gives a 10ms timeslice. Can you increase the priority of the critical process to realtime with the same results?

  2. robingroppe commented on Dec 7, 2015

    @robingroppe
    Author

    Yes, the Low Latency Preemption is enabled while the rest of the Kernel is not so realtime.
    Check the difference between PREEMPT_VOLUNTARY and PREEMPT.
    For example Ubuntu always uses PREEMPT_VOLUNTARY for Desktops and Servers.
    Only the Low-Latency Kernel uses PREEMPT combined with 1000hz and a few other tweaks.
    Full Preemption causes Kernel overhead and reduces throughput.

  3. robingroppe commented on Dec 7, 2015

    @robingroppe
    Author

    Here is my modified kernel in case you want to run a few tests.
    http://robingroppe.de/media/rpi2/kernel7.xz

    I followed this guide:
    https://www.raspberrypi.org/documentation/linux/kernel/building.md

    So all you have to do is jump into the linux directory and...

    $ sudo cp arch/arm/boot/dts/.dtb /boot/
    $ sudo cp arch/arm/boot/dts/overlays/
    .dtb* /boot/overlays/
    $ sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
    $ sudo scripts/mkknlimg arch/arm/boot/zImage /boot/kernel7.img

  4. robingroppe commented on Dec 7, 2015

    @robingroppe
    Author

    Just found a discussion about it on the Arch Board:
    http://archlinuxarm.org/forum/viewtopic.php?f=23&t=7907

  5. popcornmix commented on Dec 7, 2015

    @popcornmix
    Collaborator

    @robingroppe Can you test with CONFIG_PREEMPT_VOLUNTARY and with CONFIG_HZ_250 separately and report on the behaviour with each?

    Both these settings will increase overhead and so reduce throughput, so we need to be very sure of exactly what the benefits are before enabling.

  6. robingroppe commented on Dec 7, 2015

    @robingroppe
    Author

    In this situation changing to voluntary will actually improve throughput.
    But i can do that. Do you have any tests you want me to rely on?
    Am 07.12.2015 14:03 schrieb "popcornmix" notifications@github.com:

    @robingroppe https://github.com/robingroppe Can you test with
    CONFIG_PREEMPT_VOLUNTARY and with CONFIG_HZ_250 separately and report on
    the behaviour with each?

    Both these settings will increase overhead and so reduce throughput, so we
    need to be very sure of exactly what the benefits are before enabling.

    —
    Reply to this email directly or view it on GitHub
    #1216 (comment).

  7. popcornmix commented on Dec 7, 2015

    @popcornmix
    Collaborator

    No it may help latency but it won't improve throughput.

    These new preemption points have been selected to reduce the maximum latency of rescheduling, providing faster application reactions, at the cost of slightly lower throughput.

    http://cateee.net/lkddb/web-lkddb/PREEMPT_VOLUNTARY.html

  8. robingroppe commented on Dec 7, 2015

    @robingroppe
    Author

    Okay. Voluntary causes the throughput to drop slightly but full preemption
    like you are using right now causes even more drop of throughput and
    additionally kernel overhead.
    Am 07.12.2015 14:35 schrieb "popcornmix" notifications@github.com:

    No it may help latency but it won't improve throughput.

    These new preemption points have been selected to reduce the maximum
    latency of rescheduling, providing faster application reactions, at the
    cost of slightly lower throughput.

    http://cateee.net/lkddb/web-lkddb/PREEMPT_VOLUNTARY.html

    —
    Reply to this email directly or view it on GitHub
    #1216 (comment).

  9. Ferroin commented on Dec 7, 2015

    @Ferroin
    Contributor

    @popcornmix That's in comparison to PREEMPT_NONE, PREEMPT_VOLUNTARY came before PREEMPT_FULL (which is what the RPi is using). PREEMPT_NONE is the highest throughput option, but provides noticeable latency for many things that require interactive usage (which is why almost nobody who isn't doing exclusively HPC workloads uses it anymore), PREEMPT_FULL provides the lowest latency, but at the cost of significant throughput (and potential stability issues). PREEMPT_VOLUNTARY was originally a precursor to PREEMPT_FULL, but is now kept as a compromise between PREEMPT_FULL and PREEMPT_NONE.

  10. robingroppe commented on Dec 7, 2015

    @robingroppe
    Author

    I am compiling two more kernels. One with only 250hz and Full Preempt and one with 100hz and Voluntary Preempt. This will take a while. Has someone tested the modified kernel already?

  11. popcornmix commented on Dec 7, 2015

    @popcornmix
    Collaborator

    @Ferroin Okay, so CONFIG_PREEMPT_VOLUNTARY will make latency worse compared to current. Possible an issue for some of the hardware drivers (LIRC/I2C/I2S/SPI etc).

  12. Ferroin commented on Dec 7, 2015

    @Ferroin
    Contributor

    Unless the drivers are in user-space, this should actually make things better for them. The latency impact is entirely in user-space, and technically, reducing preemption should make timing critical stuff work more reliably (assuming they have critical sections properly wrapped in preempt_off() calls).

  13. robingroppe commented on Dec 7, 2015

    @robingroppe
    Author

    But the kernel timer of 250hz or 4ms will reduce the latency even more than you will loose by switching to the other Preemption model.

  14. Ferroin commented on Dec 7, 2015

    @Ferroin
    Contributor

    That's pretty dependent on how thee drivers are handling preemption, as well as what you are doing in general on the system. I think for most use cases, if it doesn't fully offset the latency increase from PREEMPT_VOLUNTARY, it should come very close. Some people trying to do odd timing specific things with their hardware from userspace (the DHT11 temperature sensor immediately comes to mind) may have issues, but if they really need low latency, they should probably be building their own kernel with HZ=1000 anyway.

    It's worth keeping in mind that the higher timer frequency will also increase power consumption (although I doubt that it will be more than a few micro-amps difference between HZ=100 and HZ=250), so it may be worth testing that as well.

  15. clivem commented on Dec 7, 2015

    @clivem

    I was going to stay out of this as I cannot provide any hard evidence. I don't know whether years of experience count? LOL

    IMHO, the best balance, for general usage, between latency and throughput is achieved with VOLUNTARY_PREEMPT and 250HZ for headless, and VOLUNTARY_PREEMPT and 1000HZ for desktop/GUI. But I wouldn't change the current RPI default configs. If people want to change the defaults for their specific use cases, they can compile their own kernels......

  16. 44 remaining items

  17. popcornmix commented on Dec 15, 2015

    @popcornmix
    Collaborator

    We're happy enough with switching to CONFIG_PREEMPT_VOLUNTARY to match Ubuntu and OpenELEC. This is in latest rpi-update kernel.

    We'll see if we get any positive or negative reports from this, and possibly increase the HZ value in a subsequent update.

  18. mk01 commented on Dec 24, 2015

    @mk01

    perhaps what needs to be understood:

    • voluntary <> preemptive - more preemption points doesn't mean preemption will always happen. only can happen
    • periodicity of ticks - periodic ticks are (imho) many years obsolete. sure, there can be specific requirements, but honestly - will be hard to find - in actual kernels cost to handle a tick is close to non measurable times. so it alone has barely any effect. actually if 100 if 1000, doesn't make sense as long as this can be handled dynamically. and - it can (seeing as low as 5-10 ticks /1s is not uncommon, so why to generate still those 100?)
    • what I agree with is 3-5% gain on throughput with voluntary case, but again - 95% of times our embedded devices run with ONE active task anyhow -> there will be no difference.
    • nobody checked other CONFIG params - specially HIGH_RES_TIMERS. until this is used, all being said / set / expected is being invalidated. depending on platforms timers implementation (and which one is used for HR timers) - it is responsible for 2000-3000 wakeups per second - so where is the discussion if 250 or 300

    mk01

    btw: kernel is not the same as 20years ago - this was the time when all those distros set its .config params. and never looked back.

  19. Ferroin commented on Jan 4, 2016

    @Ferroin
    Contributor

    @mk01 The point about preemption is perfectly valid, but doesn't have much bearing on the fact that more preemption points means lower latency on stuff that's latency sensitive. As far as tickless systems (which is what you appear to be referring to in the second and third points), that is all well and good except at least one CPU has to have something running to provide timekeeping, and as a result of this, a generation 1 Pi can't be run tickless at all (because it has only one CPU). On top of that, the timer frequency still has an impact when the system isn't sitting idle, because when the tick is running, that's the average frequency it runs at (it's only the average because of how linux's scheduler works, but that is beyond the scope of this discussion). The bit about hrtimers is also worth considering, but there isn't as much variance in that as you would think, and that only causes wakeups when something is directly using it.

    As far as the comment about distros not changing kernel configuration, that's blatantly wrong. Aside form the fact that the most widely used distros didn't exist 20 years ago, almost none of them just set config options the first time and never change them. It doesn't happen often in most distros, but it does happen. Usually it's as new features become stable (BTRFS and F2FS are both included as modules in all major distros that ship precompiled kernels, the didn't even exist as config options 5 years ago, let alone 20). Less frequently, distros change config options for performance reasons (this is why Ubuntu ships a standard kernel, a virtualization targeted kernel, a server targeted kernel, and a low-latency kernel (which has HZ=1000 and PREEMPT_FULL, and why they switched from the CFQ I/O scheduler to the deadline I/O scheduler), or for security reasons (I know of at least a few distros that recently disabled vm86 support in their default configs, most jumped on disabling 16-bit segment support, a lot of them quickly turn off any legacy syscall when an option to do so appears, etc).

  20. P33M commented on May 17, 2017

    @P33M
    Contributor

    We have settled on CONFIG_PREEMPT_VOLUNTARY and CONFIG_HZ=100 as the default. We have a microsecond-resolution timestamp source for precise userspace timing.

  21. trabant-asb commented on Mar 3, 2024

    @trabant-asb

    I do realize that this discussion and associated pull requests are a few years old. I'm trying to figure out the best kernel settings for a Pi3 database server. The Pi 3 defconfig references a tick of 1000Hz and full preemption. The 2711 and 2712 defconfigs set the clock to 250Hz, also with full preemption.

    May I ask why the recommended clock speed for the Pi 3 is that high, maybe related to memory access? As my database is all about I/O and interrupts, I will likely go for voluntary preemption, and not sure yet about the clock speed.

  22. pelwell commented on Mar 4, 2024

    @pelwell
    Contributor

    The arm64 config file bcmrpi3_defconfig was the first 64-bit config file, originally contributed by users keen to experiment with 64-bit builds. We've kept it moderately inline with our "official" defconfigs, but never seriously vetted it. I think there's an argument for dropping it altogether, now that 64-bit has become mainstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions