Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8437d7e authored by Peter Hurley's avatar Peter Hurley Committed by Greg Kroah-Hartman
Browse files

tty: Make driver-side flip buffers lockless



Driver-side flip buffer input is already single-threaded; 'publish'
the .next link as the last operation on the tail buffer so the
'consumer' sees the already-completed flip buffer.

The commit buffer index is already 'published' by driver-side functions.

Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7bfe0b71
Loading
Loading
Loading
Loading
+4 −27
Original line number Original line Diff line number Diff line
@@ -62,8 +62,6 @@ static void tty_buffer_reset(struct tty_buffer *p, size_t size)
 *
 *
 *	Remove all the buffers pending on a tty whether queued with data
 *	Remove all the buffers pending on a tty whether queued with data
 *	or in the free ring. Must be called when the tty is no longer in use
 *	or in the free ring. Must be called when the tty is no longer in use
 *
 *	Locking: none
 */
 */


void tty_buffer_free_all(struct tty_port *port)
void tty_buffer_free_all(struct tty_port *port)
@@ -216,29 +214,26 @@ void tty_buffer_flush(struct tty_struct *tty)
 *
 *
 *	Make at least size bytes of linear space available for the tty
 *	Make at least size bytes of linear space available for the tty
 *	buffer. If we fail return the size we managed to find.
 *	buffer. If we fail return the size we managed to find.
 *
 *	Locking: Takes port->buf.lock
 */
 */
int tty_buffer_request_room(struct tty_port *port, size_t size)
int tty_buffer_request_room(struct tty_port *port, size_t size)
{
{
	struct tty_bufhead *buf = &port->buf;
	struct tty_bufhead *buf = &port->buf;
	struct tty_buffer *b, *n;
	struct tty_buffer *b, *n;
	int left;
	int left;
	unsigned long flags;

	spin_lock_irqsave(&buf->lock, flags);
	b = buf->tail;
	b = buf->tail;
	left = b->size - b->used;
	left = b->size - b->used;


	if (left < size) {
	if (left < size) {
		/* This is the slow path - looking for new buffers to use */
		/* This is the slow path - looking for new buffers to use */
		if ((n = tty_buffer_alloc(port, size)) != NULL) {
		if ((n = tty_buffer_alloc(port, size)) != NULL) {
			b->next = n;
			b->commit = b->used;
			buf->tail = n;
			buf->tail = n;
			b->commit = b->used;
			smp_mb();
			b->next = n;
		} else
		} else
			size = left;
			size = left;
	}
	}
	spin_unlock_irqrestore(&buf->lock, flags);
	return size;
	return size;
}
}
EXPORT_SYMBOL_GPL(tty_buffer_request_room);
EXPORT_SYMBOL_GPL(tty_buffer_request_room);
@@ -252,8 +247,6 @@ EXPORT_SYMBOL_GPL(tty_buffer_request_room);
 *
 *
 *	Queue a series of bytes to the tty buffering. All the characters
 *	Queue a series of bytes to the tty buffering. All the characters
 *	passed are marked with the supplied flag. Returns the number added.
 *	passed are marked with the supplied flag. Returns the number added.
 *
 *	Locking: Called functions may take port->buf.lock
 */
 */


int tty_insert_flip_string_fixed_flag(struct tty_port *port,
int tty_insert_flip_string_fixed_flag(struct tty_port *port,
@@ -288,8 +281,6 @@ EXPORT_SYMBOL(tty_insert_flip_string_fixed_flag);
 *	Queue a series of bytes to the tty buffering. For each character
 *	Queue a series of bytes to the tty buffering. For each character
 *	the flags array indicates the status of the character. Returns the
 *	the flags array indicates the status of the character. Returns the
 *	number added.
 *	number added.
 *
 *	Locking: Called functions may take port->buf.lock
 */
 */


int tty_insert_flip_string_flags(struct tty_port *port,
int tty_insert_flip_string_flags(struct tty_port *port,
@@ -324,19 +315,14 @@ EXPORT_SYMBOL(tty_insert_flip_string_flags);
 *	processing by the line discipline.
 *	processing by the line discipline.
 *	Note that this function can only be used when the low_latency flag
 *	Note that this function can only be used when the low_latency flag
 *	is unset. Otherwise the workqueue won't be flushed.
 *	is unset. Otherwise the workqueue won't be flushed.
 *
 *	Locking: Takes port->buf.lock
 */
 */


void tty_schedule_flip(struct tty_port *port)
void tty_schedule_flip(struct tty_port *port)
{
{
	struct tty_bufhead *buf = &port->buf;
	struct tty_bufhead *buf = &port->buf;
	unsigned long flags;
	WARN_ON(port->low_latency);
	WARN_ON(port->low_latency);


	spin_lock_irqsave(&buf->lock, flags);
	buf->tail->commit = buf->tail->used;
	buf->tail->commit = buf->tail->used;
	spin_unlock_irqrestore(&buf->lock, flags);
	schedule_work(&buf->work);
	schedule_work(&buf->work);
}
}
EXPORT_SYMBOL(tty_schedule_flip);
EXPORT_SYMBOL(tty_schedule_flip);
@@ -352,8 +338,6 @@ EXPORT_SYMBOL(tty_schedule_flip);
 *	accounted for as ready for normal characters. This is used for drivers
 *	accounted for as ready for normal characters. This is used for drivers
 *	that need their own block copy routines into the buffer. There is no
 *	that need their own block copy routines into the buffer. There is no
 *	guarantee the buffer is a DMA target!
 *	guarantee the buffer is a DMA target!
 *
 *	Locking: May call functions taking port->buf.lock
 */
 */


int tty_prepare_flip_string(struct tty_port *port, unsigned char **chars,
int tty_prepare_flip_string(struct tty_port *port, unsigned char **chars,
@@ -382,8 +366,6 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
 *	accounted for as ready for characters. This is used for drivers
 *	accounted for as ready for characters. This is used for drivers
 *	that need their own block copy routines into the buffer. There is no
 *	that need their own block copy routines into the buffer. There is no
 *	guarantee the buffer is a DMA target!
 *	guarantee the buffer is a DMA target!
 *
 *	Locking: May call functions taking port->buf.lock
 */
 */


int tty_prepare_flip_string_flags(struct tty_port *port,
int tty_prepare_flip_string_flags(struct tty_port *port,
@@ -511,18 +493,13 @@ void tty_flush_to_ldisc(struct tty_struct *tty)
 *
 *
 *	In the event of the queue being busy for flipping the work will be
 *	In the event of the queue being busy for flipping the work will be
 *	held off and retried later.
 *	held off and retried later.
 *
 *	Locking: tty buffer lock. Driver locks in low latency mode.
 */
 */


void tty_flip_buffer_push(struct tty_port *port)
void tty_flip_buffer_push(struct tty_port *port)
{
{
	struct tty_bufhead *buf = &port->buf;
	struct tty_bufhead *buf = &port->buf;
	unsigned long flags;


	spin_lock_irqsave(&buf->lock, flags);
	buf->tail->commit = buf->tail->used;
	buf->tail->commit = buf->tail->used;
	spin_unlock_irqrestore(&buf->lock, flags);


	if (port->low_latency)
	if (port->low_latency)
		flush_to_ldisc(&buf->work);
		flush_to_ldisc(&buf->work);