How can I know HZ value of Android kernel through ADB shell? (without any coding)
I checked How to check HZ in the terminal?, but this is not work with Android ADB shell.
Any suggestion?
How can I know HZ value of Android kernel through ADB shell? (without any coding)
I checked How to check HZ in the terminal?, but this is not work with Android ADB shell.
Any suggestion?
You can derive the kernel space HZ value by taking an elapsed time in jiffies and dividing it by the elapsed time in seconds.
You can get both the system uptime in jiffies and in nanoseconds from the /proc/timer_list file.
now at <nanoseconds> nsecs
line<nanoseconds>
will be the uptime in nanosecondsjiffies: <jiffies>
line (any processor will do)<jiffies>
will be the uptime in jiffies
INITIAL_JIFFIES
in the kernel -- so it may not start counting at 0
. Nevertheless, this shouldn't affect the outcome of our calculation since we're concerned with the elapsed time rather than obsolute uptime.By taking these two values over an elapsed period of time, you can calculate the HZ value using the following equation:
(jiffies_after - jiffies_before)
HZ = -----------------------------------------
((nsecs_after - nsecs_before)/1000000000)
If you happen to have awk
(perhaps via BusyBox), you can automate this calculation:
$ awk '/^now at/ { nsec=$3; } /^jiffies/ { jiffies=$2; } END { print nsec, jiffies; system("sleep 1"); }' /proc/timer_list | awk 'NR==1 { nsec1=$1; jiffies1=$2; } /^now at/ NR>1 { nsec2=$3; } /^jiffies/ NR>1 { jiffies2=$2; } END { dsec=(nsec2-nsec1)/1e9; djiff=(jiffies2-jiffies1); print int(djiff/dsec); }' - /proc/timer_list
Due to rounding errors, the HZ value may be slightly off; you might want to perform this calculation several times and average it. Most modern kernels have kernel space HZ
set to 250
.
Here's the same command spread over several lines to clarify how it works:
$ awk '
> /^now at/ { nsec=$3; }
> /^jiffies/ { jiffies=$2; }
> END {
> print nsec, jiffies;
> system("sleep 1");
> }
> ' /proc/timer_list | awk '
> NR==1 { nsec1=$1; jiffies1=$2; }
> /^now at/ NR>1 { nsec2=$3; }
> /^jiffies/ NR>1 { jiffies2=$2; }
> END {
> dsec=(nsec2-nsec1)/1e9;
> djiff=(jiffies2-jiffies1);
> print int(djiff/dsec);
> }
> ' - /proc/timer_list
/^now at/ { nsec=$3; }
nsec
/^jiffies/ { jiffies=$2; }
jiffies
END {
print nsec, jiffies;
system("sleep 1");
' /proc/timer_list | awk '
awk
NR==1 { nsec1=$1; jiffies1=$2; }
nsec
and jiffies
values from the previous awk
to nsec1
and jiffies1
respectively/^now at/ NR>1 { nsec2=$3; }
nsec2
/^jiffies/ NR>1 { jiffies2=$2; }
jiffies2
END {
dsec=(nsec2-nsec1)/1e9;
djiff=(jiffies2-jiffies1);
print int(djiff/dsec);
' - /proc/timer_list
Provided you have busybox
installed:
T1=`grep gp_timer /proc/interrupts| busybox awk '{print$2}'`;sleep 1;T2=`grep gp_timer /proc/interrupts| busybox awk '{print$2}'`;echo $((T2-T1))