Skip to content

Conversation

lhenry-realtek
Copy link
Contributor

@lhenry-realtek lhenry-realtek commented Mar 18, 2025

This commit refactors peripheral object to remove kmm_free in suspend flow

The memory region is instead reused by memset to 0 and then reinitialized

@lhenry-realtek
Copy link
Contributor Author

lhenry-realtek commented Mar 18, 2025

Note: only i2c/i2s out of all other peripherals are affected due to the use of kmm_free in suspend sleep hook, thus this only addresses those 2

API Status
rtk_loguart_suspend NA
rtk_uart_suspend NA
rtk_gpio_suspend NA
rtk_i2c_suspend Affected
rtk_spi_suspend NA
rtk_i2s_suspend Affected
rtk_mipi_suspend NA
rtk_bt_suspend NA

@ewoodev
Copy link
Contributor

ewoodev commented Mar 25, 2025

Hello @lhenry-realtek,
We only need to avoid using kmm_Xalloc and kmm_free calls with sem in PG entry situations.
So, bsp peri code using static or allock doesn't matter.

How about this seperate init/deinit and suspend/resume?
I think, we don't need option using configuration.

@lhenry-realtek
Copy link
Contributor Author

lhenry-realtek commented Mar 25, 2025

Hi @ewoodev

We are thinking that maybe instead of doing free in suspend, we will instead do the following:

init flow --> check flag if not init, then do 1 time malloc. Otherwise just reuse the allocated pointer
suspend flow --> do not free, just do memset 0 only

Reason is the peripheral will lose state and registers need to be re-init when exit PG to resync the hardware, but the os driver memory side (i2c/i2s_object) do not need to malloc again

@lhenry-realtek lhenry-realtek changed the title os/arch/arm/src/amebasmart: convert peripheral object to static allocation os/arch/arm/src/amebasmart: refactor peripheral suspend flow memory management Mar 26, 2025
Copy link
Contributor

@ewoodev ewoodev left a comment

Choose a reason for hiding this comment

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

Could you please solve confict? and check edwakuwaku's comments?

…anagement

This commit refactors peripheral object to remove kmm_free in suspend flow

The memory region is instead reused by memset to 0 and then reinitialized
@@ -60,7 +60,7 @@ void i2c_send_restart(I2C_TypeDef *I2Cx, u8 *pBuf, u8 len, u8 restart);
* @retval 1: I2C1 Device.
* @retval 2: I2C2 Device.
*/
static uint32_t i2c_index_get(PinName sda)
uint32_t i2c_index_get(PinName sda)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this changes needed?

priv->initialized = true;
} else {
/* memset 0 if not required to allocate */
memset(priv->i2c_object, 0, sizeof(i2c_t));
Copy link
Contributor

Choose a reason for hiding this comment

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

The i2c_t has just two members with 32 bit size of each. Then, just allocating 0 or null will be much faster than memset which is working with 8 bit. How do you think?

@@ -242,6 +242,9 @@ static const struct amebasmart_i2s_config_s amebasmart_i2s3_config = {
.txenab = 0,
};
#endif

static u8 g_i2s_inited[I2S_NUM_MAX];
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it impossible to follow the same way with i2c?

@sunghan-chang
Copy link
Contributor

@lhenry-realtek Because I are much much urgent, let me merge it now. Please check my comments at next Monday.

@sunghan-chang sunghan-chang merged commit 1dd1ae3 into Samsung:master Apr 18, 2025
11 checks passed
@sunghan-chang
Copy link
Contributor

@lhenry-realtek This PR is not working.. When i2cuninitialize is called, then even we call i2cinitialize, i2c is not working. Because of your new variable, other necessary operation in i2cinitialize is not called.
Did you really verify this??

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