TTY: tty flip buffer with synchronous line disciplines.
Subsystems (2)
PATCH 1/1 TTY: tty flip buffer with synchronous line disciplines.
For use flip buffer with synchronous line disciplines(n_hdlc, ppp_synctty). We need only one line patch and one bit maybe in "struct tty_struct"
for turn on sync mode. If we turn on this mode on async line, nothing wrong, we loose only something performance. It works because we won't split our frame. For turn on sync mode I propose new ioctl() for pty. Although it maybe useful for other drivers too.
Restriction: We can't use frame more than TTY_BUFFER_PAGE(1792) bytes. It will be split.
It's main idea:
drivers/tty/tty_buffer.c +1 -1
@@ -207,7 +207,7 @@ int tty_buffer_request_room(struct tty_s/* OPTIMISATION: We could keep a per tty "zero" sized buffer to remove this conditional if its worth it. This would be invisible to the callers */ -if ((b = tty->buf.tail) !=NULL ) +if ((b = tty->buf.tail) !=NULL && !tty->pty_sync) left = b->size - b->used;else left =0 ;
---
drivers/tty/pty.c +18 -0
@@ -187,6 +187,22 @@ static int pty_signal(struct tty_structreturn 0 ; } +/* Set the sync flag on a pty */ +static int pty_set_sync (struct tty_struct *tty,int __user *arg) +{ +int val; +if (get_user (val, arg) ||put_user (tty->pty_sync, arg)) +return -EFAULT ; +if (val) { + tty->pty_sync =1 ; + tty->link->pty_sync =1 ; + }else { + tty->pty_sync =0 ; + tty->link->pty_sync =0 ; + } +return 0 ; +} +static void pty_flush_buffer (struct tty_struct *tty) {struct tty_struct *to = tty->link;
@@ -509,6 +525,8 @@ static int pty_unix98_ioctl(struct tty_sreturn put_user (tty->index, (unsigned int __user *)arg);case TIOCSIG :/* Send signal to other side of pty */ return pty_signal (tty, (int ) arg); +case TIOCSYNC :/* Set pty sync*/ +return pty_set_sync (tty, (int __user *)arg); }return -ENOIOCTLCMD ;
drivers/tty/tty_buffer.c +1 -1
@@ -207,7 +207,7 @@ int tty_buffer_request_room(struct tty_s/* OPTIMISATION: We could keep a per tty "zero" sized buffer to remove this conditional if its worth it. This would be invisible to the callers */ -if ((b = tty->buf.tail) !=NULL ) +if ((b = tty->buf.tail) !=NULL && !tty->pty_sync) left = b->size - b->used;else left =0 ;
include/asm-generic/ioctls.h +1 -0
@@ -74,6 +74,7 @@#define TCSETXW 0x5435#define TIOCSIG _IOW('T', 0x36, int)/* pty: generate signal */ #define TIOCVHANGUP 0x5437 +#define TIOCSYNC _IOWR('T', 0x38, int)/* Sync Pty */ #define FIONCLEX 0x5450#define FIOCLEX 0x5451
include/linux/tty.h +1 -1
@@ -280,7 +280,7 @@ struct tty_struct {int count;struct winsize winsize;/* termios mutex */ unsigned char stopped:1, hw_stopped:1, flow_stopped:1, packet:1; - unsigned char low_latency:1, warned:1; + unsigned char low_latency:1, warned:1, pty_sync:1;unsigned char ctrl_status;/* ctrl_lock */ unsigned int receive_room;/* Bytes free for queue */
Quoted 1 line · On Mon, 14 Nov 2011 21:41:36 +0400 Ilya Zykov <[email protected]> wrote:
For use flip buffer with synchronous line
disciplines(n_hdlc, ppp_synctty).
If you are doing synchronous protocols then they shouldn't be going via the tty loopback in the first place. Why can't you use tuntap and the like for synchronous protocols ? Stuffing them through the tty layer is a bad hack anyway and not one we should encourage further.
Review
Quoted 2 lines
(quoted diff) +1
-0+ if ((b = tty->buf.tail) != NULL && !tty->pty_sync) left = b->size - b->used;
What stops tty->pty_sync changing under the line discipline btw ?
Alan