From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49E371C683 for ; Tue, 31 Dec 2024 16:08:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735661289; cv=none; b=UZJEjH6wjwgEA21Hw+Ke0mRQIipbrY6H6khaeQ/6jSnbCzDXh5sk6FTfvxsGvPsBxlgPDG+eqYm5jfvAzGRN9VKtPhkYLPuPiCW1dFprZ8fWszN69IyiDzDkj/JkxcL0D5ihaBOLduzTpeAVmLdzkwR5G36hwOfiLPTLg0+4FK0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735661289; c=relaxed/simple; bh=jEMTRG1M5K0wPLoEkrop45JX02+ANpsseWYzNWTEoqc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=adqP75ZBMOqd2c8tSu3HIgn8ETcZ1giXpuafYQxjBABBvSIFI/jdg05XqsRvidlsJ1YNO5dLz+dMWMgbpZrYY/Ay53qfcFbu0M8hLtL/ZR21d+QJOYs12xnDuqY6NvbICdq0SESTeydQQ9oZO8SE4oms+dfhhArnkCM4AqfZ+Hc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PRxUTJDd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PRxUTJDd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D506C4CED2; Tue, 31 Dec 2024 16:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735661288; bh=jEMTRG1M5K0wPLoEkrop45JX02+ANpsseWYzNWTEoqc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PRxUTJDd92K6DfsomKe9zKTtytD2MANYkQZg7aLSKX1xU9naBOqzmlK8P8keJ8ke4 aF2tLjoftVe9f31ovbhrzkyAwaIYVqnWvdMrEjisGzus6tlIiZaNCApZNi87CgmfpM PGN/4aSmZPbTs0/j1F1+Grn3w6MLbjplQdKv4di+kWQq9FDHpfO00hnS++LA10Jt5r wAJ/XIB6RISV55A8HsuJcl+b0g7myEJoFN/Y3Sgm1fIDVcNvTaVLf4rCVyk12pYoDU HoQdrAKzOUo2/6EOB77NrNkKkdH78qQl3YsbkYdLWOrxSjErVBSrvGulxTbEiojnJL NwRjKEYFaRGpA== Date: Tue, 31 Dec 2024 17:08:05 +0100 From: Frederic Weisbecker To: Zhongqiu Han Cc: anna-maria@linutronix.de, tglx@linutronix.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH] timers: Optimize get_timer_cpu_base() to reduce potentially redundant per_cpu_ptr() calls Message-ID: References: <20241231150115.1978342-1-quic_zhonhan@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20241231150115.1978342-1-quic_zhonhan@quicinc.com> Le Tue, Dec 31, 2024 at 11:01:15PM +0800, Zhongqiu Han a écrit : > If the timer is deferrable and NO_HZ_COMMON is enabled, the function > get_timer_cpu_base() will call per_cpu_ptr() twice. Optimize the function > to avoid potentially redundant per_cpu_ptr() calls. > > One of the call paths of the get_timer_cpu_base() function is through the > lock_timer_base() function, which contains a loop. Within this loop, the > get_timer_base() func is called, and in turn, it calls the > get_timer_cpu_base() function. And in such a path, get_timer_cpu_base is > a hotspot function. It is called approximately 13,000 times in 12 seconds > on test x86 KVM machines. > > lock_timer_base(){ > for(;;) { > ... > --> get_timer_base() [inline] > --> get_timer_cpu_base() [inline] > ... > } > } > > With the patch, assembly code(on x86 and ARM64) to be executed in loop is > reduced. And conducting comparative tests on x86 KVM virtual machines, > comparison of runtime before and after optimization (in nanoseconds), we > can see that the distribution of runtime tends to favor smaller time > intervals. > > Before After > [0-19]: 0 [0-19]: 0 > [20-39]: 6 [20-39]: 1014 > [40-59]: 41 [40-59]: 2198 > [60-79]: 93 [60-79]: 2073 > [80-99]: 814 [80-99]: 3081 > [100-119]: 5262 [100-119]: 3268 > [120-139]: 4510 [120-139]: 671 > [140-159]: 2202 [140-159]: 468 > [160-179]: 81 [160-179]: 158 > [180-199]: 15 [180-199]: 160 > [200-219]: 3 [200-219]: 54 > [220-239]: 2 [220-239]: 7 > [240-259]: 2 [240-259]: 3 > [260-279]: 0 [260-279]: 0 > [280-299]: 0 [280-299]: 1 > [300-319]: 0 [300-319]: 0 > total: 13031 total: 13156 > > Signed-off-by: Zhongqiu Han Reviewed-by: Frederic Weisbecker