Repository navigation
ram: keep a total that is already a power of two - #269
Conversation
rounded_num() counts the halvings it takes to reach zero and returns 1 << that count, so an exact power of two comes back doubled: 512 -> 1024. A kernel MemTotal is never one, which is why it never showed, but since OpenIPC#268 the Ambarella total is the top of the DSP carve-out, and on the S3L camera from OpenIPC#266 that is exactly 512M (0x07800000 + 0x18800000). Both stock and OpenIPC kernels reported `total: 1024M` there. Return n unchanged when it is already a power of two. backup.c rounds its total with the same function and gets the same fix. ambarella_test now covers the 512M case, a 114940 kB MemTotal (112 -> 128), 513 -> 1024 and 1 -> 1; without the fix the 512M and 1 cases fail.
PR Summary by QodoPreserve RAM totals that are already powers of two
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can switch off images and animations for a plain-text comment |
openipc-ai
left a comment
There was a problem hiding this comment.
This is correct, thanks for finding it. I wrote in #268 that this camera should report 512M without checking the rounding in ram.c, and I'm glad your test caught it.
Verified at this commit:
rounded_num()has two callers,ram.candbackup.c.- Across 0 to 4999, the only values that change are exact powers of two; everything else rounds as before. 0 still gives 1.
ambarella_test,anyka_test,longse_test,reginfo_test,sensors_testandhal_hisi_testall pass.- With the fix removed, the 512M and
1checks fail, as you describe.
Behaviour change to be aware of: this isn't Ambarella-only. Any HAL whose total lands exactly on a power of two was doubled too, and now reports the true figure. For backup.c, that is the value it writes when setTotalMem is set. Both are the correct result.
Follow-up to #268, from the testing in #266.
rounded_num()counts the halvings it takes to reach zero and returns1 << count, so an exact power of two comes back doubled:rounded_num(512)is 1024. A kernelMemTotalis never a power of two, so this never showed. Since #268, though, the Ambarella total is the top of the DSP carve-out, and on the S3L camera in #266 that is exactly 512 MiB (0x07800000 + 0x18800000).ambarella_totalmem()returns the right 524288 KiB; the doubling happens inram.c's rounding.The fix returns
nunchanged when it is already a power of two.backup.crounds its total with the same function and gets the same fix.Testing
ambarella_testgains checks for the 512M case, a 114940 kB MemTotal (112 → 128), 513 → 1024 and 1 → 1. Without the fix the 512M and 1 cases fail; with it all pass.toolchain.hisilicon-hi3516cv100, musl) and packed with UPX 4.2.3 as inrelease.yml:latest(7c51a7e)IAVMEMfrom the boot log)total: 1024M,media: 392Mtotal: 512M,media: 392M/proc/device-tree/iavmem/reg)total: 1024M,media: 392Mtotal: 512M,media: 392M