From patchwork Fri Mar 4 16:46:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 8506261 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BD3E69F7CA for ; Fri, 4 Mar 2016 16:49:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 685F420121 for ; Fri, 4 Mar 2016 16:49:12 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0855E2013A for ; Fri, 4 Mar 2016 16:49:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1abss9-0002rV-FN; Fri, 04 Mar 2016 16:46:37 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1abss8-0002rM-KV for xen-devel@lists.xenproject.org; Fri, 04 Mar 2016 16:46:36 +0000 Received: from [85.158.137.68] by server-16.bemta-3.messagelabs.com id 39/03-02994-BEBB9D65; Fri, 04 Mar 2016 16:46:35 +0000 X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1457109992!26988649!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 44884 invoked from network); 4 Mar 2016 16:46:34 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-14.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 4 Mar 2016 16:46:34 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Fri, 04 Mar 2016 09:46:31 -0700 Message-Id: <56D9C9F802000078000D992D@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Fri, 04 Mar 2016 09:46:32 -0700 From: "Jan Beulich" To: "xen-devel" References: <56D9C80702000078000D9910@prv-mh.provo.novell.com> In-Reply-To: <56D9C80702000078000D9910@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Keir Fraser , Ian Jackson , Tim Deegan Subject: [Xen-devel] [PATCH v2 1/3] console: allow log level threshold adjustments X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ... from serial console and via sysctl so that one doesn't always need to reboot to see more / less messages. Note that upper thresholds driven from the serial console are sticky, i.e. while they get adjusted upwards when the lower threshold would otherwise end up above the upper one, they don't get adjusted when reducing the lower one. Full flexibility is available only via the sysctl interface. Signed-off-by: Jan Beulich --- v2: Add sysctl. console: allow log level threshold adjustments ... from serial console and via sysctl so that one doesn't always need to reboot to see more / less messages. Note that upper thresholds driven from the serial console are sticky, i.e. while they get adjusted upwards when the lower threshold would otherwise end up above the upper one, they don't get adjusted when reducing the lower one. Full flexibility is available only via the sysctl interface. Signed-off-by: Jan Beulich --- v2: Add sysctl. --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -460,6 +460,10 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe ret = tmem_control(&op->u.tmem_op); break; + case XEN_SYSCTL_loglvl_op: + ret = console_loglvl_op(&op->u.loglvl); + break; + default: ret = arch_do_sysctl(op, u_sysctl); copyback = 0; --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -168,7 +168,7 @@ static void __init parse_guest_loglvl(ch _parse_loglvl(s, &xenlog_guest_lower_thresh, &xenlog_guest_upper_thresh); } -static char * __init loglvl_str(int lvl) +static char *loglvl_str(int lvl) { switch ( lvl ) { @@ -181,6 +181,119 @@ static char * __init loglvl_str(int lvl) return "???"; } +static int *__read_mostly upper_thresh_adj = &xenlog_upper_thresh; +static int *__read_mostly lower_thresh_adj = &xenlog_lower_thresh; +static const char *__read_mostly thresh_adj = "standard"; + +static void do_toggle_guest(unsigned char key, struct cpu_user_regs *regs) +{ + if ( upper_thresh_adj == &xenlog_upper_thresh ) + { + upper_thresh_adj = &xenlog_guest_upper_thresh; + lower_thresh_adj = &xenlog_guest_lower_thresh; + thresh_adj = "guest"; + } + else + { + upper_thresh_adj = &xenlog_upper_thresh; + lower_thresh_adj = &xenlog_lower_thresh; + thresh_adj = "standard"; + } + printk("'%c' pressed -> %s log level adjustments enabled\n", + key, thresh_adj); +} + +static void do_adj_thresh(unsigned char key) +{ + if ( *upper_thresh_adj < *lower_thresh_adj ) + *upper_thresh_adj = *lower_thresh_adj; + printk("'%c' pressed -> %s log level: %s (rate limited %s)\n", + key, thresh_adj, loglvl_str(*lower_thresh_adj), + loglvl_str(*upper_thresh_adj)); +} + +static void do_inc_thresh(unsigned char key, struct cpu_user_regs *regs) +{ + ++*lower_thresh_adj; + do_adj_thresh(key); +} + +static void do_dec_thresh(unsigned char key, struct cpu_user_regs *regs) +{ + if ( *lower_thresh_adj ) + --*lower_thresh_adj; + do_adj_thresh(key); +} + +static void __putstr(const char *); +static void printk_start_of_line(const char *); + +static void do_loglvl_op(const struct xen_sysctl_loglvl_thresh *op, + int *lower, int *upper, const char *which) +{ + if ( op->lower_thresh < 0 && op->upper_thresh < 0 ) + return; + + if ( op->lower_thresh >= 0 ) + *lower = op->lower_thresh; + + if ( op->upper_thresh >= 0 ) + *upper = op->upper_thresh; + + if ( *upper < *lower ) + { + if ( op->upper_thresh < 0 ) + *upper = *lower; + else + *lower = *upper; + } + + if ( printk_ratelimit() ) + { + spin_lock_irq(&console_lock); + printk_start_of_line("(XEN) "); + __putstr(which); + __putstr(" log level: "); + __putstr(loglvl_str(*lower)); + __putstr(" (rate limited "); + __putstr(loglvl_str(*upper)); + __putstr(")\n"); + spin_unlock_irq(&console_lock); + } +} + +int console_loglvl_op(struct xen_sysctl_loglvl_op *op) +{ + switch ( op->cmd ) + { + default: + return -EOPNOTSUPP; + + case XEN_SYSCTL_LOGLVL_set: + if ( (op->host.lower_thresh >= 0 && op->host.upper_thresh >= 0 && + op->host.lower_thresh > op->host.upper_thresh) || + (op->guest.lower_thresh >= 0 && op->guest.upper_thresh >= 0 && + op->guest.lower_thresh > op->guest.upper_thresh) ) + return -EINVAL; + + do_loglvl_op(&op->host, &xenlog_lower_thresh, + &xenlog_upper_thresh, "standard"); + do_loglvl_op(&op->guest, &xenlog_guest_lower_thresh, + &xenlog_guest_upper_thresh, "guest"); + + /* fall through */ + case XEN_SYSCTL_LOGLVL_get: + op->host.lower_thresh = xenlog_lower_thresh; + op->host.upper_thresh = xenlog_upper_thresh; + + op->guest.lower_thresh = xenlog_guest_lower_thresh; + op->guest.upper_thresh = xenlog_guest_upper_thresh; + + break; + } + + return 0; +} /* * ******************************************************** * *************** ACCESS TO CONSOLE RING ***************** @@ -833,6 +946,12 @@ void __init console_endboot(void) register_keyhandler('w', dump_console_ring_key, "synchronously dump console ring buffer (dmesg)", 0); + register_irq_keyhandler('+', &do_inc_thresh, + "increase log level threshold", 0); + register_irq_keyhandler('-', &do_dec_thresh, + "decrease log level threshold", 0); + register_irq_keyhandler('G', &do_toggle_guest, + "toggle host/guest log level adjustment", 0); /* Serial input is directed to DOM0 by default. */ switch_serial_input(); --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -766,6 +766,17 @@ struct xen_sysctl_tmem_op { typedef struct xen_sysctl_tmem_op xen_sysctl_tmem_op_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_tmem_op_t); +/* XEN_SYSCTL_loglvl_op */ +#define XEN_SYSCTL_LOGLVL_get 0 +#define XEN_SYSCTL_LOGLVL_set 1 +struct xen_sysctl_loglvl_op { + uint32_t cmd; /* XEN_SYSCTL_LOGLVL_* */ + struct xen_sysctl_loglvl_thresh { + /* Negative values mean "no adjustment". */ + int32_t lower_thresh, upper_thresh; + } host, guest; +}; + struct xen_sysctl { uint32_t cmd; #define XEN_SYSCTL_readconsole 1 @@ -791,6 +802,7 @@ struct xen_sysctl { #define XEN_SYSCTL_pcitopoinfo 22 #define XEN_SYSCTL_psr_cat_op 23 #define XEN_SYSCTL_tmem_op 24 +#define XEN_SYSCTL_loglvl_op 25 uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */ union { struct xen_sysctl_readconsole readconsole; @@ -816,6 +828,7 @@ struct xen_sysctl { struct xen_sysctl_psr_cmt_op psr_cmt_op; struct xen_sysctl_psr_cat_op psr_cat_op; struct xen_sysctl_tmem_op tmem_op; + struct xen_sysctl_loglvl_op loglvl; uint8_t pad[128]; } u; }; --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -12,6 +12,8 @@ struct xen_sysctl_readconsole; long read_console_ring(struct xen_sysctl_readconsole *op); +struct xen_sysctl_loglvl_op; +int console_loglvl_op(struct xen_sysctl_loglvl_op *); void console_init_preirq(void); void console_init_ring(void); --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -460,6 +460,10 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe ret = tmem_control(&op->u.tmem_op); break; + case XEN_SYSCTL_loglvl_op: + ret = console_loglvl_op(&op->u.loglvl); + break; + default: ret = arch_do_sysctl(op, u_sysctl); copyback = 0; --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -168,7 +168,7 @@ static void __init parse_guest_loglvl(ch _parse_loglvl(s, &xenlog_guest_lower_thresh, &xenlog_guest_upper_thresh); } -static char * __init loglvl_str(int lvl) +static char *loglvl_str(int lvl) { switch ( lvl ) { @@ -181,6 +181,119 @@ static char * __init loglvl_str(int lvl) return "???"; } +static int *__read_mostly upper_thresh_adj = &xenlog_upper_thresh; +static int *__read_mostly lower_thresh_adj = &xenlog_lower_thresh; +static const char *__read_mostly thresh_adj = "standard"; + +static void do_toggle_guest(unsigned char key, struct cpu_user_regs *regs) +{ + if ( upper_thresh_adj == &xenlog_upper_thresh ) + { + upper_thresh_adj = &xenlog_guest_upper_thresh; + lower_thresh_adj = &xenlog_guest_lower_thresh; + thresh_adj = "guest"; + } + else + { + upper_thresh_adj = &xenlog_upper_thresh; + lower_thresh_adj = &xenlog_lower_thresh; + thresh_adj = "standard"; + } + printk("'%c' pressed -> %s log level adjustments enabled\n", + key, thresh_adj); +} + +static void do_adj_thresh(unsigned char key) +{ + if ( *upper_thresh_adj < *lower_thresh_adj ) + *upper_thresh_adj = *lower_thresh_adj; + printk("'%c' pressed -> %s log level: %s (rate limited %s)\n", + key, thresh_adj, loglvl_str(*lower_thresh_adj), + loglvl_str(*upper_thresh_adj)); +} + +static void do_inc_thresh(unsigned char key, struct cpu_user_regs *regs) +{ + ++*lower_thresh_adj; + do_adj_thresh(key); +} + +static void do_dec_thresh(unsigned char key, struct cpu_user_regs *regs) +{ + if ( *lower_thresh_adj ) + --*lower_thresh_adj; + do_adj_thresh(key); +} + +static void __putstr(const char *); +static void printk_start_of_line(const char *); + +static void do_loglvl_op(const struct xen_sysctl_loglvl_thresh *op, + int *lower, int *upper, const char *which) +{ + if ( op->lower_thresh < 0 && op->upper_thresh < 0 ) + return; + + if ( op->lower_thresh >= 0 ) + *lower = op->lower_thresh; + + if ( op->upper_thresh >= 0 ) + *upper = op->upper_thresh; + + if ( *upper < *lower ) + { + if ( op->upper_thresh < 0 ) + *upper = *lower; + else + *lower = *upper; + } + + if ( printk_ratelimit() ) + { + spin_lock_irq(&console_lock); + printk_start_of_line("(XEN) "); + __putstr(which); + __putstr(" log level: "); + __putstr(loglvl_str(*lower)); + __putstr(" (rate limited "); + __putstr(loglvl_str(*upper)); + __putstr(")\n"); + spin_unlock_irq(&console_lock); + } +} + +int console_loglvl_op(struct xen_sysctl_loglvl_op *op) +{ + switch ( op->cmd ) + { + default: + return -EOPNOTSUPP; + + case XEN_SYSCTL_LOGLVL_set: + if ( (op->host.lower_thresh >= 0 && op->host.upper_thresh >= 0 && + op->host.lower_thresh > op->host.upper_thresh) || + (op->guest.lower_thresh >= 0 && op->guest.upper_thresh >= 0 && + op->guest.lower_thresh > op->guest.upper_thresh) ) + return -EINVAL; + + do_loglvl_op(&op->host, &xenlog_lower_thresh, + &xenlog_upper_thresh, "standard"); + do_loglvl_op(&op->guest, &xenlog_guest_lower_thresh, + &xenlog_guest_upper_thresh, "guest"); + + /* fall through */ + case XEN_SYSCTL_LOGLVL_get: + op->host.lower_thresh = xenlog_lower_thresh; + op->host.upper_thresh = xenlog_upper_thresh; + + op->guest.lower_thresh = xenlog_guest_lower_thresh; + op->guest.upper_thresh = xenlog_guest_upper_thresh; + + break; + } + + return 0; +} /* * ******************************************************** * *************** ACCESS TO CONSOLE RING ***************** @@ -833,6 +946,12 @@ void __init console_endboot(void) register_keyhandler('w', dump_console_ring_key, "synchronously dump console ring buffer (dmesg)", 0); + register_irq_keyhandler('+', &do_inc_thresh, + "increase log level threshold", 0); + register_irq_keyhandler('-', &do_dec_thresh, + "decrease log level threshold", 0); + register_irq_keyhandler('G', &do_toggle_guest, + "toggle host/guest log level adjustment", 0); /* Serial input is directed to DOM0 by default. */ switch_serial_input(); --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -766,6 +766,17 @@ struct xen_sysctl_tmem_op { typedef struct xen_sysctl_tmem_op xen_sysctl_tmem_op_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_tmem_op_t); +/* XEN_SYSCTL_loglvl_op */ +#define XEN_SYSCTL_LOGLVL_get 0 +#define XEN_SYSCTL_LOGLVL_set 1 +struct xen_sysctl_loglvl_op { + uint32_t cmd; /* XEN_SYSCTL_LOGLVL_* */ + struct xen_sysctl_loglvl_thresh { + /* Negative values mean "no adjustment". */ + int32_t lower_thresh, upper_thresh; + } host, guest; +}; + struct xen_sysctl { uint32_t cmd; #define XEN_SYSCTL_readconsole 1 @@ -791,6 +802,7 @@ struct xen_sysctl { #define XEN_SYSCTL_pcitopoinfo 22 #define XEN_SYSCTL_psr_cat_op 23 #define XEN_SYSCTL_tmem_op 24 +#define XEN_SYSCTL_loglvl_op 25 uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */ union { struct xen_sysctl_readconsole readconsole; @@ -816,6 +828,7 @@ struct xen_sysctl { struct xen_sysctl_psr_cmt_op psr_cmt_op; struct xen_sysctl_psr_cat_op psr_cat_op; struct xen_sysctl_tmem_op tmem_op; + struct xen_sysctl_loglvl_op loglvl; uint8_t pad[128]; } u; }; --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -12,6 +12,8 @@ struct xen_sysctl_readconsole; long read_console_ring(struct xen_sysctl_readconsole *op); +struct xen_sysctl_loglvl_op; +int console_loglvl_op(struct xen_sysctl_loglvl_op *); void console_init_preirq(void); void console_init_ring(void);