From patchwork Mon Jul 24 06:24:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Schmoll X-Patchwork-Id: 9858851 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AA244600F5 for ; Mon, 24 Jul 2017 06:27:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 911CD28569 for ; Mon, 24 Jul 2017 06:27:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 854DC28571; Mon, 24 Jul 2017 06:27:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 9CA6228569 for ; Mon, 24 Jul 2017 06:27:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dZWn2-00012K-1E; Mon, 24 Jul 2017 06:24:24 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dZWn1-00012E-7z for xen-devel@lists.xenproject.org; Mon, 24 Jul 2017 06:24:23 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id A2/AB-03612-69295795; Mon, 24 Jul 2017 06:24:22 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprMIsWRWlGSWpSXmKPExsVyMbThiO7USaW RBosm61h83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBmHJy5hKVjJV7Hy2jOmBsaH3F2MXBxCAjMZ JR7PWcMG4rAIXGKReHt7DSOIIyHwjkVi3vbZ7F2MnEBOksTrz/+h7BqJz5dXsILYQgKaEl+6u xghRs1jkpg89RsLSIJNwEBi9sqLzCC2iICSxL1Vk5lAbGaBBIl7He/AmoUF9CRa138DG8oioC qx8sJjoF4ODl4BO4n9LzQhdslL7Gq7yDqBkW8BI8MqRvXi1KKy1CJdQ72kosz0jJLcxMwcXUM DM73c1OLixPTUnMSkYr3k/NxNjMBAYQCCHYw7nzsdYpTkYFIS5V2+rihSiC8pP6UyI7E4I76o NCe1+BCjDAeHkgTv0YmlkUKCRanpqRVpmTnAkIVJS3DwKInw9oCkeYsLEnOLM9MhUqcYLTmuX Fn3hYljyoHtQPLVhP/fmIRY8vLzUqXEeTeCNAiANGSU5sGNg8XVJUZZKWFeRqADhXgKUotyM0 tQ5V8xinMwKgnzXgKZwpOZVwK39RXQQUxAB+0QKgE5qCQRISXVwMjk26kRJlp6ebPunB3yPuo q/cFiCyKdpL1nt0sf+C6Uc6lnv54ao8azktgPDHuY7X6xC6XwrRbZ56Omk+gV6f25eJereX9M nCZ72zrGFw/PnQ/SX/02/d73YxM21t57sHreVcXovPZU3yXdMknsDJW7ozQ2Phb5FrV1bxRnQ qb616nFeyJslViKMxINtZiLihMB97b8J6YCAAA= X-Env-Sender: eggi.innovations@gmail.com X-Msg-Ref: server-6.tower-27.messagelabs.com!1500877461!108687140!1 X-Originating-IP: [209.85.128.196] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 13215 invoked from network); 24 Jul 2017 06:24:21 -0000 Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by server-6.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 24 Jul 2017 06:24:21 -0000 Received: by mail-wr0-f196.google.com with SMTP id y67so15828530wrb.3 for ; Sun, 23 Jul 2017 23:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rqwqKmx5yc8PW5MDqQZVFj87mYLWb1q5Wixu4Jq9UoU=; b=V1pKrPGsV2TfpYi8kgFFndKfwkVrx77mTuKKljbr8JDm6USReYDpy+rF5MAgcrUbJQ R22l/GrA/xwu8nXMtJdkPzfkqQYRlUBRbMvA4jeZFP+pmfSQvHNjUZyqYC1dHBoOPviO 50F3i8coMTjSiLlO/ZLz0UuI+nTGyyQ9z1jhRhTj6+I5SooPW//xuUo2PASbmxEHl+v2 FYbgTwPf8skQWQhUrQB8Q2Y/3GlGKWWX8psfcha6+rgRwJ/OkAGpuJtuBSYLOC/ubiG/ mFoXHeT7nOzz06iy0VoHdsBeEOboxD7cUqAgXMPkSE5yQNpvpHwviIoOvEx6+MHY0+jA UZIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rqwqKmx5yc8PW5MDqQZVFj87mYLWb1q5Wixu4Jq9UoU=; b=Ize9g0jc6fHyk7hN2URL4M3ApUDz3lwqufrCmRmXF0y3vbb0sW+cWFGs2gBJB06BTR gBkodkH7lqgx/D8HK4Hnhn/jh5XZDpJff9uZiY31Shiu/7W4ZKwOMC0eOGXiL2vQl2Mb uc2sioacEX17CDESjhQhv8+hPVuuC7ZzYcQmDkultZTlavGShoeBGFtt1tByzuvxD52/ SH+bYq2P/D7NQw7ita70OJoBSM/ZPNtSgPh62x3feXzWpDcmJC+5UytHRRZwC3RqgUNl VlLq8NFmjDmUaCMUH7pAp5yoXXd7MsiScsax2uj18TMnBQs0i+UNz9brTE6cm4swluh1 hvjA== X-Gm-Message-State: AIVw111t6l2OxcJlOv1Hb4pe3KxJgtia5C/pT1S1HNmv0CRsycdS4LHx mjiI7GQbs4Ud4A0XD/U= X-Received: by 10.223.136.178 with SMTP id f47mr13029015wrf.250.1500877461026; Sun, 23 Jul 2017 23:24:21 -0700 (PDT) Received: from localhost.localdomain (ip-109-47-3-234.web.vodafone.de. [109.47.3.234]) by smtp.gmail.com with ESMTPSA id l4sm3684884wre.46.2017.07.23.23.24.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Jul 2017 23:24:19 -0700 (PDT) From: Felix Schmoll To: xen-devel@lists.xenproject.org Date: Mon, 24 Jul 2017 08:24:15 +0200 Message-Id: <20170724062415.1542-1-eggi.innovations@gmail.com> X-Mailer: git-send-email 2.11.0 Cc: andrew.cooper3@citrix.com, wei.liu2@citrix.com, Felix Schmoll Subject: [Xen-devel] [PATCH XTF v4] Implement pv_read_some 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Implement reading from PV console. Making use of polling. Signed-off-by: Felix Schmoll Reviewed-by: Wei Liu --- Changed since v3: * Add to comment: read function blocks if no data available --- common/console.c | 26 ++++++++++++++++++++++++++ include/xtf/console.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/common/console.c b/common/console.c index 7cb2361..b1a35f4 100644 --- a/common/console.c +++ b/common/console.c @@ -46,6 +46,32 @@ static size_t pv_console_write_some(const char *buf, size_t len) } /* + * Read out data from the pv ring, either until buffer is filled or no + * more data are available. Might result in partial strings, depending + * on how xenconsoled passes in data. + * + * Will block if no data are available. + */ +size_t pv_console_read_some(char *buf, size_t len) +{ + size_t s = 0; + uint32_t cons, prod; + + while ( !test_and_clear_bit(pv_evtchn, shared_info.evtchn_pending) || + (pv_ring->in_cons == pv_ring->in_prod) ) + hypercall_poll(pv_evtchn); + + cons = pv_ring->in_cons, prod = LOAD_ACQUIRE(&pv_ring->in_prod); + + while ( (s < len) && (0 < (prod - cons)) ) + buf[s++] = pv_ring->in[cons++ & (sizeof(pv_ring->in) - 1)]; + + STORE_RELEASE(&pv_ring->in_cons, cons); + + return s; +} + +/* * Write some data into the pv ring, synchronously waiting for all data to be * consumed. */ diff --git a/include/xtf/console.h b/include/xtf/console.h index 2a93c06..caec790 100644 --- a/include/xtf/console.h +++ b/include/xtf/console.h @@ -25,6 +25,8 @@ void init_pv_console(xencons_interface_t *ring, void vprintk(const char *fmt, va_list args) __printf(1, 0); void printk(const char *fmt, ...) __printf(1, 2); +size_t pv_console_read_some(char *buf, size_t len); + #endif /* XTF_CONSOLE_H */ /*