From patchwork Mon Jul 17 10:28:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Schmoll X-Patchwork-Id: 9845213 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 165CB60392 for ; Mon, 17 Jul 2017 14:09:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07EF327D0C for ; Mon, 17 Jul 2017 14:09:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F01E928475; Mon, 17 Jul 2017 14:09:35 +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=-2.0 required=2.0 tests=BAYES_00, DATE_IN_PAST_03_06, 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 EA77D27D0C for ; Mon, 17 Jul 2017 14:09:34 +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 1dX6gH-0003gb-CY; Mon, 17 Jul 2017 14:07:25 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dX6gF-0003gU-PI for xen-devel@lists.xenproject.org; Mon, 17 Jul 2017 14:07:23 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id 18/DD-03557-B94CC695; Mon, 17 Jul 2017 14:07:23 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmkeJIrShJLcpLzFFi42Lxqg1y0p11JCf S4MdGLYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNePxXv6ChSIVbVP/sTYw3uTvYuTkEBKYyShx 9h1vFyMXB4vAJRaJVR/mM4E4EgLvWCSO39vP3MXIAeSkSfT9KAZpkBCokDjx8TwjRLOmxJfuL kaQeiGB+UwS0+5/BUuwCRhIzF55kRnEFhFQkri3ajITiM0skCBx6/JjsLiwgJrE7xczmUDmsw ioSuxewgUS5hWwk5jWvJYFYpe8xK62i6wTGPkWMDKsYtQoTi0qSy3SNbTUSyrKTM8oyU3MzNE 1NDDTy00tLk5MT81JTCrWS87P3cQIDBIGINjB+GNZwCFGSQ4mJVHei2zZkUJ8SfkplRmJxRnx RaU5qcWHGGU4OJQkeGMO50QKCRalpqdWpGXmAMMVJi3BwaMkwisCkuYtLkjMLc5Mh0idYjTmm HRg+xcmjlcT/n9jEmLJy89LlRLnnQZSKgBSmlGaBzcIFkeXGGWlhHkZgU4T4ilILcrNLEGVf8 UozsGoJMy7D2QKT2ZeCdy+V0CnMAGdIuwLdkpJIkJKqoHRULPv2g3OmoJNLaLu5SvP6vvJKRi GFNZN0u2NeXHjIsf2dRICCsV7nx09tt03REKjzeXWF6ej23Ukf8XbTf2fuWBXuZOJco70v91+ G7VnKaedfL/O/BFLukwWz4drolLNbw0zowPTfpnHXNjCOkMlz3q3yo2oG6JRIa+bOE++nZ/gb htYtUmJpTgj0VCLuag4EQCzwPjungIAAA== X-Env-Sender: eggi.innovations@gmail.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1500300442!107236565!1 X-Originating-IP: [74.125.82.66] X-SpamReason: No, hits=0.7 required=7.0 tests=DATE_IN_PAST_03_06 X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31159 invoked from network); 17 Jul 2017 14:07:22 -0000 Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by server-3.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 17 Jul 2017 14:07:22 -0000 Received: by mail-wm0-f66.google.com with SMTP id p204so23336454wmg.1 for ; Mon, 17 Jul 2017 07:07:22 -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=KybkfAvhww2EK/1yiWoehxPH34Sm5WvOQ7WKcZOpfj0=; b=UES2AcFaB5MTzbCtJ28wUR3mu1lUyxiU1jVpFfpXoOpXsLrKJ2uoVyyqsuciV4bRUI qtByDX8Sz9X5N3hdzCadKU/HFod4GRPWM93gpSnGSSJFYQFk6MMGNMOqYY1/7RBXHkYS qIW4vUgHeTedPYGNpbB+FBMsBf6bUNiJTKfrrzqRJMjByRj2K/4B3fdAUf9Y4b4A1yg6 XsDFwUegBTFchZFeaUkVeE58I5wM4ra0wIeigYApyWOyzmkZ6Dz7NFw0b+/xGc9cBykg ZNvZIEQiIXrGvcOLeOJaMeyqhSOFQ8oEe827zEZWYtdMDAt2+Uj4+hBMxyavhj5Wgjz2 fYHQ== 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=KybkfAvhww2EK/1yiWoehxPH34Sm5WvOQ7WKcZOpfj0=; b=KiqZeH0dOj9UhUeqNjAm81ntPf014sptauBeRnBT9EPRlN5oydr+/jJURC+qZEuM1X GM9P77kUgDIVLJwxeGzSALp59SLMumducXmdfAb6/KeROSs/14vyUpJSf5q7ECRUIkUG z3zn/iTzIY8OGNB/vrLXJlVkg6sJ8YHIifhWmhuTT6iTJ1K/hXT/rUKcr1fUjJvUdOA6 hfkplWONe5IDtkU8dJguYHHhX4V5bIDTBUg+4nJRR0a/vYAtw/Yc0TKFsAxsCqKQtSjD 1kO3oz5Wt4eNwejd4KDr7E+kXg+VMqnBXLZOTRTBw6fG345Pc0hPr1pTjPGD3EtGM84b kuXg== X-Gm-Message-State: AIVw113YhH8yBITtuyhU0NeA67Apwg8s1I+5bVm0GRKQOgsNS7k/SAsF IM0EYa2Jztw18i9VM7xKEQ== X-Received: by 10.28.156.20 with SMTP id f20mr4321666wme.17.1500300442035; Mon, 17 Jul 2017 07:07:22 -0700 (PDT) Received: from localhost.localdomain (ip-109-47-1-181.web.vodafone.de. [109.47.1.181]) by smtp.gmail.com with ESMTPSA id 49sm17786326wrv.23.2017.07.17.07.07.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jul 2017 07:07:21 -0700 (PDT) From: Felix Schmoll To: xen-devel@lists.xenproject.org Date: Mon, 17 Jul 2017 12:28:20 +0200 Message-Id: <20170717102820.4954-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] Implement pv_read 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 --- This is based on the console-branch of andyhhp, so that one has to be merged before applying this patch. --- common/console.c | 27 ++++++++++++++++++++++----- include/xtf/console.h | 2 ++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/common/console.c b/common/console.c index 5b4305e..66a5a06 100644 --- a/common/console.c +++ b/common/console.c @@ -7,6 +7,8 @@ #include #include +#include + /* * Output functions, registered if/when available. * Possibilities: @@ -45,6 +47,24 @@ static size_t pv_console_write_some(const char *buf, size_t len) return s; } +extern shared_info_t shared_info; +size_t pv_console_read(char *buf, size_t len) +{ + while ( !test_and_clear_bit(pv_evtchn, shared_info.evtchn_pending) || + (pv_ring->in_cons == pv_ring->in_prod ) ) + hypercall_poll(pv_evtchn); + + size_t s = 0; + uint32_t 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. @@ -70,9 +90,7 @@ static void pv_console_write(const char *buf, size_t len) { while ( ACCESS_ONCE(pv_ring->out_cons) == cons ) { - if ( !test_and_clear_bit(pv_evtchn, - shared_info.evtchn_pending) ) - hypercall_poll(pv_evtchn); + hypercall_yield(); } } @@ -81,8 +99,7 @@ static void pv_console_write(const char *buf, size_t len) /* Wait for xenconsoled to consume all the data we gave. */ while ( ACCESS_ONCE(pv_ring->out_cons) != pv_ring->out_prod ) { - if ( !test_and_clear_bit(pv_evtchn, shared_info.evtchn_pending) ) - hypercall_poll(pv_evtchn); + hypercall_yield(); } } diff --git a/include/xtf/console.h b/include/xtf/console.h index 2a93c06..9b3f85d 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(char *buf, size_t len); + #endif /* XTF_CONSOLE_H */ /*