Skip to contentSkip to conversation

devicetree: add binding for generic mmio clocksource

PATCH In review Mans Rullgard 4 participants 15 messages Oct 7, 2015 – Oct 10, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 devicetree: add binding for generic mmio clocksource

This adds a DT binding for a generic mmio clocksource as implemented by clocksource_mmio_init().

---
Changed in v2:
- added sched_clock support

---
 .../devicetree/bindings/timer/clocksource-mmio.txt | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/clocksource-mmio.txt
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +28 -0
new file mode 100644
index 0000000..cfb3601
@@ -0,0 +1,28 @@
+Generic MMIO clocksource
+
+Required properties:
+
+- compatible: should be "clocksource-mmio"
+- reg: the physical address of the counter register
+- reg-io-width: size of counter register in bytes, should be 2 or 4
+- clocks: phandle to the source clock
+- clocksource-bits: number of valid bits
+- clocksource-rating: rating of the clocksource
+
+Optional properties:
+
+- clocksource-counts-down: indicates that counter counts down
+- label: name of the clocksource
+- linux,sched-clock: boolean, register clocksource as sched_clock
+
+Example:
+
+clocksource {
+	compatible = "clocksource-mmio";
+	reg = <0x10000 4>;
+	reg-io-width = <4>;
+	clocksource-bits = <32>;
+	clocksource-rating = <300>;
+	clocks = <&clk>;
+	linux,sched_clock;
+}
Signature · 6 lines
2.5.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH v2 2/2 clocksource: mmio: add devicetree support

This implements the "clocksource-mmio" devicetree binding. It is useful for devices that have a free-running counter requiring no setup.

---
Changed in v2:
- added sched_clock support

---
 drivers/clocksource/mmio.c | 123 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 123 insertions(+)
drivers/clocksource/mmio.c +123 -0
index 1593ade..b2cb3cc 100644
@@ -5,9 +5,12 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+#include <linux/clk.h>
 #include <linux/clocksource.h>
 #include <linux/errno.h>
 #include <linux/init.h>
+#include <linux/of_address.h>
+#include <linux/sched_clock.h>
 #include <linux/slab.h>
 
 struct clocksource_mmio {
@@ -71,3 +74,123 @@ int __init clocksource_mmio_init(void __iomem *base, const char *name,
 
 	return clocksource_register_hz(&cs->clksrc, hz);
 }
+
+#ifdef CONFIG_OF
+static void __iomem *sched_clock_mmio_reg;
+
+static u64 notrace sched_clock_mmio_readl_up(void)
+{
+	return (u64)readl_relaxed(sched_clock_mmio_reg);
+}
+
+static u64 notrace sched_clock_mmio_readl_down(void)
+{
+	return ~(u64)readl_relaxed(sched_clock_mmio_reg);
+}
+
+static u64 notrace sched_clock_mmio_readw_up(void)
+{
+	return (u64)readw_relaxed(sched_clock_mmio_reg);
+}
+
+static u64 notrace sched_clock_mmio_readw_down(void)
+{
+	return ~(u64)readw_relaxed(sched_clock_mmio_reg);
+}
+
+static void __init clocksource_mmio_of_setup(struct device_node *node)
+{
+	cycle_t (*csrc_read)(struct clocksource *);
+	u64 (*sched_read)(void);
+	void __iomem *reg;
+	struct clk *clk;
+	const char *name;
+	unsigned long rate;
+	bool count_down;
+	u32 rating;
+	u32 width;
+	u32 bits;
+	int err;
+
+	if (of_property_read_u32(node, "reg-io-width", &width)) {
+		pr_err("clocksource-mmio: register width not specified\n");
+		return;
+	}
+
+	if (of_property_read_u32(node, "clocksource-bits", &bits)) {
+		pr_err("clocksource-mmio: bits not specified\n");
+		return;
+	}
+
+	if (of_property_read_u32(node, "clocksource-rating", &rating)) {
+		pr_err("clocksource-mmio: rating not specified\n");
+		return;
+	}
+
+	count_down = of_property_read_bool(node, "clocksource-counts-down");
+
+	if (width == 2) {
+		if (count_down) {
+			csrc_read = clocksource_mmio_readw_down;
+			sched_read = sched_clock_mmio_readw_down;
+		} else {
+			csrc_read = clocksource_mmio_readw_up;
+			sched_read = sched_clock_mmio_readw_up;
+		}
+	} else if (width == 4) {
+		if (count_down) {
+			csrc_read = clocksource_mmio_readl_down;
+			sched_read = sched_clock_mmio_readl_down;
+		} else {
+			csrc_read = clocksource_mmio_readl_up;
+			sched_read = sched_clock_mmio_readl_up;
+		}
+	} else {
+		pr_err("clocksource-mmio: reg-io-width must be 2 or 4\n");
+		return;
+	}
+
+	clk = of_clk_get(node, 0);
+	if (IS_ERR(clk)) {
+		pr_err("clocksource-mmio: failed to get clock\n");
+		return;
+	}
+
+	if (clk_prepare_enable(clk)) {
+		pr_err("clocksource-mmio: failed to enable clock\n");
+		return;
+	}
+
+	rate = clk_get_rate(clk);
+	if (!rate) {
+		pr_err("clocksource-mmio: clock rate is zero\n");
+		clk_disable_unprepare(clk);
+		return;
+	}
+
+	reg = of_iomap(node, 0);
+	if (!reg) {
+		pr_err("clocksource-mmio: iomap failed\n");
+		clk_disable_unprepare(clk);
+		return;
+	}
+
+	if (of_property_read_string(node, "label", &name))
+		name = node->name;
+
+	err = clocksource_mmio_init(reg, name, rate, rating, bits, csrc_read);
+	if (err) {
+		pr_err("clocksource-mmio: failed to register clock source\n");
+		clk_disable_unprepare(clk);
+		iounmap(reg);
+		return;
+	}
+
+	if (of_property_read_bool(node, "linux,sched-clock")) {
+		sched_clock_mmio_reg = reg;
+		sched_clock_register(sched_read, bits, rate);
+	}
+}
+CLOCKSOURCE_OF_DECLARE(clocksource_mmio, "clocksource-mmio",
+		       clocksource_mmio_of_setup);
+#endif
Signature · 1 line
2.5.3
#2 lore raw
In reply to Mans Rullgard
Quoted 18 lines · Mans Rullgard

This adds a DT binding for a generic mmio clocksource as implemented by clocksource_mmio_init().

---
Changed in v2:
- added sched_clock support

---
 .../devicetree/bindings/timer/clocksource-mmio.txt | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/clocksource-mmio.txt
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +0 -0
new file mode 100644
index 0000000..cfb3601

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 7

Quoted 7 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +7 -0
@@ -0,0 +1,28 @@
+Generic MMIO clocksource
+
+Required properties:
+
+- compatible: should be "clocksource-mmio"
+- reg: the physical address of the counter register
+- reg-io-width: size of counter register in bytes, should be 2 or 4

Can this not be inferred from the reg?

What about 8 byte counters?

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 8

Quoted 1 line
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +1 -0
+- clocks: phandle to the source clock

Is the frequency expected to be exactly the source clock frequency? I imagine it's possible for there to be a divisor.

We can add properties for that later, but we should be explcit as to what we currently expect the relationship between the clock and the clocksource to be.

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 10

Quoted 2 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +2 -0
+- clocksource-bits: number of valid bits
+- clocksource-rating: rating of the clocksource

NAK. This has no meaning w.r.t. the hardware. This should not be in the DT. If there are criteria that bias this (e.g. frequency, latency), they should eitehr be describedi nteh DT or determined dynamically.

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 16

Quoted 5 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +5 -0
+Optional properties:
+
+- clocksource-counts-down: indicates that counter counts down
+- label: name of the clocksource
+- linux,sched-clock: boolean, register clocksource as sched_clock

Likewise, this property doesn't belong in the DT for the same reasons as clocksource-rating.

Mark.

Quoted 15 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +12 -0
+
+Example:
+
+clocksource {
+	compatible = "clocksource-mmio";
+	reg = <0x10000 4>;
+	reg-io-width = <4>;
+	clocksource-bits = <32>;
+	clocksource-rating = <300>;
+	clocks = <&clk>;
+	linux,sched_clock;
+}
Signature · 1 line
2.5.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 13 lines · Mark Rutland
Quoted 12 lines · Mans Rullgard

This adds a DT binding for a generic mmio clocksource as implemented by clocksource_mmio_init().

---
Changed in v2:
- added sched_clock support

---
 .../devicetree/bindings/timer/clocksource-mmio.txt | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/clocksource-mmio.txt
Quoted 15 lines

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 7

Quoted 13 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +7 -0
new file mode 100644
index 0000000..cfb3601
@@ -0,0 +1,28 @@
+Generic MMIO clocksource
+
+Required properties:
+
+- compatible: should be "clocksource-mmio"
+- reg: the physical address of the counter register
+- reg-io-width: size of counter register in bytes, should be 2 or 4

Can this not be inferred from the reg?

You're right, it can.

Quoted 1 line

What about 8 byte counters?

The existing code only supports 2 or 4, but that of course doesn't matter here.

Quoted 4 lines

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 8

Quoted 1 line
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +1 -0
+- clocks: phandle to the source clock

Is the frequency expected to be exactly the source clock frequency? I imagine it's possible for there to be a divisor.

There could of course be, though there isn't in the hardware I'm dealing with. Is specifying it here preferable using a fixed-factor-clock?

Quoted 10 lines

We can add properties for that later, but we should be explcit as to what we currently expect the relationship between the clock and the clocksource to be.

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 10

Quoted 2 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +2 -0
+- clocksource-bits: number of valid bits
+- clocksource-rating: rating of the clocksource

NAK. This has no meaning w.r.t. the hardware. This should not be in the DT. If there are criteria that bias this (e.g. frequency, latency), they should either be described in the DT or determined dynamically.

I had a bad feeling about this. How would you suggest determining a suitable value from actual hardware parameters?

Quoted 4 lines

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 16

Quoted 1 line
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +1 -0
+- linux,sched-clock: boolean, register clocksource as sched_clock

Likewise, this property doesn't belong in the DT for the same reasons as clocksource-rating.

What would be a proper way to select a sched_clock source? I realise it's a Linux-specific thing and DT is supposed to be generic, but the information must be provided somehow.

Signature · 6 lines
Måns Rullgård
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw
Quoted 38 lines · Måns Rullgård
Quoted 13 lines · Mark Rutland
Quoted 12 lines · Mans Rullgard

This adds a DT binding for a generic mmio clocksource as implemented by clocksource_mmio_init().

---
Changed in v2:
- added sched_clock support

---
 .../devicetree/bindings/timer/clocksource-mmio.txt | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/clocksource-mmio.txt
Quoted 15 lines

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 7

Quoted 13 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +7 -0
new file mode 100644
index 0000000..cfb3601
@@ -0,0 +1,28 @@
+Generic MMIO clocksource
+
+Required properties:
+
+- compatible: should be "clocksource-mmio"
+- reg: the physical address of the counter register
+- reg-io-width: size of counter register in bytes, should be 2 or 4

Can this not be inferred from the reg?

You're right, it can.

Quoted 1 line

What about 8 byte counters?

The existing code only supports 2 or 4, but that of course doesn't matter here.

Quoted 7 lines
Quoted 4 lines

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 8

Quoted 1 line
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +1 -0
+- clocks: phandle to the source clock

Is the frequency expected to be exactly the source clock frequency? I imagine it's possible for there to be a divisor.

There could of course be, though there isn't in the hardware I'm dealing with. Is specifying it here preferable using a fixed-factor-clock?

I'm not actually sure; I guess it would be ok to do so.

For now we should just explicitly state that the clocksource is assumed to tick at the rate of the clock.

Quoted 7 lines
Quoted 7 lines

We can add properties for that later, but we should be explcit as to what we currently expect the relationship between the clock and the clocksource to be.

Quoted 2 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +2 -0
+- clocksource-bits: number of valid bits
+- clocksource-rating: rating of the clocksource
Quoted 6 lines
Quoted 3 lines

NAK. This has no meaning w.r.t. the hardware. This should not be in the DT. If there are criteria that bias this (e.g. frequency, latency), they should either be described in the DT or determined dynamically.

I had a bad feeling about this. How would you suggest determining a suitable value from actual hardware parameters?

I don't have a good answer to that given the rating is semi-arbitrary, but that's also the reason I don't want to see it in the DT.

Can we not just choose a fixed number in the driver for now? Likely something lower than the architected timers (400 currently).

Quoted 8 lines
Quoted 4 lines

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 16

Quoted 1 line
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +1 -0
+- linux,sched-clock: boolean, register clocksource as sched_clock

Likewise, this property doesn't belong in the DT for the same reasons as clocksource-rating.

What would be a proper way to select a sched_clock source? I realise it's a Linux-specific thing and DT is supposed to be generic, but the information must be provided somehow.

I think that any source above a certain rate and below a certain latency, which does not lose state, should be registered (and the best gets chosen dynamically).

Come to think of it, what's the expected behaviour of this source w.r.t. power management? I expect that the kernel needs to leave the clock enabled at all times for this to possibly work.

Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 5 lines · Mark Rutland
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

+- clocks: phandle to the source clock

Is the frequency expected to be exactly the source clock frequency? I imagine it's possible for there to be a divisor.

Quoted 7 lines
Quoted 2 lines

There could of course be, though there isn't in the hardware I'm dealing with. Is specifying it here preferable using a fixed-factor-clock?

I'm not actually sure; I guess it would be ok to do so.

For now we should just explicitly state that the clocksource is assumed to tick at the rate of the clock.

OK, I'll come up with a clearer wording.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

We can add properties for that later, but we should be explcit as to what we currently expect the relationship between the clock and the clocksource to be.

Quoted 2 lines
+- clocksource-bits: number of valid bits
+- clocksource-rating: rating of the clocksource

NAK. This has no meaning w.r.t. the hardware. This should not be in the DT. If there are criteria that bias this (e.g. frequency, latency), they should either be described in the DT or determined dynamically.

Quoted 8 lines
Quoted 2 lines

I had a bad feeling about this. How would you suggest determining a suitable value from actual hardware parameters?

I don't have a good answer to that given the rating is semi-arbitrary, but that's also the reason I don't want to see it in the DT.

Can we not just choose a fixed number in the driver for now? Likely something lower than the architected timers (400 currently).

Fine with me.

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

+- linux,sched-clock: boolean, register clocksource as sched_clock

Likewise, this property doesn't belong in the DT for the same reasons as clocksource-rating.

What would be a proper way to select a sched_clock source? I realise it's a Linux-specific thing and DT is supposed to be generic, but the information must be provided somehow.

Quoted 7 lines

I think that any source above a certain rate and below a certain latency, which does not lose state, should be registered (and the best gets chosen dynamically).

Come to think of it, what's the expected behaviour of this source w.r.t. power management? I expect that the kernel needs to leave the clock enabled at all times for this to possibly work.

The platform I'm dealing with has a 32-bit register counting cycles of the external clock input which never stops. It also has a few counters with a configurable clock source, and those might indeed stop so should probably not be used for this.

Signature · 6 lines
Måns Rullgård
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw
In reply to Måns Rullgård
Quoted 15 lines · Måns Rullgård
Quoted 13 lines · Mark Rutland
Quoted 12 lines · Mans Rullgard

This adds a DT binding for a generic mmio clocksource as implemented by clocksource_mmio_init().

---
Changed in v2:
- added sched_clock support

---
 .../devicetree/bindings/timer/clocksource-mmio.txt | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/clocksource-mmio.txt
Quoted 11 lines
Quoted 11 lines

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 5

Quoted 11 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +5 -0
new file mode 100644
index 0000000..cfb3601
@@ -0,0 +1,28 @@
+Generic MMIO clocksource
+
+Required properties:
+
+- compatible: should be "clocksource-mmio"

I'm doubtful this matches any h/w. This would assume there is no other control like enabling, reset, clock dividers, etc.

Who is your user of this?

Quoted 27 lines
Quoted 4 lines

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 7

Quoted 2 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +2 -0
+- reg: the physical address of the counter register
+- reg-io-width: size of counter register in bytes, should be 2 or 4

Can this not be inferred from the reg?

You're right, it can.

Quoted 1 line

What about 8 byte counters?

The existing code only supports 2 or 4, but that of course doesn't matter here.

Quoted 4 lines

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 8

Quoted 1 line
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +1 -0
+- clocks: phandle to the source clock

Is the frequency expected to be exactly the source clock frequency? I imagine it's possible for there to be a divisor.

There could of course be, though there isn't in the hardware I'm dealing with. Is specifying it here preferable using a fixed-factor-clock?

Quoted 7 lines

We can add properties for that later, but we should be explcit as to what we currently expect the relationship between the clock and the clocksource to be.

Quoted 2 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +2 -0
+- clocksource-bits: number of valid bits
+- clocksource-rating: rating of the clocksource
Quoted 6 lines
Quoted 3 lines

NAK. This has no meaning w.r.t. the hardware. This should not be in the DT. If there are criteria that bias this (e.g. frequency, latency), they should either be described in the DT or determined dynamically.

I had a bad feeling about this. How would you suggest determining a suitable value from actual hardware parameters?

I wouldn't. I think there is general agreement that rating is broken.

This has come up a few times before in context of given a pile of timer h/w how do you select one. Chosen properties have been one example (I think that actually went in on Integrator, but we since removed it). Think about what the properties of a timer are and then you can decide based on properties for those. OMAP timers are a good example.

Quoted 9 lines
Quoted 5 lines

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 16

Quoted 2 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +1 -0
+- linux,sched-clock: boolean, register clocksource as sched_clock

Likewise, this property doesn't belong in the DT for the same reasons as clocksource-rating.

What would be a proper way to select a sched_clock source? I realise it's a Linux-specific thing and DT is supposed to be generic, but the information must be provided somehow.

The kernel already has some logic to do this. Most number of bits followed by highest frequency will be the winning sched_clock. You might also want to look at things like always on or not.

Rob

Quoted 4 lines

--
Måns Rullgård
[email protected]

#7 lore raw
Quoted 16 lines · Rob Herring
Quoted 15 lines · Måns Rullgård
Quoted 13 lines · Mark Rutland
Quoted 12 lines · Mans Rullgard

This adds a DT binding for a generic mmio clocksource as implemented by clocksource_mmio_init().

---
Changed in v2:
- added sched_clock support

---
 .../devicetree/bindings/timer/clocksource-mmio.txt | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/clocksource-mmio.txt
Quoted 14 lines
Quoted 11 lines
Quoted 11 lines

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 5

Quoted 11 lines
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +5 -0
new file mode 100644
index 0000000..cfb3601
@@ -0,0 +1,28 @@
+Generic MMIO clocksource
+
+Required properties:
+
+- compatible: should be "clocksource-mmio"

I'm doubtful this matches any h/w. This would assume there is no other control like enabling, reset, clock dividers, etc.

I know it matches real hardware.

Quoted 1 line

Who is your user of this?

Various Sigma Designs chips have such counters. I figured others might as well, and it seemed silly to tie such generic functionality to a specific chip family.

Quoted 4 lines
Quoted 2 lines

I had a bad feeling about this. How would you suggest determining a suitable value from actual hardware parameters?

I wouldn't. I think there is general agreement that rating is broken.

So hardcoding something like 300 would be OK?

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Documentation/devicetree/bindings/timer/clocksource-mmio.txt line 16

Quoted 1 line
Documentation/devicetree/bindings/timer/clocksource-mmio.txt new file +1 -0
+- linux,sched-clock: boolean, register clocksource as sched_clock

Likewise, this property doesn't belong in the DT for the same reasons as clocksource-rating.

Quoted 7 lines
Quoted 3 lines

What would be a proper way to select a sched_clock source? I realise it's a Linux-specific thing and DT is supposed to be generic, but the information must be provided somehow.

The kernel already has some logic to do this. Most number of bits followed by highest frequency will be the winning sched_clock. You might also want to look at things like always on or not.

The problem is that sched_clock_register() doesn't take a pointer to be passed back to the read_sched_clock callback like most interfaces of this type do. This means the callback must use global variables set up before the register call, but at that time there's no way of knowing which one will be used. If there were a way of getting a pointer to the callback, it would be a simple matter of registering all instances and letting the kernel choose which to use.

Signature · 6 lines
Måns Rullgård
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw
Quoted 11 lines · Måns Rullgård
Quoted 8 lines · Rob Herring
Quoted 3 lines · Måns Rullgård

What would be a proper way to select a sched_clock source? I realise it's a Linux-specific thing and DT is supposed to be generic, but the information must be provided somehow.

The kernel already has some logic to do this. Most number of bits followed by highest frequency will be the winning sched_clock. You might also want to look at things like always on or not.

Quoted 7 lines

The problem is that sched_clock_register() doesn't take a pointer to be passed back to the read_sched_clock callback like most interfaces of this type do. This means the callback must use global variables set up before the register call, but at that time there's no way of knowing which one will be used. If there were a way of getting a pointer to the callback, it would be a simple matter of registering all instances and letting the kernel choose which to use.

Anyone got a comment on this? Do I have to send a patch adding this before anyone will tell me why it's a bad idea? (That method almost always works.)

Signature · 2 lines
Måns Rullgård
[email protected]
#9 lore raw

+Stephen who has worked on this code.

Quoted 21 lines · Måns Rullgård
Quoted 11 lines · Måns Rullgård
Quoted 8 lines · Rob Herring
Quoted 3 lines · Måns Rullgård

What would be a proper way to select a sched_clock source? I realise it's a Linux-specific thing and DT is supposed to be generic, but the information must be provided somehow.

The kernel already has some logic to do this. Most number of bits followed by highest frequency will be the winning sched_clock. You might also want to look at things like always on or not.

Quoted 7 lines

The problem is that sched_clock_register() doesn't take a pointer to be passed back to the read_sched_clock callback like most interfaces of this type do. This means the callback must use global variables set up before the register call, but at that time there's no way of knowing which one will be used. If there were a way of getting a pointer to the callback, it would be a simple matter of registering all instances and letting the kernel choose which to use.

Quoted 3 lines

Anyone got a comment on this? Do I have to send a patch adding this before anyone will tell me why it's a bad idea? (That method almost always works.)

Adding a ptr to the callback seems fine to me.

Rob

#10 lore raw
Quoted 24 lines · Rob Herring

+Stephen who has worked on this code.

Quoted 21 lines · Måns Rullgård
Quoted 18 lines · Måns Rullgård
Quoted 8 lines · Rob Herring
Quoted 3 lines · Måns Rullgård

What would be a proper way to select a sched_clock source? I realise it's a Linux-specific thing and DT is supposed to be generic, but the information must be provided somehow.

The kernel already has some logic to do this. Most number of bits followed by highest frequency will be the winning sched_clock. You might also want to look at things like always on or not.

The problem is that sched_clock_register() doesn't take a pointer to be passed back to the read_sched_clock callback like most interfaces of this type do. This means the callback must use global variables set up before the register call, but at that time there's no way of knowing which one will be used. If there were a way of getting a pointer to the callback, it would be a simple matter of registering all instances and letting the kernel choose which to use.

Quoted 6 lines
Quoted 3 lines

Anyone got a comment on this? Do I have to send a patch adding this before anyone will tell me why it's a bad idea? (That method almost always works.)

Adding a ptr to the callback seems fine to me.

Does that mean a flag day? Urgh. Pain. I'm not opposed to adding a pointer, in fact it might be better for performance so that we don't take a cache miss in read() functions that need to load some pointer. We were talking about that problem a few months ago, but nothing came of it.

Signature · 6 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#11 lore raw
Quoted 29 lines · Stephen Boyd
Quoted 28 lines · Rob Herring

+Stephen who has worked on this code.

Quoted 24 lines · Måns Rullgård
Quoted 11 lines · Måns Rullgård
Quoted 8 lines · Rob Herring
Quoted 3 lines · Måns Rullgård

What would be a proper way to select a sched_clock source? I realise it's a Linux-specific thing and DT is supposed to be generic, but the information must be provided somehow.

The kernel already has some logic to do this. Most number of bits followed by highest frequency will be the winning sched_clock. You might also want to look at things like always on or not.

Quoted 7 lines

The problem is that sched_clock_register() doesn't take a pointer to be passed back to the read_sched_clock callback like most interfaces of this type do. This means the callback must use global variables set up before the register call, but at that time there's no way of knowing which one will be used. If there were a way of getting a pointer to the callback, it would be a simple matter of registering all instances and letting the kernel choose which to use.

Anyone got a comment on this? Do I have to send a patch adding this before anyone will tell me why it's a bad idea? (That method almost always works.)

Quoted 8 lines
Quoted 2 lines

Adding a ptr to the callback seems fine to me.

Does that mean a flag day? Urgh. Pain. I'm not opposed to adding a pointer, in fact it might be better for performance so that we don't take a cache miss in read() functions that need to load some pointer. We were talking about that problem a few months ago, but nothing came of it.

Flag day in what sense? There aren't all that many users of the interface (56, to be precise), and sched_clock_register() isn't exported. Verifying the change will be a minor pain, but I don't see why it should have any major consequences. Obviously I'd just set the pointer to null for existing users and leave it for the respective maintainers to make proper use of it where sensible.

Signature · 6 lines
Måns Rullgård
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#12 lore raw
Quoted 13 lines · Måns Rullgård
Quoted 10 lines · Stephen Boyd
Quoted 3 lines · Rob Herring

Adding a ptr to the callback seems fine to me.

Does that mean a flag day? Urgh. Pain. I'm not opposed to adding a pointer, in fact it might be better for performance so that we don't take a cache miss in read() functions that need to load some pointer. We were talking about that problem a few months ago, but nothing came of it.

Quoted 3 lines

Flag day in what sense? There aren't all that many users of the interface (56, to be precise), and sched_clock_register() isn't exported.

That's exactly what a flag day is. Lots of coordination, lots of acks, etc. Last time when I changed the registration API I made a new registration API, moved every caller over one by one, and then deleted the old registration API. That's how you manage a flag day.

We could probably do the same thing again with two different types of registration APIs so that we move over users one by one. The old registration API would be wrapped with a sched_clock local function that doesn't pass the pointer it gets called with, while the new registration API would fill in the function pointer that we call directly from the core code. The double function call is probably bad for performance, so I guess we should get rid of it and always pass the pointer to the callback. But this is at least a method to convert everything gradually without breaking users that may be going through different trees.

Quoted 5 lines

Verifying the change will be a minor pain, but I don't see why it should have any major consequences. Obviously I'd just set the pointer to null for existing users and leave it for the respective maintainers to make proper use of it where sensible.

Sure.

Signature · 6 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#13 lore raw
In reply to Stephen Boyd
Quoted 29 lines · Stephen Boyd
Quoted 28 lines · Rob Herring

+Stephen who has worked on this code.

Quoted 24 lines · Måns Rullgård
Quoted 11 lines · Måns Rullgård
Quoted 8 lines · Rob Herring
Quoted 3 lines · Måns Rullgård

What would be a proper way to select a sched_clock source? I realise it's a Linux-specific thing and DT is supposed to be generic, but the information must be provided somehow.

The kernel already has some logic to do this. Most number of bits followed by highest frequency will be the winning sched_clock. You might also want to look at things like always on or not.

Quoted 7 lines

The problem is that sched_clock_register() doesn't take a pointer to be passed back to the read_sched_clock callback like most interfaces of this type do. This means the callback must use global variables set up before the register call, but at that time there's no way of knowing which one will be used. If there were a way of getting a pointer to the callback, it would be a simple matter of registering all instances and letting the kernel choose which to use.

Anyone got a comment on this? Do I have to send a patch adding this before anyone will tell me why it's a bad idea? (That method almost always works.)

Quoted 8 lines
Quoted 2 lines

Adding a ptr to the callback seems fine to me.

Does that mean a flag day? Urgh. Pain. I'm not opposed to adding a pointer, in fact it might be better for performance so that we don't take a cache miss in read() functions that need to load some pointer. We were talking about that problem a few months ago, but nothing came of it.

I've sent a patch. Let the flames begin.

Signature · 6 lines
Måns Rullgård
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#14 lore raw
Quoted 10 lines · Måns Rullgård
Quoted 6 lines · Stephen Boyd

Does that mean a flag day? Urgh. Pain. I'm not opposed to adding a pointer, in fact it might be better for performance so that we don't take a cache miss in read() functions that need to load some pointer. We were talking about that problem a few months ago, but nothing came of it.

I've sent a patch. Let the flames begin.

I never got it. Was I Cced?

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project