Skip to content

Commit 9dfd16d

Browse files
peterhurleygregkh
authored andcommitted
n_tty: Avoid false-sharing echo buffer indices
Separate the head & commit indices from the tail index to avoid cache-line contention (so called 'false-sharing') between concurrent threads. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 29c7c5c commit 9dfd16d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/tty/n_tty.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ struct n_tty_data {
9090
/* producer-published */
9191
size_t read_head;
9292
size_t canon_head;
93+
size_t echo_head;
94+
size_t echo_commit;
9395
DECLARE_BITMAP(process_char_map, 256);
9496

9597
/* private to n_tty_receive_overrun (single-threaded) */
@@ -105,20 +107,17 @@ struct n_tty_data {
105107
/* shared by producer and consumer */
106108
char *read_buf;
107109
DECLARE_BITMAP(read_flags, N_TTY_BUF_SIZE);
110+
unsigned char *echo_buf;
108111

109112
int minimum_to_wake;
110113

111114
/* consumer-published */
112115
size_t read_tail;
113116

114-
unsigned char *echo_buf;
115-
size_t echo_head;
116-
size_t echo_tail;
117-
size_t echo_commit;
118-
119117
/* protected by output lock */
120118
unsigned int column;
121119
unsigned int canon_column;
120+
size_t echo_tail;
122121

123122
struct mutex atomic_read_lock;
124123
struct mutex output_lock;

0 commit comments

Comments
 (0)