Skip to content

interpreters/bas: Convert clock() with CLOCKS_PER_SEC in TIME. - #3906

Open
casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:i-clk-tck-bas-up
Open

casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:i-clk-tck-bas-up

Conversation

@casaroli

Copy link
Copy Markdown
Contributor

Summary

The TIME function of bas (fn_timei() in interpreters/bas/bas_global.c) divides clock() by CLK_TCK. CLK_TCK is the system tick rate, but clock() counts in CLOCKS_PER_SEC units. In NuttX both are the tick rate today, so the result is correct, but the code uses the wrong constant. This PR divides by CLOCKS_PER_SEC.

This is the bas part of the CLOCKS_PER_SEC series of the dev@ thread "[DISCUSS] Breaking change: make CLOCKS_PER_SEC 1000000" (https://lists.apache.org/thread/bqxry570g9t63j63zmk4c5l82lybtx4s). #3904 (step 1, the other apps) and apache/nuttx#20923 (step 2) are merged. This PR does not need either of them.

Impact

None today. The object code does not change (see Testing). The result stays correct if CLOCKS_PER_SEC changes. Not a breaking change.

Testing

qemu-armv8a:nsh with CONFIG_INTERPRETERS_BAS=y, built with apps master and with this PR. bas_global.o compared with objdump -dr (code and relocations) and objdump -s (all sections except debug information): the only difference is the line number of three assert() calls after the change, because the new line break adds one line. fn_timei() and all data are the same. (The build needs -Wno-error on master too: bas_statement.c has older -Werror=array-bounds errors with GCC 14.)

Style check: tools/checkpatch.sh -c -u -m -g checks the whole of bas_global.c and reports 1045 errors, the same number as on master. 1020 of them are mixed-case identifiers of the third-party bas code (for example Value_new_INTEGER()), which a whitespace commit cannot fix; the others are older alignment and brace errors. The changed lines add no error.

The TIME function (fn_timei()) divided clock() by CLK_TCK, the system
tick rate.  clock() counts in CLOCKS_PER_SEC units, which is the tick
rate in NuttX today.

Divide by CLOCKS_PER_SEC.  The result does not change today, and stays
correct if CLOCKS_PER_SEC changes.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@casaroli casaroli closed this Oct 24, 2026
@casaroli casaroli reopened this Oct 24, 2026
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

let's ignore style error since the foreign code base don't follow nuttx style and ci error which is fixed by apache/nuttx#20949 instead wasting ci resource by retrigger.

@cederom

cederom commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

@xiaoxiang781216: let's ignore style error since the foreign code base don't follow nuttx style and ci error which is fixed by apache/nuttx#20949 instead wasting ci resource by retrigger.

@jerpelea what do you think can we do that or would that mess up backporting later on? :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants