[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: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • From: Ayan Kumar Halder <ayankuma@xxxxxxx>
  • Date: Wed, 10 Aug 2022 13:54:55 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none
  • 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=e3cA+KTSXYELMHlA8I7bHiZ4wz5E/mk3H1vEQ3cwKUY=; b=h1lp4Fq7aqy+uCxAc7ZJjQwXvE4suf6B2bDzLOX1QjtfB/gfYBEqgUYBASWmHt4DQgdfdTGb9NrzDU2tjqCkyGBNLBxr+MB3ysJ5pXVPs9oxSNrAs26cRHhRHHbMfcKrYNruLwuDvFyjtYkc1+oP5Cys6K4W/qGmbptjYbHZtNMNnmWNFh+CZaNIvjlvefb0aYQgoIqHsx7Ji0SObA0c1l5pTFBsPxZEm+fUKtjEpa2IyOmWRo24HgddCY2rGmkbuuYW8GvrQ7XPJQisVFcVjTKUuh1oH/8rYA/LMWY3wq7MHK3lHj30rieyIv/WHFj2p8chBJ1N1zW6thV6sXANoQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I2l4/KYYGK7kHxrBs36SyV2tG+wRrtwa2eLMiNOWLK3w5uf1ah7mKY6jtRYgnxKik0ZmxaLgxBtR+jjr2w61qRyD/v2V5uNhCiKDd5w1Jc5BwCFawjWnat8LuTveE6zmEavrN9hUOPrxwcRqOBPVbDLaCHrr3AMwt+sEy1L6Kvat52qVjTfvubrf7fk/6uI3d3lmXwsGODa8PHpza2/VWBH+g9gv/8YCq154Qvm2U2tX+y7aEyvyREfmRQ4uMmmviBntOBAk/EYrDBpGfmY9BS9xkhHlZ/mdTGsUu2zfiTFo7CJY5wFuIfkSoT4akTCxC9kQMVbx3m1JQBisRKq4nw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.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:55:25 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 10/08/2022 13:16, Bertrand Marquis wrote:
Hi Ayan,

Hi Bertrand,


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))
This will return true even if either CNTx_CTL_PENDING or CNTx_CTL_ENABLE is set.

Or in fact just adding CNTx_CTL_ENABLE in the if directly.
We want to check that both are set.

So this should be :-
#define CNTx_CTL_IS_PENDING(reg) ( (READ_SYSREG(reg) & (CNTx_CTL_PENDING | 
CNTx_CTL_ENABLE)) ==
(CNTx_CTL_PENDING | CNTx_CTL_ENABLE) )

Let me know if you agree. I will prefer using a macro rather putting this in 
'if' condition as it might make readability difficult.

- Ayan

+    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®.