[PATCH] TTY: tty flip buffer with synchronous line disciplines.

From: Ilya Zykov
Date: Mon Nov 14 2011 - 12:41:41 EST


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:

diff -uprN -X ../../dontdiff a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
--- a/drivers/tty/tty_buffer.c 2011-11-12 00:19:27.000000000 +0400
+++ b/drivers/tty/tty_buffer.c 2011-11-14 20:29:50.000000000 +0400
@@ -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;


Signed-off-by: Ilya Zykov <ilya@xxxxxxx>
---
diff -uprN -X ../../dontdiff a/drivers/tty/pty.c b/drivers/tty/pty.c
--- a/drivers/tty/pty.c 2011-11-12 00:19:27.000000000 +0400
+++ b/drivers/tty/pty.c 2011-11-14 20:34:07.000000000 +0400
@@ -187,6 +187,22 @@ static int pty_signal(struct tty_struct
return 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_s
return 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;
diff -uprN -X ../../dontdiff a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
--- a/drivers/tty/tty_buffer.c 2011-11-12 00:19:27.000000000 +0400
+++ b/drivers/tty/tty_buffer.c 2011-11-14 20:29:50.000000000 +0400
@@ -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;
diff -uprN -X ../../dontdiff a/include/asm-generic/ioctls.h b/include/asm-generic/ioctls.h
--- a/include/asm-generic/ioctls.h 2011-11-12 00:19:27.000000000 +0400
+++ b/include/asm-generic/ioctls.h 2011-11-14 20:28:15.000000000 +0400
@@ -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
diff -uprN -X ../../dontdiff a/include/linux/tty.h b/include/linux/tty.h
--- a/include/linux/tty.h 2011-11-12 00:19:27.000000000 +0400
+++ b/include/linux/tty.h 2011-11-14 20:28:56.000000000 +0400
@@ -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 */

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/