Skip to content

Commit

Permalink
os: Use enter/leave_critical section for SMP
Browse files Browse the repository at this point in the history
TizenRT originally makes use of irqsave and irqrestore API for
to provide critical sections. However, when SMP is implemented, we
need to consider the irq and lock status on multiple cores. This is
implemented in enter/leave_critical_section APIs. When the SMP
configuration is enabled, we need to use these new API's instead of
irqsave/restore.

Signed-off-by: Kishore S N <[email protected]>
  • Loading branch information
kishore-sn authored and sunghan-chang committed Jan 18, 2024
1 parent 4ce7ded commit fccb999
Show file tree
Hide file tree
Showing 133 changed files with 586 additions and 583 deletions.
4 changes: 2 additions & 2 deletions lib/libc/syslog/lib_lowsyslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ int lowvsyslog(int priority, FAR const char *fmt, va_list ap)
#if defined(CONFIG_LOGM) && defined(CONFIG_SYSLOG2LOGM)
ret = logm_internal(LOGM_LOWPUT, LOGM_UNKNOWN, priority, fmt, ap);
#else
irqstate_t flags = irqsave();
irqstate_t flags = enter_critical_section();
ret = lowvsyslog_internal(fmt, ap);
irqrestore(flags);
leave_critical_section(flags);
#endif
}
return ret;
Expand Down
4 changes: 2 additions & 2 deletions lib/libc/syslog/lib_setlogmask.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ int setlogmask(int mask)
* as interrupts.
*/

flags = irqsave();
flags = enter_critical_section();

oldmask = g_syslog_mask;
g_syslog_mask = (uint8_t)mask;

irqrestore(flags);
leave_critical_section(flags);
return oldmask;
}
2 changes: 1 addition & 1 deletion os/arch/arm/src/armv7-a/arm_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void _exit(int status)
sched_foreach(_up_dumponexit, NULL);
#endif

(void)irqsave();
(void)enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

Expand Down
8 changes: 4 additions & 4 deletions os/binfmt/binfmt_execsymtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols)
* size are returned as a single atomic operation.
*/

flags = irqsave();
flags = enter_critical_section();

#ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
/* If a bring-up symbol table has been provided and if the exec symbol
Expand All @@ -148,7 +148,7 @@ void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols)

*symtab = g_exec_symtab;
*nsymbols = g_exec_nsymbols;
irqrestore(flags);
leave_critical_section(flags);
}

/****************************************************************************
Expand Down Expand Up @@ -176,10 +176,10 @@ void exec_setsymtab(FAR const struct symtab_s *symtab, int nsymbols)
* size are set as a single atomic operation.
*/

flags = irqsave();
flags = enter_critical_section();
g_exec_symtab = symtab;
g_exec_nsymbols = nsymbols;
irqrestore(flags);
leave_critical_section(flags);
}

#endif /* CONFIG_LIBC_EXECFUNCS */
4 changes: 2 additions & 2 deletions os/binfmt/binfmt_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ int binfmt_exit(FAR struct binary_s *bin)
while (address) {
mllvdbg("Remove addr %p from deplaed kufree, uheap (%p, %p)\n", address, uheap_start, uheap_end);
if (uheap_start <= (uint32_t)address && (uint32_t)address <= uheap_end) {
flags = irqsave();
flags = enter_critical_section();
sq_rem((FAR sq_entry_t *)address, (FAR sq_queue_t *)&g_delayed_kufree);
irqrestore(flags);
leave_critical_section(flags);
}
address = (FAR void *)sq_next((FAR sq_entry_t *)address);
}
Expand Down
16 changes: 8 additions & 8 deletions os/drivers/analog/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static int adc_open(FAR struct file *filep)
* Yes.. perform one time hardware
* initialization.
*/
irqstate_t flags = irqsave();
irqstate_t flags = enter_critical_section();
ret = dev->ad_ops->ao_setup(dev);
if (ret == OK) {
/* Mark the FIFOs empty */
Expand All @@ -174,7 +174,7 @@ static int adc_open(FAR struct file *filep)
dev->ad_ocount = tmp;
}

irqrestore(flags);
leave_critical_section(flags);
}
}

Expand Down Expand Up @@ -230,9 +230,9 @@ static int adc_close(FAR struct file *filep)
dev->ad_ocount = 0;

/* Free the IRQ and disable the ADC device */
flags = irqsave(); /* Disable interrupts */
flags = enter_critical_section(); /* Disable interrupts */
dev->ad_ops->ao_shutdown(dev); /* Disable the ADC */
irqrestore(flags);
leave_critical_section(flags);

sem_post(&dev->ad_closesem);
}
Expand Down Expand Up @@ -274,7 +274,7 @@ static ssize_t adc_read(FAR struct file *filep, FAR char *buffer,
* Interrupts must be disabled while accessing the ad_recv
* FIFO
*/
flags = irqsave();
flags = enter_critical_section();
while (dev->ad_recv.af_head == dev->ad_recv.af_tail) {
/*
* The receive FIFO is empty
Expand Down Expand Up @@ -354,7 +354,7 @@ static ssize_t adc_read(FAR struct file *filep, FAR char *buffer,
ret = nread;

return_with_irqdisabled:
irqrestore(flags);
leave_critical_section(flags);
}

avdbg("Returning: %d\n", ret);
Expand Down Expand Up @@ -470,7 +470,7 @@ static int adc_poll(FAR struct file *filep, struct pollfd *fds, bool setup)
* and ad_recv FIFO.
*/

flags = irqsave();
flags = enter_critical_section();

if (setup) {
/* Ignore waits that do not include POLLIN */
Expand Down Expand Up @@ -522,7 +522,7 @@ static int adc_poll(FAR struct file *filep, struct pollfd *fds, bool setup)
}

return_with_irqdisabled:
irqrestore(flags);
leave_critical_section(flags);
return ret;
}
#endif
Expand Down
12 changes: 6 additions & 6 deletions os/drivers/analog/dac.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static int dac_open(FAR struct file *filep)
if (tmp == 1) {
/* Yes.. perform one time hardware initialization. */

irqstate_t flags = irqsave();
irqstate_t flags = enter_critical_section();
ret = dev->ad_ops->ao_setup(dev);
if (ret == OK) {
/* Mark the FIFOs empty */
Expand All @@ -164,7 +164,7 @@ static int dac_open(FAR struct file *filep)
dev->ad_ocount = tmp;
}

irqrestore(flags);
leave_critical_section(flags);
}
}

Expand Down Expand Up @@ -217,9 +217,9 @@ static int dac_close(FAR struct file *filep)

/* Free the IRQ and disable the DAC device */

flags = irqsave(); /* Disable interrupts */
flags = enter_critical_section(); /* Disable interrupts */
dev->ad_ops->ao_shutdown(dev); /* Disable the DAC */
irqrestore(flags);
leave_critical_section(flags);

sem_post(&dev->ad_closesem);
}
Expand Down Expand Up @@ -288,7 +288,7 @@ static ssize_t dac_write(FAR struct file *filep, FAR const char *buffer, size_t

/* Interrupts must disabled throughout the following */

flags = irqsave();
flags = enter_critical_section();

/* Check if the TX FIFO was empty when we started. That is a clue that we have
* to kick off a new TX sequence.
Expand Down Expand Up @@ -409,7 +409,7 @@ static ssize_t dac_write(FAR struct file *filep, FAR const char *buffer, size_t
ret = nsent;

return_with_irqdisabled:
irqrestore(flags);
leave_critical_section(flags);
return ret;
}

Expand Down
20 changes: 10 additions & 10 deletions os/drivers/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static int can_open(FAR struct file *filep)
if (tmp == 1) {
/* Yes.. perform one time hardware initialization. */

irqstate_t flags = irqsave();
irqstate_t flags = enter_critical_section();
ret = dev_setup(dev);
if (ret == OK) {
/* Mark the FIFOs empty */
Expand All @@ -192,7 +192,7 @@ static int can_open(FAR struct file *filep)

dev->cd_ocount = tmp;
}
irqrestore(flags);
leave_critical_section(flags);
}
}
sem_post(&dev->cd_closesem);
Expand Down Expand Up @@ -260,9 +260,9 @@ static int can_close(FAR struct file *filep)

/* Free the IRQ and disable the CAN device */

flags = irqsave(); /* Disable interrupts */
flags = enter_critical_section(); /* Disable interrupts */
dev_shutdown(dev); /* Disable the CAN */
irqrestore(flags);
leave_critical_section(flags);

sem_post(&dev->cd_closesem);
}
Expand Down Expand Up @@ -297,7 +297,7 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer, size_t buflen)
if (buflen >= CAN_MSGLEN(0)) {
/* Interrupts must be disabled while accessing the cd_recv FIFO */

flags = irqsave();
flags = enter_critical_section();
while (dev->cd_recv.rx_head == dev->cd_recv.rx_tail) {
/* The receive FIFO is empty -- was non-blocking mode selected? */

Expand Down Expand Up @@ -349,7 +349,7 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer, size_t buflen)
ret = nread;

return_with_irqdisabled:
irqrestore(flags);
leave_critical_section(flags);
}

return ret;
Expand Down Expand Up @@ -443,7 +443,7 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, size_t

/* Interrupts must disabled throughout the following */

flags = irqsave();
flags = enter_critical_section();

/* Check if the TX is inactive when we started. In certain race conditions,
* there may be a pending interrupt to kick things back off, but we will
Expand Down Expand Up @@ -540,7 +540,7 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, size_t
ret = nsent;

return_with_irqdisabled:
irqrestore(flags);
leave_critical_section(flags);
return ret;
}

Expand All @@ -564,7 +564,7 @@ static inline ssize_t can_rtrread(FAR struct can_dev_s *dev, FAR struct canioctl

/* Disable interrupts through this operation */

flags = irqsave();
flags = enter_critical_section();

/* Find an available slot in the pending RTR list */

Expand All @@ -590,7 +590,7 @@ static inline ssize_t can_rtrread(FAR struct can_dev_s *dev, FAR struct canioctl
}
}

irqrestore(flags);
leave_critical_section(flags);
return ret;
}

Expand Down
18 changes: 9 additions & 9 deletions os/drivers/gpio/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static void gpio_sample(FAR struct gpio_upperhalf_s *priv)
* This routine is called both task level and interrupt level,
* so interrupts must be disabled.
*/
flags = irqsave();
flags = enter_critical_section();

/* Sample the new GPIO state */
DEBUGASSERT(lower->ops && lower->ops->get);
Expand Down Expand Up @@ -208,7 +208,7 @@ static void gpio_sample(FAR struct gpio_upperhalf_s *priv)
#endif

priv->gu_sample = sample;
irqrestore(flags);
leave_critical_section(flags);
}

#if !defined(CONFIG_DISABLE_POLL) || !defined(CONFIG_DISABLE_SIGNALS)
Expand Down Expand Up @@ -243,7 +243,7 @@ static void gpio_enable(FAR struct gpio_upperhalf_s *priv)
* This routine is called both task level and interrupt level, so
* interrupts must be disabled.
*/
flags = irqsave();
flags = enter_critical_section();

/* Visit each opened reference to the device */
rising = 0;
Expand Down Expand Up @@ -285,7 +285,7 @@ static void gpio_enable(FAR struct gpio_upperhalf_s *priv)
lower->ops->enable(lower, false, false, NULL);
}

irqrestore(flags);
leave_critical_section(flags);
}
#endif

Expand All @@ -302,7 +302,7 @@ static int gpio_enable_interrupt(FAR struct gpio_upperhalf_s *priv, unsigned lon
int ret;
irqstate_t flags;

flags = irqsave();
flags = enter_critical_section();

switch (arg) {
case GPIO_EDGE_NONE:
Expand All @@ -323,7 +323,7 @@ static int gpio_enable_interrupt(FAR struct gpio_upperhalf_s *priv, unsigned lon
break;
default:
lldbg("Interrupt value is invalid\n");
irqrestore(flags);
leave_critical_section(flags);
return ERROR;
break;
}
Expand All @@ -335,7 +335,7 @@ static int gpio_enable_interrupt(FAR struct gpio_upperhalf_s *priv, unsigned lon
/* Disable further interrupts */
ret = lower->ops->enable(lower, false, false, NULL);
}
irqrestore(flags);
leave_critical_section(flags);

return ret;
}
Expand Down Expand Up @@ -570,10 +570,10 @@ static int gpio_close(FAR struct file *filep)
DEBUGASSERT(inode->i_private);
priv = (FAR struct gpio_upperhalf_s *)inode->i_private;

flags = irqsave();
flags = enter_critical_section();
closing = opriv->go_closing;
opriv->go_closing = true;
irqrestore(flags);
leave_critical_section(flags);

if (closing) {
/* Another thread is doing the close */
Expand Down
4 changes: 2 additions & 2 deletions os/drivers/iotdev/iotbus_sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void iotbus_interrupt_trigger(iotbus_int_type_e int_type)

ibdbg("interrupt triggered int : %d, sig : %d\n", int_type, signal);

flags = irqsave();
flags = enter_critical_section();
struct int_node_s *itr = dev->table[int_type];
for (; itr != NULL; itr = itr->next) {
pid = itr->data->pid;
Expand All @@ -243,7 +243,7 @@ void iotbus_interrupt_trigger(iotbus_int_type_e int_type)
ibdbg("Trigger Error!\n");
}
}
irqrestore(flags);
leave_critical_section(flags);
return;
}

Expand Down
Loading

0 comments on commit fccb999

Please sign in to comment.