From nobody Tue Feb 10 13:01:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1602183509; cv=none; d=zohomail.com; s=zohoarc; b=N8roeMchG22HcZ9OMFwvwdOjs/p/E7dqrP8ES6d+gBR6Fvp1Qb0Q8Xc7IFPLGi5fR0cl3LS5iupJ0amXzj/olFt3wtB1NUJDhQhUIAJ9v8mNfhGy7nxM1QHVTqdamYnnUK4Z1c1f5lscBqozkA0MI4tUANZU43+73HEvu7mHPKo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602183509; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AC7LRRI1wOmmMw28VRmEhixnQ6YAW+ioZhx4wAS3Mgc=; b=QxZmmUzwq6jL7JKCKAnYxWc2Iflkl+HqmKlm9rfdUuqiWOJsuEJPvl+B8jbdwgIkpbQDYoRKLrDeQsjIcoP0SuNF5fnBeflprX4jhg504KK7gkUV+etLonf1mW/ZJ1bQpuTT7uyqnf8Q2AnEJqlyYNvk9qpxCSzIxgbu1Vvw75g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602183509960136.9951281237412; Thu, 8 Oct 2020 11:58:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.4565.12014 (Exim 4.92) (envelope-from ) id 1kQb77-0005rT-EA; Thu, 08 Oct 2020 18:58:05 +0000 Received: by outflank-mailman (output) from mailman id 4565.12014; Thu, 08 Oct 2020 18:58:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb77-0005rF-8n; Thu, 08 Oct 2020 18:58:05 +0000 Received: by outflank-mailman (input) for mailman id 4565; Thu, 08 Oct 2020 18:58:03 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb75-0005RO-P5 for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:58:03 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f4a4771c-8495-46c6-aa76-25ee6f552b4b; Thu, 08 Oct 2020 18:57:48 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6p-00041s-5r; Thu, 08 Oct 2020 18:57:47 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6o-0002P9-Ug; Thu, 08 Oct 2020 18:57:47 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb75-0005RO-P5 for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:58:03 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f4a4771c-8495-46c6-aa76-25ee6f552b4b; Thu, 08 Oct 2020 18:57:48 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6p-00041s-5r; Thu, 08 Oct 2020 18:57:47 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6o-0002P9-Ug; Thu, 08 Oct 2020 18:57:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f4a4771c-8495-46c6-aa76-25ee6f552b4b DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=AC7LRRI1wOmmMw28VRmEhixnQ6YAW+ioZhx4wAS3Mgc=; b=I/SgwdNaU4Vq24kIJOAwqscdRv Z+eGMyM/eyRDVC81hbY0ckFcIxoD/5YtKXYklLcHW+/UM6+8noE3kpf+Ypmml9H8WOHSBgBzAg+CJ GLXHQyhBAsN0XxH+fbzrHDHvHjY4YmBcLWfzIpmUae7OvJO5tvaNyWbGd8yeDq+SzE+0=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Jan Beulich , Ian Jackson , Wei Liu , Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v10 06/11] x86/time: add a domain context record for tsc_info... Date: Thu, 8 Oct 2020 19:57:30 +0100 Message-Id: <20201008185735.29875-7-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008185735.29875-1-paul@xen.org> References: <20201008185735.29875-1-paul@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) From: Paul Durrant ... and update xen-domctx to dump some information describing the record. NOTE: Whilst the record is x86 specific, it is visible directly in the comm= on header as context record numbers should be unique across all architectures. Signed-off-by: Paul Durrant Reviewed-by: Jan Beulich --- Cc: Ian Jackson Cc: Wei Liu Cc: Andrew Cooper Cc: George Dunlap Cc: Julien Grall Cc: Stefano Stabellini Cc: "Roger Pau Monn=C3=A9" v10: - Re-base - Amend the specification now there is one - Kept Jan's R-b as the changes are cosmetic v8: - Removed stray blank line v7: - New in v7 --- docs/specs/domain-context.md | 32 ++++++++++++++++++++++++++++++++ tools/misc/xen-domctx.c | 12 ++++++++++++ xen/arch/x86/time.c | 30 ++++++++++++++++++++++++++++++ xen/include/public/save.h | 8 ++++++++ 4 files changed, 82 insertions(+) diff --git a/docs/specs/domain-context.md b/docs/specs/domain-context.md index 95e9f9d1ab..8aa3466d96 100644 --- a/docs/specs/domain-context.md +++ b/docs/specs/domain-context.md @@ -155,6 +155,38 @@ The record body contains the following fields: | `buffer` | The shared info (`length` being architecture | | | dependent[4]) | =20 +### TSC_INFO + +``` + 0 1 2 3 4 5 6 7 octet ++-------+-------+-------+-------+-------+-------+-------+-------+ +| type =3D=3D 3 | instance =3D=3D 0 | ++-------------------------------+-------------------------------+ +| length =3D=3D 20 | ++-------------------------------+-------------------------------+ +| mode | khz | ++-------------------------------+-------------------------------+ +| nsec | ++-------------------------------+-------------------------------+ +| incarnation | ++-------------------------------+ +``` + +The record body contains the following fields: + +| Field | Description | +|---------------|-----------------------------------------------| +| `mode` | 0x00000000: Default (emulate if necessary) | +| | 0x00000001: Always emulate | +| | 0x00000002: Never emulate | +| | | +| `khz` | The TSC frequency in kHz | +| | | +| `nsec` | Elapsed time in nanoseconds | +| | | +| `incarnation` | Incarnation (counter indicating how many | +| | times the TSC value has been set) | + * * * =20 [1] See https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dblob;f=3Ddocs/desi= gns/non-cooperative-migration.md diff --git a/tools/misc/xen-domctx.c b/tools/misc/xen-domctx.c index 5ea6de50d1..1a5dfb9d5a 100644 --- a/tools/misc/xen-domctx.c +++ b/tools/misc/xen-domctx.c @@ -136,6 +136,17 @@ static void dump_shared_info(void) #undef GET_FIELD_PTR } =20 +static void dump_tsc_info(void) +{ + struct domain_context_tsc_info *t; + + GET_PTR(t); + + printf(" TSC_INFO: mode: %u incarnation: %u\n" + " khz %u nsec: %"PRIu64"\n", + t->mode, t->incarnation, t->khz, t->nsec); +} + static void dump_end(void) { struct domain_context_end *e; @@ -225,6 +236,7 @@ int main(int argc, char **argv) { case DOMAIN_CONTEXT_START: dump_start(); break; case DOMAIN_CONTEXT_SHARED_INFO: dump_shared_info(); break; + case DOMAIN_CONTEXT_TSC_INFO: dump_tsc_info(); break; case DOMAIN_CONTEXT_END: dump_end(); break; default: printf("Unknown type %u: skipping\n", rec->type); diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 8938c0f435..aec4bfb0f3 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -2451,6 +2452,35 @@ int tsc_set_info(struct domain *d, return 0; } =20 +static int save_tsc_info(struct domain *d, struct domain_ctxt_state *c, + bool dry_run) +{ + struct domain_context_tsc_info t =3D {}; + + if ( !dry_run ) + tsc_get_info(d, &t.mode, &t.nsec, &t.khz, &t.incarnation); + + return domain_save_ctxt_rec(c, DOMAIN_CONTEXT_TSC_INFO, 0, &t, sizeof(= t)); +} + +static int load_tsc_info(struct domain *d, struct domain_ctxt_state *c) +{ + struct domain_context_tsc_info t; + unsigned int i; + int rc; + + rc =3D domain_load_ctxt_rec(c, DOMAIN_CONTEXT_TSC_INFO, &i, &t, sizeof= (t)); + if ( rc ) + return rc; + + if ( i ) /* expect only a single instance */ + return -ENXIO; + + return tsc_set_info(d, t.mode, t.nsec, t.khz, t.incarnation); +} + +DOMAIN_REGISTER_CTXT_TYPE(TSC_INFO, save_tsc_info, load_tsc_info); + /* vtsc may incur measurable performance degradation, diagnose with this */ static void dump_softtsc(unsigned char key) { diff --git a/xen/include/public/save.h b/xen/include/public/save.h index bccbaadd0b..86881864cf 100644 --- a/xen/include/public/save.h +++ b/xen/include/public/save.h @@ -50,6 +50,7 @@ enum { DOMAIN_CONTEXT_END, DOMAIN_CONTEXT_START, DOMAIN_CONTEXT_SHARED_INFO, + DOMAIN_CONTEXT_TSC_INFO, /* New types go here */ DOMAIN_CONTEXT_NR_TYPES }; @@ -69,6 +70,13 @@ struct domain_context_shared_info { uint8_t buffer[XEN_FLEX_ARRAY_DIM]; }; =20 +struct domain_context_tsc_info { + uint32_t mode; + uint32_t khz; + uint64_t nsec; + uint32_t incarnation; +}; + /* Terminating entry */ struct domain_context_end {}; =20 --=20 2.20.1