-
Notifications
You must be signed in to change notification settings - Fork 618
compression: Replace global variables with per-fd context #6913
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
base: master
Are you sure you want to change the base?
compression: Replace global variables with per-fd context #6913
Conversation
os/drivers/compression/compress.c
Outdated
| comp_semtake(&dev->exclsem); | ||
| if (dev->refs) { | ||
| comp_semgive(&dev->exclsem); | ||
| return -EMFILE; // We allow only 1 ref count; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
os/drivers/compression/compress.c
Outdated
| { | ||
| struct comp_dev_s *dev = filep->f_inode->i_private; | ||
|
|
||
| if (!dev) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
os/drivers/compression/compress.c
Outdated
|
|
||
| struct comp_dev_s { | ||
| bool refs; | ||
| sem_t exclsem; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I checked. Thank you. |
8e61fd1 to
85b15b0
Compare
os/drivers/compression/compress.c
Outdated
| }; | ||
|
|
||
| struct comp_dev_s { | ||
| sem_t sem; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for check.
85b15b0 to
4769ae5
Compare
os/drivers/compression/compress.c
Outdated
| DEBUGASSERT(dev != NULL); | ||
|
|
||
| comp_semtake(&dev->sem); | ||
| if (dev->crefs == (uint8_t)255) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
bbd03dc to
9315c58
Compare
os/drivers/compression/compress.c
Outdated
| { | ||
| (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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
9315c58 to
fcd08c8
Compare
928bea9 to
851d16d
Compare
os/drivers/compression/compress.c
Outdated
| ****************************************************************************/ | ||
| void compress_register(void) | ||
| { | ||
| initialize_comp_ctx_list(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
1cbf808 to
1e95268
Compare
1e95268 to
45b9603
Compare
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]>
45b9603 to
6f002e7
Compare
There was a problem hiding this 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?
I'll add test case for compression drivers concurrently with new commit. |
|
Hello, @kishore-sn |
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