Compare commits

...

3 commits

Author SHA1 Message Date
hujun5
54cbe462f7
Merge a98289d533 into aa0aecbd80 2025-01-12 01:36:23 +08:00
wangmingrong1
aa0aecbd80 mempool: addbacktrace should be before kasan_unpoison
If thread 1 is executing kasan_unpoison but a scheduling occurs and the block is trampled upon, the displayed backtracking may still be from the previously allocated backtracking

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-12 01:29:14 +08:00
hujun5
a98289d533 sched_processtimer: use small lock to protect g_timer_interval and g_timer_tick
reason:
We would like to replace the critical section with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-12-11 13:59:44 +08:00
2 changed files with 28 additions and 14 deletions

View file

@ -397,16 +397,17 @@ retry:
pool->nalloc++;
spin_unlock_irqrestore(&pool->lock, flags);
blk = kasan_unpoison(blk, pool->blocksize);
#ifdef CONFIG_MM_FILL_ALLOCATIONS
memset(blk, MM_ALLOC_MAGIC, pool->blocksize);
#endif
#if CONFIG_MM_BACKTRACE >= 0
mempool_add_backtrace(pool, (FAR struct mempool_backtrace_s *)
((FAR char *)blk + pool->blocksize));
#endif
blk = kasan_unpoison(blk, pool->blocksize);
#ifdef CONFIG_MM_FILL_ALLOCATIONS
memset(blk, MM_ALLOC_MAGIC, pool->blocksize);
#endif
return blk;
}

View file

@ -102,6 +102,8 @@ static clock_t g_timer_tick;
static unsigned int g_timer_interval;
static spinlock_t g_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -377,6 +379,7 @@ static clock_t nxsched_timer_process(clock_t ticks, clock_t elapsed,
static clock_t nxsched_timer_start(clock_t ticks, clock_t interval)
{
irqstate_t flags;
int ret;
if (interval > 0)
@ -388,6 +391,8 @@ static clock_t nxsched_timer_start(clock_t ticks, clock_t interval)
}
#endif
flags = enter_critical_section();
#ifdef CONFIG_SCHED_TICKLESS_ALARM
/* Convert the delay to a time in the future (with respect
* to the time when last stopped the timer).
@ -400,6 +405,8 @@ static clock_t nxsched_timer_start(clock_t ticks, clock_t interval)
ret = up_timer_tick_start(interval);
#endif
leave_critical_section(flags);
if (ret < 0)
{
serr("ERROR: up_timer_start/up_alarm_start failed: %d\n", ret);
@ -443,18 +450,18 @@ void nxsched_alarm_tick_expiration(clock_t ticks)
/* Save the time that the alarm occurred */
flags = enter_critical_section();
flags = spin_lock_irqsave_wo_note(&g_lock);
elapsed = ticks - g_timer_tick;
g_timer_tick = ticks;
leave_critical_section(flags);
spin_unlock_irqrestore_wo_note(&g_lock, flags);
/* Process the timer ticks and set up the next interval (or not) */
nexttime = nxsched_timer_process(ticks, elapsed, false);
flags = enter_critical_section();
flags = spin_lock_irqsave_wo_note(&g_lock);
g_timer_interval = nxsched_timer_start(ticks, nexttime);
leave_critical_section(flags);
spin_unlock_irqrestore_wo_note(&g_lock, flags);
}
void nxsched_alarm_expiration(FAR const struct timespec *ts)
@ -494,19 +501,19 @@ void nxsched_timer_expiration(void)
/* Get the interval associated with last expiration */
flags = enter_critical_section();
flags = spin_lock_irqsave_wo_note(&g_lock);
up_timer_gettick(&ticks);
g_timer_tick = ticks;
elapsed = g_timer_interval;
leave_critical_section(flags);
spin_unlock_irqrestore_wo_note(&g_lock, flags);
/* Process the timer ticks and set up the next interval (or not) */
nexttime = nxsched_timer_process(ticks, elapsed, false);
flags = enter_critical_section();
flags = spin_lock_irqsave_wo_note(&g_lock);
g_timer_interval = nxsched_timer_start(ticks, nexttime);
leave_critical_section(flags);
spin_unlock_irqrestore_wo_note(&g_lock, flags);
}
#endif
@ -549,6 +556,7 @@ void nxsched_timer_expiration(void)
void nxsched_reassess_timer(void)
{
irqstate_t flags;
clock_t nexttime;
clock_t ticks;
clock_t elapsed;
@ -565,13 +573,18 @@ void nxsched_reassess_timer(void)
/* Convert this to the elapsed time and update clock tickbase */
flags = spin_lock_irqsave_wo_note(&g_lock);
elapsed = ticks - g_timer_tick;
g_timer_tick = ticks;
spin_unlock_irqrestore_wo_note(&g_lock, flags);
/* Process the timer ticks and start next timer */
nexttime = nxsched_timer_process(ticks, elapsed, true);
flags = spin_lock_irqsave_wo_note(&g_lock);
g_timer_interval = nxsched_timer_start(ticks, nexttime);
spin_unlock_irqrestore_wo_note(&g_lock, flags);
}
/****************************************************************************
@ -593,9 +606,9 @@ clock_t nxsched_get_next_expired(void)
irqstate_t flags;
sclock_t ret;
flags = enter_critical_section();
flags = spin_lock_irqsave_wo_note(&g_lock);
ret = g_timer_tick + g_timer_interval - clock_systime_ticks();
leave_critical_section(flags);
spin_unlock_irqrestore_wo_note(&g_lock, flags);
return ret < 0 ? 0 : ret;
}