Compare commits

...

3 commits

Author SHA1 Message Date
Huang Qi
ed37e966b9
Merge d96ed13cbd into aa0aecbd80 2025-01-12 01:36:34 +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
Huang Qi
d96ed13cbd risc-v: Accelerate schedule by percpu
Fetch TCB info in percpu scratch register for better performance.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-12-20 11:26:07 +08:00
3 changed files with 36 additions and 5 deletions

View file

@ -702,6 +702,29 @@ irqstate_t up_irq_enable(void);
int up_cpu_index(void) noinstrument_function;
/****************************************************************************
* Schedule acceleration macros
****************************************************************************/
/* If RISCV_PERCPU_SCRATCH is not enabled, we can use the scratch register
* to store the current task pointer.
*/
#ifndef CONFIG_RISCV_PERCPU_SCRATCH
#define up_this_task() \
({ \
struct tcb_s *t; \
t = (struct tcb_s *)READ_CSR(CSR_SCRATCH); \
t; \
})
#define up_update_task(t) WRITE_CSR(CSR_SCRATCH, (uintptr_t)t)
#else
/* TODO: Implement up_this_task()/up_update_task() if RISCV_PERCPU_SCRATCH
* enabled.
*/
#endif
/****************************************************************************
* Name: up_this_cpu
*

View file

@ -37,6 +37,8 @@
#include <nuttx/spinlock.h>
#include <nuttx/sched_note.h>
#include <arch/irq.h>
#include "sched/sched.h"
#include "init/init.h"
#include "riscv_internal.h"
@ -69,6 +71,8 @@
void riscv_cpu_boot(int cpu)
{
struct tcb_s *tcb;
/* Clear IPI for CPU(cpu) */
riscv_ipi_clear(cpu);
@ -100,8 +104,9 @@ void riscv_cpu_boot(int cpu)
sinfo("CPU%d Started\n", this_cpu());
tcb = current_task(this_cpu());
#ifdef CONFIG_STACK_COLORATION
struct tcb_s *tcb = this_task();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
@ -111,6 +116,8 @@ void riscv_cpu_boot(int cpu)
riscv_stack_color(tcb->stack_alloc_ptr, 0);
#endif
up_update_task(tcb);
/* TODO: Setup FPU */
/* Clear machine software interrupt for CPU(cpu) */

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;
}