From patchwork Thu Sep 3 23:49:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Klimov X-Patchwork-Id: 7119561 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A3604BEEC1 for ; Thu, 3 Sep 2015 23:50:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CC9DE2080E for ; Thu, 3 Sep 2015 23:50:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D07282081F for ; Thu, 3 Sep 2015 23:50:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753615AbbICXuJ (ORCPT ); Thu, 3 Sep 2015 19:50:09 -0400 Received: from mail-lb0-f172.google.com ([209.85.217.172]:35943 "EHLO mail-lb0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753011AbbICXuI (ORCPT ); Thu, 3 Sep 2015 19:50:08 -0400 Received: by lbcao8 with SMTP id ao8so2616684lbc.3 for ; Thu, 03 Sep 2015 16:50:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=tm7z7yh+nmgqjmnz0b3V0ALFyFmMjn+xL685RSxEkc4=; b=N3E72P/ViJBQrj3aELajOgH9tBKIxBA3C9QDNymKcZ6kv6BPep/i+3ioX97T7h5MsA dMrj0iUsYS8WHIwStyQAzg1kcB6yKm8OO0wLJCe/CdK4Eidqx9ENxjRf98muQ23+texI iknL8k5edG4J9NVOiRWMtAUQUm9sZCe9wVEOfZjJF65nDuwnX4GQ3QFxD9vPm+GpHARw Gt6lbBbRlxR+KPwi7U3LALrvrB9KAMZfj7BHnJbC4x/gSR0HUvfAmYnE0lcrJ5D80fRP SW3hl2ipOjSmOjRUuzP9rNRxdb9W6HKbRArSfb2Jrrx/CFzYPnka0iaugA/8tYG2GqwT S4fw== X-Gm-Message-State: ALoCoQmaUhu0wodXH0S9meJDen4wJx/SwQUL4RVCmRZuSXlsAZb0urh6Rm6RtYcqQwwLRVtpENfK X-Received: by 10.152.5.169 with SMTP id t9mr590425lat.55.1441324207197; Thu, 03 Sep 2015 16:50:07 -0700 (PDT) Received: from localhost.localdomain ([46.39.50.164]) by smtp.gmail.com with ESMTPSA id ju7sm105324lbc.43.2015.09.03.16.50.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Sep 2015 16:50:06 -0700 (PDT) From: Alexey Klimov To: daniel.lezcano@linaro.org, k.kozlowski@samsung.com, linux-samsung-soc@vger.kernel.org Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org, alexey.klimov@linaro.org, yury.norov@gmail.com, klimov.linux@gmail.com, kgene@kernel.org Subject: [RFC PATCH] clocksource: exynos_mct: use container_of() instead of this_cpu_ptr() Date: Fri, 4 Sep 2015 02:49:58 +0300 Message-Id: <1441324198-14513-1-git-send-email-alexey.klimov@linaro.org> X-Mailer: git-send-email 2.1.4 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Krzysztof Kozlowski --- drivers/clocksource/exynos_mct.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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); - 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);