Schorschi
Posts: 245
Joined: Thu Nov 22, 2012 9:38 pm

Odd result from node.js os module for processor speed?

Thu Jun 25, 2020 4:43 am

I have been trying to resolve why the node.js os module returns what appears to be half of the maximum processor speed. For example on a raspberry pi 4, the maximum processor speed is 1500, but as noted the os module reports only 750. I know for a fact this is not the current frequency which is 600:

# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
1500000
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
600000
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
600000

Whereas...

var theOS = require('os');
var theProcessors = theOS.cpus();

Buried in object structure returned in theProcessors variable...

array[4]
0: object
model: "ARMv7 Processor rev 3 (v7l)"
speed: 750
times: object
1: object
2: object
3: object

Anyone know why this is the case?

Schorschi
Posts: 245
Joined: Thu Nov 22, 2012 9:38 pm

Re: Odd result from node.js os module for processor speed?

Thu Jun 25, 2020 4:58 am

Never mind... I figured out what was going on... the OS module ONLY reports the current frequency. After setting up a loop and polling the results, it started to align with the cpu frequency current value from query of the sys object structure. Mystery solved. Because the processor was scaling down (since it was under a light load) it was like trying to catch a greased pig, always moving, hard to pin down, so to speak.

Return to “General discussion”