Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Changing The Kernels Timer Frequency To A Custom Value
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
mrtelekinesis
n00b
n00b


Joined: 06 Mar 2018
Posts: 7

PostPosted: Fri May 08, 2020 8:07 pm    Post subject: Changing The Kernels Timer Frequency To A Custom Value Reply with quote

[WIP]
Hello all, this is a guide on how to change the linux kernels timer frequency to custom values.

References:
https://en.wikipedia.org/wiki/Hertz
https://lwn.net/Articles/549580/
https://lwn.net/Articles/145973/
https://wiki.osdev.org/HPET
https://wiki.osdev.org/RTC

Kernel Sources References:
kernel/Kconfig.hz
include/linux/jiffies.h

There is 3 Timer Subsystems to be chosen at General Setup>Timers subsystem>Timer tick handling in the make menuconfig

1.CONFIG_HZ_PERIODIC
This option keeps the tick rate running periodically at a constant rate, even when the CPU doesn't need it.
2.CONFIG_NO_HZ_IDLE << The balance between both options
This option enables a tickless idle system: timer interrupts will only trigger on an as-needed basis when the system is idle.
3.CONFIG_NO_HZ_FULL
Adaptively try to shutdown the tick whenever possible, even when the cpu is running tasks.


https://github.com/torvalds/linux/blob/master/kernel/Kconfig.hz << this is the file in the kernel tree where you can change the timer frequency.

File Location: KernelDirectory/kernel/Kconfig.hz

The example below is the fair timer frequency idea, github link is below.
Code:

# SPDX-License-Identifier: GPL-2.0-only
#
# Timer Interrupt Frequency Configuration
#
# Github: https://github.com/mrtelekinesis


choice
   prompt "Fair timer frequency"
   default HZ_1000
   help
    Configuration of the Fair timer frequency.

    This selection of timer frequencys balances the ticks on all cores by divideing from 1000 to the number of CPU cores you have,
    giving fairness and balance between throughput and latency while reducing unnecessary energy consumption and avoiding
    reduced performance on CPU cores due to many timer interrupts occurring across all cores.

    1000Hz for single cores.
    500Hz for dual cores.
    250Hz for quad cores.
    166Hz for six cores.
    125Hz for eight cores.

    To get the hertz value for your CPU do
    1000 / number of CPU cores.
 
    Example (bc -l):
    1000 / 6 is 166Hz and 1000 / 166 is the result 6ms, the periodic tick value.

    References: include/linux/jiffies.h

   config HZ_1000
      bool "1000 HZ"
   help
    1000 ticks per second.
    1ms each tick.
    Use with single core CPUs.

   config HZ_500
      bool "500 HZ"
   help
    500 ticks per second.
    2ms each tick.
    Use with dual core CPUs.

   config HZ_250
      bool "250 HZ"
   help
    250 ticks per second.
    4ms each tick.
    Use with quad core CPUs.

   config HZ_166
      bool "166 HZ"
   help
    166 ticks per second.
    6ms each tick.
    Use with six core CPUs.

   config HZ_125
      bool "125 HZ"
   help
    125 ticks per second.
    8ms each tick.
    Use with eight core CPUs.

endchoice

config HZ
   int
   default 1000 if HZ_1000
   default 500 if HZ_500
   default 250 if HZ_250
   default 166 if HZ_166
   default 125 if HZ_125

config SCHED_HRTICK
   def_bool HIGH_RES_TIMERS


To select the timer frequency, go to Processor type and features>Timer frequency in make menuconfig.

Increasing the timer frequency will also increase power consumption.

You can also tune HPET timers with a sysctl value, you can place this in a file in /etc/sysctl.d/local.conf
Code:

dev.hpet.max-user-freq = 20

And you can also tune RTC timers with a udev rule, you can place this in a file in /etc/udev/rules.d/10-local.rules
Code:

ACTION=="add|change", SUBSYSTEM=="rtc", KERNEL=="rtc0", ATTR{max_user_freq}="20"


20Hz = 50ms each cycle per second.

To calculate your own values, you do 1000 / X
X is the hertz value you define
I used the command line tool "bc -l" to calculate these values, it is recommended to use a decimal point calculator.

Normally the linux kernel uses TSC as a clocksource, but if the kernel sees that it is unstable it can use other timers like HPET or even ACPI-PM as a clocksource.

The clocksource can also be set by a kernel parameter clocksource= which for x86-32 can take pit, hpet and tsc and x86-64 can take hpet or tsc.

Github Link:
Here is the github link for the Kconfig.hz
https://github.com/mrtelekinesis/Linux-Configuration


Last edited by mrtelekinesis on Fri Aug 21, 2020 8:14 pm; edited 62 times in total
Back to top
View user's profile Send private message
pietinger
Guru
Guru


Joined: 17 Oct 2006
Posts: 406
Location: Bavaria

PostPosted: Fri May 08, 2020 10:51 pm    Post subject: Re: Changing The Kernel's Timer Frequency To A Custom Value Reply with quote

mrtelekinesis wrote:
The higher the frequency the lower the latency, but if the CPU cannot keep up with low latency then throughput might be affected, so it is a matter of finding the right timer frequency for your CPU, but for responsiveness(like gaming) you might want a value greater than or equal to 852Hz.

I dont think its necessary to optimize the timer frequency when using "tickless idle" (General setup > Timers subsystem -> Timer tick handling (Idle dynticks system (tickless idle))
With this you should not have any problems with 1000 hz. (I use 300 hz since today)
mrtelekinesis wrote:
https://lwn.net/Articles/145973/ << this is a good link on the kernels HZ timer frequency.

This is a very old article. Today the patch described there is a standard kernel feauture.
Back to top
View user's profile Send private message
mrtelekinesis
n00b
n00b


Joined: 06 Mar 2018
Posts: 7

PostPosted: Sat May 09, 2020 12:04 am    Post subject: Re: Changing The Kernel's Timer Frequency To A Custom Value Reply with quote

pietinger wrote:
mrtelekinesis wrote:
The higher the frequency the lower the latency, but if the CPU cannot keep up with low latency then throughput might be affected, so it is a matter of finding the right timer frequency for your CPU, but for responsiveness(like gaming) you might want a value greater than or equal to 852Hz.

I dont think its necessary to optimize the timer frequency when using "tickless idle" (General setup > Timers subsystem -> Timer tick handling (Idle dynticks system (tickless idle))
With this you should not have any problems with 1000 hz. (I use 300 hz since today)
mrtelekinesis wrote:
https://lwn.net/Articles/145973/ << this is a good link on the kernels HZ timer frequency.

This is a very old article. Today the patch described there is a standard kernel feauture.


I have that option set already, not saying that I have any problems, this is just a guide for anybody who wants to tinker with the timer frequency as there is no right Hz value, it really depends on the user, the CPU and the kind of computer work they do.


Last edited by mrtelekinesis on Wed May 13, 2020 12:17 am; edited 1 time in total
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6780

PostPosted: Sat May 09, 2020 12:20 am    Post subject: Reply with quote

If you want low latency then use MuQSS, which uses the hpet for scheduling (~14MHz).

Hacking random values into the kernel tick rate was debunked years ago as useless except for very specific broken software (proprietary game servers).
Back to top
View user's profile Send private message
mrtelekinesis
n00b
n00b


Joined: 06 Mar 2018
Posts: 7

PostPosted: Sat May 09, 2020 12:49 am    Post subject: Reply with quote

Ant P. wrote:
If you want low latency then use MuQSS, which uses the hpet for scheduling (~14MHz).

Hacking random values into the kernel tick rate was debunked years ago as useless except for very specific broken software (proprietary game servers).


oooh, do you remember the article you read on the kernel tick rate being debunked?, i would like to read that to understand this concept better

I have used MuQSS and also PDS/BMQ, they are really great CPU schedulers, but right now im using CFS and I am using it with SCHED_TUNABLESCALING_NONE in kernel/sched/fair.c , seems good so far compared to SCHED_TUNABLESCALING_LOG on my six core


Last edited by mrtelekinesis on Wed May 13, 2020 12:18 am; edited 1 time in total
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6780

PostPosted: Sat May 09, 2020 5:46 am    Post subject: Reply with quote

mrtelekinesis wrote:
oooh, do you remember the article you read on the kernel tick rate being debunked?, i would like to read that to understand this concept better

It wasn't an article, it was help text from the -ck patchset back in the RSDL days. It added options up to 100,000hz and then explained the ones above 1000 were mostly useless and only increase CPU load.

If you're having latency problems and it's not visibly limited by CPU usage, it's probably related to cpufreq or C-states.
Back to top
View user's profile Send private message
mrtelekinesis
n00b
n00b


Joined: 06 Mar 2018
Posts: 7

PostPosted: Sat May 09, 2020 12:54 pm    Post subject: Reply with quote

Ant P. wrote:
mrtelekinesis wrote:
oooh, do you remember the article you read on the kernel tick rate being debunked?, i would like to read that to understand this concept better

It wasn't an article, it was help text from the -ck patchset back in the RSDL days. It added options up to 100,000hz and then explained the ones above 1000 were mostly useless and only increase CPU load.

If you're having latency problems and it's not visibly limited by CPU usage, it's probably related to cpufreq or C-states.


Not having any latency issues at all, just trying to get the most out of my computer, that's all :D

I am also using schedutil cpufreq governor, but have been experimenting with ondemand cpufreq governor, i read somewhere that schedutil will be the only cpufreq governor in the future so, im gonna stick with that one
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7466

PostPosted: Sat May 09, 2020 3:14 pm    Post subject: Re: Changing The Kernel's Timer Frequency To A Custom Value Reply with quote

mrtelekinesis wrote:
https://www.relaxmelodies.com/blog/science-behind-solfeggio-frequencies/

That article looks like history channel made :)
Quote:

Solfeggio frequencies refer to specific tones of sound that help with and promote various aspects of body and mind health. These frequencies are reputed to date back to ancient history and said to be the fundamental sounds used in both Western Christianity and Eastern Indian religions
Physician and researcher, Dr. Joseph Puleo, rediscovered Solfeggio frequencies in the 1970s...identify six measurable tones that bring the body back into balance and aid in healing.

yeah i always doubt something knew since age of time gets discovered as late as 1970...
the so-call Doctor guy nobody's knows discovering a major thing
and the pseudo science that claims healing of body thru obscure methods

nothing from him on wikipedia
and this https://rationalwiki.org/wiki/Solfeggio_frequencies
Quote:

Solfeggio frequencies, often promoted as "ancient solfeggio frequencies",[2] are a crank concept in sound healing. They involve grandiose claims about a certain series of sound frequencies (396, 417, 528, 639, 741, 852 Hz) derived from a numerological system of family number groups. The concept hijacks and misapplies terminology (including the name) from the "solfeggio" or solfègeWikipedia's W.svg music-education method, but other than that, has nothing in common with it.


no idea why, but i won't play with my kernel for this
I prefer my method by putting my hands on the kenrel .config to make it heal faster
Back to top
View user's profile Send private message
mrtelekinesis
n00b
n00b


Joined: 06 Mar 2018
Posts: 7

PostPosted: Sun May 10, 2020 11:47 pm    Post subject: Re: Changing The Kernel's Timer Frequency To A Custom Value Reply with quote

krinn wrote:
mrtelekinesis wrote:
https://www.relaxmelodies.com/blog/science-behind-solfeggio-frequencies/

That article looks like history channel made :)
Quote:

Solfeggio frequencies refer to specific tones of sound that help with and promote various aspects of body and mind health. These frequencies are reputed to date back to ancient history and said to be the fundamental sounds used in both Western Christianity and Eastern Indian religions
Physician and researcher, Dr. Joseph Puleo, rediscovered Solfeggio frequencies in the 1970s...identify six measurable tones that bring the body back into balance and aid in healing.

yeah i always doubt something knew since age of time gets discovered as late as 1970...
the so-call Doctor guy nobody's knows discovering a major thing
and the pseudo science that claims healing of body thru obscure methods

nothing from him on wikipedia
and this https://rationalwiki.org/wiki/Solfeggio_frequencies
Quote:

Solfeggio frequencies, often promoted as "ancient solfeggio frequencies",[2] are a crank concept in sound healing. They involve grandiose claims about a certain series of sound frequencies (396, 417, 528, 639, 741, 852 Hz) derived from a numerological system of family number groups. The concept hijacks and misapplies terminology (including the name) from the "solfeggio" or solfègeWikipedia's W.svg music-education method, but other than that, has nothing in common with it.


no idea why, but i won't play with my kernel for this
I prefer my method by putting my hands on the kenrel .config to make it heal faster


:D, yeah i guess so, still is interesting though, but the only way it can possibly work is if the monitors refresh rate were in those frequencies, but who knows, i am trying out 64Hz kernel timer frequency now, stuff is complex but you gotta figure it out for yourself right? :D
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum