From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752521AbbIJEVe (ORCPT ); Thu, 10 Sep 2015 00:21:34 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:26838 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750781AbbIJEVb (ORCPT ); Thu, 10 Sep 2015 00:21:31 -0400 X-AuditID: cbfec7f5-f794b6d000001495-8d-55f105478080 Subject: Re: [RFC PATCH] clocksource: exynos_mct: use container_of() instead of this_cpu_ptr() To: Alexey Klimov , daniel.lezcano@linaro.org, linux-samsung-soc@vger.kernel.org References: <1441324198-14513-1-git-send-email-alexey.klimov@linaro.org> Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org, yury.norov@gmail.com, klimov.linux@gmail.com, kgene@kernel.org From: Krzysztof Kozlowski Message-id: <55F10543.2050007@samsung.com> Date: Thu, 10 Sep 2015 13:21:23 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-version: 1.0 In-reply-to: <1441324198-14513-1-git-send-email-alexey.klimov@linaro.org> Content-type: text/plain; charset=windows-1252 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrGLMWRmVeSWpSXmKPExsVy+t/xy7rurB9DDe7vM7CYe7WLxWLeZ1mL 1y8MLfofv2a2OHX+IYvF5V1z2CxmnN/HZLF501RmiwffdBw4PXbOusvusWlVJ5vHnWt72Dze nTvH7tG3ZRWjx+dNcgFsUVw2Kak5mWWpRfp2CVwZ86dsZC64KlVxe8YClgbGTaJdjJwcEgIm Emd3HGODsMUkLtxbD2RzcQgJLGWUWPShB8r5wihxcMk9dpAqYYEEieWrXzGC2CICORIvOx+z gNhCAh4SF1fPZwWxmQXKJBasOQAWZxMwlti8fAnYBl4BLYlvy9+AzWERUJW4s+UYE4gtKhAh cersW6gaQYkfk++B9XIKeEr8nXYbaCYH0Ew9ifsXtSDGy0tsXvOWeQKjwCwkHbMQqmYhqVrA yLyKUTS1NLmgOCk910ivODG3uDQvXS85P3cTIyT0v+5gXHrM6hCjAAejEg9vwsUPoUKsiWXF lbmHGCU4mJVEeNO2A4V4UxIrq1KL8uOLSnNSiw8xSnOwKInzztz1PkRIID2xJDU7NbUgtQgm y8TBKdXAOPn0z9itslE3vyicfltv+en6uZtpspeNJfZU6Eruyi7pPL3BV+VK7JznDPbemTzm gWYS0TfbHy1mifDOneMiyeJ9hkGMY/qE7BMnvAzD3mmU7peeHx2u12w8m/UH1/bW9S/SXqt7 XuPUjLy4KOvfm0OcDSwOYimL3qbN3PF+g7Lge//ujiBBJZbijERDLeai4kQAVTSeJnkCAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04.09.2015 08:49, Alexey Klimov wrote: > Since evt structure is embedded in per-CPU mevt structure it's > definitely faster to use container_of() to get access to mevt > if we have evt (for example as incoming function argument) instead > of more expensive approach with this_cpu_ptr(&percpu_mct_tick). > this_cpu_ptr() on per-CPU mevt structure leads to access to cp15 > to get cpu id and arithmetic operations. > Container_of() is cheaper since it's just one asm instruction. > This should work if used evt pointer is correct and owned by > local mevt structure. > > For example, before this patch set_state_shutdown() looks like: > > 4a4: e92d4010 push {r4, lr} > 4a8: e3004000 movw r4, #0 > 4ac: ebfffffe bl 0 > 4b0: e3003000 movw r3, #0 > 4b4: e3404000 movt r4, #0 > 4b8: e3403000 movt r3, #0 > 4bc: e7933100 ldr r3, [r3, r0, lsl #2] > 4c0: e0844003 add r4, r4, r3 > 4c4: e59400c0 ldr r0, [r4, #192] ; 0xc0 > 4c8: ebffffd4 bl 420 > 4cc: e3a00000 mov r0, #0 > 4d0: e8bd8010 pop {r4, pc} > > With this patch: > > 4a4: e92d4010 push {r4, lr} > 4a8: e59000c0 ldr r0, [r0, #192] ; 0xc0 > 4ac: ebffffdb bl 420 > 4b0: e3a00000 mov r0, #0 > 4b4: e8bd8010 pop {r4, pc} > > Also, for me size of exynos_mct.o decreased from 84588 bytes > to 83956. > > Signed-off-by: Alexey Klimov > --- > drivers/clocksource/exynos_mct.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) Looks good and sensible. Why you called this RFC? You are not sure if this is correct? One minor nit-pick below, but I am fine without it anyway: Reviewed-by: Krzysztof Kozlowski > > diff --git a/drivers/clocksource/exynos_mct.c b/drivers/clocksource/exynos_mct.c > index 029f96a..ff44082 100644 > --- a/drivers/clocksource/exynos_mct.c > +++ b/drivers/clocksource/exynos_mct.c > @@ -382,24 +382,28 @@ static void exynos4_mct_tick_start(unsigned long cycles, > static int exynos4_tick_set_next_event(unsigned long cycles, > struct clock_event_device *evt) > { > - struct mct_clock_event_device *mevt = this_cpu_ptr(&percpu_mct_tick); > + struct mct_clock_event_device *mevt; > > + mevt = container_of(evt, struct mct_clock_event_device, evt); > exynos4_mct_tick_start(cycles, mevt); > - Actually I would prefer leaving the empty line here and add such in function below. For me the code is more readable with ending return separated by one line. Best regards, Krzysztof > return 0; > } > > static int set_state_shutdown(struct clock_event_device *evt) > { > - exynos4_mct_tick_stop(this_cpu_ptr(&percpu_mct_tick)); > + struct mct_clock_event_device *mevt; > + > + mevt = container_of(evt, struct mct_clock_event_device, evt); > + exynos4_mct_tick_stop(mevt); > return 0; > } > > static int set_state_periodic(struct clock_event_device *evt) > { > - struct mct_clock_event_device *mevt = this_cpu_ptr(&percpu_mct_tick); > + struct mct_clock_event_device *mevt; > unsigned long cycles_per_jiffy; > > + mevt = container_of(evt, struct mct_clock_event_device, evt); > cycles_per_jiffy = (((unsigned long long)NSEC_PER_SEC / HZ * evt->mult) > >> evt->shift); > exynos4_mct_tick_stop(mevt); >