-->
Page 1 of 2

Increase CPU Frequency

PostPosted: Sat Jan 24, 2015 5:03 pm
by Fr4gg0r
Code: Select allstatic int node_set_cpu_freq( lua_State* L )
{
  uint32_t new_freq = luaL_checkinteger( L, 1 );
  if(new_freq == 160){
    REG_SET_BIT(0x3ff00014, BIT(0));
    os_update_cpu_frequency(160);
  }else{
    REG_CLR_BIT(0x3ff00014, BIT(0));
    os_update_cpu_frequency(80);
  }
  new_freq = ets_get_cpu_frequency();
  lua_pushinteger(L, new_freq);
  return 1;
}


This is supposed to increase cpu freq from 80 to 160. However, I do not see any differences in execution speed with the following benchmark:
Code: Select allfunction runOnce(freq)
sum = 0
node.set_cpu_freq(freq)
for runs=0,4 do

  now=tmr.now()
  a = 0
  b = 2
  c = 1
for ii=0,10 do
  for i=0,1000 do
    a = i+b
    c = bit.bxor(c, 1)
    tmr.wdclr()
    node.set_cpu_freq(freq)
  end
end

  nnow = tmr.now()
  timeDiff = (nnow-now)/1000
  sum = sum + timeDiff
 
  print("time needed: " .. timeDiff )
end
print("total time needed: " .. sum)
end


print("======================")
freq=node.setcpufreq(80)
print("Setting CPU FREQUENCY TO " .. freq .. "MHz")
runOnce(80)
print("======================")

print("======================")
freq=node.setcpufreq(160)
print("Setting CPU FREQUENCY TO " .. freq .. "MHz")
runOnce(160)
print("======================")


Maybe someone else has an idea? tmr.now() is supposed to return the system time in micro seconds. Maybe the system time runs faster at 160MHz?

Re: Increase CPU Frequency

PostPosted: Tue Feb 03, 2015 1:02 am
by raz123
1. Have you seen this post? viewtopic.php?p=8107#p8107 -- he claims that he has seen an improvement in speed. If you build it with 160 Mhz, especially if you implement it as part of a function, I'd love to test it :)

2. "SDK periodically disables 160MHz."

3. Unrelated, but are you sure that you shouldn't be clearing the bit, here?
Code: Select all}else{
    REG_SET_BIT(0x3ff00014, BIT(0));

Re: Increase CPU Frequency

PostPosted: Tue Feb 03, 2015 1:00 pm
by Fr4gg0r
pvvx claims a lot ;)

However, thanks for the finding. Now it works. It is indeed a lot faster. Someone with a good multimeter should compare the power consumption. For most users 160Mhz as default seems to be adequate.
Code: Select all> dofile("benchmark.lua")
======================
Setting CPU FREQUENCY TO 80MHz
time needed: 2118
time needed: 2118
time needed: 2118
time needed: 2118
time needed: 2118
total time needed: 10590
======================
======================
Setting CPU FREQUENCY TO 160MHz
time needed: 1059
time needed: 1059
time needed: 1059
time needed: 1059
time needed: 1059
total time needed: 5295
======================


You can test it here: https://github.com/jrahlf/nodemcu-firmw ... master/bin
Someone else can make a pull request, I can't. xD

Re: Increase CPU Frequency

PostPosted: Thu Feb 05, 2015 2:57 am
by Markus Gritsch
I would very much like to have this in the official version.