From patchwork Fri Nov 13 12:20:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Gonzalez X-Patchwork-Id: 7611161 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5B6B69F2F7 for ; Fri, 13 Nov 2015 12:24:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 54A0D207C3 for ; Fri, 13 Nov 2015 12:24:37 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6D8C220794 for ; Fri, 13 Nov 2015 12:24:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZxDLy-00016Z-E3; Fri, 13 Nov 2015 12:21:18 +0000 Received: from mail1.bemta12.messagelabs.com ([216.82.251.6]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZxDLu-00014x-DG for linux-arm-kernel@lists.infradead.org; Fri, 13 Nov 2015 12:21:15 +0000 Received: from [216.82.249.212] by server-6.bemta-12.messagelabs.com id E9/6A-02708-3A5D5465; Fri, 13 Nov 2015 12:20:51 +0000 X-Env-Sender: Marc_Gonzalez@sigmadesigns.com X-Msg-Ref: server-8.tower-219.messagelabs.com!1447417249!8999985!1 X-Originating-IP: [195.215.56.170] X-StarScan-Received: X-StarScan-Version: 7.19.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 12980 invoked from network); 13 Nov 2015 12:20:50 -0000 Received: from 195-215-56-170-static.dk.customer.tdc.net (HELO CPH-EX1.SDESIGNS.COM) (195.215.56.170) by server-8.tower-219.messagelabs.com with AES128-SHA encrypted SMTP; 13 Nov 2015 12:20:50 -0000 Received: from [172.27.0.114] (172.27.0.114) by CPH-EX1.sdesigns.com (192.168.10.36) with Microsoft SMTP Server (TLS) id 14.1.339.1; Fri, 13 Nov 2015 13:20:48 +0100 Subject: Re: [PATCH] clocksource/drivers/tango-xtal: Replace code by clocksource_mmio_init To: Daniel Lezcano , Thomas Gleixner References: <1447412292-841-1-git-send-email-daniel.lezcano@linaro.org> From: Marc Gonzalez Message-ID: <5645D5A0.1000502@sigmadesigns.com> Date: Fri, 13 Nov 2015 13:20:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0 SeaMonkey/2.38 MIME-Version: 1.0 In-Reply-To: <1447412292-841-1-git-send-email-daniel.lezcano@linaro.org> X-Originating-IP: [172.27.0.114] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151113_042114_487130_A4E93E7E X-CRM114-Status: GOOD ( 16.12 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , LKML , Linux ARM Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 On 13/11/2015 11:58, Daniel Lezcano wrote: > The current code to initialize, register and read the clocksource is > already factored out in mmio.c via the clocksource_mmio_init function. > > Factor out the code with the clocksource_mmio_init function. The reason I didn't like clocksource_mmio_init() is because it exports 4 generic accessors. I guess this function makes more sense when all platforms are using it, in an ARCH_MULTIPLATFORM kernel. (Also the accessors are probably quite small, so the waste is probably minimal.) In my opinion, defining struct clocksource_mmio with reg "outside" struct clocksource leads to less efficient(1) and less clear(2) code. 1) because of the padding from ____cacheline_aligned 2) because of the container_of() gymnastics I tried discussing this in March, but it didn't go anywhere. Lemme brush up the patch. Should the reg field be considered "hot-path data"? One problem with my patch: if some ports define CLKSRC_MMIO but have lots of static struct clocksource, the extra reg field might waste memory / worsen cache locality? Also, maybe the fields should be copied in ascending order? Regards. diff --git a/drivers/clocksource/mmio.c b/drivers/clocksource/mmio.c index 1593ade2a815..aba5f24ba346 100644 --- a/drivers/clocksource/mmio.c +++ b/drivers/clocksource/mmio.c @@ -10,34 +10,24 @@ #include #include -struct clocksource_mmio { - void __iomem *reg; - struct clocksource clksrc; -}; - -static inline struct clocksource_mmio *to_mmio_clksrc(struct clocksource *c) -{ - return container_of(c, struct clocksource_mmio, clksrc); -} - cycle_t clocksource_mmio_readl_up(struct clocksource *c) { - return (cycle_t)readl_relaxed(to_mmio_clksrc(c)->reg); + return (cycle_t)readl_relaxed(c->reg); } cycle_t clocksource_mmio_readl_down(struct clocksource *c) { - return ~(cycle_t)readl_relaxed(to_mmio_clksrc(c)->reg) & c->mask; + return ~(cycle_t)readl_relaxed(c->reg) & c->mask; } cycle_t clocksource_mmio_readw_up(struct clocksource *c) { - return (cycle_t)readw_relaxed(to_mmio_clksrc(c)->reg); + return (cycle_t)readw_relaxed(c->reg); } cycle_t clocksource_mmio_readw_down(struct clocksource *c) { - return ~(cycle_t)readw_relaxed(to_mmio_clksrc(c)->reg) & c->mask; + return ~(cycle_t)readw_relaxed(c->reg) & c->mask; } /** @@ -53,21 +43,21 @@ int __init clocksource_mmio_init(void __iomem *base, const char *name, unsigned long hz, int rating, unsigned bits, cycle_t (*read)(struct clocksource *)) { - struct clocksource_mmio *cs; + struct clocksource *cs; if (bits > 32 || bits < 16) return -EINVAL; - cs = kzalloc(sizeof(struct clocksource_mmio), GFP_KERNEL); + cs = kzalloc(sizeof *cs, GFP_KERNEL); if (!cs) return -ENOMEM; cs->reg = base; - cs->clksrc.name = name; - cs->clksrc.rating = rating; - cs->clksrc.read = read; - cs->clksrc.mask = CLOCKSOURCE_MASK(bits); - cs->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS; + cs->name = name; + cs->rating = rating; + cs->read = read; + cs->mask = CLOCKSOURCE_MASK(bits); + cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; - return clocksource_register_hz(&cs->clksrc, hz); + return clocksource_register_hz(cs, hz); } diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index 278dd279a7a8..03807ca0d54e 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h @@ -74,6 +74,9 @@ struct clocksource { u32 shift; u64 max_idle_ns; u32 maxadj; +#ifdef CONFIG_CLKSRC_MMIO + void __iomem *reg; +#endif #ifdef CONFIG_ARCH_CLOCKSOURCE_DATA struct arch_clocksource_data archdata; #endif