Skip to content

Conversation

@lyakh
Copy link
Collaborator

@lyakh lyakh commented Sep 29, 2025

src_get_copy_limits() only returns false if both
sink_get_free_frames(sink) and
source_get_data_frames_available(source) return 0. They are calculated in the beginning of the function, the rest of the function is calculating intermediate values, used later for sample calculation. But src_get_copy_limits(() is also called in src_process(), so inside src_is_ready_to_process() it's enough to perform a much simpler check, skipping all the calculations.

src_get_copy_limits() only returns false if both
sink_get_free_frames(sink) and
source_get_data_frames_available(source) return 0. They are
calculated in the beginning of the function, the rest of the
function is calculating intermediate values, used later for sample
calculation. But src_get_copy_limits(() is also called in
src_process(), so inside src_is_ready_to_process() it's enough to
perform a much simpler check, skipping all the calculations.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Copilot AI review requested due to automatic review settings September 29, 2025 14:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR simplifies the src_is_ready_to_process() function by replacing a call to src_get_copy_limits() with a direct check of sink and source availability. The optimization avoids unnecessary calculations since src_get_copy_limits() is already called later in src_process().

  • Replaces src_get_copy_limits() call with direct frame availability checks
  • Removes unused struct comp_data *cd variable declaration
  • Maintains the same logical behavior while improving efficiency

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

struct comp_data *cd = module_get_private_data(mod);

return src_get_copy_limits(cd, sources[0], sinks[0]);
return sink_get_free_frames(sinks[0]) || source_get_data_frames_available(sources[0]);
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The logic appears incorrect. Based on the description, src_get_copy_limits() returns false when BOTH functions return 0, which means it returns true when at least one is non-zero (OR condition). However, for processing to be ready, you typically need BOTH a source with data AND a sink with space available (AND condition). The current OR condition would return true even when the sink is full but source has data, or when sink has space but source is empty.

Suggested change
return sink_get_free_frames(sinks[0]) || source_get_data_frames_available(sources[0]);
return sink_get_free_frames(sinks[0]) && source_get_data_frames_available(sources[0]);

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in fact that was also my doubt about src_get_copy_limits() but @singalsu was sure, that it's correct...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copilot is not perfect :)

@lgirdwood
Copy link
Member

@lyakh it could do with a inline comment describing the logic.

Copy link
Collaborator

@singalsu singalsu left a comment

Choose a reason for hiding this comment

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

Thanks! Everything works, checked with testbench src_test() and MTL nocodec tplg.

@lgirdwood lgirdwood merged commit a05cb2f into thesofproject:main Oct 1, 2025
26 of 45 checks passed
@lyakh lyakh deleted the src branch October 2, 2025 06:16
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