public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Russell King <linux@arm.linux.org.uk>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Mans Rullgard <mans@mansr.com>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Nicolas Pitre <nico@linaro.org>, Tony Lindgren <tony@atomide.com>,
	Sebastian Frias <sebastian_frias@sigmadesigns.com>
Subject: [PATCH] clocksource: Store reg field within struct clocksource
Date: Wed, 18 Nov 2015 14:43:34 +0100	[thread overview]
Message-ID: <564C8086.80804@sigmadesigns.com> (raw)

Since 'struct clocksource' is ____cacheline_aligned, gcc must insert
a lot of padding between reg and clksrc in 'struct clocksource_mmio'
(for example, L1_CACHE_BYTES = 64 on ARMv7).

Storing reg within 'struct clocksource' removes unnecessary padding,
and reg can then be grouped with other hot data. A nice side-effect
of this patch is making container_of() unnecessary, which makes the
code a bit simpler.

On 32-bit platforms, reg fits in the padding between read and mask,
meaning no downside from storing it there.

	0                4                8
	+----------------+----------------+
	|      read      |     pad/reg    |
	+----------------+----------------+
	|              mask               |
	+----------------+----------------+
	|      mult      |     shift      |
	+----------------+----------------+
	|           max_idle_ns           |
	+----------------+----------------+

On 64-bit platforms, placing reg between read and mask changes the
layout, moving max_idle_ns to offset +32 instead of +24.

	0                4                8
	+----------------+----------------+
	|              read               |
	+----------------+----------------+
	|               reg               |
	+----------------+----------------+
	|              mask               |
	+----------------+----------------+
	|      mult      |     shift      |
	+----------------+----------------+
	|           max_idle_ns           |
	+----------------+----------------+

Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
---
 drivers/clocksource/mmio.c  | 36 +++++++++++++-----------------------
 include/linux/clocksource.h |  3 +++
 2 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/drivers/clocksource/mmio.c b/drivers/clocksource/mmio.c
index 1593ade2a815..c28fc6ef63ef 100644
--- a/drivers/clocksource/mmio.c
+++ b/drivers/clocksource/mmio.c
@@ -10,34 +10,24 @@
 #include <linux/init.h>
 #include <linux/slab.h>
 
-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->read = read;
+	cs->reg  = base;
+	cs->name = name;
+	cs->rating = rating;
+	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..50725fd23ab0 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -69,6 +69,9 @@ struct clocksource {
 	 * clocksource itself is cacheline aligned.
 	 */
 	cycle_t (*read)(struct clocksource *cs);
+#ifdef CONFIG_CLKSRC_MMIO
+	void __iomem *reg;
+#endif
 	cycle_t mask;
 	u32 mult;
 	u32 shift;
-- 
2.4.5


             reply	other threads:[~2015-11-18 13:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-18 13:43 Marc Gonzalez [this message]
2015-11-18 13:51 ` [PATCH] clocksource: Store reg field within struct clocksource Måns Rullgård
2015-11-18 17:21 ` Russell King - ARM Linux
2015-11-19  9:27   ` Marc Gonzalez
2015-11-19 10:33     ` Russell King - ARM Linux
2015-11-19 10:36       ` Thomas Gleixner
2015-11-19 10:40         ` Russell King - ARM Linux
2015-11-19 10:33   ` Thomas Gleixner
2015-11-19 10:36     ` Russell King - ARM Linux
2015-11-19 10:42       ` Thomas Gleixner
2015-11-19 11:08         ` Russell King - ARM Linux
2015-11-19 11:14           ` Thomas Gleixner
2015-11-19 12:26             ` Marc Gonzalez
2015-11-19 13:57               ` Thomas Gleixner
2015-11-24 12:36                 ` Marc Gonzalez
2015-11-25 21:33             ` [tip:timers/core] timekeeping: Lift clocksource cacheline restriction tip-bot for Thomas Gleixner
2015-11-19 10:55       ` [PATCH] clocksource: Store reg field within struct clocksource Marc Gonzalez
2015-11-19 11:21         ` Russell King - ARM Linux
2015-11-19 12:41           ` Marc Gonzalez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=564C8086.80804@sigmadesigns.com \
    --to=marc_gonzalez@sigmadesigns.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=mans@mansr.com \
    --cc=nico@linaro.org \
    --cc=sebastian_frias@sigmadesigns.com \
    --cc=tglx@linutronix.de \
    --cc=tony@atomide.com \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox