Skip to content

Commit

Permalink
core/console: refactor __flush_console()
Browse files Browse the repository at this point in the history
Simplifies the flushing logic so that we only call into
con_driver->write() once. The existing implementation splits the
function into a normal path and a separate path when the in memory
console has wrapped. The logic is the same in both branches and
__flush_console() has enough bizarre crap happening with it's
not-a-lock-but-actually-a-lock flag variable.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Spelling-corrected-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
oohal authored and stewartsmith committed Feb 23, 2017
1 parent 5bcb6c4 commit c55f3f8
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions core/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,35 +137,36 @@ static bool __flush_console(bool flush_to_drivers)
}
in_flush = true;

/*
* NB: this must appear after the in_flush check since it modifies
* con_out.
*/
if (!flush_to_drivers) {
con_out = con_in;
in_flush = false;
return false;
}

do {
more_flush = false;

if (con_out > con_in) {
req = INMEM_CON_OUT_LEN - con_out;
if (!flush_to_drivers) {
len = req;
} else {
unlock(&con_lock);
len = con_driver->write(con_buf + con_out,
req);
lock(&con_lock);
}
con_out = (con_out + len) % INMEM_CON_OUT_LEN;
if (len < req)
goto bail;
}
if (con_out < con_in) {
if (!flush_to_drivers) {
len = con_in - con_out;
} else {
unlock(&con_lock);
len = con_driver->write(con_buf + con_out,
con_in - con_out);
lock(&con_lock);
}
con_out = (con_out + len) % INMEM_CON_OUT_LEN;
}
more_flush = true;
} else
req = con_in - con_out;

unlock(&con_lock);
len = con_driver->write(con_buf + con_out, req);
lock(&con_lock);

con_out = (con_out + len) % INMEM_CON_OUT_LEN;

/* write error? */
if (len < req)
break;
} while(more_flush);
bail:

in_flush = false;
return con_out != con_in;
}
Expand Down

0 comments on commit c55f3f8

Please sign in to comment.