Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xrun: storage: fix xrun_file_read_debounce() to return read bytes #97

Merged
merged 2 commits into from
Jul 23, 2024

Conversation

GrygiriiS
Copy link

This PR fixes:

  • xrun: storage: fix xrun_file_read_debounce() to return read bytes
  • CONFIG_XRUN_STORAGE_DMA_DEBOUNCE default value to be set only for RPI5.

@@ -43,10 +43,14 @@ static int xrun_file_read_debounce(struct fs_file_t *file, uint8_t *buf, size_t
LOG_DBG("file count %zd read %zd", count, read);
count -= read;
buf += read;
if (count && read < sizeof(debounce_buf)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can just check for read==0 as this is the indication that read_fs reached end of file. At least this stands true for POSIX read() function ...

Copy link
Author

Choose a reason for hiding this comment

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

Not sure what you mean - Zephyr doc says https://docs.zephyrproject.org/apidoc/latest/group__file__system__api.html#gaba7e07127777187eedcd6976d352ab76

A returned value may be lower than size if there were fewer bytes available than requested.

And it sounds logically correct - file size is 5K. buf size is 4K. Read request is 8K (for example)

  • first read gets 4K.
  • second read 1K. But not 0.
  • total 5K

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I was looking at POSIX docs, which add more context:

        On success, the number of bytes read is returned (zero indicates end of file), and the file position is advanced by this number.  It is not an error if this number is smaller than the
       number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we are reading from
       a pipe, or from a terminal), or because read() was interrupted by a signal. 

and

 If the file offset is at or past the
 end of file, no bytes are read, and read() returns zero.

Honestly, I don't know how much this is applicable to Zephyr, but I expect that they plan basically the behaviour: ret = 0 indicates EOF and ret > 0 indicates that there still be might more data.

Copy link
Author

Choose a reason for hiding this comment

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

Actually it's working as described above:

  • file_pos is close to EOF. ret = EOF - file_pos
  • file_pos is at EOF. ret = 0

xrun/Kconfig Outdated
@@ -47,7 +47,8 @@ config XRUN_IRQS_MAX

config XRUN_STORAGE_DMA_DEBOUNCE
int "Set debounce buffer for FS storage access in KB"
default 4
default 4 if BOARD_RPI_5
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't want zephyr-xenlib to know about specific board(s). This is dependency in wrong direction. Please remove this change.

Copy link
Author

Choose a reason for hiding this comment

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

Ok. But here to options possible:

  1. Set it to 0 by default. and fix dom0-xt for RPI5
  2. Keep as is - but rcar don't need it

?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Option 1, as it will not break existing setups.
Also, this feature is only required on boards with not IO-MMU, which are rare. So it should be disabled in most cases.

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@GrygiriiS GrygiriiS force-pushed the xenlib-fs_read_fix branch from e9a37f7 to 3b4d59a Compare July 23, 2024 06:48
Copy link
Collaborator

@firscity firscity left a comment

Choose a reason for hiding this comment

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

Acked-by: Dmytro Firsov <[email protected]>

@al1img
Copy link

al1img commented Jul 23, 2024

Tested-by: Oleksandr Grytsov <[email protected]>

Grygorii Strashko added 2 commits July 23, 2024 12:35
The xrun_file_read_debounce() should work the same way as fs_read() and so
return number of read bytes on success. A returned value may be lower than
size if there were fewer bytes available than requested.

Hence fix xrun_file_read_debounce() to follow fs_read() approach.

Signed-off-by: Grygorii Strashko <[email protected]>
Acked-by: Dmytro Firsov <[email protected]>
Tested-by: Oleksandr Grytsov <[email protected]>
The XRUN_STORAGE_DMA_DEBOUNCE is needed only for RPI5 for now, so set
default value to 0.

Signed-off-by: Grygorii Strashko <[email protected]>
Acked-by: Dmytro Firsov <[email protected]>
Tested-by: Oleksandr Grytsov <[email protected]>
@GrygiriiS GrygiriiS force-pushed the xenlib-fs_read_fix branch from 3b4d59a to 0454386 Compare July 23, 2024 09:35
Copy link
Collaborator

@lorc lorc left a comment

Choose a reason for hiding this comment

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

Reviewed-by: Volodymyr Babchuk <[email protected]>

@firscity firscity merged commit 8619124 into xen-troops:main Jul 23, 2024
5 checks passed
@GrygiriiS GrygiriiS deleted the xenlib-fs_read_fix branch July 25, 2024 07:44
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.

4 participants