From patchwork Tue May 30 15:30:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13260490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68BF1C7EE23 for ; Tue, 30 May 2023 15:30:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.541236.843770 (Exim 4.92) (envelope-from ) id 1q41IW-0003DK-PJ; Tue, 30 May 2023 15:30:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 541236.843770; Tue, 30 May 2023 15:30:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q41IW-0003DD-Lt; Tue, 30 May 2023 15:30:08 +0000 Received: by outflank-mailman (input) for mailman id 541236; Tue, 30 May 2023 15:30:08 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q41IW-00038g-07 for xen-devel@lists.xenproject.org; Tue, 30 May 2023 15:30:08 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on060a.outbound.protection.outlook.com [2a01:111:f400:fe0c::60a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id da4be508-fefe-11ed-8611-37d641c3527e; Tue, 30 May 2023 17:30:06 +0200 (CEST) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by PAXPR04MB8830.eurprd04.prod.outlook.com (2603:10a6:102:20d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 15:30:04 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::e442:306f:7711:e24c]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::e442:306f:7711:e24c%5]) with mapi id 15.20.6433.022; Tue, 30 May 2023 15:30:04 +0000 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: da4be508-fefe-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fVMIRt4Ysn2ESQ9jE8OCzequOH+oPAWYSM31g1/uf4ebEp+IkPpv7Npiwbwi3JUi00C5QisJOjmTGyURDbn4eRM9zurX35rwJsaf+c1WvMl0LXlU5H4hPlWfDtkXBigp5fkA2ERy/lG1xf/HplALIVv92Yic1AM9/s/tu8ZI8IjKdpmQHnxdnrmCkm0j7LghHxqE0VIPAokEo455K0D3bbUL/vm9vswxWxo21JGrnamOn6gx5pzdE7gWY6rhz53pWZqal4DLmcLH9KcUTEctTWR2U2EMpnZddFcWsWAzLG08uQe6srPGxwVswGvXFQEpoma556KUKWtvAyWpq9gquw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IAG71PtkJKdo4vtdYFhwpAHf5tOfIIddYmApNP3+/zY=; b=ZvRgD52vO67tz+jGJPgVi/WvOjMWCvhWDX+Qg5SvtxAFf0Msz9Aa3Q1Nk+v2ZlPLAOx7YFMuRrZJwAyjgZxs7OHym0Tb5N+0318Za4XTUauvz6L+4IUvekjJwhhFnl814CHltbB0un1Nq/7g38E1oNPAayqBKTj4ttEjyV2lyiZcE71RxfsZoBlleCHkUA/kJAxtYc4wFGo9m4H/6jyzVdzxebtWSls1xqMD7ICkQnPzixtT0Y5Qd3sHuOYe3ASxRd2LnZ6MwoiSJ3gAVdu81XDEsXRaIFvKaMfI0DiOKsBimbSVdfA+YMwO9vuMrUJxbFBefOOqj+ZEjonWAm88kg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IAG71PtkJKdo4vtdYFhwpAHf5tOfIIddYmApNP3+/zY=; b=KAfos2uGCkE8yU1H/NNG5lwzBXyGTkO6KJ6EOkk+wnwwGBiZYRRl8ruMSYPYAqf2LgN73ICj+qb3kqsFKpIETl4VYAg6ayXhVGOTmIJ20n1obYEZtQ/dKCJQblPyZDi9sdRsm1nvVBhj+qvS0iarPWc9GuSlW/QcR1ZJ3wg6qip8nFJL6x7nMIpGqK3Oybl3qFREDY5bH9Zw5Xpo57l9opLqkvF6YR4Avl/OSJs0UxjDcgaMBqlDSHvuUGChvpNxYypu5LfLbHraTvogBk6Ikw2HLsTTpUbJy+BLrYmGeuETpXNCTaByWYfRkHMidyofM/owHwWE/6A10Wv7UyFyHQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Tue, 30 May 2023 17:30:02 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: [PATCH 1/2] x86/vPIT: re-order functions Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= References: In-Reply-To: X-ClientProxiedBy: FR3P281CA0160.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a2::15) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|PAXPR04MB8830:EE_ X-MS-Office365-Filtering-Correlation-Id: 1036e4d9-9588-4803-ddcf-08db6122bd90 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hKEbQKUepn9bXgc7glL2LuoAybckJ8ZaNz/BFFeNcbo1Sci1wS1Yczxy2qxq0ldNz8UeMMvMuKzDFTsnKiI5iqLjyRNfPu0wKh1QmAPJVOMaKTzKns/fIDFNAbZ+noEOFrPzKKAxzmurM6HxgqajIMTuvmFsKLhmJjlXUZknzflFjAsrRLNIPKB/0GE9mC0clH/wOxenvXIDQEs8k4Ox1RwfFIRimY0wuHHHdZFw9dmbAhym3yyjhBcufVzKyN/ZJ5JrnOfh5L+IwEaBYB5J5YLw0pLk4rd10pkm9ViAwo2nJcaLAZ9YrvIzNAzfnOeLh/kiQBaoa8Wdd4j7bALsbvaczJBjlpk0jRXwxGQSNjtbkWMvrhxU3CGtWNSIsNVnwC+X7R4L7l5NDr3++27TPEgJGndqneb7y+UkatQ5oX5aTlNecKALWXfEu4sfxnbV/elBjpsOIhQsfmteG6BpJZhYfrfUnlQVY7OHfbOmb2K3gRHT4hiISL4MMlvjT/xeH2EKpoBO+1GUVYa7n+icnep0bKOG0tL71WhvtfW5GjVrl6ASseJXQteS171buLfl9ap2wfkbQJ5kJGgT5Q1OtV++u1atKtASrR3ADAtDOzsEDGrCwgk7ERopykdWCXpAdMSGdFfg2j782F4psdHDwxOaPZA463JmzbYIePnlV8eoSyXNYE1Bol7jtSZXx6lS X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(136003)(396003)(346002)(366004)(376002)(451199021)(478600001)(6486002)(54906003)(6512007)(6506007)(186003)(26005)(2906002)(6916009)(8676002)(316002)(66556008)(66476007)(8936002)(41300700001)(5660300002)(66946007)(4326008)(38100700002)(31696002)(86362001)(36756003)(83380400001)(2616005)(31686004)(169823001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?C+NJo3m74AEw+I+E9GdJq7bmK6d3?= =?utf-8?q?QkAlfzJi/y0x1v7NpIvmTP67ljFBM3ivEmk1VwHECTelo7mWRdznrmKj1D7sii8PE?= =?utf-8?q?XmFFAKvUHrjCVbZtwKFlJuWEWeq8h6HhlM/6Cyl4JUNIJxW/m0B9dXxSkGFvDDETN?= =?utf-8?q?6YVIW18yMfRh2gyGG+/iuoEKNwXZbsfZKhIn2GBMkiEwTxOUbD4AFVS1ItSu6dI0m?= =?utf-8?q?3ZdGqN/XO3iilKXHlTO9KL+3mHxPtVJJzy3MxzOL+wAoYV5Wpw/+o/MkPW2LruiVt?= =?utf-8?q?fsd5c53OP5Nj7oqsWgllqHuYWNAb0zvHgUadwi6gUJLHFG+3ZSP5rIa3IZurdfFuH?= =?utf-8?q?Y97Q9Ibz+URt8pTRR+QJRZZe+mVTL3l5UP5MqkSpyF5rumel3NF9Kma1eJ0SfJF0j?= =?utf-8?q?QE4TrO9m6Tb95R2k9uTBHUvq06vTJP/tb4wKi1oiauHHafYFFN8x3xfouiNZxyet6?= =?utf-8?q?i9xFG7QvnkmP0dZjTpiXZbz5PS1BH9BblrfIrB/qt9tom6iEl/RRlBjjpt4+Fa27d?= =?utf-8?q?DLtrF9/B4A0cC5GGX3ZYY4L6O9PWf6D5T4roc06c+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YzL79hfo9SjiybT22IOX?= =?utf-8?q?20l8FiJInE2g454TPIECIKH3p3Mez/vKgwyUawuBRm4rVIf9N5+gbcLFz7qrSNNfv?= =?utf-8?q?rwc2Tb65I2qu?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1036e4d9-9588-4803-ddcf-08db6122bd90 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 15:30:04.1710 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: D740qdPzNjVufyk4Q7plvA6Pk0Ptp8tltmIr8v+dK+aPxIXnzZ8/61L7ZXG5KUYvRGRMSYQKkKOeWNfhkq2ISA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8830 To avoid the need for a forward declaration of pit_load_count() in a subsequent change, move it earlier in the file (along with its helper callback). Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné --- a/xen/arch/x86/emul-i8254.c +++ b/xen/arch/x86/emul-i8254.c @@ -87,6 +87,57 @@ static int pit_get_count(PITState *pit, return counter; } +static void cf_check pit_time_fired(struct vcpu *v, void *priv) +{ + uint64_t *count_load_time = priv; + TRACE_0D(TRC_HVM_EMUL_PIT_TIMER_CB); + *count_load_time = get_guest_time(v); +} + +static void pit_load_count(PITState *pit, int channel, int val) +{ + u32 period; + struct hvm_hw_pit_channel *s = &pit->hw.channels[channel]; + struct vcpu *v = vpit_vcpu(pit); + + ASSERT(spin_is_locked(&pit->lock)); + + if ( val == 0 ) + val = 0x10000; + + if ( v == NULL ) + pit->count_load_time[channel] = 0; + else + pit->count_load_time[channel] = get_guest_time(v); + s->count = val; + period = DIV_ROUND(val * SYSTEM_TIME_HZ, PIT_FREQ); + + if ( (v == NULL) || !is_hvm_vcpu(v) || (channel != 0) ) + return; + + switch ( s->mode ) + { + case 2: + case 3: + /* Periodic timer. */ + TRACE_2D(TRC_HVM_EMUL_PIT_START_TIMER, period, period); + create_periodic_time(v, &pit->pt0, period, period, 0, pit_time_fired, + &pit->count_load_time[channel], false); + break; + case 1: + case 4: + /* One-shot timer. */ + TRACE_2D(TRC_HVM_EMUL_PIT_START_TIMER, period, 0); + create_periodic_time(v, &pit->pt0, period, 0, 0, pit_time_fired, + &pit->count_load_time[channel], false); + break; + default: + TRACE_0D(TRC_HVM_EMUL_PIT_STOP_TIMER); + destroy_periodic_time(&pit->pt0); + break; + } +} + static int pit_get_out(PITState *pit, int channel) { struct hvm_hw_pit_channel *s = &pit->hw.channels[channel]; @@ -156,57 +207,6 @@ static int pit_get_gate(PITState *pit, i return pit->hw.channels[channel].gate; } -static void cf_check pit_time_fired(struct vcpu *v, void *priv) -{ - uint64_t *count_load_time = priv; - TRACE_0D(TRC_HVM_EMUL_PIT_TIMER_CB); - *count_load_time = get_guest_time(v); -} - -static void pit_load_count(PITState *pit, int channel, int val) -{ - u32 period; - struct hvm_hw_pit_channel *s = &pit->hw.channels[channel]; - struct vcpu *v = vpit_vcpu(pit); - - ASSERT(spin_is_locked(&pit->lock)); - - if ( val == 0 ) - val = 0x10000; - - if ( v == NULL ) - pit->count_load_time[channel] = 0; - else - pit->count_load_time[channel] = get_guest_time(v); - s->count = val; - period = DIV_ROUND(val * SYSTEM_TIME_HZ, PIT_FREQ); - - if ( (v == NULL) || !is_hvm_vcpu(v) || (channel != 0) ) - return; - - switch ( s->mode ) - { - case 2: - case 3: - /* Periodic timer. */ - TRACE_2D(TRC_HVM_EMUL_PIT_START_TIMER, period, period); - create_periodic_time(v, &pit->pt0, period, period, 0, pit_time_fired, - &pit->count_load_time[channel], false); - break; - case 1: - case 4: - /* One-shot timer. */ - TRACE_2D(TRC_HVM_EMUL_PIT_START_TIMER, period, 0); - create_periodic_time(v, &pit->pt0, period, 0, 0, pit_time_fired, - &pit->count_load_time[channel], false); - break; - default: - TRACE_0D(TRC_HVM_EMUL_PIT_STOP_TIMER); - destroy_periodic_time(&pit->pt0); - break; - } -} - static void pit_latch_count(PITState *pit, int channel) { struct hvm_hw_pit_channel *c = &pit->hw.channels[channel]; From patchwork Tue May 30 15:30:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13260491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1B8C8C7EE2C for ; Tue, 30 May 2023 15:30:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.541239.843780 (Exim 4.92) (envelope-from ) id 1q41JB-0003jA-15; Tue, 30 May 2023 15:30:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 541239.843780; Tue, 30 May 2023 15:30:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q41JA-0003j3-UI; Tue, 30 May 2023 15:30:48 +0000 Received: by outflank-mailman (input) for mailman id 541239; Tue, 30 May 2023 15:30:48 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q41J9-0003i8-Uv for xen-devel@lists.xenproject.org; Tue, 30 May 2023 15:30:47 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on061f.outbound.protection.outlook.com [2a01:111:f400:fe0c::61f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f251c4a2-fefe-11ed-8611-37d641c3527e; Tue, 30 May 2023 17:30:46 +0200 (CEST) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by AS4PR04MB9507.eurprd04.prod.outlook.com (2603:10a6:20b:4ca::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 15:30:42 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::e442:306f:7711:e24c]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::e442:306f:7711:e24c%5]) with mapi id 15.20.6433.022; Tue, 30 May 2023 15:30:42 +0000 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: f251c4a2-fefe-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EeUJXB7Hxu9nClLUT5qqeakN+ZVjjNK6Pr+Xqaaf8SAHsoQhgTGiP3xpB43YtBIC0+V33giY8Ru4RSSxiegVLMlOpkxnaPQXmM+lRV4eI8QrYRkNze720HPSjeWNb24XlrZzt47iX62KtBHvvzHkdz5w0RplS8rHxL1HuQvQOgUAgys/tEY3X0FUHhSRuoBGDtFZDdQkWJV6H6NzYNrPGLm5is7TnD56ttandTnb97Y85R5ldZ5Zixi6pWs7S5OCvA6eF1IcmakmFoNh8LMXdV6z5wL+F/r6gNCVFzMvX5RGPVSVP24lPGYpmiXCguFkTu3gSLzYX48oP7kXVaLY1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aunSS5Nrb6KWs1AKnO9tx17OTd48iXWiBzukoYas7WI=; b=m0P0jlLbNwk+sXDhcTFqPPOUZVokbTsXQfQZg7TKIy/77dH9QpfguAUqli4dgoECuafR99aPYY9PUG3mrrJ61HtI0ELkqPGFp95mU7nrI0QpfSQrOqIWAo/P66TtJcUd7xRCAtRs8Q4W/RBTPYTvSl89b/NdI3mMqPYi6GzcHsLiXRbYG1c83T1o90DyJhZ/WFQd92sa1T4YdaaVAF/6WwbPrmJEu5hc3GXjwCaKbWs+29ILtLVS/lxtnbYnNTTL24oC9bo0aeEUt1dpqPB/ftPOXpoQJKVUKbwxtJbOBZRiIZYjHDpmeWyRaMtaFpT4CIEUupdkkJxC084GM2VTNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aunSS5Nrb6KWs1AKnO9tx17OTd48iXWiBzukoYas7WI=; b=Z8fIuuWO9EIsUKyUqSnDEFdjE9Y83usJ+1NewKo3zTyT61Ed2+vgl2ysPljux1emMmI2M74iOgEAc22ceaWII7st7KxaDJn4o9njwoLyw9adgOBbv2ShfXKaFfC56NOAeaePq6YFbfoZ84iR0Zhs1wEWk83Lfm+mkUdxJO6vZaYlwclxdVuuRBN8s7C7XjjqwM6JFc46V0hbEhfWDNLgfb9i/8c62JVQ19b25oJxynFMR97IqFgB+9MK3wQxvsN9Q5i+hnUTQWSyvoRrI/2t1Y1L2l4MAv2hj78q7O5VS+PwcYSG38QdAbh4oWkC+M8sLrN5unMV+RHzy3NmBL9ApA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <355c5379-ea9e-582c-0131-816204eb3ace@suse.com> Date: Tue, 30 May 2023 17:30:40 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: [PATCH 2/2] x86/vPIT: account for "counter stopped" time Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= References: In-Reply-To: X-ClientProxiedBy: FR0P281CA0104.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a9::15) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|AS4PR04MB9507:EE_ X-MS-Office365-Filtering-Correlation-Id: 723ce213-4386-4277-ebca-08db6122d42a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vXYFg0yQlOzJCKUvGJ3uK4K9bWi5Ey+9UOutKdyCqowqgwJS3WCLfDwNmf+7/jL7yKfDeHq9nJElpQGQuXyoqqUR/PASHwFUoZQE8v+201OTOoZyN4eZ4vVBQhEVuHDUj9VdEu2v/FY7BR6m0Kk7w4YY5GhokDCOB/BVcRszkVYnx19R8a8rzbnvAYyWtQVr3viuj8GlGK+HdiY4qDaiglGg0ZVGt9RDuMyuahyZdI72JageLRlyY/jqoN3CYkdA7xfghXUMpk2Cj6jYndUQXYtucHrPmtyhdLcg7Vd/IYQdkFyUYuXwL2bObA4Gxd0vB0B0gbJIpv8UdnOidUt6bNsJQku1AtBWoB7vIkcZCPW9Ig+Kz8CTKuehhCtBWs+wPHuaaH65RAKUPiK+z8po4k8/REhkJBUdIHrVaPcIZIp35gv4UHj8R4sZLaqD3uYwE4PctrTd5KDT/RU29KDng2ZGTFm3Pva75WVdd4HyjjtLYhySOgjNe6xCpLbRBnGfse0cKQl+2FFdRVQzb+bat/QKpO7wDHkI/Djn6UrJw6x/Pp7+HDZcu8pA9AUGIPEcQ2u7U52iUNRgPwrMiRnowMso6G+dCrcx6AhbZbDDLCq3dyfk76f8dG1awQFRZuyV/nupplM9Usv9to+ul7eGzCxmmd9uphnHBwfeas4LpaAqMtfAqztv8mscBPm+KsDFWPXVyzT+SJ3Ro5U6x66G4w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(396003)(136003)(376002)(366004)(346002)(451199021)(86362001)(31696002)(36756003)(4326008)(54906003)(6916009)(66946007)(66556008)(66476007)(966005)(316002)(478600001)(6486002)(5660300002)(8936002)(8676002)(41300700001)(2906002)(15650500001)(38100700002)(2616005)(6512007)(6506007)(26005)(186003)(83380400001)(66899021)(31686004)(21314003)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?dU2IUF7sfLFly9OkCm5GbUjnOlka?= =?utf-8?q?A21iNZVzCKUWHE50PLehS9fGShM2Ivx92n7/TxUIcXUP4397O6/4Nveu4uYkGk8jd?= =?utf-8?q?OD0td+STZ5kS/T9ML2hz3Na7T6SyrKRFQ6XR3CqoXBCU+1Km7mwtRGwPKQN5I+3yR?= =?utf-8?q?KbHFj0sqGGLG3H///UMwDZpDKjy9THruXA1AkuG/i/4aUf+6KZlgMM/KHVDiGF0fe?= =?utf-8?q?vehIZt48v/RNWcj8ydo/lFyFow50Hw+AJQMFlOVvLc/AgmY+cE8CDJ/NOwEXYYwWz?= =?utf-8?q?fIBC/MPcUtSo0ob2kDJRpxYfw7SNre0zPKuumhmi4ayK+04hnRP3Bvu1JyjJs7DzN?= =?utf-8?q?ui+Ml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WtEdKTLamShrexzNjmSFyFfOyaOtuZnh+V0GfmJgpjAfSYNozdrKa4?= =?utf-8?q?KbM6a2iuBoqjrKsl5erv+F6nuujq3ldDIraTV5udFQyldi7DNZgwZweFSJ40ov/M2?= =?utf-8?q?MjXHEn+xq5ikvF4QVk6JbGeMpIcyL/OoOGJ1ZHaBjJ8GxxpfS1evbi7k7ldZrQuns?= =?utf-8?q?Cr4WHekJewZlB8P52MVs/74AFq3951szetaDSVyaAiS/Dq9sblhPoRLQiWy3Ldnrt?= =?utf-8?q?r5tTchKk8RGA1sR5WZ3+XDbdTHjqBjQIeMAxkSS7/rv698x/dXrrNpn/j7A2EyNkx?= =?utf-8?q?y420cOQw2n6D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 723ce213-4386-4277-ebca-08db6122d42a X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 15:30:42.0772 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JW10tIzEMhVCB2CSklc+v8fl+bENzBULQELbEmDiq06F0gI2nwJiGCHiswlvR38qEh9GwUtSv0ZDI+qEJTUKpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR04MB9507 For an approach like that used in "x86: detect PIT aliasing on ports other than 0x4[0-3]" [1] to work, channel 2 may not (appear to) continue counting when "gate" is low. Record the time when "gate" goes low, and adjust pit_get_{count,out}() accordingly. Additionally for most of the modes a rising edge of "gate" doesn't mean just "resume counting", but "initiate counting", i.e. specifically the reloading of the counter with its init value. No special handling for state save/load: See the comment near the end of pit_load(). [1] https://lists.xen.org/archives/html/xen-devel/2023-05/msg00898.html Signed-off-by: Jan Beulich --- TBD: "gate" can only ever be low for chan2 (with "x86/vPIT: check/bound values loaded from state save record" [2] in place), so in principle we could get away without a new pair of arrays, but just two individual fields. At the expense of more special casing in code. TBD: Should we deal with other aspects of "gate low" in pit_get_out() here as well, right away? I was hoping to get away without ... (Note how the two functions also disagree in their placement of the "default" labels, even if that's largely benign when taking into account that modes 6 and 7 are transformed to 2 and 3 respectively by pit_load(). A difference would occur only before the guest first sets the mode, as pit_reset() sets it to 7.) Other observations: - Loading of new counts occurs too early in some of the modes (2/3: at end of current sequence or when gate goes high; 1/5: only when gate goes high). - BCD counting doesn't appear to be properly supported either (at least that's mentioned in the public header). [2] https://lists.xen.org/archives/html/xen-devel/2023-05/msg00887.html --- a/xen/arch/x86/emul-i8254.c +++ b/xen/arch/x86/emul-i8254.c @@ -65,7 +65,10 @@ static int pit_get_count(PITState *pit, ASSERT(spin_is_locked(&pit->lock)); - d = muldiv64(get_guest_time(v) - pit->count_load_time[channel], + d = pit->hw.channels[channel].gate || (c->mode & 3) == 1 + ? get_guest_time(v) - pit->count_load_time[channel] + : pit->count_stop_time[channel]; + d = muldiv64(d - pit->stopped_time[channel], PIT_FREQ, SYSTEM_TIME_HZ); switch ( c->mode ) @@ -109,6 +112,7 @@ static void pit_load_count(PITState *pit pit->count_load_time[channel] = 0; else pit->count_load_time[channel] = get_guest_time(v); + pit->stopped_time[channel] = 0; s->count = val; period = DIV_ROUND(val * SYSTEM_TIME_HZ, PIT_FREQ); @@ -147,7 +151,10 @@ static int pit_get_out(PITState *pit, in ASSERT(spin_is_locked(&pit->lock)); - d = muldiv64(get_guest_time(v) - pit->count_load_time[channel], + d = pit->hw.channels[channel].gate || (s->mode & 3) == 1 + ? get_guest_time(v) - pit->count_load_time[channel] + : pit->count_stop_time[channel]; + d = muldiv64(d - pit->stopped_time[channel], PIT_FREQ, SYSTEM_TIME_HZ); switch ( s->mode ) @@ -181,22 +188,39 @@ static void pit_set_gate(PITState *pit, ASSERT(spin_is_locked(&pit->lock)); - switch ( s->mode ) - { - default: - case 0: - case 4: - /* XXX: just disable/enable counting */ - break; - case 1: - case 5: - case 2: - case 3: - /* Restart counting on rising edge. */ - if ( s->gate < val ) - pit->count_load_time[channel] = get_guest_time(v); - break; - } + if ( s->gate > val ) + switch ( s->mode ) + { + case 0: + case 2: + case 3: + case 4: + /* Disable counting. */ + if ( !channel ) + destroy_periodic_time(&pit->pt0); + pit->count_stop_time[channel] = get_guest_time(v); + break; + } + + if ( s->gate < val ) + switch ( s->mode ) + { + default: + case 0: + case 4: + /* Enable counting. */ + pit->stopped_time[channel] += get_guest_time(v) - + pit->count_stop_time[channel]; + break; + + case 1: + case 5: + case 2: + case 3: + /* Initiate counting on rising edge. */ + pit_load_count(pit, channel, pit->hw.channels[channel].count); + break; + } s->gate = val; } --- a/xen/arch/x86/include/asm/hvm/vpt.h +++ b/xen/arch/x86/include/asm/hvm/vpt.h @@ -48,8 +48,14 @@ struct periodic_time { typedef struct PITState { /* Hardware state */ struct hvm_hw_pit hw; + /* Last time the counters read zero, for calcuating counter reads */ int64_t count_load_time[3]; + /* Last time the counters were stopped, for calcuating counter reads */ + int64_t count_stop_time[3]; + /* Accumulate "stopped" time, since the last counter write/reload. */ + uint64_t stopped_time[3]; + /* Channel 0 IRQ handling. */ struct periodic_time pt0; spinlock_t lock;