Re: [PATCH 2/9] cpukit/jffs2: Protect the inode cache

2023-12-14 Thread Sebastian Huber

On 13.12.23 21:29, Kinsey Moore wrote:

 > The lock is not available to the delayed work caller without
modifying
 > the JFFS2 code and, while I'm sure it would work fine from a data
 > integrity perspective, it was not intended to operate that way. If I
 > were going to go this direction to reduce complexity, it might
make more
 > sense to disable delayed write support and force all writes to be
 > immediate such that it behaves like NOR. The downside to reduced
locking
 > granularity or delayed write removal would be additional wear on the
 > NAND flash.

In which place in the code do you have problems to get the fs info
block? I am absolutely not in favour of having the internal locking
enabled for JFFS2. We use this file system on lower end controllers.

The call to submit delayed work does not provide the FS info as a parameter:
void jffs2_queue_delayed_work(struct delayed_work *work, int delay_ms);
This is wrapped as:
#define queue_delayed_work(workqueue, delayed_work, delay_ms) ...

The initialization call for delayed work does not have direct access to 
the FS info, either:

#define INIT_DELAYED_WORK(delayed_work, delayed_workqueue_callback) ...


From the struct work_struct you get to the struct delayed_work via

static inline struct delayed_work *
to_delayed_work(struct work_struct *work)
{

return container_of(work, struct delayed_work, work);
}

from this you get to struct jffs2_sb_info via container_of()

static struct jffs2_sb_info *work_to_sb(struct work_struct *work)
{
struct delayed_work *dwork;

dwork = to_delayed_work(work);
return container_of(dwork, struct jffs2_sb_info, wbuf_dwork);
}

From struct jffs2_sb_info you get via OFNI_BS_2SFFJ() the struct 
super_block which is already RTEMS-specific. You can add the delayed 
work support to struct super_block and simply use the instance lock in 
your delayed work thread. For the queues you can use ISR locks and 
events, or a mutex with a condition variable.


--
embedded brains GmbH & Co. KG
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH] bsps/arm/stm32f4: Enable USART RX interrupts

2023-12-14 Thread Kinsey Moore
This looks good to me.

A minor nit for future patches: Try to keep unrelated whitespace changes
out of functional patches unless you're already touching the code in
question.

Thanks for the contribution!

Kinsey

On Wed, Dec 13, 2023 at 6:49 PM Jacob Killelea 
wrote:

> Hi all,
>
> A quick bump, is anyone able to take a look at this?
>
> Best,
> Jacob
>
> On Thu, Dec 7, 2023, 9:00 PM Jacob Killelea 
> wrote:
>
>> From: Jacob Killelea 
>>
>> Hi all, this is my first email patch submission and my first contribution
>> to RTEMS, so please give any feedback you have!
>>
>> This patch enables interrupt driven data reception on USART ports on
>> STM32F4 series chips. This feature is gated behind the config flag
>> BSP_CONSOLE_USE_INTERRUPTS. If this flag is not set to True, the older
>> polling implementation will be used. I tested this feature on STM32F401CE
>> (blackpill) and STM32 Nucleo F411RE boards, with both capable of keeping
>> up with a 115200 baud continous data stream. With the older polling
>> implementation, both would drop bytes at 9600 baud. In addition, I
>> updated the implementation of usart_set_attributes to support changing
>> the baud rate of the USART port based on the input speed.
>> ---
>>  bsps/arm/stm32f4/console/usart.c| 81 -
>>  spec/build/bsps/arm/stm32f4/grp.yml |  2 +
>>  2 files changed, 69 insertions(+), 14 deletions(-)
>>
>> diff --git a/bsps/arm/stm32f4/console/usart.c
>> b/bsps/arm/stm32f4/console/usart.c
>> index 37566ef9d7..129249dc29 100644
>> --- a/bsps/arm/stm32f4/console/usart.c
>> +++ b/bsps/arm/stm32f4/console/usart.c
>> @@ -14,6 +14,8 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>> +#include 
>>
>>  static volatile stm32f4_usart *usart_get_regs(const console_tbl *ct)
>>  {
>> @@ -27,6 +29,24 @@ static rtems_vector_number usart_get_irq_number(const
>> console_tbl *ct)
>>  }
>>  #endif
>>
>> +#ifdef BSP_CONSOLE_USE_INTERRUPTS
>> +/**
>> + * Read characters in an interrupt
>> + */
>> +static void stm32f4_usart_interrupt(void *arg)
>> +{
>> +  rtems_termios_tty *tty = (rtems_termios_tty *) arg;
>> +  const console_tbl *ct = Console_Port_Tbl [tty->minor];
>> +  volatile stm32f4_usart *usart = usart_get_regs(ct);
>> +
>> +  while ((usart->sr & STM32F4_USART_SR_RXNE) == STM32F4_USART_SR_RXNE)
>> +  {
>> +char data = STM32F4_USART_DR_GET(usart->dr);
>> +rtems_termios_enqueue_raw_characters(tty, &data, sizeof(data));
>> +  }
>> +}
>> +#endif
>> +
>>  static const stm32f4_rcc_index usart_rcc_index [] = {
>>STM32F4_RCC_USART1,
>>STM32F4_RCC_USART2,
>> @@ -128,29 +148,50 @@ static void usart_initialize(int minor)
>>usart->cr2 = 0;
>>usart->cr3 = 0;
>>usart->bbr = usart_get_bbr(usart, pclk, baud);
>> -  usart->cr1 = STM32F4_USART_CR1_UE
>> -| STM32F4_USART_CR1_TE
>> -| STM32F4_USART_CR1_RE;
>> +  usart->cr1 = STM32F4_USART_CR1_UE // UART enable
>> +#ifdef BSP_CONSOLE_USE_INTERRUPTS
>> +| STM32F4_USART_CR1_RXNEIE // RX interrupt
>> +#endif
>> +| STM32F4_USART_CR1_TE  // TX enable
>> +| STM32F4_USART_CR1_RE; // RX enable
>>  }
>>
>>  static int usart_first_open(int major, int minor, void *arg)
>>  {
>> +  rtems_status_code sc = RTEMS_SUCCESSFUL;
>>rtems_libio_open_close_args_t *oc = (rtems_libio_open_close_args_t *)
>> arg;
>> -  struct rtems_termios_tty *tty = (struct rtems_termios_tty *)
>> oc->iop->data1;
>> +  rtems_termios_tty *tty = (struct rtems_termios_tty *) oc->iop->data1;
>>const console_tbl *ct = Console_Port_Tbl [minor];
>>console_data *cd = &Console_Port_Data [minor];
>>
>>cd->termios_data = tty;
>>rtems_termios_set_initial_baud(tty, ct->ulClock);
>>
>> -  return 0;
>> +#ifdef BSP_CONSOLE_USE_INTERRUPTS
>> +  sc = rtems_interrupt_handler_install(ct->ulIntVector,
>> +  ct->sDeviceName,
>> +  RTEMS_INTERRUPT_UNIQUE,
>> +  stm32f4_usart_interrupt,
>> +  tty);
>> +#endif
>> +
>> +  return sc;
>>  }
>>
>>  static int usart_last_close(int major, int minor, void *arg)
>>  {
>> -  return 0;
>> +  rtems_status_code sc = RTEMS_SUCCESSFUL;
>> +#ifdef BSP_CONSOLE_USE_INTERRUPTS
>> +  rtems_libio_open_close_args_t *oc = (rtems_libio_open_close_args_t *)
>> arg;
>> +  rtems_termios_tty *tty = (struct rtems_termios_tty *) oc->iop->data1;
>> +  const console_tbl *ct = Console_Port_Tbl [minor];
>> +
>> +  sc = rtems_interrupt_handler_remove(ct->ulIntVector,
>> stm32f4_usart_interrupt, tty);
>> +#endif
>> +  return sc;
>>  }
>>
>> +#ifndef BSP_CONSOLE_USE_INTERRUPTS
>>  static int usart_read_polled(int minor)
>>  {
>>const console_tbl *ct = Console_Port_Tbl [minor];
>> @@ -162,6 +203,7 @@ static int usart_read_polled(int minor)
>>  return -1;
>>}
>>  }
>> +#endif
>>
>>  static void usart_write_polled(int minor, char c)
>>  {
>> @@ -175,11 +217,7 @@ static void usart_write_polled(int minor, char c)
>>usart->dr = STM32F4_USART_DR(c);
>>  }
>>
>> -static ssize_t usart_write_support_polled(
>> -  int minor,
>> -  const char *s,
>> -  size_t n
>