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

RE: [PATCH] xen/arm: avoid extra caclulations when setting vtimer in context switch


  • To: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • From: Jiamei Xie <Jiamei.Xie@xxxxxxx>
  • Date: Tue, 28 Jun 2022 08:17:37 +0000
  • Accept-language: 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=hIAh/tt34y2FHhmXu+jB0X/mDmoFFAYal2qtxwfInFA=; b=NKGjR6rLTX2aNcrftGn4pBs1/28EyRvWfha+U5tl7WEHsLnLWXPavEklx3vC8+fkqwxjE9Va1rKo3xUr51+GaqCQgLzJi9HPUB3ko3XnBatMCusvyYNSVIm7nfvzWiLqTiwlS4sybeNYLpG0apsP8ALeY2MyWWGgCEZHLshioph/E55iu3GBSAC4BYPgbc6xjYtpcUHAvgg0UyMN9A/ki3NXCLE1zHYi1BlJX12eeO5akFHYkzyf9YDlbBhDhDTJRYgDaPi8OHSECe2HWHd5dPX1ni8eyB639w86qWXMlrOM2ac5ZKSV+slwVxcpX7MZRlIedmKs7NlmiCfcoi01kw==
  • 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=hIAh/tt34y2FHhmXu+jB0X/mDmoFFAYal2qtxwfInFA=; b=MwFD2M3sE3+80NaOVLsqZ5YmIkYIU+wccA3GmIbovySbahAPwER7xuSwlqAvqyaHguQzTb4wHrzPtB6liWI10sIccidf/L1fKRzofqz63H9LaSjHQr5JLaJSach6XzrSecQ70Pr7wuSgpKIUYWZlPIDoR3GpZ3d/uy9zIgFX6FfibEL8C1FyJie7ZCsGrkvQfvSMHSoeSOSe4CO67SCS0dyu1qMyCikXuf6h6R0GJS2fmNZRRHiE+pkhMAQv4mkJrgX6vl8KaO5iHErEyRegfCFP1nUp4TMaOZUixxIUmEmZHsmGRO/lh7VT/TzKw0UpQI2+bBGoc6NDVcFYOGvSHg==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=Eb1rlAdfcdNnygh/6uw4WVfZBHV02e53RCPGymL7GIuFcFgDg7Y+XsN9R5IwghDtYyeF4/iYuIxxseyzihL6lTNfO3PJAv03qp5LBfhMDnP5SXbxIK+9AEKoRrfv/gEc3LVV6BrDGeX6AtfPWV7nGXe+aqjJAvNbU8n+C2zXMX81xfMtLFtqWZ3HDn0qxMZOvFjUUtQB4q6yvoXJ9AIm/FPopw76JF53UfgtjSVaSFY1FP1QGxAMNnT65iFz3j0iK7SWf1rrqNXdZW2YCw0TDEn2Vvp97XgvwhG86g/bhhdH5odcO1l/09/Go6AO7EEbdIq5TL+HW13FTOr2DTjmzQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ScrLtuE4aY858b6mqgqgZFHe9K96+ko80KEPzk54ZaGZt4UGdCjvs/UKRDz9TeuAlNVY715oO2V+WoRzZjfixJHn44zcDXr0xh2x5AfihUtROLOW5Xysz8dwUZ40OZPdt7/0dleFZZmf3zXBSJEEyLxlk7X8yM/BJd1/mfrP6RrJTp7pxqdITKAF/KzQx2C4hob+aQaBDQRYnydqaoEys2A0qIGf+87X7uIeZqHU98oD3LlmXJ8rzGbJ2LhJIpdlm16FxoQka3eB7hbx6+QZ8UYk6jstvpwchDJN31ov8FAlsaB1n6s19858ND28WZjkVSPtb+LRTNywxt10maya9A==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Julien Grall <julien@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Wei Chen <Wei.Chen@xxxxxxx>
  • Delivery-date: Tue, 28 Jun 2022 08:18:05 +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: AQHYidHeBWnNLqFeFEKI7B/maNA44q1jD7IAgAFN1oCAABBlgIAADOqA
  • Thread-topic: [PATCH] xen/arm: avoid extra caclulations when setting vtimer in context switch

Hi Bertrand,

> -----Original Message-----
> From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
> Sent: 2022年6月28日 15:29
> To: Jiamei Xie <Jiamei.Xie@xxxxxxx>
> Cc: Julien Grall <julien@xxxxxxx>; xen-devel@xxxxxxxxxxxxxxxxxxxx; Stefano
> Stabellini <sstabellini@xxxxxxxxxx>; Volodymyr Babchuk
> <Volodymyr_Babchuk@xxxxxxxx>; Wei Chen <Wei.Chen@xxxxxxx>
> Subject: Re: [PATCH] xen/arm: avoid extra caclulations when setting vtimer
> in context switch
> 
> Hi Jiamei,
> 
> > On 28 Jun 2022, at 07:35, Jiamei Xie <Jiamei.Xie@xxxxxxx> wrote:
> >
> > Hi Julien,
> >
> >> -----Original Message-----
> >> From: Julien Grall <julien@xxxxxxx>
> >> Sent: 2022年6月27日 18:36
> >> To: Jiamei Xie <Jiamei.Xie@xxxxxxx>; xen-devel@xxxxxxxxxxxxxxxxxxxx
> >> Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>; Bertrand Marquis
> >> <Bertrand.Marquis@xxxxxxx>; Volodymyr Babchuk
> >> <Volodymyr_Babchuk@xxxxxxxx>; Wei Chen <Wei.Chen@xxxxxxx>
> >> Subject: Re: [PATCH] xen/arm: avoid extra caclulations when setting
> vtimer
> >> in context switch
> >>
> >> Hi Jiami
> >>
> >> Title: s/caclulations/calculations/
> >>
> >> However, I think the title should mention the overflow rather than the
> >> extra calculations. The former is more important the latter.
> >>
> > I will change the title to " xen/arm: avoid overflow when setting vtimer in
> context switch"
> >
> >> On 27/06/2022 03:58, Jiamei Xie wrote:
> >>> virt_vtimer_save is calculating the new time for the vtimer in:
> >>> "v->arch.virt_timer.cval + v->domain->arch.virt_timer_base.offset
> >>> - boot_count".
> >>> In this formula, "cval + offset" might cause uint64_t overflow.
> >>> Changing it to "v->domain->arch.virt_timer_base.offset - boot_count +
> >>> v->arch.virt_timer.cval" can reduce the possibility of overflow
> >>
> >> This read strange to me. We want to remove the overflow completely not
> >> reducing it. The overflow is completely removed by converting the
> >> "offset - bount_count" to ns upfront.
> >>
> >> AFAICT, the commit message doesn't explain that.
> > Thanks for pointing out that. How about putting the commit message like
> the below:
> > xen/arm: avoid overflow when setting vtimer in context switch
> >
> > virt_vtimer_save is calculating the new time for the vtimer in:
> > "v->arch.virt_timer.cval + v->domain->arch.virt_timer_base.offset
> > - boot_count".
> > In this formula, "cval + offset" might cause uint64_t overflow.
> > Changing it to "ticks_to_ns(v->domain->arch.virt_timer_base.offset -
> > boot_count) + ticks_to_ns(v->arch.virt_timer.cval)" can avoid overflow,
> > and "ticks_to_ns(arch.virt_timer_base.offset - boot_count)" will be
> > always the same, which has been caculated in domain_vtimer_init.
> > Introduce a new field virt_timer_base.nanoseconds to store this value
> > for arm in struct arch_domain, so we can use it directly.
> >>
> >>> , and
> >>> "arch.virt_timer_base.offset - boot_count" will be always the same,
> >>> which has been caculated in domain_vtimer_init. Introduce a new field
> >>> vtimer_offset.nanoseconds to store this value for arm in struct
> >>> arch_domain, so we can use it directly and extra caclulations can be
> >>> avoided.
> >>>
> >>> This patch is enlightened from [1].
> >>>
> >>> Signed-off-by: Jiamei Xie <jiamei.xie@xxxxxxx>
> >>>
> >>> [1] https://www.mail-archive.com/xen-
> >> devel@xxxxxxxxxxxxxxxxxxxx/msg123139.htm
> >>
> >> This link doesn't work. But I would personally remove it from the commit
> >> message (or add ---) because it doesn't bring value (this patch looks
> >> like a v2 to me).
> > Sorry, a 'l' is missing at the end of the link. The link is 
> > https://www.mail-
> archive.com/xen-devel@xxxxxxxxxxxxxxxxxxxx/msg123139.html .
> > I will put it after --- in v3.
> >>
> >>> ---
> >>> xen/arch/arm/include/asm/domain.h | 4 ++++
> >>> xen/arch/arm/vtimer.c | 6 ++++--
> >>> 2 files changed, 8 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/xen/arch/arm/include/asm/domain.h
> >> b/xen/arch/arm/include/asm/domain.h
> >>> index ed63c2b6f9..94fe5b6444 100644
> >>> --- a/xen/arch/arm/include/asm/domain.h
> >>> +++ b/xen/arch/arm/include/asm/domain.h
> >>> @@ -73,6 +73,10 @@ struct arch_domain
> >>> uint64_t offset;
> >>> } virt_timer_base;
> >>>
> >>> + struct {
> >>> + int64_t nanoseconds;
> >>
> >> This should be s_time_t to match the argument of set_timer() and return
> >> of ticks_to_ns().
> >>
> >>> + } vtimer_offset;
> >>
> >> Why are you adding a new structure rather than re-using virt_timer_base?
> > Sure, I'll add this field in virt_timer_base.
> > struct {
> > uint64_t offset;
> > s_time_t nanoseconds;
> > } virt_timer_base;
> >>
> >>> +
> >>> struct vgic_dist vgic;
> >>>
> >>> struct vuart {
> >>> diff --git a/xen/arch/arm/vtimer.c b/xen/arch/arm/vtimer.c
> >>> index 6b78fea77d..54161e5fea 100644
> >>> --- a/xen/arch/arm/vtimer.c
> >>> +++ b/xen/arch/arm/vtimer.c
> >>> @@ -64,6 +64,7 @@ int domain_vtimer_init(struct domain *d, struct
> >> xen_arch_domainconfig *config)
> >>> {
> >>> d->arch.virt_timer_base.offset = get_cycles();
> >>> d->time_offset.seconds = ticks_to_ns(d->arch.virt_timer_base.offset -
> >> boot_count);
> >>> + d->arch.vtimer_offset.nanoseconds = d->time_offset.seconds;
> >>
> >> Hmmm... I find odd to assign a field "nanoseconds" to "seconds". I would
> >> suggest to re-order so you first set nanoseconds and then set seconds.
> >>
> >> This will make more obvious that this is not a mistake and "seconds"
> >> will be closer to the do_div() below.
> > Is it ok to remove do_div and write like below?
> > d->arch.virt_timer_base.nanoseconds =
> > ticks_to_ns(d->arch.virt_timer_base.offset - boot_count);
> > d->time_offset.seconds = d->arch.virt_timer_base.nanoseconds /
> > 1000000000;
> 
> The implementation must use do_div to properly handle the division from a
> 64bit by a 32bit on arm32 otherwise the code will be a lot slower.

Thanks for your explanation for this. I will keep the do_div. 

Best wishes
Jiamei Xie


> 
> Cheers
> Bertrand
> 


 


Rackspace

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