Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2678562pxa; Mon, 17 Aug 2020 16:23:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylDBsXFyJr9LWoASio2dRHADAwvUoaXuxXACIeYmC+DTytBa2kYT1vIXgBoKgJHh2nWJ09 X-Received: by 2002:a17:906:8510:: with SMTP id i16mr637061ejx.76.1597706607364; Mon, 17 Aug 2020 16:23:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597706607; cv=none; d=google.com; s=arc-20160816; b=JC1LRAjByvDlp+Mrou8daoEpYiOD3B1FGW6Y5IbF9ZEyjLvpmIRMQPsGkhQGKxXQuF 05Hn0x/6+c2SkR6ItYkjP/bUTQatAhmutKFL8EJ4ZRdNsdLksA5rbCaNxMpl1P1r3UYJ XaORIuo1xeqR431LQ5/BFWqv5EsBryMhhRDx61L5hsdu6iyKT7prEeYICXFGGHjQumHy 9a4EWalAKkzMXMYxc4/J6/eI3XC1HoN1GN/7t+D+sEJOs4qeA/4VNby+jPuHJvdEVX2c zDY9ZNyT52b4DrHYWdvmqrRjxHm1Fh4JMcI8wSTgMXzoS3o2Sahw2YTJ0zsHeMGzS8EJ ufGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=u/EbLMfNqW+ecm7P7/+lVeVWoCyaxMA1ruHKaBP8G5U=; b=sS6gRmB2opnZYFIdWcl/sYFdxZmgyrQO150QRSwiOIY7ov7VI9R61CV3FOL5grg6gE wHH7yIAYH131sMGR6md+njy3vn087qI9tm2Od5aP620FVzmhMtitcdx1rcXpuCV5pPMG lDXJ/xbDHODgcOOjK91mqoDkuS3cDK0Vm7aT6mJ6ZEs2qMvHa1D4cpqQZ2yFe5/iT8fX Pzn1fMzXDHv37SRTgY3JzAJ2EUZMBCYEAKWFWl8y9y7fKLT+86xd11gQlA9gex0HDQXb p3ijmjF26GLHZuLmpcJcMLVl6qxGV31eRSYEhyX7PmmeHLLtXwidpCx4zpBuVucamDAi NDUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=icCuRZwJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u8si12130083ejr.485.2020.08.17.16.23.03; Mon, 17 Aug 2020 16:23:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=icCuRZwJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727845AbgHQW4O (ORCPT + 99 others); Mon, 17 Aug 2020 18:56:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726474AbgHQW4N (ORCPT ); Mon, 17 Aug 2020 18:56:13 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A4F1C061389; Mon, 17 Aug 2020 15:56:13 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id f9so8347535pju.4; Mon, 17 Aug 2020 15:56:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=u/EbLMfNqW+ecm7P7/+lVeVWoCyaxMA1ruHKaBP8G5U=; b=icCuRZwJpyEhTcs4ikvqOQkHvROTT02PWoLdjFa/HOzrnVkZU4wKLjhaMk2QwVvJ7U lk3Fp/gTh3pu2DtFl/jQGrUwY4obpqee+IiAVBiseYTfmHXpF/rtNXAPR2seeJEW4oDm 83ygyGZTTwRb1elwEL1DBcfsBRpLogJoAs1A/ZVEeNxNT5aOgPbGO9TudnxdRe/7cotA OKJOxkaeekdBKkxgX6mKcuoAmUCNrUmZrugwWf/PcROdFvfbr9fGx42no6wlRy1vVH4P f5TfhOTVuTtkd8O053Dlauq6IgUauPKNXhdRC7nBSxc6ADoyCTKc/rPvkCoxAr7sujN2 s32A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=u/EbLMfNqW+ecm7P7/+lVeVWoCyaxMA1ruHKaBP8G5U=; b=dZ3PLaYQoprXo2lN2nJ4LgUhpc7lBKH4dAE3op2tfyjG/832TwJOLn9zN6mbL0VcQ3 At58nrrOmoupQ3pwNQDc5QjYzGdq0BReNuzqu7jJ50VxEaHKv/9N+yM2eQGh13Bf/ndD rGxa1cDm8PpVQxQXNYkEBb2YvnYU0yXdlsTTqqEqqqpyr+zMa7pAt7GXFXlhXuq3CEDR 65V90UdWFq+IFGqqzx2PTpnFSRcEINfxBYAa26CglsGcLDHsOLy5Ns6z/kOYuFmqljNA vF1Bz47JgU2VPCQOta/3+fVDtUJxTJNXmoPQxa436uhuE9JrWassQuKTqUM94Vob4Asc nzOg== X-Gm-Message-State: AOAM530buFdsN7YGGeCFy55vHJJ8OD2Z8WmyChQhhIJy9KBwuOGaj8gd Pli00UUojsPXx+ig6DH7Tq0= X-Received: by 2002:a17:90b:384b:: with SMTP id nl11mr14089528pjb.91.1597704971653; Mon, 17 Aug 2020 15:56:11 -0700 (PDT) Received: from taoren-ubuntu-R90MNF91 (c-73-252-146-110.hsd1.ca.comcast.net. [73.252.146.110]) by smtp.gmail.com with ESMTPSA id e142sm8475411pfh.108.2020.08.17.15.56.10 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 Aug 2020 15:56:11 -0700 (PDT) Date: Mon, 17 Aug 2020 15:56:04 -0700 From: Tao Ren To: Felipe Balbi Cc: Greg Kroah-Hartman , Joel Stanley , Andrew Jeffery , Benjamin Herrenschmidt , Chunfeng Yun , Stephen Boyd , linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, taoren@fb.com Subject: Re: [PATCH] usb: gadget: aspeed: fixup vhub port irq handling Message-ID: <20200817225603.GA21228@taoren-ubuntu-R90MNF91> References: <20200528011154.30355-1-rentao.bupt@gmail.com> <875z9hz8k3.fsf@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <875z9hz8k3.fsf@kernel.org> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 17, 2020 at 04:49:32PM +0300, Felipe Balbi wrote: > > Hi, > > rentao.bupt@gmail.com writes: > > From: Tao Ren > > > > This is a follow-on patch for commit a23be4ed8f48 ("usb: gadget: aspeed: > > improve vhub port irq handling"): for_each_set_bit() is replaced with > > simple for() loop because for() loop runs faster on ASPEED BMC. > > > > Signed-off-by: Tao Ren > > --- > > drivers/usb/gadget/udc/aspeed-vhub/core.c | 10 +++------- > > drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 3 +++ > > 2 files changed, 6 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/usb/gadget/udc/aspeed-vhub/core.c b/drivers/usb/gadget/udc/aspeed-vhub/core.c > > index cdf96911e4b1..be7bb64e3594 100644 > > --- a/drivers/usb/gadget/udc/aspeed-vhub/core.c > > +++ b/drivers/usb/gadget/udc/aspeed-vhub/core.c > > @@ -135,13 +135,9 @@ static irqreturn_t ast_vhub_irq(int irq, void *data) > > > > /* Handle device interrupts */ > > if (istat & vhub->port_irq_mask) { > > - unsigned long bitmap = istat; > > - int offset = VHUB_IRQ_DEV1_BIT; > > - int size = VHUB_IRQ_DEV1_BIT + vhub->max_ports; > > - > > - for_each_set_bit_from(offset, &bitmap, size) { > > - i = offset - VHUB_IRQ_DEV1_BIT; > > - ast_vhub_dev_irq(&vhub->ports[i].dev); > > + for (i = 0; i < vhub->max_ports; i++) { > > + if (istat & VHUB_DEV_IRQ(i)) > > + ast_vhub_dev_irq(&vhub->ports[i].dev); > > how have you measured your statement above? for_each_set_bit() does > exactly what you did. Unless your architecture has an instruction which > helps finds the next set bit (like cls on ARM), which, then, makes it > much faster. I did some testing and result shows for() loop runs faster than for_each_set_bit() loop. Please refer to details below (discussion with Benjamin in the original patch) and kindly let me know your suggestions. > On Mon, 2020-04-06 at 23:02 -0700, Tao Ren wrote: > > I ran some testing on my ast2400 and ast2500 BMC and looks like the > > for() loop runs faster than for_each_set_bit_from() loop in my > > environment. I'm not sure if something needs to be revised in my test > > code, but please kindly share your suggestions: > > > > I use get_cycles() to calculate execution time of 2 different loops, and > > ast_vhub_dev_irq() is replaced with barrier() to avoid "noise"; below > > are the results: > > > > - when downstream port number is 5 and only 1 irq bit is set, it takes > > ~30 cycles to finish for_each_set_bit() loop, and 20-25 cycles to > > finish the for() loop. > > > > - if downstream port number is 5 and all 5 bits are set, then > > for_each_set_bit() loop takes ~50 cycles and for() loop takes ~25 > > cycles. > > > > - when I increase downsteam port number to 16 and set 1 irq bit, the > > for_each_set_bit() loop takes ~30 cycles and for() loop takes 25 > > cycles. It's a little surprise to me because I thought for() loop > > would cost 60+ cycles (3 times of the value when port number is 5). > > > > - if downstream port number is 16 and all irq status bits are set, > > then for_each_set_bit() loop takes 60-70 cycles and for() loop takes > > 30+ cycles. Cheers, Tao