Hi Biju, CC clk On Mon, Oct 14, 2019 at 9:46 AM Biju Das <biju.das@xxxxxxxxxxxxxx> wrote: > I have further investigated this issue, please find my findings below > > The "cpg_z_clk_round_rate" function is called 2 times from "dev_pm_opp_set_rate" (1 is direct call and other through "clk_set_rate") function. > > For 500000000 frequency, after doing math operation(mult = div_u64(rate * 32ULL, prate);), it gets a factor 10--> 10.66 truncated to 10 and the frequency returned by the system is 468748125 > > On the second " cpg_z_clk_round_rate ", the below function make the value to worse, it gets a value of 9.9999, since it is integer division it is truncated to 9. > mult = div_u64(rate * 32ULL, prate); > > Now the frequency 468748125, after doing math operation becomes 421874 KHz. This is the problem. > > So I think the div_64 is wrong here, Instead we could go with DIV64_U64_ROUND_CLOSEST. > > With "DIV64_U64_ROUND_CLOSEST" the factor is 10.66 which is rounded to 11. > > So for 500000, after math operation, it becomes 515624 > > Please share your opinion this issue. I don't know what's the best way to solve this. Rounding instead of truncating may lead to programming a too high clock frequency, which might damage the hardware. Please note that the current code no longer uses div_u64(), but div64_ul() instead, which should have no impact on your findings. > > -----Original Message----- > > From: Biju Das > > Sent: Thursday, September 19, 2019 11:49 AM > > To: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>; Simon Horman > > <horms@xxxxxxxxxxxx>; linux-renesas-soc@xxxxxxxxxxxxxxx; Dien Pham > > <dien.pham.ry@xxxxxxxxxxxxxxx>; TAKESHI KIHARA > > <takeshi.kihara.df@xxxxxxxxxxx>; Niklas Söderlund > > <niklas.soderlund+renesas@xxxxxxxxxxxx> > > Subject: Regarding CPU frequency reported by Salvator-X board > > > > Hi All, > > > > I started testing frequency mentioned in OPP table with M3-W1.1 Salvator-X > > board (NOT salvator-XS) using user space governor > > > > The actual frequency reported for 0.5GHz(500000 KHz) is too much deviated > > from the target frequency [INFO] Target frequency: 500000 KHz [INFO] > > Actual frequency: 421874 KHz > > > > But if I change the extal value, as per the board schematic (16.6666MHz), the > > value is some what closer to target frequency. > > &extal_clk { > > - clock-frequency = <16666666>; > > + clock-frequency = <16666600>; > > }; > > [INFO] Target frequency: 500000 KHz > > [INFO] Actual frequency: 468748 KHz > > > > Q1) Have any one seen this issue? Please share your thoughts on this issue. > > > > Note:- > > I am not seeing this issue on Salvator-XS board, where the extal_clk value= > > 16640000(16.64MHz). > > > > Please see the logs > > with clock-frequency = <16666666>; > > ----------------------------------------------- > > root@salvator-x:/cip-test-scripts# ./opp_t_001.sh [INFO] Testing cpufreq for > > policy: > > [INFO] /sys/devices/system/cpu/cpufreq/policy0 > > [INFO] > > [INFO] CPUs affected: > > [INFO] 0 1 > > [INFO] > > [INFO] Available frequencies: > > [INFO] 500000 1000000 1500000 > > [INFO] > > [INFO] Target frequency: 500000 KHz > > [INFO] Actual frequency: 421874 KHz > > [INFO] > > [INFO] Target frequency: 1000000 KHz > > [INFO] Actual frequency: 937499 KHz > > [INFO] > > [INFO] Target frequency: 1500000 KHz > > [INFO] Actual frequency: 1499999 KHz > > [INFO] > > [INFO] Testing cpufreq for policy: > > [INFO] /sys/devices/system/cpu/cpufreq/policy2 > > [INFO] > > [INFO] CPUs affected: > > [INFO] 2 3 4 5 > > [INFO] > > [INFO] Available frequencies: > > [INFO] 800000 1000000 1200000 > > [INFO] > > [INFO] Target frequency: 800000 KHz > > [INFO] Actual frequency: 749999 KHz > > [INFO] > > [INFO] Target frequency: 1000000 KHz > > [INFO] Actual frequency: 974999 KHz > > [INFO] > > [INFO] Target frequency: 1200000 KHz > > [INFO] Actual frequency: 1199999 KHz > > > > With clock-frequency = <16666600> > > ---------------------------------------------- > > root@salvator-x:/cip-test-scripts# ./opp_t_001.sh [INFO] Testing cpufreq for > > policy: > > [INFO] /sys/devices/system/cpu/cpufreq/policy0 > > [INFO] > > [INFO] CPUs affected: > > [INFO] 0 1 > > [INFO] > > [INFO] Available frequencies: > > [INFO] 500000 1000000 1500000 > > [INFO] > > [INFO] Target frequency: 500000 KHz > > [INFO] Actual frequency: 468748 KHz > > [INFO] > > [INFO] Target frequency: 1000000 KHz > > [INFO] Actual frequency: 937496 KHz > > [INFO] > > [INFO] Target frequency: 1500000 KHz > > [INFO] Actual frequency: 1499994 KHz > > [INFO] > > [INFO] Testing cpufreq for policy: > > [INFO] /sys/devices/system/cpu/cpufreq/policy2 > > [INFO] > > [INFO] CPUs affected: > > [INFO] 2 3 4 5 > > [INFO] > > [INFO] Available frequencies: > > [INFO] 800000 1000000 1200000 > > [INFO] > > [INFO] Target frequency: 800000 KHz > > [INFO] Actual frequency: 787496 KHz > > [INFO] > > [INFO] Target frequency: 1000000 KHz > > [INFO] Actual frequency: 974996 KHz > > [INFO] > > [INFO] Target frequency: 1200000 KHz > > [INFO] Actual frequency: 1199995 KHz > > > > Regards, > > Biju > > > -- Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds