[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XEN v1] xen: arm: Check if timer is enabled for timer irq


  • To: Ayan Kumar Halder <ayankuma@xxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Wed, 10 Aug 2022 12:16:19 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=G+8nAjrwJpLnxSnU7MxAlYjalExUSHWjKcIYgXlSkmA=; b=GaM+KpxO3W+vB5n8/GFUzembNtqc6ujJouysWGHn9qIWcDYBwn3yQXA5ARS4HaZQNNDj41AyCmSLOI5Y4za+X4jQqlqZyBo3WZww6Auyb+9yIF5RY9bBe3iez13Y4NlcK57FwjfDcH7frmdvFsqKyrxIGvJaxpe/I79bySmwNWjb019BzLlv5u6GCac/t3J26GIbEdO6z6p8mC5g512CEkVyd15GvuEPQmxbdNVmtsUIhG3DlttXlkT2/sov4YmsFGuWvqjbLwH8grcvXh9+xj6McRDTbor8a1R8KAW5LIE9vlG/6nbt1m2ayH1u6NzQ/Ke0R9RY2susi9Xw+r8ZZw==
  • 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=G+8nAjrwJpLnxSnU7MxAlYjalExUSHWjKcIYgXlSkmA=; b=Fj4z5j+Tz4F62V9dwil9NEQ/PwIAVAqBkjUMiGnF00sfmH573fNfYJ5XZbE2wP7Qcc9/1nidUEUC6gDzEEyv4t43lgwnLg2AvbZOzL2V5GNUfP4dWKzLwMKJvdE6+/amZWPZeZYV4Cm6DLzWZ5Z3fLYgVlaHutVKeV7YCPfKDIVRPmo85C/4K0n5wYwMBleYt0MhAR7yD2asPQghzprQFoPFS1VYMJRinyrQe2qm9QWwV3uLNJjyQkhs4RTVf0u6qcFpjy+BNw+KahiRiTJ4gWMplY8d+k5JAZhIRK8vONAJNryBlYisErW12WvRDLS+wq88itykPJ1sYeM4KANa/w==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=cD9yxeHYs7DtJiVIbuCIOxZm3xRLhIsCWdziBwWMH3azRjAp0Mz+7ZaDy3Fi16gODRFiVPBqvEU/UKe5caP3qqhG4kFHIstJHpz+6tQMNzXKtvK3kYm1zVllcC5qDO9QL5Hn7M3j17b1oTztqbDdmHFLJhxKqr1cxeoTx+ot6saHb3aReE+j7350Ns3w098z1o8MBeYid0nd1ZcgO7vZuw6E9ZVSMUZJv62NHXlZT0J5NiNOsm58t8v2ov4AJpcOG7/Vgk9X/KnA/sohIFJf9MRKnBvcjw/7iOnIfWJAeVG0NdnQR/8dQzxHZUpu31Q2hECFb2JXPRwQBAtyMWyB8g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DmuNnrnpcljIcgqKlw6NjfIeUluIChueJQgUrT/OLCj1d8DgAFtlUnVwrjUbeEUO4E9uDXmulXgiYz5EolTpa1ry6VJfYLBfF0AAdABwSKsSUH5EzwEB+XlkUXD87pGw63DGHQwbaVk207BsTLbjCBQf2agYISAWVF31/3qJLRSrZLh0Xf0tElExMxCxd+3AhmxR01T0c3d/Ke2xQBxy0ffjvWQjr+DruPKdH8m1neJGBmXQU0WUoojLq6djBPrrF3JSAX/XM22nuJCby25DjrPqB5DHc7vDbxvZWVBT5C0pa+3kF7jd/faqpbb/Jawh10tzrvaPCqeRAu/C/WGUvw==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "sstabellini@xxxxxxxxxx" <sstabellini@xxxxxxxxxx>, "stefanos@xxxxxxx" <stefanos@xxxxxxx>, "julien@xxxxxxx" <julien@xxxxxxx>, "Volodymyr_Babchuk@xxxxxxxx" <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Wed, 10 Aug 2022 12:16:42 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYrKg/Alw9YSR5EEKrOxRi8qogf62oDK2A
  • Thread-topic: [XEN v1] xen: arm: Check if timer is enabled for timer irq

Hi Ayan,

> On 10 Aug 2022, at 11:58, Ayan Kumar Halder <ayankuma@xxxxxxx> wrote:
> 
> Refer "Arm Architecture Registers DDI 0595", AArch32 system registers,
> CNTHP_CTL :- "When the value of the ENABLE bit is 1, ISTATUS indicates
> whether the timer condition is met."
> 
> Also similar description applies to CNTP_CTL as well.
> 
> One should always check that the timer is enabled and status is set, to
> determine if the timer interrupt has been generated.
> 
> Signed-off-by: Ayan Kumar Halder <ayankuma@xxxxxxx>
> ---
> xen/arch/arm/time.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c
> index dec53b5f7d..f220586c52 100644
> --- a/xen/arch/arm/time.c
> +++ b/xen/arch/arm/time.c
> @@ -222,8 +222,13 @@ int reprogram_timer(s_time_t timeout)
> /* Handle the firing timer */
> static void timer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)
> {
> -    if ( irq == (timer_irq[TIMER_HYP_PPI]) &&
> -         READ_SYSREG(CNTHP_CTL_EL2) & CNTx_CTL_PENDING )
> +    uint8_t timer_en_mask = (CNTx_CTL_PENDING | CNTx_CTL_ENABLE);

This should either be a macro or be added directly into the condition.

But here seeing the rest of the code, I would suggest to create a macro for the
whole condition and use it directly into the ifs as I find that this solution 
using
boolean variable is making the code unclear.

May I suggest the following:
#define CNTx_CTL_IS_PENDING(reg) (READ_SYSREG(reg) & (CNTx_CTL_PENDING | 
CNTx_CTL_ENABLE))

Or in fact just adding CNTx_CTL_ENABLE in the if directly.

> +    bool timer_cond_el2 = (READ_SYSREG(CNTHP_CTL_EL2) & timer_en_mask) ==
> +        timer_en_mask ? true : false;

? True:false is redundant here and not needed.

> +    bool timer_cond_el0 = (READ_SYSREG(CNTP_CTL_EL0) & timer_en_mask) ==
> +        timer_en_mask ? true : false;

Same here

> +
> +    if ( irq == (timer_irq[TIMER_HYP_PPI]) && timer_cond_el2 )
>     {
>         perfc_incr(hyp_timer_irqs);
>         /* Signal the generic timer code to do its work */
> @@ -232,8 +237,7 @@ static void timer_interrupt(int irq, void *dev_id, struct 
> cpu_user_regs *regs)
>         WRITE_SYSREG(0, CNTHP_CTL_EL2);
>     }
> 
> -    if ( irq == (timer_irq[TIMER_PHYS_NONSECURE_PPI]) &&
> -         READ_SYSREG(CNTP_CTL_EL0) & CNTx_CTL_PENDING )
> +    if ( irq == (timer_irq[TIMER_PHYS_NONSECURE_PPI]) && timer_cond_el0 )
>     {
>         perfc_incr(phys_timer_irqs);
>         /* Signal the generic timer code to do its work */
> -- 
> 2.17.1
> 

Cheers
Bertrand


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.