Skip to content

Commit

Permalink
n_tty: Remove read_cnt
Browse files Browse the repository at this point in the history
Storing the read_cnt creates an unnecessary shared variable
between the single-producer (n_tty_receive_buf()) and the
single-consumer (n_tty_read()).

Compute read_cnt from head & tail instead of storing.

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
peterhurley authored and gregkh committed Jul 23, 2013
1 parent bc5a5e3 commit a2f73be
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions drivers/tty/n_tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ struct n_tty_data {
char *read_buf;
size_t read_head;
size_t read_tail;
int read_cnt;
int minimum_to_wake;

unsigned char *echo_buf;
Expand All @@ -117,7 +116,7 @@ struct n_tty_data {

static inline size_t read_cnt(struct n_tty_data *ldata)
{
return ldata->read_cnt;
return ldata->read_head - ldata->read_tail;
}

static inline unsigned char read_buf(struct n_tty_data *ldata, size_t i)
Expand Down Expand Up @@ -198,7 +197,6 @@ static void put_tty_queue_nolock(unsigned char c, struct n_tty_data *ldata)
if (read_cnt(ldata) < N_TTY_BUF_SIZE) {
*read_buf_addr(ldata, ldata->read_head) = c;
ldata->read_head++;
ldata->read_cnt++;
}
}

Expand Down Expand Up @@ -239,7 +237,7 @@ static void reset_buffer_flags(struct n_tty_data *ldata)
unsigned long flags;

raw_spin_lock_irqsave(&ldata->read_lock, flags);
ldata->read_head = ldata->read_tail = ldata->read_cnt = 0;
ldata->read_head = ldata->read_tail = 0;
raw_spin_unlock_irqrestore(&ldata->read_lock, flags);

mutex_lock(&ldata->echo_lock);
Expand Down Expand Up @@ -942,16 +940,12 @@ static void eraser(unsigned char c, struct tty_struct *tty)
else {
if (!L_ECHO(tty)) {
raw_spin_lock_irqsave(&ldata->read_lock, flags);
ldata->read_cnt -= ((ldata->read_head - ldata->canon_head) &
(N_TTY_BUF_SIZE - 1));
ldata->read_head = ldata->canon_head;
raw_spin_unlock_irqrestore(&ldata->read_lock, flags);
return;
}
if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) {
raw_spin_lock_irqsave(&ldata->read_lock, flags);
ldata->read_cnt -= ((ldata->read_head - ldata->canon_head) &
(N_TTY_BUF_SIZE - 1));
ldata->read_head = ldata->canon_head;
raw_spin_unlock_irqrestore(&ldata->read_lock, flags);
finish_erasing(ldata);
Expand Down Expand Up @@ -989,7 +983,6 @@ static void eraser(unsigned char c, struct tty_struct *tty)
cnt = ldata->read_head - head;
raw_spin_lock_irqsave(&ldata->read_lock, flags);
ldata->read_head = head;
ldata->read_cnt -= cnt;
raw_spin_unlock_irqrestore(&ldata->read_lock, flags);
if (L_ECHO(tty)) {
if (L_ECHOPRT(tty)) {
Expand Down Expand Up @@ -1448,7 +1441,6 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
i = min(count, i);
memcpy(read_buf_addr(ldata, ldata->read_head), cp, i);
ldata->read_head += i;
ldata->read_cnt += i;
cp += i;
count -= i;

Expand All @@ -1457,7 +1449,6 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
i = min(count, i);
memcpy(read_buf_addr(ldata, ldata->read_head), cp, i);
ldata->read_head += i;
ldata->read_cnt += i;
raw_spin_unlock_irqrestore(&ldata->read_lock, cpuflags);
} else {
for (i = count, p = cp, f = fp; i; i--, p++) {
Expand Down Expand Up @@ -1762,7 +1753,6 @@ static int copy_from_read_buf(struct tty_struct *tty,
ldata->icanon);
raw_spin_lock_irqsave(&ldata->read_lock, flags);
ldata->read_tail += n;
ldata->read_cnt -= n;
/* Turn single EOF into zero-length read */
if (L_EXTPROC(tty) && ldata->icanon && is_eof && !read_cnt(ldata))
n = 0;
Expand Down Expand Up @@ -1850,7 +1840,6 @@ static int canon_copy_from_read_buf(struct tty_struct *tty,

raw_spin_lock_irqsave(&ldata->read_lock, flags);
ldata->read_tail += c;
ldata->read_cnt -= c;
if (found) {
__clear_bit(eol, ldata->read_flags);
/* this test should be redundant:
Expand Down

0 comments on commit a2f73be

Please sign in to comment.