Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Uartlite - ulite_transmit

90 views
Skip to first unread message

Michal Simek

unread,
Jan 16, 2011, 4:10:02 AM1/16/11
to
Hi Peter,

sorry for delay. I had to look at another issue.

Below is full log:
1. I setup baudrate to 50. (It could be possible to set it up to 0 too)
That's why I think that doesn't matter what baudrate is setup.

2. You see where ulite_startup is called. It is called only once.

3. You see that there is no call __uart_wait_until_sent(). It could be
called for ASYNC mode. The second thing is __uart_wait_until_sent
function is checking if tx fifo is empty not circ buffer is empty.

4. Next thing is that in uart_close. port->count is 2 which means that
the executing path is
if (port->count) {
spin_unlock_irqrestore(&port->lock, flags);
goto done;
}
which means that there is no chance to call __uart_wait_until_sent
function anyway.

5. I did one modification to add simple while loop till circ buffer is
empty to the same location to see what happen (timouts are bogus values).

if (port->count) {
spin_unlock_irqrestore(&port->lock, flags);
printk("************ %x %x\n", (&uport->state->xmit)->tail,
(&uport->state->xmit)->head);
while (!uart_circ_empty(&uport->state->xmit)) {
msleep_interruptible(jiffies_to_msecs((uport->timeout - HZ/50)));
if (signal_pending(current))
break;
if (time_after(jiffies, jiffies + uport->timeout))
break;
}
printk("************\n");
goto done;
}

Here is log: (Between **** you can see what chars are not printed)

NET: Registered protocol family 17
uart_open(0) called
ulite_startup ------------------------
Freeing unused kernel memory: 11235k freed
Mounting proc:
Mounting var:
Populating /var:
Running local start scripts.
Mounting sysfs:
mdev: initialising /dev
Mounting /etc/config:
Populating /etc/config:
flatfsd: Created 8 configuration files (168 bytes)
Mounting denet eth0: Promiscuous mode disabled.
vpts:
Setting hostname:
Bringing up network interfaces:
udhcpc (v1.14.3) started
Sending discover...
Sending seuart_open(0) called
lect for 192.168uart_close(0) called, port->count 2
************ 172 362
.0.100...
Lease of 192.168.0.100 obtained, lease time 7200
adding dns 172.16.0.5
adding dns 172.16.10.1
Starting portmap:

Welcome to
_____ _ _ _
| ___ \ | | | | (_)
| |_/ / ___ | |_ __ _ | | _ _ __ _ _ __ __
| __/ / _ \| __| / _` || | | || '_ \ | | | |\ \/ /
| | | __/| |_ | (_| || |____| || | | || |_| | > <
\_| \___| \__| \__,_|\_____/|_||_| |_| \__,_|/_/\_\

on Xilinx-SP605-LTP-full-WB-pc-msr-next-22-watch-wt-mdm

************
uart_open(0) called
uart_flush_buffer(0) called

Xilinx-SP605-LTP-full-WB-pc-msr-next-22-watch-wt-mdm login:

I think that will be good to check if circ buffer is empty. As you
suggest uart_close function will be probably the best place.

Any other suggestion?

Thanks,
Michal


Full log with debug messages:

Linux version 2.6.37-00014-g85eb775-dirty (mon...@monstr.eu) (gcc
version 4.1.2) #15 Sun Jan 16 08:43:08 CET 2011
less 8
setup_cpuinfo: initialising
setup_cpuinfo: Using full CPU PVR support
cache: wt_msr_noirq
setup_memory: max_mapnr: 0x8000
setup_memory: min_low_pfn: 0x48000
setup_memory: max_low_pfn: 0x50000
On node 0 totalpages: 32768
free_area_init_node: node 0, pgdat c029f0b8, node_mem_map c0dab000
Normal zone: 256 pages used for memmap
Normal zone: 0 pages reserved
Normal zone: 32512 pages, LIFO batch:7
pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
pcpu-alloc: [0] 0
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512
Kernel command line: console=ttyUL0,50
PID hash table entries: 512 (order: -1, 2048 bytes)
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory: 115776k/131072k available
NR_IRQS:32
xlnx,xps-intc-1.00.a #0 at 0xc8000000, num_irq=8, edge=0x93
xlnx,xps-timer-1.00.a #0 at 0xc8004000, irq=4
microblaze_timer_set_mode: shutdown
microblaze_timer_set_mode: periodic
Calibrating delay loop... 43.90 BogoMIPS (lpj=87808)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
NET: Registered protocol family 16
bio: create slab <bio-0> at 0
Switching to clocksource microblaze_clocksource
microblaze_timer_set_mode: oneshot
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
Skipping unavailable RESET gpio -2 (reset)
GPIO pin is already allocated
JFFS2 version 2.2. (NAND) (SUMMARY) © 2001-2006 Red Hat, Inc.
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
84400000.debug: ttyUL0 at MMIO 0x84400000 (irq = 7) is a uartlite
console [ttyUL0] enabled
Xilinx SystemACE device driver, major=254
86000000.flash: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer
ID 0x000089 Chip ID 0x008919
Intel/Sharp Extended Query Table at 0x010A
Intel/Sharp Extended Query Table at 0x010A
Intel/Sharp Extended Query Table at 0x010A
Intel/Sharp Extended Query Table at 0x010A
Intel/Sharp Extended Query Table at 0x010A
Using buffer write method
Using auto-unlock on power-up/resume
cfi_cmdset_0001: Erase suspend on write enabled
erase region 0: offset=0x0,size=0x20000,blocks=255
erase region 1: offset=0x1fe0000,size=0x8000,blocks=4
RedBoot partition parsing not available
Creating 6 MTD partitions on "86000000.flash":
0x000000000000-0x000000100000 : "fpga"
0x000000100000-0x000000140000 : "boot"
0x000000140000-0x000000160000 : "bootenv"
0x000000160000-0x000000180000 : "config"
0x000000180000-0x000000b80000 : "image"
0x000000b80000-0x000002000000 : "spare"
Xilinx TEMAC MDIO: probed
eth0: Dropping NETIF_F_SG since no checksum feature.
TCP cubic registered
NET: Registered protocol family 17
uart_open(0) called
ulite_startup ------------------------
Freeing unused kernel memory: 11235k freed
Mounting proc:
Mounting var:
Populating /var:
Running local start scripts.
Mounting sysfs:
mdev: initialising /dev
Mounting /etc/config:
Populating /etc/config:
flatfsd: Created 8 configuration files (168 bytes)
Mounting devpnet eth0: Promiscuous mode disabled.
ts:
Setting hostname:
Bringing up network interfaces:
udhcpc (v1.14.3) started
Sending discover...
Sending seluart_open(0) called
ect for 192.168.uart_close(0) called
uart_open(0) called
uart_flush_buffer(0) called

Xilinx-SP605-LTP-full-WB-pc-msr-next-22-watch-wt-mdm login:


Peter Korsgaard wrote:
>>>>>> "Michal" == Michal Simek <mon...@monstr.eu> writes:
>
> Hi,
>
> Michal> The point is that clearing is called but there are still some
> Michal> characters which are not printed. If you call that clearing you
> Michal> just lost the part of log.
>
> Yes, but it shouldn't happen as __uart_wait_until_sent() is called
> first.
>
> >> What is the problem here? Is it that the uart gets closed and reopened
> >> (which causes ulite_startup() to get called)
> Michal> while there's still data in
> >> the uarts internal tx fifo (which then gets discarded)
>
> Michal> No data in internal tx fifo are not discarded.
>
> It is if ulite_startup is called.
>
> Michal> , or is it that
> >> there's still data in the sw xmit circular buffer that isn't sent to the
> >> hardware yet?
>
> Michal> yes, data are in the circ buffer head and tail are correctly setup and
> Michal> because sending is slow that circ buffer clearing is called and head
> Michal> and tail is zeroed.
> Michal> I think the best solution will be to wait if head/tail is not the same
> Michal> value which means there is data in circ buffer. Not sure if driver can
> Michal> do anything with it or if there is any way how to delay buffer
> Michal> clearing in the driver.
>
> I don't know much of the details of serial_core, but I believe
> uart_close (and hence uart_circ_clear) is only called when all
> characters in the circular buffer have been sent. What still might not
> be sent is any data in the uart TX fifo, but __uart_wait_until_sent()
> should handle that if you provide correct baudrate.
>
> >> What baudrate is your hardware running at? What baudrate have you
> >> configured the kernel to use? Even though the uartlite itself doesn't do
> >> anything with the baudrate setting (E.G. it is fixed in hardware), the
> >> baudrate is used by the kernel to calculate timeouts (E.G. in
> >> __uart_wait_until_sent and similar).
>
> Michal> It is the same style. You can't even setup baudrate in EDK. There is
> Michal> no hardware connection through serial line. The whole communication is
> Michal> done through jtag. I really don't know how fast xilinx can communicate
> Michal> with mdm.
>
> Ok, does behaviour change if you set the kernel baudrate to something
> really low (300bps or so)? Also don't forget to adjust your getty
> settings!
>


--
Michal Simek, Ing. (M.Eng)
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel 2.6 Microblaze Linux - http://www.monstr.eu/fdt/
Microblaze U-BOOT custodian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Peter Korsgaard

unread,
Jan 16, 2011, 4:10:02 PM1/16/11
to
>>>>> "Michal" == Michal Simek <mon...@monstr.eu> writes:

Hi,

Michal> Hi Peter,
Michal> sorry for delay. I had to look at another issue.

No problem.

Michal> Below is full log:
Michal> 1. I setup baudrate to 50. (It could be possible to set it up to 0 too)
Michal> That's why I think that doesn't matter what baudrate is setup.

Michal> 2. You see where ulite_startup is called. It is called only once.

Ok, good.

Michal> 3. You see that there is no call __uart_wait_until_sent(). It could be
Michal> called for ASYNC mode. The second thing is __uart_wait_until_sent
Michal> function is checking if tx fifo is empty not circ buffer is empty.

Yes, that's afaik what that function should do.

Michal> 4. Next thing is that in uart_close. port->count is 2 which means that
Michal> the executing path is
Michal> if (port->count) {
Michal> spin_unlock_irqrestore(&port->lock, flags);
Michal> goto done;
Michal> }
Michal> which means that there is no chance to call __uart_wait_until_sent
Michal> function anyway.

And no buffer flushing, so that's fine.

Michal> 5. I did one modification to add simple while loop till circ buffer is
Michal> empty to the same location to see what happen (timouts are bogus
Michal> values).

Michal> if (port->count) {
Michal> spin_unlock_irqrestore(&port->lock, flags);
Michal> printk("************ %x %x\n", (&uport->state->xmit)->tail,
Michal> (&uport->state->xmit)->head);
Michal> while (!uart_circ_empty(&uport->state->xmit)) {
Michal> msleep_interruptible(jiffies_to_msecs((uport->timeout - HZ/50)));
Michal> if (signal_pending(current))
Michal> break;
Michal> if (time_after(jiffies, jiffies + uport->timeout))
Michal> break;
Michal> }
Michal> printk("************\n");
Michal> goto done;
Michal> }

Ok, so this shows that there's still data in the circular buffer when
uart is closed, like expected.

For me, it all looks normal:

1. serial port gets opened, uart_open -> uart_startup -> ulite_startup
gets called, ASYNC_INITIALIZED gets set, circular buffer and hardware
TX fifo cleared.

2. Some time later serial port gets opened again, and uart_startup is a
NOP because ASYNC_INITIALIZED is set. No circular buffer / hw fifo
clear.

3. serial port gets closed, uart_close is a NOP because port->count > 0

4. serial port gets opened again, NOP like in 2.

The problem is the uart_flush_buffer() call we see after uart_open() in
4. If doesn't seem to come from serial_core (only called from uart_close
/ uart_hangup), so presumably it comes from the TTY core or
userspace. Could you add a bit more debug to figure out where exactly it
comes from?

Michal> ************
Michal> uart_open(0) called
Michal> uart_flush_buffer(0) called

--
Bye, Peter Korsgaard

Michal Simek

unread,
Jan 17, 2011, 1:40:01 AM1/17/11
to

But ASYNC_INITIALIZED is not set.

>
> 2. Some time later serial port gets opened again, and uart_startup is a
> NOP because ASYNC_INITIALIZED is set. No circular buffer / hw fifo
> clear.
>
> 3. serial port gets closed, uart_close is a NOP because port->count > 0
>
> 4. serial port gets opened again, NOP like in 2.
>
> The problem is the uart_flush_buffer() call we see after uart_open() in
> 4. If doesn't seem to come from serial_core (only called from uart_close
> / uart_hangup), so presumably it comes from the TTY core or
> userspace. Could you add a bit more debug to figure out where exactly it
> comes from?

ok. will do.

Thanks,
Michal

>
> Michal> ************
> Michal> uart_open(0) called
> Michal> uart_flush_buffer(0) called
>


--

Michal Simek, Ing. (M.Eng)
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel 2.6 Microblaze Linux - http://www.monstr.eu/fdt/
Microblaze U-BOOT custodian

Michal Simek

unread,
Jan 17, 2011, 10:20:01 AM1/17/11
to

Last week I have also implemented simple ioctl function for uartlite -
just printk to see what happen. Look at the second log below.

If there is defined uartlite ioctl function (but always returns
-ENOIOCTLCMD)

Sending select for 192.168.0.100...
Lease of 192.168.0.100 obtaulite_ioctl 5401 bf9b1ed8
n_tty_ioctl


ined, lease time 7200
adding dns 172.16.0.5
adding dns 172.16.10.1

Stuart_open(0) called
arting portmap:

Welcome to
ulite_ioctl 5401 bf9f8a8c
n_tty_ioctl
ulite_ioctl 5402 bf9f8a70
n_tty_ioctl
_____ _ uart_close(0) called, port->count 2
************ 210 362


_ _
| ___ \ | | | | (_)
| |_/ / ___ | |_ __ _ | | _ _ __ _ _ __ __
| __/ / _ \| __| / _` || | | || '_ \ | | | |\ \/ /
| | | __/| |_ | (_| || |____| || | | || |_| | > <
\_| \___| \__| \__,_|\_____/|_||_| |_| \__,_|/_/\_\

on Xilinx-SP605-LTP-full-WB-pc-msr-next-22-watch-wt-mdm

************
uart_open(0) called
ulite_ioctl 5401 bff76a18
n_tty_ioctl
ulite_ioctl 540b 2
n_tty_ioctl
n_tty_ioctl_helper TCFLSH
tty_perform_flush TCIOFLUSH
tty_perform_flush TCOFLUSH
tty_driver_flush_buffer
uart_flush_buffer(0) called
ulite_ioctl 5402 bff769a4
n_tty_ioctl
ulite_ioctl 540b 0
n_tty_ioctl
n_tty_ioctl_helper TCFLSH
tty_perform_flush TCIFLUSH
ulite_ioctl 5401 bff76558
n_tty_ioctl

Xilinx-SP605-LTP-full-WB-pc-msr-next-22-watch-wt-mdm login:


If uarlite ioctl is defined: (cases: TCFLSH, TCGETS, TCSETS) - return 0;
It is interested but maybe implement that function could be enough. What
do you think?

Thanks,
Michal


NET: Registered protocol family 17
uart_open(0) called
ulite_startup ------------------------

Freeing unused kernel memory: 11218k freed
ulite_ioctl 5600 bf9d1bc8
n_tty_ioctl
ulite_ioctl TCGETS bf9d1b1c
ulite_ioctl TCSETS bf9d1b00
ulite_ioctl TCGETS bf9d1a8c
ulite_ioctl TCSETS bf9d1a70
ulite_ioctl TCGETS bff204d0
Mounting proc:
Mounting var:
Populatinulite_ioctl TCGETS bfd8b4c0
g /var:
Runningulite_ioctl TCGETS bf87e4c0


local start scripts.
Mounting sysfs:
mdev: initialising /dev

ulite_ioctl TCGETS bf8164c0
Mounting /etc/config:
Populating /etc/culite_ioctl TCGETS bf95a4c0
onfig:
flatfsd:ulite_ioctl TCGETS bf9744c0
Created 8 configulite_ioctl TCGETS bf9434c0
uration files (168 bytes)
Mounting devpts:


Setting hostname:
Bringing up network interfaces:

net eth0: Promiscuous mode disabled.


udhcpc (v1.14.3) started
Sending discover...

Sending select for 192.168.0.100...
Lease of 192.168.0.100 obtaulite_ioctl TCGETS bfa3bed8


ined, lease time 7200
adding dns 172.16.0.5

adding uart_open(0) called
ulite_ioctl TCGETS bf9d1a8c
ulite_ioctl TCSETS bf9d1a70


uart_close(0) called, port->count 2

************ 1dd 362

Starting portmap:

Welcome to
_____ _ _ _
| ___ \ | | | | (_)
| |_/ / ___ | |_ __ _ | | _ _ __ _ _ __ __
| __/ / _ \| __| / _` || | | || '_ \ | | | |\ \/ /
| | | __/| |_ | (_| || |____| || | | || |_| | > <
\_| \___| \__| \__,_|\_____/|_||_| |_| \__,_|/_/\_\

on Xilinx-SP605-LTP-full-WB-pc-msr-next-22-watch-wt-mdm

************
uart_open(0) called
ulite_ioctl TCGETS bfd98a18
ulite_ioctl TCFLSH 2
ulite_ioctl TCSETS bfd989a4
ulite_ioctl TCFLSH 0
ulite_ioctl TCGETS bfd98558

Xilinx-SP605-LTP-full-WB-pc-msr-next-22-watch-wt-mdm login:


--
Michal Simek, Ing. (M.Eng)
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel 2.6 Microblaze Linux - http://www.monstr.eu/fdt/
Microblaze U-BOOT custodian

Peter Korsgaard

unread,
Jan 19, 2011, 10:30:01 AM1/19/11
to
>>>>> "Michal" == Michal Simek <mon...@monstr.eu> writes:

Hi,

>> The problem is the uart_flush_buffer() call we see after uart_open() in


>> 4. If doesn't seem to come from serial_core (only called from uart_close
>> / uart_hangup), so presumably it comes from the TTY core or
>> userspace. Could you add a bit more debug to figure out where exactly it
>> comes from?

Michal> Last week I have also implemented simple ioctl function for
Michal> uartlite - just printk to see what happen. Look at the second
Michal> log below.

Michal> uart_open(0) called
Michal> ulite_ioctl 5401 bff76a18
Michal> n_tty_ioctl
Michal> ulite_ioctl 540b 2
Michal> n_tty_ioctl
Michal> n_tty_ioctl_helper TCFLSH
Michal> tty_perform_flush TCIOFLUSH
Michal> tty_perform_flush TCOFLUSH
Michal> tty_driver_flush_buffer
Michal> uart_flush_buffer(0) called

So your userspace is calling tcflush, and serial_core responds by
flushing (dropping) the buffer. That seems like expected behaviour to
me.

This is presumably from the busybox getty applet, which does:

static void termios_init(struct termios *tp, int speed, struct options *op)
{
speed_t ispeed, ospeed;
/*
* Initial termios settings: 8-bit characters, raw-mode, blocking i/o.
* Special characters are set after we have read the login name; all
* reads will be done in raw mode anyway. Errors will be dealt with
* later on.
*/
/* flush input and output queues, important for modems! */
tcflush(0, TCIOFLUSH);

You could change that to a tcdrain() if that's not what you want.

--
Bye, Peter Korsgaard

Michal Simek

unread,
Jan 20, 2011, 3:10:01 AM1/20/11
to
Hi Peter,

Great that's work. Just for the record it is tcdrain(STDOUT_FILENO);
Patch against busybox 1.14.3 version is below. Maybe worth to added it
mainline busybox.

Thanks for your big help.
Michal


diff --git
a/software/petalinux-dist/user/busybox/busybox-1.14.3/loginutils/getty.c
b/software/petalinux-dist/user/busybox/busybo
index 24a182f..4c99e92 100644
--- a/software/petalinux-dist/user/busybox/busybox-1.14.3/loginutils/getty.c
+++ b/software/petalinux-dist/user/busybox/busybox-1.14.3/loginutils/getty.c
@@ -279,6 +279,8 @@ static void termios_init(struct termios *tp, int
speed, struct options *op)
* later on.
*/
#ifdef __linux__
+ /* wait until all output written to the stdout has been
transmitted */
+ tcdrain(STDOUT_FILENO);


/* flush input and output queues, important for modems! */

ioctl(0, TCFLSH, TCIOFLUSH); /* tcflush(0, TCIOFLUSH)? - same */
#endif


--
Michal Simek, Ing. (M.Eng)
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel 2.6 Microblaze Linux - http://www.monstr.eu/fdt/
Microblaze U-BOOT custodian

Michal Simek

unread,
Jan 20, 2011, 3:10:01 AM1/20/11
to
Peter Korsgaard wrote:
>>>>>> "Michal" == Michal Simek <mon...@monstr.eu> writes:
>
> Hi,
>
> >> /* flush input and output queues, important for modems! */
> >> tcflush(0, TCIOFLUSH);
> >>
> >> You could change that to a tcdrain() if that's not what you want.
> >>
>
> Michal> Great that's work. Just for the record it is tcdrain(STDOUT_FILENO);
>
> Yes. Notice that the code has changed a bit in busybox git (but same
> functionality).
>
> Michal> Patch against busybox 1.14.3 version is below. Maybe worth to
> Michal> added it mainline busybox.
>
> Yes, please bring it up with the busybox devs.
>
> Michal> Thanks for your big help.
>
> You're welcome.

Will do in a sec. I will CC you too.

Thanks,
Michal

Peter Korsgaard

unread,
Jan 20, 2011, 3:10:01 AM1/20/11
to
>>>>> "Michal" == Michal Simek <mon...@monstr.eu> writes:

Hi,

>> /* flush input and output queues, important for modems! */


>> tcflush(0, TCIOFLUSH);
>>
>> You could change that to a tcdrain() if that's not what you want.
>>

Michal> Great that's work. Just for the record it is tcdrain(STDOUT_FILENO);

Yes. Notice that the code has changed a bit in busybox git (but same
functionality).

Michal> Patch against busybox 1.14.3 version is below. Maybe worth to
Michal> added it mainline busybox.

Yes, please bring it up with the busybox devs.

Michal> Thanks for your big help.

You're welcome.

--
Bye, Peter Korsgaard

0 new messages