Skip to content

crc_funcs_perf: Fix for Anomalous Data Under LTO Optimization - #434

Closed
zl523856 wants to merge 1 commit into
intel:masterfrom
zte-riscv:crc_funcs_perf
Closed

zl523856 wants to merge 1 commit into
intel:masterfrom
zte-riscv:crc_funcs_perf

Conversation

@zl523856

@zl523856 zl523856 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Under LTO optimization, the crc_funcs_perf benchmark produced anomalous results for crc16_t10dif_copy. The function was inlined by the compiler, but since its return value was unused, the entire CRC computation logic was optimized away. Fix this by storing the returned value into a volatile variable, which prevents the compiler from eliminating the computation.

Verification by running ./crc/crc_funcs_perf on Spacemit(R) X100:
Before fix:
crc16_t10dif_copy : runtime = 3061974 usecs, bandwidth 65783 MB in 3.0620 sec = 21484.12 MB/s
After fix:
crc16_t10dif_copy : runtime = 3076511 usecs, bandwidth 822 MB in 3.0765 sec = 267.32 MB/s

@zl523856

Copy link
Copy Markdown
Contributor Author

I submitted this PR a while ago and would appreciate it if you could trigger the CI and take a look when you have a chance. Thanks! @pablodelara

@pablodelara

Copy link
Copy Markdown
Contributor

Hi @zl523856. Apologies for the delay. CI is triggered now. @tkanteck is the new maintainer, as I have left the company and therefore, this project.

Comment thread crc/crc_funcs_perf.c Outdated
crc16_t10dif_copy(TEST_SEED, dst_buf, buffer, len));
crc = crc16_t10dif_copy(TEST_SEED, dst_buf, buffer, len));
}
printf("finish 0x%x\n", crc);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this printf() required?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this printf() required?
Yes, the printf() call is used following the same pattern as in crc16_t10dif_copy_perf.c to print the output of crc16_t10dif_copy, thereby preventing LTO from optimizing away the CRC computation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I see - the printf prevents the code from being optimized out. Would it be possible to explore other options instead of printf? i.e. would declaring crc as volatile help instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I see - the printf prevents the code from being optimized out. Would it be possible to explore other options instead of printf? i.e. would declaring crc as volatile help instead?

I've made the changes as you suggested. Could you please review it again? Thank you!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

Under LTO optimization, the crc_funcs_perf benchmark produced anomalous results for crc16_t10dif_copy. The function was inlined by the compiler, but since its return value was unused, the entire CRC computation logic was optimized away. Fix this by storing the returned value into a volatile variable, which prevents the compiler from eliminating the computation.

Verification by running ./crc/crc_funcs_perf on Spacemit(R) X100:
Before fix:
crc16_t10dif_copy : runtime =    3061974 usecs, bandwidth 65783 MB in 3.0620 sec = 21484.12 MB/s
After fix:
crc16_t10dif_copy : runtime =    3076511 usecs, bandwidth 822 MB in 3.0765 sec = 267.32 MB/s

Signed-off-by: zhoulu <zhou.lu1@zte.com.cn>

@tkanteck tkanteck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@tkanteck tkanteck added the wip work in progress label Nov 9, 2026
@tkanteck

Copy link
Copy Markdown
Contributor

Thanks. It's merged now

@tkanteck tkanteck closed this Nov 10, 2026
@tkanteck tkanteck removed the wip work in progress label Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants