[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:58:08 +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=YljHEp5KpgzEgZuXkKvaWSJRwVkL+cWNXToYLrpMveg=; b=Z6HXzxU0Pxx1h2xUG7iI+n0d4dmPPHfswqfNZ0NNTUFnK58VNNS1GgsPnafxroiN7FnZz0pJRghs12SAE1GxuE4Uvp/SxIx90Cga6NunAheMNdIrLdki6zQJhEsetC0NB12OcZyYjlS0KPxO929roDlHZs3Vp6MNqPZzHCLTfqlb6OJ6sFTS5S0pNzVKjYvzaUNGZrOwl47UWl+fsgZYkrQcxreW5BIdFjfLlkjycpbs6QsB2fU1YFH1whNwHhwpJw6Av/jduNzLIYfjdPrIxbUNu3LufjUohbjAGh6MqdvTZ7DqCWoO8+mnYuhW81/vQlZEB0yz5DtNRUHZOHg3wg==
  • 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=YljHEp5KpgzEgZuXkKvaWSJRwVkL+cWNXToYLrpMveg=; b=AyGfv2JbHl84hNiDc4ivvClLYSqTpc+M3I+XQBxIGgRCP0o/F+uI4JADhYDVT3C4nkMt8FTsH5VodhrK2YD3lBSYyChc2NXMbX/NuFDohD4QV427KOBozeDXpKhUnCkzYzIeQ7/O0T20Jsk9/VLQnhihG4H5Pyf/2uMRXOPr1CDQcnOjX7K/cb2wAutT13EUdJYUHvyryruvI516SQwy13P2TTkXq/kHXupLTHmu1wkxtWe3QWGCVi/a1Mnd/gfz7Bc/GOLxZNvPxUl6VmsNB3eyFTOsQ2gi2GhUTJ2GJ95WXbT7yxIgn3inOztQrA/+kBgGp4rPKgxR9g5kmZr8+A==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=Ymi591X6/Nju06uousMkgXPXSDOJkzBBFG52EMoW9aZgx/uhpyJsoVVWd96PwRldA8n7Z4aD9VAcKkvVelRRI/J5bXihy6MY7ZseBDf4gr5o7QGBWufQRg1cqVb6rdqvXfhYN5G+EqePk10X3Kfx3oXOQLdrABnwSA328gOHhuruqkkOey1IgyRQKIintcYvwNqYW46UHQBn6jTPEOSR9iO/3p92aF7jkwu/m1cmvFgzXCnZK1vnaypB2fuFCkytnLO+ET8qgjppn5NHswvYVR3OkG+p+Vs8bK3LeFfdtzccGSIN1fSqkX7eaQRNBxU5wI+yQptT4z3s1OizSwZrVw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T1vELt888pRK9qNx/lhjwY2O9z8v0xD/sFtsEJCPrP9eseAgCh/Jyv0/NqgLjDoUNKKyaZm2e0wWhxu54LKooghTWI/Ibd/Z1zOBHk7bkiPro+2U8rDVRuQdxw8uXQYATnZgPORzj9JzgbECaj0G//CQm/kffYkuI+0xNvzaF438mVCv/ANuk5JxN9XBL9/Cq/9M6VO82c8Y+ivFnNNgKZDKOZaaZhrBHqnVadRyE6+L0FG+3kIbfY2Nm15D/J986bw5coGI4fFJQ/fPZrBr5IrMpYM5nsUMpKUQVWSwV9lSfb5cs7xWGtlEI0a/uL0QDAemNXcPYQp/JxI2qZJjGg==
  • 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:58:25 +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/Alw9YSR5EEKrOxRi8qogf62oDK2AgAAKyYCAAADmAA==
  • Thread-topic: [XEN v1] xen: arm: Check if timer is enabled for timer irq

Hi Ayan,

> On 10 Aug 2022, at 13:54, Ayan Kumar Halder <ayankuma@xxxxxxx> wrote:
> 
> 
> 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.

Yes this is missing the comparison part

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

Yes I agree

Bertrand

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