Compare commits

...

6 commits

Author SHA1 Message Date
hujun5
ea03bf558d
Merge f14378a83a into a2d4d74af7 2025-01-12 16:53:25 +08:00
hujun5
a2d4d74af7 clock_timekeeping: remove enter_critical_section in sched/clock/clock_timekeeping.c
reason:
We would like to replace the critical section with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-12 16:51:40 +08:00
wangmingrong1
2149d89336 macro/align: Use ALIGN_UP and ALIGN_DOWN uniformly
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-12 16:48:35 +08:00
Yanfeng Liu
71a4e86718 risc-v/Toolchain.defs: guard -r in LDELFFLAGS
This guards use of `-r` in LDELFFLAGS in risc-v common/Toolchain.defs so
that it is only used when BINFMT_ELF_RELOCATABLE is selected.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2025-01-12 16:47:54 +08:00
hujun5
f14378a83a sched/wdog: use small lock to protect g_wdactivelist
reason:
We would like to replace the critical section with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-12 16:14:43 +08:00
hujun5
86d6a0be6f irq: enter_critical_section_wo_note/leave_critical_section_wo_note
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-12 16:14:43 +08:00
19 changed files with 171 additions and 121 deletions

View file

@ -1103,7 +1103,7 @@ static void imx9_lpi2c_setclock(struct imx9_lpi2c_priv_s *priv,
&src_freq);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
*
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/

View file

@ -1161,7 +1161,7 @@ static void imxrt_lpi2c_setclock(struct imxrt_lpi2c_priv_s *priv,
#endif
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
*
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/

View file

@ -1010,7 +1010,7 @@ static void s32k1xx_lpi2c_setclock(struct s32k1xx_lpi2c_priv_s *priv,
DEBUGASSERT(src_freq != 0);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
*
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/

View file

@ -990,7 +990,7 @@ static void s32k3xx_lpi2c_setclock(struct s32k3xx_lpi2c_priv_s *priv,
DEBUGASSERT(src_freq != 0);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
*
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/

View file

@ -1122,7 +1122,7 @@ static void imx9_lpi2c_setclock(struct imx9_lpi2c_priv_s *priv,
imx9_get_rootclock(priv->config->clk_root, &src_freq);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
*
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/

View file

@ -433,7 +433,12 @@ LDMODULEFLAGS = -r -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/modlib/gnu-elf.ld)
CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden
LDELFFLAGS = -r -e main
LDELFFLAGS = -e main
ifeq ($(CONFIG_BINFMT_ELF_RELOCATABLE),y)
LDELFFLAGS += -r
endif
ifeq ($(CONFIG_ARCH_RV32),y)
LDELFFLAGS += --oformat elf32-littleriscv
else

View file

@ -31,18 +31,13 @@
#include <errno.h>
#include <nuttx/kmalloc.h>
#include <nuttx/nuttx.h>
#include <nuttx/binfmt/binfmt.h>
#include "binfmt.h"
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) && !defined(CONFIG_BINFMT_DISABLE)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ROUNDUP(x, y) (((x) + (y) - 1) / (y) * (y))
/****************************************************************************
* Public Functions
****************************************************************************/
@ -98,7 +93,7 @@ int binfmt_copyactions(FAR const posix_spawn_file_actions_t **copy,
case SPAWN_FILE_ACTION_OPEN:
open = (FAR struct spawn_open_file_action_s *)entry;
size += ROUNDUP(SIZEOF_OPEN_FILE_ACTION_S(strlen(open->path)),
size += ALIGN_UP(SIZEOF_OPEN_FILE_ACTION_S(strlen(open->path)),
sizeof(FAR void *));
break;
@ -155,7 +150,7 @@ int binfmt_copyactions(FAR const posix_spawn_file_actions_t **copy,
strcpy(open->path, tmp->path);
buffer = (FAR char *)buffer +
ROUNDUP(SIZEOF_OPEN_FILE_ACTION_S(strlen(tmp->path)),
ALIGN_UP(SIZEOF_OPEN_FILE_ACTION_S(strlen(tmp->path)),
sizeof(FAR void *));
break;

View file

@ -1393,10 +1393,12 @@ void sched_note_irqhandler(int irq, FAR void *handler, bool enter)
void sched_note_wdog(uint8_t event, FAR void *handler, FAR const void *arg)
{
FAR struct note_driver_s **driver;
irqstate_t flags;
struct note_wdog_s note;
bool formatted = false;
FAR struct tcb_s *tcb = this_task();
flags = enter_critical_section_wo_note();
for (driver = g_note_drivers; *driver; driver++)
{
if (note_wdog(*driver, event, handler, arg))
@ -1421,6 +1423,8 @@ void sched_note_wdog(uint8_t event, FAR void *handler, FAR const void *arg)
note_add(*driver, &note, sizeof(note));
}
leave_critical_section_wo_note(flags);
}
#endif

View file

@ -258,9 +258,19 @@ int irqchain_detach(int irq, xcpt_t isr, FAR void *arg);
****************************************************************************/
#ifdef CONFIG_IRQCOUNT
# if (defined(CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION) && \
CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0) || \
defined(CONFIG_SCHED_INSTRUMENTATION_CSECTION)
irqstate_t enter_critical_section(void) noinstrument_function;
# else
# define enter_critical_section() enter_critical_section_wo_note()
# endif
irqstate_t enter_critical_section_wo_note(void) noinstrument_function;
#else
# define enter_critical_section() up_irq_save()
# define enter_critical_section_wo_note() up_irq_save()
#endif
/****************************************************************************
@ -288,9 +298,19 @@ irqstate_t enter_critical_section(void) noinstrument_function;
****************************************************************************/
#ifdef CONFIG_IRQCOUNT
# if (defined(CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION) && \
CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0) || \
defined(CONFIG_SCHED_INSTRUMENTATION_CSECTION)
void leave_critical_section(irqstate_t flags) noinstrument_function;
# else
# define leave_critical_section(f) leave_critical_section_wo_note(f)
# endif
void leave_critical_section_wo_note(irqstate_t flags) noinstrument_function;
#else
# define leave_critical_section(f) up_irq_restore(f)
# define leave_critical_section_wo_note(f) up_irq_restore(f)
#endif
/****************************************************************************

View file

@ -35,6 +35,7 @@
#include <nuttx/init.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/nuttx.h>
#include <nuttx/spinlock.h>
/****************************************************************************
@ -112,11 +113,6 @@
#define MAXARCS (1 << 20)
/* General rounding functions. */
#define ROUNDDOWN(x, y) (((x) / (y)) * (y))
#define ROUNDUP(x, y) ((((x) + (y) - 1) / (y)) * (y))
/* See profil(2) where this is described (incorrectly) */
#define SCALE_1_TO_1 0x10000
@ -288,12 +284,12 @@ void moncontrol(int mode)
if (mode)
{
uintptr_t lowpc = ROUNDDOWN((uintptr_t)&_stext,
uintptr_t lowpc = ALIGN_DOWN((uintptr_t)&_stext,
HISTFRACTION * sizeof(HISTCOUNTER));
uintptr_t highpc = ROUNDUP((uintptr_t)&_etext,
uintptr_t highpc = ALIGN_UP((uintptr_t)&_etext,
HISTFRACTION * sizeof(HISTCOUNTER));
size_t textsize = highpc - lowpc;
size_t kcountsize = ROUNDUP(textsize / HISTFRACTION,
size_t kcountsize = ALIGN_UP(textsize / HISTFRACTION,
sizeof(*p->kcount));
int scale = kcountsize >= textsize ? SCALE_1_TO_1 :
(float)kcountsize / textsize * SCALE_1_TO_1;
@ -370,10 +366,10 @@ void monstartup(unsigned long lowpc, unsigned long highpc)
* so the rest of the scaling (here and in gprof) stays in ints.
*/
lowpc = ROUNDDOWN(lowpc, HISTFRACTION * sizeof(HISTCOUNTER));
highpc = ROUNDUP(highpc, HISTFRACTION * sizeof(HISTCOUNTER));
lowpc = ALIGN_DOWN(lowpc, HISTFRACTION * sizeof(HISTCOUNTER));
highpc = ALIGN_UP(highpc, HISTFRACTION * sizeof(HISTCOUNTER));
textsize = highpc - lowpc;
fromssize = ROUNDUP(textsize / HASHFRACTION, sizeof(*p->froms));
fromssize = ALIGN_UP(textsize / HASHFRACTION, sizeof(*p->froms));
tolimit = textsize * ARCDENSITY / 100;
if (tolimit < MINARCS)

View file

@ -41,8 +41,6 @@
* Pre-processor Definitions
****************************************************************************/
#define ROUNDUP(x, y) (((x) + (y) - 1) / (y) * (y))
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
# define ioberr _err
# define iobwarn _warn

View file

@ -35,6 +35,7 @@
#ifdef CONFIG_IOB_ALLOC
# include <nuttx/kmalloc.h>
#endif
#include <nuttx/nuttx.h>
#include <nuttx/mm/iob.h>
#include "iob.h"
@ -333,7 +334,7 @@ FAR struct iob_s *iob_alloc_dynamic(uint16_t size)
FAR struct iob_s *iob;
size_t alignsize;
alignsize = ROUNDUP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) + size;
alignsize = ALIGN_UP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) + size;
iob = kmm_memalign(CONFIG_IOB_ALIGNMENT, alignsize);
if (iob)
@ -344,7 +345,7 @@ FAR struct iob_s *iob_alloc_dynamic(uint16_t size)
iob->io_bufsize = size; /* Total length of the iob buffer */
iob->io_pktlen = 0; /* Total length of the packet */
iob->io_free = iob_free_dynamic; /* Customer free callback */
iob->io_data = (FAR uint8_t *)ROUNDUP((uintptr_t)(iob + 1),
iob->io_data = (FAR uint8_t *)ALIGN_UP((uintptr_t)(iob + 1),
CONFIG_IOB_ALIGNMENT);
}

View file

@ -28,6 +28,7 @@
#include <stdbool.h>
#include <nuttx/nuttx.h>
#include <nuttx/mm/iob.h>
#include "iob.h"
@ -39,10 +40,10 @@
/* Fix the I/O Buffer size with specified alignment size */
#ifdef CONFIG_IOB_ALLOC
# define IOB_ALIGN_SIZE ROUNDUP(sizeof(struct iob_s) + CONFIG_IOB_BUFSIZE, \
# define IOB_ALIGN_SIZE ALIGN_UP(sizeof(struct iob_s) + CONFIG_IOB_BUFSIZE, \
CONFIG_IOB_ALIGNMENT)
#else
# define IOB_ALIGN_SIZE ROUNDUP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT)
# define IOB_ALIGN_SIZE ALIGN_UP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT)
#endif
#define IOB_BUFFER_SIZE (IOB_ALIGN_SIZE * CONFIG_IOB_NBUFFERS + \
@ -137,7 +138,7 @@ void iob_initialize(void)
* aligned to the CONFIG_IOB_ALIGNMENT memory boundary
*/
buf = ROUNDUP((uintptr_t)g_iob_buffer + offsetof(struct iob_s, io_data),
buf = ALIGN_UP((uintptr_t)g_iob_buffer + offsetof(struct iob_s, io_data),
CONFIG_IOB_ALIGNMENT) - offsetof(struct iob_s, io_data);
/* Get I/O buffer instance from the start address and add each I/O buffer

View file

@ -53,6 +53,7 @@ static struct timespec g_clock_wall_time;
static uint64_t g_clock_last_counter;
static uint64_t g_clock_mask;
static long g_clock_adjust;
static spinlock_t g_clock_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
@ -72,7 +73,7 @@ static int clock_get_current_time(FAR struct timespec *ts,
time_t sec;
int ret;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_clock_lock);
ret = up_timer_gettick(&counter);
if (ret < 0)
@ -96,7 +97,7 @@ static int clock_get_current_time(FAR struct timespec *ts,
ts->tv_sec = base->tv_sec + sec;
errout_in_critical_section:
leave_critical_section(flags);
spin_unlock_irqrestore(&g_clock_lock, flags);
return ret;
}
@ -123,7 +124,7 @@ int clock_timekeeping_set_wall_time(FAR const struct timespec *ts)
uint64_t counter;
int ret;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_clock_lock);
ret = up_timer_gettick(&counter);
if (ret < 0)
@ -137,7 +138,7 @@ int clock_timekeeping_set_wall_time(FAR const struct timespec *ts)
g_clock_last_counter = counter;
errout_in_critical_section:
leave_critical_section(flags);
spin_unlock_irqrestore(&g_clock_lock, flags);
return ret;
}
@ -188,7 +189,7 @@ int adjtime(FAR const struct timeval *delta, FAR struct timeval *olddelta)
return -1;
}
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_clock_lock);
adjust_usec = delta->tv_sec * USEC_PER_SEC + delta->tv_usec;
@ -199,7 +200,7 @@ int adjtime(FAR const struct timeval *delta, FAR struct timeval *olddelta)
g_clock_adjust = adjust_usec;
leave_critical_section(flags);
spin_unlock_irqrestore(&g_clock_lock, flags);
return OK;
}
@ -217,7 +218,7 @@ void clock_update_wall_time(void)
time_t sec;
int ret;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_clock_lock);
ret = up_timer_gettick(&counter);
if (ret < 0)
@ -271,7 +272,7 @@ void clock_update_wall_time(void)
g_clock_last_counter = counter;
errout_in_critical_section:
leave_critical_section(flags);
spin_unlock_irqrestore(&g_clock_lock, flags);
}
/****************************************************************************
@ -280,6 +281,9 @@ errout_in_critical_section:
void clock_inittimekeeping(FAR const struct timespec *tp)
{
irqstate_t flags;
flags = spin_lock_irqsave(&g_clock_lock);
up_timer_getmask(&g_clock_mask);
if (tp)
@ -292,6 +296,7 @@ void clock_inittimekeeping(FAR const struct timespec *tp)
}
up_timer_gettick(&g_clock_last_counter);
spin_unlock_irqrestore(&g_clock_lock, flags);
}
#endif /* CONFIG_CLOCK_TIMEKEEPING */

View file

@ -80,7 +80,7 @@ volatile uint8_t g_cpu_nestcount[CONFIG_SMP_NCPUS];
****************************************************************************/
/****************************************************************************
* Name: enter_critical_section
* Name: enter_critical_section_wo_note
*
* Description:
* Take the CPU IRQ lock and disable interrupts on all CPUs. A thread-
@ -90,7 +90,7 @@ volatile uint8_t g_cpu_nestcount[CONFIG_SMP_NCPUS];
****************************************************************************/
#ifdef CONFIG_SMP
irqstate_t enter_critical_section(void)
irqstate_t enter_critical_section_wo_note(void)
{
FAR struct tcb_s *rtcb;
irqstate_t ret;
@ -246,15 +246,6 @@ irqstate_t enter_critical_section(void)
cpu_irqlock_set(cpu);
rtcb->irqcount = 1;
/* Note that we have entered the critical section */
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
nxsched_critmon_csection(rtcb, true, return_address(0));
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
sched_note_csection(rtcb, true);
#endif
}
}
@ -265,7 +256,7 @@ irqstate_t enter_critical_section(void)
#else
irqstate_t enter_critical_section(void)
irqstate_t enter_critical_section_wo_note(void)
{
irqstate_t ret;
@ -285,10 +276,28 @@ irqstate_t enter_critical_section(void)
*/
DEBUGASSERT(rtcb->irqcount >= 0 && rtcb->irqcount < INT16_MAX);
if (++rtcb->irqcount == 1)
{
/* Note that we have entered the critical section */
rtcb->irqcount++;
}
/* Return interrupt status */
return ret;
}
#endif
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0 ||\
defined(CONFIG_SCHED_INSTRUMENTATION_CSECTION)
irqstate_t enter_critical_section(void)
{
FAR struct tcb_s *rtcb;
irqstate_t flags;
flags = enter_critical_section_wo_note();
if (!up_interrupt_context())
{
rtcb = this_task();
if (rtcb->irqcount == 1)
{
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
nxsched_critmon_csection(rtcb, true, return_address(0));
#endif
@ -298,14 +307,12 @@ irqstate_t enter_critical_section(void)
}
}
/* Return interrupt status */
return ret;
return flags;
}
#endif
/****************************************************************************
* Name: leave_critical_section
* Name: leave_critical_section_wo_note
*
* Description:
* Decrement the IRQ lock count and if it decrements to zero then release
@ -314,7 +321,7 @@ irqstate_t enter_critical_section(void)
****************************************************************************/
#ifdef CONFIG_SMP
void leave_critical_section(irqstate_t flags)
void leave_critical_section_wo_note(irqstate_t flags)
{
int cpu;
@ -388,14 +395,6 @@ void leave_critical_section(irqstate_t flags)
}
else
{
/* No.. Note that we have left the critical section */
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
nxsched_critmon_csection(rtcb, false, return_address(0));
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
sched_note_csection(rtcb, false);
#endif
/* Decrement our count on the lock. If all CPUs have
* released, then unlock the spinlock.
*/
@ -421,10 +420,8 @@ void leave_critical_section(irqstate_t flags)
up_irq_restore(flags);
}
#else
void leave_critical_section(irqstate_t flags)
void leave_critical_section_wo_note(irqstate_t flags)
{
/* Check if we were called from an interrupt handler and that the tasks
* lists have been initialized.
@ -440,17 +437,7 @@ void leave_critical_section(irqstate_t flags)
*/
DEBUGASSERT(rtcb->irqcount > 0);
if (--rtcb->irqcount <= 0)
{
/* Note that we have left the critical section */
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
nxsched_critmon_csection(rtcb, false, return_address(0));
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
sched_note_csection(rtcb, false);
#endif
}
--rtcb->irqcount;
}
/* Restore the previous interrupt state. */
@ -458,4 +445,29 @@ void leave_critical_section(irqstate_t flags)
up_irq_restore(flags);
}
#endif
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0 ||\
defined(CONFIG_SCHED_INSTRUMENTATION_CSECTION)
void leave_critical_section(irqstate_t flags)
{
FAR struct tcb_s *rtcb;
if (!up_interrupt_context())
{
rtcb = this_task();
if (rtcb->irqcount == 1)
{
# if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
nxsched_critmon_csection(rtcb, false, return_address(0));
# endif
# ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
sched_note_csection(rtcb, false);
# endif
}
}
leave_critical_section_wo_note(flags);
}
#endif
#endif /* CONFIG_IRQCOUNT */

View file

@ -32,6 +32,7 @@
#include <nuttx/coredump.h>
#include <nuttx/elf.h>
#include <nuttx/nuttx.h>
#include <nuttx/sched.h>
#include "sched/sched.h"
@ -54,9 +55,6 @@
#define PROGRAM_ALIGNMENT 64
#define ROUNDUP(x, y) ((x + (y - 1)) / (y)) * (y)
#define ROUNDDOWN(x ,y) (((x) / (y)) * (y))
/****************************************************************************
* Private Types
****************************************************************************/
@ -166,7 +164,7 @@ static int elf_emit(FAR struct elf_dumpinfo_s *cinfo,
static int elf_emit_align(FAR struct elf_dumpinfo_s *cinfo)
{
off_t align = ROUNDUP(cinfo->stream->nput,
off_t align = ALIGN_UP(cinfo->stream->nput,
ELF_PAGESIZE) - cinfo->stream->nput;
unsigned char null[256];
off_t total = align;
@ -258,9 +256,9 @@ static int elf_get_note_size(int stksegs)
{
int total;
total = stksegs * (sizeof(Elf_Nhdr) + ROUNDUP(CONFIG_TASK_NAME_SIZE, 8) +
total = stksegs * (sizeof(Elf_Nhdr) + ALIGN_UP(CONFIG_TASK_NAME_SIZE, 8) +
sizeof(elf_prstatus_t));
total += stksegs * (sizeof(Elf_Nhdr) + ROUNDUP(CONFIG_TASK_NAME_SIZE, 8) +
total += stksegs * (sizeof(Elf_Nhdr) + ALIGN_UP(CONFIG_TASK_NAME_SIZE, 8) +
sizeof(elf_prpsinfo_t));
return total;
}
@ -276,7 +274,7 @@ static int elf_get_note_size(int stksegs)
static void elf_emit_tcb_note(FAR struct elf_dumpinfo_s *cinfo,
FAR struct tcb_s *tcb)
{
char name[ROUNDUP(CONFIG_TASK_NAME_SIZE, 8)];
char name[ALIGN_UP(CONFIG_TASK_NAME_SIZE, 8)];
elf_prstatus_t status;
elf_prpsinfo_t info;
FAR uintptr_t *regs;
@ -414,8 +412,8 @@ static void elf_emit_tcb_stack(FAR struct elf_dumpinfo_s *cinfo,
(tcb->stack_base_ptr - tcb->stack_alloc_ptr);
}
sp = ROUNDDOWN(buf, PROGRAM_ALIGNMENT);
len = ROUNDUP(len + (buf - sp), PROGRAM_ALIGNMENT);
sp = ALIGN_DOWN(buf, PROGRAM_ALIGNMENT);
len = ALIGN_UP(len + (buf - sp), PROGRAM_ALIGNMENT);
buf = sp;
elf_emit(cinfo, (FAR void *)buf, len);
@ -546,17 +544,17 @@ static void elf_emit_tcb_phdr(FAR struct elf_dumpinfo_s *cinfo,
(tcb->stack_base_ptr - tcb->stack_alloc_ptr);
}
sp = ROUNDDOWN(phdr->p_vaddr, PROGRAM_ALIGNMENT);
phdr->p_filesz = ROUNDUP(phdr->p_filesz +
sp = ALIGN_DOWN(phdr->p_vaddr, PROGRAM_ALIGNMENT);
phdr->p_filesz = ALIGN_UP(phdr->p_filesz +
(phdr->p_vaddr - sp), PROGRAM_ALIGNMENT);
phdr->p_vaddr = sp;
phdr->p_type = PT_LOAD;
phdr->p_offset = ROUNDUP(*offset, ELF_PAGESIZE);
phdr->p_offset = ALIGN_UP(*offset, ELF_PAGESIZE);
phdr->p_paddr = phdr->p_vaddr;
phdr->p_memsz = phdr->p_filesz;
phdr->p_flags = PF_X | PF_W | PF_R;
*offset += ROUNDUP(phdr->p_memsz, ELF_PAGESIZE);
*offset += ALIGN_UP(phdr->p_memsz, ELF_PAGESIZE);
elf_emit(cinfo, phdr, sizeof(*phdr));
}
@ -608,13 +606,13 @@ static void elf_emit_phdr(FAR struct elf_dumpinfo_s *cinfo,
for (i = 0; i < memsegs; i++)
{
phdr.p_type = PT_LOAD;
phdr.p_offset = ROUNDUP(offset, ELF_PAGESIZE);
phdr.p_offset = ALIGN_UP(offset, ELF_PAGESIZE);
phdr.p_vaddr = cinfo->regions[i].start;
phdr.p_paddr = phdr.p_vaddr;
phdr.p_filesz = cinfo->regions[i].end - cinfo->regions[i].start;
phdr.p_memsz = phdr.p_filesz;
phdr.p_flags = cinfo->regions[i].flags;
offset += ROUNDUP(phdr.p_memsz, ELF_PAGESIZE);
offset += ALIGN_UP(phdr.p_memsz, ELF_PAGESIZE);
elf_emit(cinfo, &phdr, sizeof(phdr));
}
}

View file

@ -38,6 +38,8 @@
#include "sched/sched.h"
#include "wdog/wdog.h"
spinlock_t g_wdog_spinlock = SP_UNLOCKED;
/****************************************************************************
* Public Functions
****************************************************************************/
@ -60,15 +62,10 @@
int wd_cancel(FAR struct wdog_s *wdog)
{
irqstate_t flags;
int ret;
flags = enter_critical_section();
ret = wd_cancel_irq(wdog);
leave_critical_section(flags);
return ret;
}
@ -91,12 +88,16 @@ int wd_cancel(FAR struct wdog_s *wdog)
int wd_cancel_irq(FAR struct wdog_s *wdog)
{
irqstate_t flags;
bool head;
flags = spin_lock_irqsave(&g_wdog_spinlock);
/* Make sure that the watchdog is valid and still active. */
if (wdog == NULL || !WDOG_ISACTIVE(wdog))
{
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
return -EINVAL;
}
@ -116,6 +117,7 @@ int wd_cancel_irq(FAR struct wdog_s *wdog)
/* Mark the watchdog inactive */
wdog->func = NULL;
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
if (head)
{

View file

@ -112,10 +112,11 @@ static unsigned int g_wdtimernested;
static inline_function void wd_expiration(clock_t ticks)
{
FAR struct wdog_s *wdog;
wdparm_t arg;
irqstate_t flags;
wdentry_t func;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_wdog_spinlock);
#ifdef CONFIG_SCHED_TICKLESS
/* Increment the nested watchdog timer count to handle cases where wd_start
@ -147,12 +148,17 @@ static inline_function void wd_expiration(clock_t ticks)
/* Indicate that the watchdog is no longer active. */
func = wdog->func;
arg = wdog->arg;
wdog->func = NULL;
/* Execute the watchdog function */
up_setpicbase(wdog->picbase);
CALL_FUNC(func, wdog->arg);
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
CALL_FUNC(func, arg);
flags = spin_lock_irqsave(&g_wdog_spinlock);
}
#ifdef CONFIG_SCHED_TICKLESS
@ -161,7 +167,7 @@ static inline_function void wd_expiration(clock_t ticks)
g_wdtimernested--;
#endif
leave_critical_section(flags);
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
}
/****************************************************************************
@ -293,7 +299,7 @@ int wd_start_abstick(FAR struct wdog_s *wdog, clock_t ticks,
* the critical section is established.
*/
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_wdog_spinlock);
#ifdef CONFIG_SCHED_TICKLESS
/* We need to reassess timer if the watchdog list head has changed. */
@ -314,8 +320,13 @@ int wd_start_abstick(FAR struct wdog_s *wdog, clock_t ticks,
* then this will pick that new delay.
*/
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
nxsched_reassess_timer();
}
else
{
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
}
#else
UNUSED(reassess);
@ -328,8 +339,8 @@ int wd_start_abstick(FAR struct wdog_s *wdog, clock_t ticks,
}
wd_insert(wdog, ticks, wdentry, arg);
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
#endif
leave_critical_section(flags);
sched_note_wdog(NOTE_WDOG_START, wdentry, (FAR void *)(uintptr_t)ticks);
return OK;
@ -425,13 +436,13 @@ clock_t wd_timer(clock_t ticks, bool noswitches)
wd_expiration(ticks);
}
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_wdog_spinlock);
/* Return the delay for the next watchdog to expire */
if (list_is_empty(&g_wdactivelist))
{
leave_critical_section(flags);
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
return 0;
}
@ -442,7 +453,7 @@ clock_t wd_timer(clock_t ticks, bool noswitches)
wdog = list_first_entry(&g_wdactivelist, struct wdog_s, node);
ret = wdog->expired - ticks;
leave_critical_section(flags);
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
/* Return the delay for the next watchdog to expire */

View file

@ -37,6 +37,7 @@
#include <nuttx/queue.h>
#include <nuttx/wdog.h>
#include <nuttx/list.h>
#include <nuttx/spinlock_type.h>
/****************************************************************************
* Pre-processor Definitions
@ -64,6 +65,7 @@ extern "C"
*/
extern struct list_node g_wdactivelist;
extern spinlock_t g_wdog_spinlock;
/****************************************************************************
* Public Function Prototypes