SAMA5D2 Flexcom as UART high CPU usage

This forum is for users of Microchip MPUs and who are interested in using Linux OS.

Moderator: nferre

OndrejAdamec
Posts: 2
Joined: Wed Oct 09, 2019 4:26 pm

SAMA5D2 Flexcom as UART high CPU usage

Wed Oct 09, 2019 4:52 pm

Hello,

We have a custom board with SAMA5D2, using linux at91-4.9.47.
When using Flexcoms configured as UARTs, we're noticing very high CPU usage ([irq/num-ttyS6] using top utulity, where ttyS6 is the flexcom), higher the bandwith higher the CPU usage. We're talking about tens of percent of CPU used.

Is this a normal behaviour or a case of misconfiguration/misuse?

Snippet from the dtsi

Code: Select all

flx3: flexcom@fc014000 {
	atmel,flexcom-mode = <ATMEL_FLEXCOM_MODE_USART>;
	status = "okay";

	uart6: serial@200 {
		compatible = "atmel,at91sam9260-usart";
		reg = <0x200 0x200>;
		interrupts = <22 IRQ_TYPE_LEVEL_HIGH 7>;
		clocks = <&flx3_clk>;
		clock-names = "usart";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_flx3_default>;
		atmel,fifo-size = <32>;
		status = "okay";
	};
};

pinctrl_flx3_default: flx3_default {
	pinmux = <PIN_PC20__FLEXCOM3_IO0>,
		 <PIN_PC19__FLEXCOM3_IO1>;
	bias-disable;
};
blue_z
Location: USA
Posts: 2006
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D2 Flexcom as UART high CPU usage

Thu Oct 10, 2019 11:26 pm

OndrejAdamec wrote: ... higher the bandwith [sic] higher the CPU usage.
What "bandwidth" are you referring to?
Do you mean baudrate?
The actual throughput would be the salient metric IMO that could correlate with CPU usage.

OndrejAdamec wrote: We're talking about tens of percent of CPU used.
You could be more specific.
Is it 20% or 70%?
Used by what? A process or hardware/software interrupts?

OndrejAdamec wrote: Is this a normal behaviour or a case of misconfiguration/misuse?
Since top focuses on reporting process statistics and apparently the issue is "tens of percent of CPU used" by a process, then the suspect is (your?) userspace code.
What does this userspace code that accesses the serial terminal look like?
Does it poll the system buffer for data and/or make single-byte syscall requests?
Does this userspace code use blocking or non-blocking I/O?
Odds are that this userspace code is not as efficient as it could be.
FWIW the port is configured for PIO rather than DMA.

Regards
OndrejAdamec
Posts: 2
Joined: Wed Oct 09, 2019 4:26 pm

Re: SAMA5D2 Flexcom as UART high CPU usage

Mon Oct 14, 2019 1:10 pm

blue_z wrote:
Thu Oct 10, 2019 11:26 pm
FWIW the port is configured for PIO rather than DMA.
Based on the measurements (see below), I feel this is the crux of the issue as I was under the impression that DMA is used (As you have surely noticed by now I know very little about this, I'm just using it on a user level).

blue_z wrote:
Thu Oct 10, 2019 11:26 pm
OndrejAdamec wrote: ... higher the bandwith [sic] higher the CPU usage.
What "bandwidth" are you referring to?
Do you mean baudrate?
The actual throughput would be the salient metric IMO that could correlate with CPU usage.
I meant throughput, as in number of bytes received/transmitted per second.

blue_z wrote:
Thu Oct 10, 2019 11:26 pm
OndrejAdamec wrote: We're talking about tens of percent of CPU used.
You could be more specific.
Is it 20% or 70%?
Used by what? A process or hardware/software interrupts?
Some actual numbers:
3 kB/s in both directions at 57600 baud: 14-15%
5 kB/s in both directions at 57600 baud: 25%
3 kB/s in both directions at 115200 baud: 14%
5 kB/s in both directions at 115200 baud: 23%
10 kB/s in both directions at 115200 baud: 40%
10 kB/s in both directions at 921600 baud: 13%
50 kB/s in both directions at 921600 baud: 51%
Used by hardware interrupts.


Thank you for the reply
blue_z
Location: USA
Posts: 2006
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D2 Flexcom as UART high CPU usage

Tue Oct 15, 2019 2:55 am

OndrejAdamec wrote: Based on the measurements (see below), I feel this is the crux of the issue as I was under the impression that DMA is used
Typically the default Atmel configuration for serial ports has been PIO rather than DMA, and that has caused confusion in the past (e.g. viewtopic.php?f=9&t=25864&p=49381#p49381).
The DT nodes for SAMA5D2 UARTs seem to be a recent change from that old pattern.

OndrejAdamec wrote: Used by hardware interrupts.
So the CPU usage is easily explained by PIO.
Define the DMA properties and enable DMA in the Device Tree for that USART, and those numbers should go down.
(The Atmel USART driver is rather verbose in informing you that DMA is enabled.)

Regards

Return to “LINUX”

Who is online

Users browsing this forum: No registered users and 2 guests