Skip to content

Conversation

@seokhun-eom24
Copy link
Contributor

@seokhun-eom24 seokhun-eom24 commented Jul 30, 2025

Previous, global variables were used for compress_read from file.
compress_read can be called without compress_init when global variables were set by other fd's compress_init.
And when multiple files call compress_read, it caused a problem that the previous fd's state was affected by the current fd's state.

This patch replaces global variables with per-fd context to prevent this problem.
Maintain all live contexts in a dq_queue_t with helpers to find/add/remove by fd.
Store the comp_ctx in the driver's filep->f_priv for the opened fd.
Driver's ioctl args are not changed.
This patch enables concurrent decompression by eliminating global varialbe and isolating each operation's context.

Additionaly adds explicit comp_open() and comp_close() functions for drivers.

API changes in compress_read.h

  1. compress_uninit(void) → compress_uninit(int filfd)
  2. get_compression_header(void) → get_compression_header(int filfd)
  3. New: initialize_comp_ctx_list(void) (called once during system init)

comp_semtake(&dev->exclsem);
if (dev->refs) {
comp_semgive(&dev->exclsem);
return -EMFILE; // We allow only 1 ref count;
Copy link
Contributor

Choose a reason for hiding this comment

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

lzma and miniz allow multiple calling.
we don't need to block this driver

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.
I'll fix it and modify compress_read.c too.

Copy link
Contributor

@Taejun-Kwon Taejun-Kwon left a comment

Choose a reason for hiding this comment

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

VFS layer already check validation of fileep in fs_ioctl, so you can remove all DEBUGASSERT(filep) from ioctl.

{
struct comp_dev_s *dev = filep->f_inode->i_private;

if (!dev) {
Copy link
Contributor

Choose a reason for hiding this comment

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

EINVAL is not proper value here.
You can add DEBUGASSERT(dev != NULL), comp_dev_s must be added when driver registered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


struct comp_dev_s {
bool refs;
sem_t exclsem;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can add 'int running' here.
Then you can use it as below.

	case COMPIOC_FCOMP_INIT:
		if ((char *)arg == NULL) {
			return -EINVAL;
		}
		if (dev->running) {
			return -EBUSY;
		}
		...
		break;
	case COMPIOC_FCOMP_DEINIT:
		if (!dev->running) {
			return -EACCES; //or -EIO
		}

Also instead of refs, I think 'reserved' is better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.
I will refer to the code when I edit it later.

@seokhun-eom24
Copy link
Contributor Author

VFS layer already check validation of fileep in fs_ioctl, so you can remove all DEBUGASSERT(filep) from ioctl.

I checked. Thank you.

@seokhun-eom24 seokhun-eom24 force-pushed the 250730-add-compress-drive-open-close branch 3 times, most recently from 8e61fd1 to 85b15b0 Compare July 30, 2025 05:55
};

struct comp_dev_s {
sem_t sem;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please include header for semaphore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for check.

@seokhun-eom24 seokhun-eom24 force-pushed the 250730-add-compress-drive-open-close branch from 85b15b0 to 4769ae5 Compare July 30, 2025 07:49
DEBUGASSERT(dev != NULL);

comp_semtake(&dev->sem);
if (dev->crefs == (uint8_t)255) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change this to UINT8_MAX or use defined value like COMP_REF_MAX

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed using COMP_CREF_MAX.

@seokhun-eom24 seokhun-eom24 force-pushed the 250730-add-compress-drive-open-close branch 2 times, most recently from bbd03dc to 9315c58 Compare July 30, 2025 10:01
{
(void)register_driver(COMP_DRVPATH, &compress_fops, 0666, NULL);
int ret;
struct comp_dev_s *dev = (struct comp_dev_s *)kmm_malloc(sizeof(struct comp_dev_s));
Copy link
Contributor

Choose a reason for hiding this comment

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

crefs initialization is missing.
Please change kmm_malloc to kmm_zalloc or initialize crefs to 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll fix this. Thank you.

@seokhun-eom24 seokhun-eom24 marked this pull request as draft July 31, 2025 22:13
@seokhun-eom24 seokhun-eom24 force-pushed the 250730-add-compress-drive-open-close branch from 9315c58 to fcd08c8 Compare August 4, 2025 03:46
@seokhun-eom24 seokhun-eom24 marked this pull request as ready for review August 4, 2025 03:46
@seokhun-eom24 seokhun-eom24 force-pushed the 250730-add-compress-drive-open-close branch 3 times, most recently from 928bea9 to 851d16d Compare August 4, 2025 04:49
@seokhun-eom24 seokhun-eom24 changed the title drivers/compression: implement comp_open, comp_close compression: Replace global variables with per-fd context Aug 4, 2025
****************************************************************************/
void compress_register(void)
{
initialize_comp_ctx_list();
Copy link
Contributor

@jeongarmy jeongarmy Aug 7, 2025

Choose a reason for hiding this comment

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

I think we need to set flag to check initialization. If compress_register is called multiple times during running by mistake, an assert or error seems to be occured because of dq_init.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed to avoid double initialization.

@seokhun-eom24 seokhun-eom24 force-pushed the 250730-add-compress-drive-open-close branch 2 times, most recently from 1cbf808 to 1e95268 Compare August 11, 2025 00:20
@seokhun-eom24 seokhun-eom24 force-pushed the 250730-add-compress-drive-open-close branch from 1e95268 to 45b9603 Compare August 20, 2025 07:50
@seokhun-eom24 seokhun-eom24 marked this pull request as draft August 21, 2025 05:30
Previous, global variables were used for compress_read from file.
compress_read can be called without compress_init when global variables were set by other fd's compress_init.
And when multiple files call compress_read, it caused a problem that the previous fd's state was affected by the current fd's state.

This patch replaces global variables with per-fd context to prevent this problem.
Maintain all live contexts in a dq_queue_t with helpers to find/add/remove by fd.
Store the comp_ctx in the driver's filep->f_priv for the opened fd.
Driver's ioctl args are not changed.
This patch enables concurrent decompression by eliminating global varialbe and isolating each operation's context.

Additionaly adds explicit comp_open() and comp_close() functions for drivers.

* API changes in compress_read.h
1. compress_uninit(void) → compress_uninit(int filfd)
2. get_compression_header(void) → get_compression_header(int filfd)
3. New: initialize_comp_ctx_list(void) (called once during system init)

Signed-off-by: seokhun-eom <[email protected]>
@seokhun-eom24 seokhun-eom24 force-pushed the 250730-add-compress-drive-open-close branch from 45b9603 to 6f002e7 Compare August 21, 2025 06:03
@seokhun-eom24 seokhun-eom24 marked this pull request as ready for review August 21, 2025 06:35
Copy link
Contributor

@sunghan-chang sunghan-chang left a comment

Choose a reason for hiding this comment

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

@seokhun-eom24 Could you leave how to verify the change in commit description?

@seokhun-eom24
Copy link
Contributor Author

seokhun-eom24 commented Aug 29, 2025

@seokhun-eom24 Could you leave how to verify the change in commit description?

I'll add test case for compression drivers concurrently with new commit.

@seokhun-eom24
Copy link
Contributor Author

Hello, @kishore-sn
Can you review this PR?

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.

5 participants