From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61A67C433E0 for ; Tue, 7 Jul 2020 01:52:54 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2BF4B206F6 for ; Tue, 7 Jul 2020 01:52:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LHaY5LZg"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LKVZ0Xls" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2BF4B206F6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0GH9dgu51O2EUfQUCnz5qUY9LINvM2DzpNiVgkChBzE=; b=LHaY5LZgNT2RPhFyzzy5+szW7 55oDf/tIawHghv7gfy2/Tfe+nBzpnfQctcfKG7Zv0HZoYP4jTt5FcWg6Q19JsOhFBcrDlZtpUikAp GNz/UXb+94mxDZmyg7gOw+ZvsDt2hdpWATo6eNJY5jeonw7SV+kAC7f8wXnQfjTIR8HZnpyS0sPZs ifgrGmzjuZC5wv6E91IdASgfdieHSJyq8N6YF0zNXAc1XsOaGHsP5If7hPorram/3/V0JGhVATtlx KOVbCavwYycrxDrI/iAugyfANEcPaEGm3sD5TPQVN9RoFsENeQy+rZB06zgoW7cRmrOmd2s6k+skS bjuQw+mdg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsclR-0007eH-5F; Tue, 07 Jul 2020 01:51:17 +0000 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsclM-0007dq-3E for linux-arm-kernel@lists.infradead.org; Tue, 07 Jul 2020 01:51:14 +0000 Received: by mail-io1-xd41.google.com with SMTP id f6so25931170ioj.5 for ; Mon, 06 Jul 2020 18:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ftiox8VogXMcDaXl+jlV/61ufjpqRHFuthnUL2qNl5Y=; b=LKVZ0Xls3ZjaZXPCWJzFSu873y8aSutLaTydJU9RJUwA7iqisWSlsVrQgtqCsWMECc OEwwp02jaeYatuAL9cit6KHUDPpFGWvlLTmrEjJhQf59raU+SMlCcd2lFrJ23VGeVwi7 f3CgTNITGu0dTnEcJUPtzthzsJKALysX5uoSPL4GyrUrqUmuXHt8ndXTk87d5lGfBkHp xOVUn49fDXPOXfzdQohF6OfVgUjh8taZm4PYjltUPSP18PUfUhZr+0mQKADDT9j+so65 3tgAQ+jwb+S/w4EYw2pUWXjHv2M/zqRIHm8lfJSq5eFsqdMCy8oFYqe0UDMxD9Ee77xP lC6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ftiox8VogXMcDaXl+jlV/61ufjpqRHFuthnUL2qNl5Y=; b=YkvCrXkRU559mGxAowqz6jS2KmsPhNzGgmQ2+/eRPG0ms4x8mddxcOooqZWzuedqPN xLtow1Ek9HcIM7TvL16RA2YVTWuh6oKPJqKkYpDgj2XkTAOjP34IVGeY0jLWTO87q0id kVQKtuoZbMOdFs25RbQTOOdAGs8TzY9obZKXdZwNqMxoutcO0W/fG81t9JRY5GXAQsq4 cSZk3ruHB1Eh+EfOQKU0nRgBXjkhVuyWs16LVagw97Gq2gi4UVvB2Mq0+ca7wR6jiN6R H6ep67RuIm/hsmnwiokWVwbStxR9miBD8QeGl0i8G+iupzqFej3LRFPf0XTGl5EPVMDR hSMg== X-Gm-Message-State: AOAM533LnvDSC7Pn0871rVfBuIYSJqclfA86KPN87F2Etex8P0N9/cqm x0EiyAieuTVdojH5hJ38VFanfK/h3QEFfGdViA== X-Google-Smtp-Source: ABdhPJzS9tpkh7GCFsW5gT/nUjF6sS3ELjGFPkxtq8p/X5NJ5ZtTbiH67pLPpL+mcyjMtwz4kcdnmWmIjirJ2M4gtYA= X-Received: by 2002:a5d:96d7:: with SMTP id r23mr28574825iol.126.1594086670166; Mon, 06 Jul 2020 18:51:10 -0700 (PDT) MIME-Version: 1.0 References: <1593755079-2160-1-git-send-email-kernelfans@gmail.com> <20200703101336.GA31383@C02TD0UTHF1T.local> In-Reply-To: From: Pingfan Liu Date: Tue, 7 Jul 2020 09:50:58 +0800 Message-ID: Subject: Re: [PATCH] arm64/mm: save memory access in check_and_switch_context() fast switch path To: Mark Rutland X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200706_215112_296582_D5702735 X-CRM114-Status: GOOD ( 21.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , Vladimir Murzin , Steve Capper , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Jul 6, 2020 at 4:10 PM Pingfan Liu wrote: > > On Fri, Jul 3, 2020 at 6:13 PM Mark Rutland wrote: > > > > On Fri, Jul 03, 2020 at 01:44:39PM +0800, Pingfan Liu wrote: > > > The cpu_number and __per_cpu_offset cost two different cache lines, and may > > > not exist after a heavy user space load. > > > > > > By replacing per_cpu(active_asids, cpu) with this_cpu_ptr(&active_asids) in > > > fast path, register is used and these memory access are avoided. > > > > How about: > > > > | On arm64, smp_processor_id() reads a per-cpu `cpu_number` variable, > > | using the per-cpu offset stored in the tpidr_el1 system register. In > > | some cases we generate a per-cpu address with a sequence like: > > | > > | | cpu_ptr = &per_cpu(ptr, smp_processor_id()); > > | > > | Which potentially incurs a cache miss for both `cpu_number` and the > > | in-memory `__per_cpu_offset` array. This can be written more optimally > > | as: > > | > > | | cpu_ptr = this_cpu_ptr(ptr); > > | > > | ... which only needs the offset from tpidr_el1, and does not need to > > | load from memory. > Appreciate for your clear document. > > > > > By replacing per_cpu(active_asids, cpu) with this_cpu_ptr(&active_asids) in > > > fast path, register is used and these memory access are avoided. > > > > Do you have any numbers that show benefit here? It's not clear to me how > > often the above case would apply where the cahes would also be hot for > > everything else we need, and numbers would help to justify that. > Initially, I was just abstracted by the macro __my_cpu_offset > implement, and came to this question. But following your thinking, I > realized data is needed to make things clear. > > I have finished a test with 5.8.0-rc4 kernel on a 46 cpus qualcomm machine. > command: time -p make all -j138 > > Before this patch: > real 291.86 > user 11050.18 > sys 362.91 > > After this patch > real 291.11 > user 11055.62 > sys 363.39 > > As the data, it shows a very small improvement. The data may be affected by random factors, and less persuasive. And I tried to do some repeated tests with perf-stat. #cat b.sh make clean && make all -j138 #perf stat --repeat 10 --null --sync sh b.sh - before this patch Performance counter stats for 'sh b.sh' (10 runs): 298.62 +- 1.86 seconds time elapsed ( +- 0.62% ) - after this patch Performance counter stats for 'sh b.sh' (10 runs): 297.734 +- 0.954 seconds time elapsed ( +- 0.32% ) As the mean value 298.62 VS 297.734 shows, this trivial change does bring a small improvement in performance. > > Thanks, > Pingfan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel