Skip to contentSkip to conversation

clocksource: Fix MIPS GIC and DW APB Timer for Baikal-T1 SoC support

PATCH Applied Serge Semin 3 participants 20 messages May 21, 2020 – Jun 1, 2020

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

v5 cover clocksource: Fix MIPS GIC and DW APB Timer for Baikal-T1 SoC support

As for all Baikal-T1 SoC related patchsets, which need this, we replaced the DW APB Timer legacy plain text-based dt-binding file with DT schema. Similarly the MIPS GIC bindings file is also converted to DT schema seeing it also defines the MIPS GIC Timer binding.

Aside from MIPS-specific r4k timer Baikal-T1 chip also provides a functionality of two another timers: embedded into the MIPS GIC timer and three external DW timers available over APB bus. But we can't use them before the corresponding drivers are properly fixed. First of all DW APB Timer shouldn't be bound to a single CPU, since as being accessible over APB they are external with respect to all possible CPUs. Secondly there might be more than just two DW APB Timers in the system (Baikal-T1 has three of them), so permit the driver to use one of them as a clocksource and the rest - for clockevents. Thirdly it's possible to use MIPS GIC timer as a clocksource so register it in the corresponding subsystem (the patch has been found in the Paul Burton MIPS repo so I left the original Signed-off-by attribute). Finally in the same way as r4k timer the MIPS GIC timer should be used with care when CPUFREQ config is enabled since in case of CM2 the timer counting depends on the CPU reference clock frequency while the clocksource subsystem currently doesn't support the timers with non-stable clock.

This patchset is rebased and tested on the mainline Linux kernel 5.7-rc4:
base-commit: 0e698dfa2822 ("Linux 5.7-rc4")
tag: v5.7-rc4

Changelog v2:
- Fix the SoB tags.
- Our corporate email server doesn't change Message-Id anymore, so the patchset is resubmitted being in the cover-letter-threaded format.
- Convert the "snps,dw-apb-timer" binding to DT schema in a dedicated patch.
- Convert the "mti,gic" binding to DT schema in a dedicated patch.

Changelog v3:
- Make the MIPS GIC timer sub-node name not having a unit-address number.
- Discard allOf: [ $ref: /schemas/interrupt-controller.yaml# ] from MIPS GIC bindings.
- Add patch moving the "snps,dw-apb-timer" binding file to the directory with timers binding files.

Changelog v4:
- Mark clocksource as unstable instead of lowering its rating.
- Move conditional sched clocks registration to the Paul' patch.
- Add Thomas Gleixner to the patchset To-list to draw his attention to the patch "dt-bindings: interrupt-controller: Convert mti,gic to DT schema".

Changelog v5:
- Fix mistakenly added "git_" prefix. Obviously it was supposed to be gic_.
- Add new patch "clocksource: dw_apb_timer: Affiliate of-based timer with any CPU"

Cc Alexey Malahov <[email protected]>
Cc Maxim Kaurkin <[email protected]>
Cc Pavel Parkhomenko <[email protected]>
Cc Ramil Zaripov <[email protected]>
Cc Ekaterina Skachko <[email protected]>
Cc Vadim Vlasov <[email protected]>
Cc Alexey Kolotnikov <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Rob Herring <[email protected]>

Paul Burton (1):
clocksource: mips-gic-timer: Register as sched_clock

Serge Semin (7):
dt-bindings: rtc: Convert snps,dw-apb-timer to DT schema
dt-bindings: timer: Move snps,dw-apb-timer DT schema from rtc
dt-bindings: interrupt-controller: Convert mti,gic to DT schema
clocksource: dw_apb_timer: Make CPU-affiliation being optional
clocksource: dw_apb_timer: Affiliate of-based timer with any CPU
clocksource: dw_apb_timer_of: Fix missing clockevent timers
clocksource: mips-gic-timer: Mark GIC timer as unstable if ref clock
changes

 .../interrupt-controller/mips-gic.txt         |  67 --------
 .../interrupt-controller/mti,gic.yaml         | 148 ++++++++++++++++++
 .../devicetree/bindings/rtc/dw-apb.txt        |  32 ----
 .../bindings/timer/snps,dw-apb-timer.yaml     |  88 +++++++++++
 drivers/clocksource/Kconfig                   |   1 +
 drivers/clocksource/dw_apb_timer.c            |   5 +-
 drivers/clocksource/dw_apb_timer_of.c         |   8 +-
 drivers/clocksource/mips-gic-timer.c          |  50 +++++-
 8 files changed, 288 insertions(+), 111 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/interrupt-controller/mips-gic.txt
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/mti,gic.yaml
 delete mode 100644 Documentation/devicetree/bindings/rtc/dw-apb.txt
 create mode 100644 Documentation/devicetree/bindings/timer/snps,dw-apb-timer.yaml
Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 1/8 dt-bindings: rtc: Convert snps,dw-apb-timer to DT schema

Modern device tree bindings are supposed to be created as YAML-files in accordance with DT schema. This commit replaces Synopsys DW Timer legacy bare text binding with YAML file. As before the binding file states that the corresponding dts node is supposed to be compatible with generic DW APB Timer indicated by the "snps,dw-apb-timer" compatible string and to provide a mandatory registers memory range, one timer interrupt, either reference clock source or a fixed clock rate value. It may also have an optional APB bus reference clock phandle specified.

Cc Alexey Malahov <[email protected]>
Cc Thomas Bogendoerfer <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Arnd Bergmann <[email protected]>

---

This binding file doesn't belong to the bindings/rtc seeing it's a pure timer with no rtc facilities like days/months/years counting and alarms. The binding file will be moved to the "Documentation/devicetree/bindings/timer/" directory in the next patch.

I also don't know who is the corresponding driver maintainer, so I added Daniel Lezcano to the maintainers schema. Any idea what email should be specified there instead?

Changelog v3:
- Since it's a conversion patch use GPL-2.0-only SPDX header.
- Replace "additionalProperties: false" property with "unevaluatedProperties: false".

---
 .../devicetree/bindings/rtc/dw-apb.txt        | 32 -------
 .../bindings/rtc/snps,dw-apb-timer.yaml       | 88 +++++++++++++++++++
 2 files changed, 88 insertions(+), 32 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/rtc/dw-apb.txt
 create mode 100644 Documentation/devicetree/bindings/rtc/snps,dw-apb-timer.yaml
Documentation/devicetree/bindings/rtc/dw-apb.txt deleted +0 -32
deleted file mode 100644
index c703d51abb6c..000000000000
@@ -1,32 +0,0 @@
-* Designware APB timer
-
-Required properties:
-- compatible: One of:
- 	"snps,dw-apb-timer"
-	"snps,dw-apb-timer-sp" <DEPRECATED>
-	"snps,dw-apb-timer-osc" <DEPRECATED>
-- reg: physical base address of the controller and length of memory mapped
-  region.
-- interrupts: IRQ line for the timer.
-- either clocks+clock-names or clock-frequency properties
-
-Optional properties:
-- clocks	: list of clock specifiers, corresponding to entries in
-		  the clock-names property;
-- clock-names	: should contain "timer" and "pclk" entries, matching entries
-		  in the clocks property.
-- clock-frequency: The frequency in HZ of the timer.
-- clock-freq: For backwards compatibility with picoxcell
-
-If using the clock specifiers, the pclk clock is optional, as not all
-systems may use one.
-
-
-Example:
-	timer@ffe00000 {
-		compatible = "snps,dw-apb-timer";
-		interrupts = <0 170 4>;
-		reg = <0xffe00000 0x1000>;
-		clocks = <&timer_clk>, <&timer_pclk>;
-		clock-names = "timer", "pclk";
-	};
Documentation/devicetree/bindings/rtc/snps,dw-apb-timer.yaml new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
2.25.1
merge bot Applied
#2 lore raw

[tip: timers/core] dt-bindings: rtc: Convert snps,dw-apb-timer to DT schema

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     b33aaf5cd68d0fa0f0d6aa15831a1e82e2ef98e1
Gitweb:        https://git.kernel.org/tip/b33aaf5cd68d0fa0f0d6aa15831a1e82e2ef98e1
Author:        Serge Semin <[email protected]>
AuthorDate:    Thu, 21 May 2020 23:48:10 +03:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Sat, 23 May 2020 00:02:26 +02:00

dt-bindings: rtc: Convert snps,dw-apb-timer to DT schema

Modern device tree bindings are supposed to be created as YAML-files in accordance with DT schema. This commit replaces Synopsys DW Timer legacy bare text binding with YAML file. As before the binding file states that the corresponding dts node is supposed to be compatible with generic DW APB Timer indicated by the "snps,dw-apb-timer" compatible string and to provide a mandatory registers memory range, one timer interrupt, either reference clock source or a fixed clock rate value. It may also have an optional APB bus reference clock phandle specified.

---
 Documentation/devicetree/bindings/rtc/dw-apb.txt             | 32 +---
 Documentation/devicetree/bindings/rtc/snps,dw-apb-timer.yaml | 88 +++++++-
 2 files changed, 88 insertions(+), 32 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/rtc/dw-apb.txt
 create mode 100644 Documentation/devicetree/bindings/rtc/snps,dw-apb-timer.yaml
Documentation/devicetree/bindings/rtc/dw-apb.txt deleted +0 -32
deleted file mode 100644
index c703d51..0000000
@@ -1,32 +0,0 @@
-* Designware APB timer
-
-Required properties:
-- compatible: One of:
- 	"snps,dw-apb-timer"
-	"snps,dw-apb-timer-sp" <DEPRECATED>
-	"snps,dw-apb-timer-osc" <DEPRECATED>
-- reg: physical base address of the controller and length of memory mapped
-  region.
-- interrupts: IRQ line for the timer.
-- either clocks+clock-names or clock-frequency properties
-
-Optional properties:
-- clocks	: list of clock specifiers, corresponding to entries in
-		  the clock-names property;
-- clock-names	: should contain "timer" and "pclk" entries, matching entries
-		  in the clocks property.
-- clock-frequency: The frequency in HZ of the timer.
-- clock-freq: For backwards compatibility with picoxcell
-
-If using the clock specifiers, the pclk clock is optional, as not all
-systems may use one.
-
-
-Example:
-	timer@ffe00000 {
-		compatible = "snps,dw-apb-timer";
-		interrupts = <0 170 4>;
-		reg = <0xffe00000 0x1000>;
-		clocks = <&timer_clk>, <&timer_pclk>;
-		clock-names = "timer", "pclk";
-	};
Documentation/devicetree/bindings/rtc/snps,dw-apb-timer.yaml new file +88 -0

88 lines not on this page · raw message

#3 lore raw

PATCH v5 2/8 dt-bindings: timer: Move snps,dw-apb-timer DT schema from rtc

In reply to Serge Semin

This binding file doesn't belong to the rtc seeing it's a pure timer with no rtc facilities like days/months/years counting and alarms. So move the YAML-file to the Documentation/devicetree/bindings/timer/ directory.

---
 .../devicetree/bindings/{rtc => timer}/snps,dw-apb-timer.yaml   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
 rename Documentation/devicetree/bindings/{rtc => timer}/snps,dw-apb-timer.yaml (96%)
Documentation/devicetree/bindings/timer/snps,dw-apb-timer.yaml renamed from Documentation/devicetree/bindings/rtc/snps,dw-apb-timer.yaml +1 -1
similarity index 96%
rename from Documentation/devicetree/bindings/rtc/snps,dw-apb-timer.yaml
rename to Documentation/devicetree/bindings/timer/snps,dw-apb-timer.yaml
index 002fe1ee709b..5d300efdf0ca 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 %YAML 1.2
 ---
-$id: http://devicetree.org/schemas/rtc/snps,dw-apb-timer.yaml#
+$id: http://devicetree.org/schemas/timer/snps,dw-apb-timer.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
 title: Synopsys DesignWare APB Timer
Signature · 1 line
2.25.1
merge bot Applied
#4 lore raw

[tip: timers/core] dt-bindings: timer: Move snps,dw-apb-timer DT schema from rtc

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     e69bc8999662a3fa6d856820dd09717afff1cbb0
Gitweb:        https://git.kernel.org/tip/e69bc8999662a3fa6d856820dd09717afff1cbb0
Author:        Serge Semin <[email protected]>
AuthorDate:    Thu, 21 May 2020 23:48:11 +03:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Sat, 23 May 2020 00:02:33 +02:00

dt-bindings: timer: Move snps,dw-apb-timer DT schema from rtc

This binding file doesn't belong to the rtc seeing it's a pure timer with no rtc facilities like days/months/years counting and alarms. So move the YAML-file to the Documentation/devicetree/bindings/timer/ directory.

---
 Documentation/devicetree/bindings/rtc/snps,dw-apb-timer.yaml   | 88 +-------
 Documentation/devicetree/bindings/timer/snps,dw-apb-timer.yaml | 88 +++++++-
 2 files changed, 88 insertions(+), 88 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/rtc/snps,dw-apb-timer.yaml
 create mode 100644 Documentation/devicetree/bindings/timer/snps,dw-apb-timer.yaml
Documentation/devicetree/bindings/rtc/snps,dw-apb-timer.yaml deleted +0 -88
deleted file mode 100644
index 002fe1e..0000000
@@ -1,88 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-only
-%YAML 1.2
----
-$id: http://devicetree.org/schemas/rtc/snps,dw-apb-timer.yaml#
-$schema: http://devicetree.org/meta-schemas/core.yaml#
-
-title: Synopsys DesignWare APB Timer
-
-maintainers:
-  - Daniel Lezcano <[email protected]>
-
-properties:
-  compatible:
-    oneOf:
-      - const: snps,dw-apb-timer
-      - enum:
-          - snps,dw-apb-timer-sp
-          - snps,dw-apb-timer-osc
-        deprecated: true
-
-  reg:
-    maxItems: 1
-
-  interrupts:
-    maxItems: 1
-
-  clocks:
-    minItems: 1
-    items:
-       - description: Timer ticks reference clock source
-       - description: APB interface clock source
-
-  clock-names:
-    minItems: 1
-    items:
-      - const: timer
-      - const: pclk
-
-  clock-frequency: true
-
-  clock-freq:
-    $ref: "/schemas/types.yaml#/definitions/uint32"
-    description: |
-      Has the same meaning as the 'clock-frequency' property - timer clock
-      frequency in HZ, but is defined only for the backwards compatibility
-      with the picoxcell platform.
-
-unevaluatedProperties: false
-
-required:
-  - compatible
-  - reg
-  - interrupts
-
-oneOf:
-  - required:
-      - clocks
-      - clock-names
-  - required:
-      - clock-frequency
-  - required:
-      - clock-freq
-
-examples:
-  - |
-    timer@ffe00000 {
-      compatible = "snps,dw-apb-timer";
-      interrupts = <0 170 4>;
-      reg = <0xffe00000 0x1000>;
-      clocks = <&timer_clk>, <&timer_pclk>;
-      clock-names = "timer", "pclk";
-    };
-  - |
-    timer@ffe00000 {
-      compatible = "snps,dw-apb-timer";
-      interrupts = <0 170 4>;
-      reg = <0xffe00000 0x1000>;
-      clocks = <&timer_clk>;
-      clock-names = "timer";
-    };
-  - |
-    timer@ffe00000 {
-      compatible = "snps,dw-apb-timer";
-      interrupts = <0 170 4>;
-      reg = <0xffe00000 0x1000>;
-      clock-frequency = <25000000>;
-    };
-...
Documentation/devicetree/bindings/timer/snps,dw-apb-timer.yaml new file +88 -0

88 lines not on this page · raw message

#5 lore raw

PATCH v5 3/8 dt-bindings: interrupt-controller: Convert mti,gic to DT schema

In reply to Serge Semin

Modern device tree bindings are supposed to be created as YAML-files in accordance with DT schema. This commit replaces MIPS GIC legacy bare text binding with YAML file. As before the binding file states that the corresponding dts node is supposed to be compatible with MIPS Global Interrupt Controller indicated by the "mti,gic" compatible string and to provide a mandatory interrupt-controller and '#interrupt-cells' properties. There might be optional registers memory range, "mti,reserved-cpu-vectors" and "mti,reserved-ipi-vectors" properties specified.

MIPS GIC also includes a free-running global timer, per-CPU count/compare timers, and a watchdog. Since currently the GIC Timer is only supported the DT schema expects an IRQ and clock-phandler charged timer sub-node with "mti,mips-gic-timer" compatible string.

Cc Alexey Malahov <[email protected]>
Cc Thomas Bogendoerfer <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Arnd Bergmann <[email protected]>

---

I don't really know who is the corresponding driver maintainer, so I added Paul to the maintainers property since he used to be looking for the MIPS arch and Thomas looking after it now. Any idea what email should be specified there instead?

Changelog v3:
- Since timer sub-node has no unit-address, the node shouldn't be named with one. So alter the MIPS GIC bindings to have a pure "timer" sub-node.
- Discard allOf: [ $ref: /schemas/interrupt-controller.yaml# ].
- Since it's a conversion patch use GPL-2.0-only SPDX header.

---
 .../interrupt-controller/mips-gic.txt         |  67 --------
 .../interrupt-controller/mti,gic.yaml         | 148 ++++++++++++++++++
 2 files changed, 148 insertions(+), 67 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/interrupt-controller/mips-gic.txt
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/mti,gic.yaml
Documentation/devicetree/bindings/interrupt-controller/mips-gic.txt deleted +0 -67
deleted file mode 100644
index 173595305e26..000000000000
@@ -1,67 +0,0 @@
-MIPS Global Interrupt Controller (GIC)
-
-The MIPS GIC routes external interrupts to individual VPEs and IRQ pins.
-It also supports local (per-processor) interrupts and software-generated
-interrupts which can be used as IPIs.  The GIC also includes a free-running
-global timer, per-CPU count/compare timers, and a watchdog.
-
-Required properties:
-- compatible : Should be "mti,gic".
-- interrupt-controller : Identifies the node as an interrupt controller
-- #interrupt-cells : Specifies the number of cells needed to encode an
-  interrupt specifier.  Should be 3.
-  - The first cell is the type of interrupt, local or shared.
-    See <include/dt-bindings/interrupt-controller/mips-gic.h>.
-  - The second cell is the GIC interrupt number.
-  - The third cell encodes the interrupt flags.
-    See <include/dt-bindings/interrupt-controller/irq.h> for a list of valid
-    flags.
-
-Optional properties:
-- reg : Base address and length of the GIC registers.  If not present,
-  the base address reported by the hardware GCR_GIC_BASE will be used.
-- mti,reserved-cpu-vectors : Specifies the list of CPU interrupt vectors
-  to which the GIC may not route interrupts.  Valid values are 2 - 7.
-  This property is ignored if the CPU is started in EIC mode.
-- mti,reserved-ipi-vectors : Specifies the range of GIC interrupts that are
-  reserved for IPIs.
-  It accepts 2 values, the 1st is the starting interrupt and the 2nd is the size
-  of the reserved range.
-  If not specified, the driver will allocate the last 2 * number of VPEs in the
-  system.
-
-Required properties for timer sub-node:
-- compatible : Should be "mti,gic-timer".
-- interrupts : Interrupt for the GIC local timer.
-
-Optional properties for timer sub-node:
-- clocks : GIC timer operating clock.
-- clock-frequency : Clock frequency at which the GIC timers operate.
-
-Note that one of clocks or clock-frequency must be specified.
-
-Example:
-
-	gic: interrupt-controller@1bdc0000 {
-		compatible = "mti,gic";
-		reg = <0x1bdc0000 0x20000>;
-
-		interrupt-controller;
-		#interrupt-cells = <3>;
-
-		mti,reserved-cpu-vectors = <7>;
-		mti,reserved-ipi-vectors = <40 8>;
-
-		timer {
-			compatible = "mti,gic-timer";
-			interrupts = <GIC_LOCAL 1 IRQ_TYPE_NONE>;
-			clock-frequency = <50000000>;
-		};
-	};
-
-	uart@18101400 {
-		...
-		interrupt-parent = <&gic>;
-		interrupts = <GIC_SHARED 24 IRQ_TYPE_LEVEL_HIGH>;
-		...
-	};
Documentation/devicetree/bindings/interrupt-controller/mti,gic.yaml new file +148 -0

148 lines not on this page · raw message

Signature · 1 line
2.25.1
#6 lore raw

PATCH v5 4/8 clocksource: dw_apb_timer: Make CPU-affiliation being optional

In reply to Serge Semin

Currently the DW APB Timer driver binds each clockevent timers to a particular CPU. This isn't good for multiple reasons. First of all seeing the device is placed on APB bus (which makes it accessible from any CPU core), accessible over MMIO and having the DYNIRQ flag set we can be sure that manually binding the timer to any CPU just isn't correct. By doing so we just set an extra limitation on device usage. This also doesn't reflect the device actual capability, since by setting the IRQ affinity we can make it virtually local to any CPU. Secondly imagine if you had a real CPU-local timer with the same rating and the same CPU-affinity. In this case if DW APB timer was registered first, then due to the clockevent framework tick-timer selection procedure we'll end up with the real CPU-local timer being left unselected for clock-events tracking. But on most of the platforms (MIPS/ARM/etc) such timers are normally embedded into the CPU core and are accessible with much better performance then devices placed on APB. For instance in MIPS architectures there is r4k-timer, which is CPU-local, assigned with the same rating, and normally its clockevent device is registered after the platform-specific one.

So in order to fix all of these issues let's make the DW APB Timer CPU affinity being optional and deactivated by passing a negative CPU id, which will effectively set the DW APB clockevent timer cpumask to 'cpu_possible_mask'.

Cc Alexey Malahov <[email protected]>
Cc Thomas Bogendoerfer <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Rob Herring <[email protected]>

---

Changelog v5:
- Don't discard CPU affiliation functionality, but allow it being optional. If CPU id passed to the clockevent registration method is negative, then don't assign the timer events to any particular CPU.
- Discard the OF-based DW APB Timer CPU-affiliation setting change. It'll be moved to a dedicated patch.

---
 drivers/clocksource/dw_apb_timer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clocksource/dw_apb_timer.c +3 -2
index b207a77b0831..f5f24a95ee82 100644
@@ -222,7 +222,8 @@ static int apbt_next_event(unsigned long delta,
 /**
  * dw_apb_clockevent_init() - use an APB timer as a clock_event_device
  *
- * @cpu:	The CPU the events will be targeted at.
+ * @cpu:	The CPU the events will be targeted at or -1 if CPU affiliation
+ *		isn't required.
  * @name:	The name used for the timer and the IRQ for it.
  * @rating:	The rating to give the timer.
  * @base:	I/O base for the timer registers.
@@ -257,7 +258,7 @@ dw_apb_clockevent_init(int cpu, const char *name, unsigned rating,
 	dw_ced->ced.max_delta_ticks = 0x7fffffff;
 	dw_ced->ced.min_delta_ns = clockevent_delta2ns(5000, &dw_ced->ced);
 	dw_ced->ced.min_delta_ticks = 5000;
-	dw_ced->ced.cpumask = cpumask_of(cpu);
+	dw_ced->ced.cpumask = cpu < 0 ? cpu_possible_mask : cpumask_of(cpu);
 	dw_ced->ced.features = CLOCK_EVT_FEAT_PERIODIC |
 				CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_DYNIRQ;
 	dw_ced->ced.set_state_shutdown = apbt_shutdown;
Signature · 1 line
2.25.1
merge bot Applied
#7 lore raw

[tip: timers/core] clocksource: dw_apb_timer: Make CPU-affiliation being optional

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     cee43dbf2ee3f430434e2b66994eff8a1aeda889
Gitweb:        https://git.kernel.org/tip/cee43dbf2ee3f430434e2b66994eff8a1aeda889
Author:        Serge Semin <[email protected]>
AuthorDate:    Thu, 21 May 2020 23:48:13 +03:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Sat, 23 May 2020 00:02:41 +02:00

clocksource: dw_apb_timer: Make CPU-affiliation being optional

Currently the DW APB Timer driver binds each clockevent timers to a particular CPU. This isn't good for multiple reasons. First of all seeing the device is placed on APB bus (which makes it accessible from any CPU core), accessible over MMIO and having the DYNIRQ flag set we can be sure that manually binding the timer to any CPU just isn't correct. By doing so we just set an extra limitation on device usage. This also doesn't reflect the device actual capability, since by setting the IRQ affinity we can make it virtually local to any CPU. Secondly imagine if you had a real CPU-local timer with the same rating and the same CPU-affinity. In this case if DW APB timer was registered first, then due to the clockevent framework tick-timer selection procedure we'll end up with the real CPU-local timer being left unselected for clock-events tracking. But on most of the platforms (MIPS/ARM/etc) such timers are normally embedded into the CPU core and are accessible with much better performance then devices placed on APB. For instance in MIPS architectures there is r4k-timer, which is CPU-local, assigned with the same rating, and normally its clockevent device is registered after the platform-specific one.

So in order to fix all of these issues let's make the DW APB Timer CPU affinity being optional and deactivated by passing a negative CPU id, which will effectively set the DW APB clockevent timer cpumask to 'cpu_possible_mask'.

---
 drivers/clocksource/dw_apb_timer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clocksource/dw_apb_timer.c +3 -2
index b207a77..f5f24a9 100644
@@ -222,7 +222,8 @@ static int apbt_next_event(unsigned long delta,
 /**
  * dw_apb_clockevent_init() - use an APB timer as a clock_event_device
  *
- * @cpu:	The CPU the events will be targeted at.
+ * @cpu:	The CPU the events will be targeted at or -1 if CPU affiliation
+ *		isn't required.
  * @name:	The name used for the timer and the IRQ for it.
  * @rating:	The rating to give the timer.
  * @base:	I/O base for the timer registers.
@@ -257,7 +258,7 @@ dw_apb_clockevent_init(int cpu, const char *name, unsigned rating,
 	dw_ced->ced.max_delta_ticks = 0x7fffffff;
 	dw_ced->ced.min_delta_ns = clockevent_delta2ns(5000, &dw_ced->ced);
 	dw_ced->ced.min_delta_ticks = 5000;
-	dw_ced->ced.cpumask = cpumask_of(cpu);
+	dw_ced->ced.cpumask = cpu < 0 ? cpu_possible_mask : cpumask_of(cpu);
 	dw_ced->ced.features = CLOCK_EVT_FEAT_PERIODIC |
 				CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_DYNIRQ;
 	dw_ced->ced.set_state_shutdown = apbt_shutdown;
#8 lore raw

PATCH v5 5/8 clocksource: dw_apb_timer: Affiliate of-based timer with any CPU

In reply to Serge Semin

Currently any DW APB Timer device detected in OF is bound to CPU #0. Doing so is redundant since DW APB Timer isn't CPU-local timer, but as having APB interface is normally accessible from any CPU in the system. By artificially affiliating the DW timer to the very first CPU we may and in our case will make the clockevent subsystem to decline the more performant real CPU-local timers selection in favor of in fact non-local and accessible over a slow bus - DW APB Timers.

Let's not affiliate the of-detected DW APB Timers to any CPU. By doing so the clockevent framework would prefer to select the real CPU-local timer instead of DW APB one. Otherwise if there is no other than DW APB device for clockevents tracking then it will be selected.

Cc Alexey Malahov <[email protected]>
Cc Thomas Bogendoerfer <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Rob Herring <[email protected]>

---

Changelog v5:
- This is a new patch created after reconsidering the solution of the DW APB Timer CPU-affiliation problem.

---
 drivers/clocksource/dw_apb_timer_of.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clocksource/dw_apb_timer_of.c +1 -1
index 8c28b127759f..2db490f35c20 100644
@@ -73,7 +73,7 @@ static void __init add_clockevent(struct device_node *event_timer)
 
 	timer_get_base_and_rate(event_timer, &iobase, &rate);
 
-	ced = dw_apb_clockevent_init(0, event_timer->name, 300, iobase, irq,
+	ced = dw_apb_clockevent_init(-1, event_timer->name, 300, iobase, irq,
 				     rate);
 	if (!ced)
 		panic("Unable to initialise clockevent device");
Signature · 1 line
2.25.1
merge bot Applied
#9 lore raw

[tip: timers/core] clocksource: dw_apb_timer: Affiliate of-based timer with any CPU

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     65e0f876405ef4f0ff25eb1c5ff3e9b536d68805
Gitweb:        https://git.kernel.org/tip/65e0f876405ef4f0ff25eb1c5ff3e9b536d68805
Author:        Serge Semin <[email protected]>
AuthorDate:    Thu, 21 May 2020 23:48:14 +03:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Sat, 23 May 2020 00:02:50 +02:00

clocksource: dw_apb_timer: Affiliate of-based timer with any CPU

Currently any DW APB Timer device detected in OF is bound to CPU #0. Doing so is redundant since DW APB Timer isn't CPU-local timer, but as having APB interface is normally accessible from any CPU in the system. By artificially affiliating the DW timer to the very first CPU we may and in our case will make the clockevent subsystem to decline the more performant real CPU-local timers selection in favor of in fact non-local and accessible over a slow bus - DW APB Timers.

Let's not affiliate the of-detected DW APB Timers to any CPU. By doing so the clockevent framework would prefer to select the real CPU-local timer instead of DW APB one. Otherwise if there is no other than DW APB device for clockevents tracking then it will be selected.

---
 drivers/clocksource/dw_apb_timer_of.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clocksource/dw_apb_timer_of.c +1 -1
index 8c28b12..2db490f 100644
@@ -73,7 +73,7 @@ static void __init add_clockevent(struct device_node *event_timer)
 
 	timer_get_base_and_rate(event_timer, &iobase, &rate);
 
-	ced = dw_apb_clockevent_init(0, event_timer->name, 300, iobase, irq,
+	ced = dw_apb_clockevent_init(-1, event_timer->name, 300, iobase, irq,
 				     rate);
 	if (!ced)
 		panic("Unable to initialise clockevent device");
#10 lore raw

PATCH v5 6/8 clocksource: dw_apb_timer_of: Fix missing clockevent timers

In reply to Serge Semin

Commit 100214889973 ("clocksource: dw_apb_timer_of: use clocksource_of_init") replaced a publicly available driver initialization method with one called by the timer_probe() method available after CLKSRC_OF. In current implementation it traverses all the timers available in the system and calls their initialization methods if corresponding devices were either in dtb or in acpi. But if before the commit any number of available timers would be installed as clockevent and clocksource devices, after that there would be at most two. The rest are just ignored since default case branch doesn't do anything. I don't see a reason of such behaviour, neither the commit message explains it. Moreover this might be wrong if on some platforms these timers might be used for different purpose, as virtually CPU-local clockevent timers and as an independent broadcast timer. So in order to keep the compatibility with the platforms where the order of the timers detection has some meaning, lets add the secondly discovered timer to be of clocksource/sched_clock type, while the very first and the others would provide the clockevents service.

Fixes 100214889973 ("clocksource: dw_apb_timer_of: use clocksource_of_init")
Cc Alexey Malahov <[email protected]>
Cc Thomas Bogendoerfer <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Rob Herring <[email protected]>
---
 drivers/clocksource/dw_apb_timer_of.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/clocksource/dw_apb_timer_of.c +2 -4
index 2db490f35c20..ab3ddebe8344 100644
@@ -147,10 +147,6 @@ static int num_called;
 static int __init dw_apb_timer_init(struct device_node *timer)
 {
 	switch (num_called) {
-	case 0:
-		pr_debug("%s: found clockevent timer\n", __func__);
-		add_clockevent(timer);
-		break;
 	case 1:
 		pr_debug("%s: found clocksource timer\n", __func__);
 		add_clocksource(timer);
@@ -161,6 +157,8 @@ static int __init dw_apb_timer_init(struct device_node *timer)
 #endif
 		break;
 	default:
+		pr_debug("%s: found clockevent timer\n", __func__);
+		add_clockevent(timer);
 		break;
 	}
 
Signature · 1 line
2.25.1
merge bot Applied
#11 lore raw

[tip: timers/core] clocksource: dw_apb_timer_of: Fix missing clockevent timers

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     6d2e16a3181bafb77b535095c39ad1c8b9558c8c
Gitweb:        https://git.kernel.org/tip/6d2e16a3181bafb77b535095c39ad1c8b9558c8c
Author:        Serge Semin <[email protected]>
AuthorDate:    Thu, 21 May 2020 23:48:15 +03:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Sat, 23 May 2020 00:02:59 +02:00

clocksource: dw_apb_timer_of: Fix missing clockevent timers

Commit 100214889973 ("clocksource: dw_apb_timer_of: use clocksource_of_init") replaced a publicly available driver initialization method with one called by the timer_probe() method available after CLKSRC_OF. In current implementation it traverses all the timers available in the system and calls their initialization methods if corresponding devices were either in dtb or in acpi. But if before the commit any number of available timers would be installed as clockevent and clocksource devices, after that there would be at most two. The rest are just ignored since default case branch doesn't do anything. I don't see a reason of such behaviour, neither the commit message explains it. Moreover this might be wrong if on some platforms these timers might be used for different purpose, as virtually CPU-local clockevent timers and as an independent broadcast timer. So in order to keep the compatibility with the platforms where the order of the timers detection has some meaning, lets add the secondly discovered timer to be of clocksource/sched_clock type, while the very first and the others would provide the clockevents service.

Fixes 100214889973 ("clocksource: dw_apb_timer_of: use clocksource_of_init")
Cc Alexey Malahov <[email protected]>
Cc Thomas Bogendoerfer <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Rob Herring <[email protected]>
---
 drivers/clocksource/dw_apb_timer_of.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/clocksource/dw_apb_timer_of.c +2 -4
index 2db490f..ab3ddeb 100644
@@ -147,10 +147,6 @@ static int num_called;
 static int __init dw_apb_timer_init(struct device_node *timer)
 {
 	switch (num_called) {
-	case 0:
-		pr_debug("%s: found clockevent timer\n", __func__);
-		add_clockevent(timer);
-		break;
 	case 1:
 		pr_debug("%s: found clocksource timer\n", __func__);
 		add_clocksource(timer);
@@ -161,6 +157,8 @@ static int __init dw_apb_timer_init(struct device_node *timer)
 #endif
 		break;
 	default:
+		pr_debug("%s: found clockevent timer\n", __func__);
+		add_clockevent(timer);
 		break;
 	}
 
#12 lore raw

PATCH v5 7/8 clocksource: mips-gic-timer: Register as sched_clock

In reply to Serge Semin

From: Paul Burton <[email protected]>

The MIPS GIC timer is well suited for use as sched_clock, so register it as such.

Whilst the existing gic_read_count() function matches the prototype needed by sched_clock_register() already, we split it into 2 functions in order to remove the need to evaluate the mips_cm_is64 condition within each call since sched_clock should be as fast as possible.

Note the sched clock framework needs the clock source being stable in order to rely on it. So we register the MIPS GIC timer as schedule clocks only if it's, if either the system doesn't have CPU-frequency enabled or the CPU frequency is changed by means of the CPC core clock divider available on the platforms with CM3 or newer.

[[email protected]: Register sched-clock if CM3 or !CPU-freq]
Cc Alexey Malahov <[email protected]>
Cc Thomas Bogendoerfer <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Rob Herring <[email protected]>

---

Changelog v3:
- Register sched clocks only if MIPS GIC belongs to CM3 or if CPU-freq isn't supported.

---
 drivers/clocksource/mips-gic-timer.c | 31 ++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
drivers/clocksource/mips-gic-timer.c +27 -4
index 8b5f8ae723cb..ef12c12c2432 100644
@@ -16,6 +16,7 @@
 #include <linux/notifier.h>
 #include <linux/of_irq.h>
 #include <linux/percpu.h>
+#include <linux/sched_clock.h>
 #include <linux/smp.h>
 #include <linux/time.h>
 #include <asm/mips-cps.h>
@@ -24,13 +25,10 @@ static DEFINE_PER_CPU(struct clock_event_device, gic_clockevent_device);
 static int gic_timer_irq;
 static unsigned int gic_frequency;
 
-static u64 notrace gic_read_count(void)
+static u64 notrace gic_read_count_2x32(void)
 {
 	unsigned int hi, hi2, lo;
 
-	if (mips_cm_is64)
-		return read_gic_counter();
-
 	do {
 		hi = read_gic_counter_32h();
 		lo = read_gic_counter_32l();
@@ -40,6 +38,19 @@ static u64 notrace gic_read_count(void)
 	return (((u64) hi) << 32) + lo;
 }
 
+static u64 notrace gic_read_count_64(void)
+{
+	return read_gic_counter();
+}
+
+static u64 notrace gic_read_count(void)
+{
+	if (mips_cm_is64)
+		return gic_read_count_64();
+
+	return gic_read_count_2x32();
+}
+
 static int gic_next_event(unsigned long delta, struct clock_event_device *evt)
 {
 	int cpu = cpumask_first(evt->cpumask);
@@ -228,6 +239,18 @@ static int __init gic_clocksource_of_init(struct device_node *node)
 	/* And finally start the counter */
 	clear_gic_config(GIC_CONFIG_COUNTSTOP);
 
+	/*
+	 * It's safe to use the MIPS GIC timer as a sched clock source only if
+	 * its ticks are stable, which is true on either the platforms with
+	 * stable CPU frequency or on the platforms with CM3 and CPU frequency
+	 * change performed by the CPC core clocks divider.
+	 */
+	if (mips_cm_revision() >= CM_REV_CM3 || !IS_ENABLED(CONFIG_CPU_FREQ)) {
+		sched_clock_register(mips_cm_is64 ?
+				     gic_read_count_64 : gic_read_count_2x32,
+				     64, gic_frequency);
+	}
+
 	return 0;
 }
 TIMER_OF_DECLARE(mips_gic_timer, "mti,gic-timer",
Signature · 1 line
2.25.1
merge bot Applied
#13 lore raw

[tip: timers/core] clocksource: mips-gic-timer: Register as sched_clock

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     48016e78d328998b1f00bcfb639adeabca51abe5
Gitweb:        https://git.kernel.org/tip/48016e78d328998b1f00bcfb639adeabca51abe5
Author:        Paul Burton <[email protected]>
AuthorDate:    Thu, 21 May 2020 23:48:16 +03:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Sat, 23 May 2020 00:03:08 +02:00

clocksource: mips-gic-timer: Register as sched_clock

The MIPS GIC timer is well suited for use as sched_clock, so register it as such.

Whilst the existing gic_read_count() function matches the prototype needed by sched_clock_register() already, we split it into 2 functions in order to remove the need to evaluate the mips_cm_is64 condition within each call since sched_clock should be as fast as possible.

Note the sched clock framework needs the clock source being stable in order to rely on it. So we register the MIPS GIC timer as schedule clocks only if it's, if either the system doesn't have CPU-frequency enabled or the CPU frequency is changed by means of the CPC core clock divider available on the platforms with CM3 or newer.

[[email protected]: Register sched-clock if CM3 or !CPU-freq]
Cc Alexey Malahov <[email protected]>
Cc Thomas Bogendoerfer <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Rob Herring <[email protected]>
---
 drivers/clocksource/mips-gic-timer.c | 31 +++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
drivers/clocksource/mips-gic-timer.c +27 -4
index 8b5f8ae..ef12c12 100644
@@ -16,6 +16,7 @@
 #include <linux/notifier.h>
 #include <linux/of_irq.h>
 #include <linux/percpu.h>
+#include <linux/sched_clock.h>
 #include <linux/smp.h>
 #include <linux/time.h>
 #include <asm/mips-cps.h>
@@ -24,13 +25,10 @@ static DEFINE_PER_CPU(struct clock_event_device, gic_clockevent_device);
 static int gic_timer_irq;
 static unsigned int gic_frequency;
 
-static u64 notrace gic_read_count(void)
+static u64 notrace gic_read_count_2x32(void)
 {
 	unsigned int hi, hi2, lo;
 
-	if (mips_cm_is64)
-		return read_gic_counter();
-
 	do {
 		hi = read_gic_counter_32h();
 		lo = read_gic_counter_32l();
@@ -40,6 +38,19 @@ static u64 notrace gic_read_count(void)
 	return (((u64) hi) << 32) + lo;
 }
 
+static u64 notrace gic_read_count_64(void)
+{
+	return read_gic_counter();
+}
+
+static u64 notrace gic_read_count(void)
+{
+	if (mips_cm_is64)
+		return gic_read_count_64();
+
+	return gic_read_count_2x32();
+}
+
 static int gic_next_event(unsigned long delta, struct clock_event_device *evt)
 {
 	int cpu = cpumask_first(evt->cpumask);
@@ -228,6 +239,18 @@ static int __init gic_clocksource_of_init(struct device_node *node)
 	/* And finally start the counter */
 	clear_gic_config(GIC_CONFIG_COUNTSTOP);
 
+	/*
+	 * It's safe to use the MIPS GIC timer as a sched clock source only if
+	 * its ticks are stable, which is true on either the platforms with
+	 * stable CPU frequency or on the platforms with CM3 and CPU frequency
+	 * change performed by the CPC core clocks divider.
+	 */
+	if (mips_cm_revision() >= CM_REV_CM3 || !IS_ENABLED(CONFIG_CPU_FREQ)) {
+		sched_clock_register(mips_cm_is64 ?
+				     gic_read_count_64 : gic_read_count_2x32,
+				     64, gic_frequency);
+	}
+
 	return 0;
 }
 TIMER_OF_DECLARE(mips_gic_timer, "mti,gic-timer",
#14 lore raw

PATCH v5 8/8 clocksource: mips-gic-timer: Mark GIC timer as unstable if ref clock changes

In reply to Serge Semin

Currently clocksource framework doesn't support the clocks with variable frequency. Since MIPS GIC timer ticks rate might be unstable on some platforms, we must make sure that it justifies the clocksource requirements. MIPS GIC timer is incremented with the CPU cluster reference clocks rate. So in case if CPU frequency changes, the MIPS GIC tick rate changes synchronously. Due to this the clocksource subsystem can't rely on the timer to measure system clocks anymore. This commit marks the MIPS GIC based clocksource as unstable if reference clock (normally it's a CPU reference clocks) rate changes. The clocksource will execute a watchdog thread, which lowers the MIPS GIC timer rating to zero and fallbacks to a new stable one.

Note we don't need to set the CLOCK_SOURCE_MUST_VERIFY flag to the MIPS GIC clocksource since normally the timer is stable. The only reason why it gets unstable is due to the ref clock rate change, which event we detect here in the driver by means of the clocks event notifier.

Cc Alexey Malahov <[email protected]>
Cc Thomas Bogendoerfer <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Rob Herring <[email protected]>

---

Changelog v4:
- Mark clocksource as unstable instead of lowering its rating.

Changelog v5:
- Fix mistakenly added "git_" prefix.

---
 drivers/clocksource/Kconfig          |  1 +
 drivers/clocksource/mips-gic-timer.c | 19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
drivers/clocksource/Kconfig +1 -0
index f2142e6bbea3..37a745f3ca91 100644
@@ -572,6 +572,7 @@ config CLKSRC_VERSATILE
 config CLKSRC_MIPS_GIC
 	bool
 	depends on MIPS_GIC
+	select CLOCKSOURCE_WATCHDOG
 	select TIMER_OF
 
 config CLKSRC_TANGO_XTAL
drivers/clocksource/mips-gic-timer.c +18 -1
index ef12c12c2432..be4175f415ba 100644
@@ -24,6 +24,9 @@
 static DEFINE_PER_CPU(struct clock_event_device, gic_clockevent_device);
 static int gic_timer_irq;
 static unsigned int gic_frequency;
+static bool __read_mostly gic_clock_unstable;
+
+static void gic_clocksource_unstable(char *reason);
 
 static u64 notrace gic_read_count_2x32(void)
 {
@@ -125,8 +128,10 @@ static int gic_clk_notifier(struct notifier_block *nb, unsigned long action,
 {
 	struct clk_notifier_data *cnd = data;
 
-	if (action == POST_RATE_CHANGE)
+	if (action == POST_RATE_CHANGE) {
+		gic_clocksource_unstable("ref clock rate change");
 		on_each_cpu(gic_update_frequency, (void *)cnd->new_rate, 1);
+	}
 
 	return NOTIFY_OK;
 }
@@ -172,6 +177,18 @@ static struct clocksource gic_clocksource = {
 	.vdso_clock_mode	= VDSO_CLOCKMODE_GIC,
 };
 
+static void gic_clocksource_unstable(char *reason)
+{
+	if (gic_clock_unstable)
+		return;
+
+	gic_clock_unstable = true;
+
+	pr_info("GIC timer is unstable due to %s\n", reason);
+
+	clocksource_mark_unstable(&gic_clocksource);
+}
+
 static int __init __gic_clocksource_init(void)
 {
 	unsigned int count_width;
Signature · 1 line
2.25.1
merge bot Applied
#15 lore raw

[tip: timers/core] clocksource: mips-gic-timer: Mark GIC timer as unstable if ref clock changes

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     7d7de1a65349811b24971c5e8e040e6aac192dd4
Gitweb:        https://git.kernel.org/tip/7d7de1a65349811b24971c5e8e040e6aac192dd4
Author:        Serge Semin <[email protected]>
AuthorDate:    Thu, 21 May 2020 23:48:17 +03:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Sat, 23 May 2020 00:03:16 +02:00

clocksource: mips-gic-timer: Mark GIC timer as unstable if ref clock changes

Currently clocksource framework doesn't support the clocks with variable frequency. Since MIPS GIC timer ticks rate might be unstable on some platforms, we must make sure that it justifies the clocksource requirements. MIPS GIC timer is incremented with the CPU cluster reference clocks rate. So in case if CPU frequency changes, the MIPS GIC tick rate changes synchronously. Due to this the clocksource subsystem can't rely on the timer to measure system clocks anymore. This commit marks the MIPS GIC based clocksource as unstable if reference clock (normally it's a CPU reference clocks) rate changes. The clocksource will execute a watchdog thread, which lowers the MIPS GIC timer rating to zero and fallbacks to a new stable one.

Note we don't need to set the CLOCK_SOURCE_MUST_VERIFY flag to the MIPS GIC clocksource since normally the timer is stable. The only reason why it gets unstable is due to the ref clock rate change, which event we detect here in the driver by means of the clocks event notifier.

---
 drivers/clocksource/Kconfig          |  1 +
 drivers/clocksource/mips-gic-timer.c | 19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
drivers/clocksource/Kconfig +1 -0
index c824002..9141838 100644
@@ -570,6 +570,7 @@ config CLKSRC_VERSATILE
 config CLKSRC_MIPS_GIC
 	bool
 	depends on MIPS_GIC
+	select CLOCKSOURCE_WATCHDOG
 	select TIMER_OF
 
 config CLKSRC_TANGO_XTAL
drivers/clocksource/mips-gic-timer.c +18 -1
index ef12c12..be4175f 100644
@@ -24,6 +24,9 @@
 static DEFINE_PER_CPU(struct clock_event_device, gic_clockevent_device);
 static int gic_timer_irq;
 static unsigned int gic_frequency;
+static bool __read_mostly gic_clock_unstable;
+
+static void gic_clocksource_unstable(char *reason);
 
 static u64 notrace gic_read_count_2x32(void)
 {
@@ -125,8 +128,10 @@ static int gic_clk_notifier(struct notifier_block *nb, unsigned long action,
 {
 	struct clk_notifier_data *cnd = data;
 
-	if (action == POST_RATE_CHANGE)
+	if (action == POST_RATE_CHANGE) {
+		gic_clocksource_unstable("ref clock rate change");
 		on_each_cpu(gic_update_frequency, (void *)cnd->new_rate, 1);
+	}
 
 	return NOTIFY_OK;
 }
@@ -172,6 +177,18 @@ static struct clocksource gic_clocksource = {
 	.vdso_clock_mode	= VDSO_CLOCKMODE_GIC,
 };
 
+static void gic_clocksource_unstable(char *reason)
+{
+	if (gic_clock_unstable)
+		return;
+
+	gic_clock_unstable = true;
+
+	pr_info("GIC timer is unstable due to %s\n", reason);
+
+	clocksource_mark_unstable(&gic_clocksource);
+}
+
 static int __init __gic_clocksource_init(void)
 {
 	unsigned int count_width;
#16 lore raw
In reply to Serge Semin
Quoted 22 lines · Serge Semin

As for all Baikal-T1 SoC related patchsets, which need this, we replaced the DW APB Timer legacy plain text-based dt-binding file with DT schema. Similarly the MIPS GIC bindings file is also converted to DT schema seeing it also defines the MIPS GIC Timer binding.

Aside from MIPS-specific r4k timer Baikal-T1 chip also provides a functionality of two another timers: embedded into the MIPS GIC timer and three external DW timers available over APB bus. But we can't use them before the corresponding drivers are properly fixed. First of all DW APB Timer shouldn't be bound to a single CPU, since as being accessible over APB they are external with respect to all possible CPUs. Secondly there might be more than just two DW APB Timers in the system (Baikal-T1 has three of them), so permit the driver to use one of them as a clocksource and the rest - for clockevents. Thirdly it's possible to use MIPS GIC timer as a clocksource so register it in the corresponding subsystem (the patch has been found in the Paul Burton MIPS repo so I left the original Signed-off-by attribute). Finally in the same way as r4k timer the MIPS GIC timer should be used with care when CPUFREQ config is enabled since in case of CM2 the timer counting depends on the CPU reference clock frequency while the clocksource subsystem currently doesn't support the timers with non-stable clock.

Quoted 3 lines

This patchset is rebased and tested on the mainline Linux kernel 5.7-rc4:
base-commit: 0e698dfa2822 ("Linux 5.7-rc4")
tag: v5.7-rc4

Applied patch 1,2,4,5,6,7,8

Thanks!

-- Daniel

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#17 lore raw
Quoted 23 lines · Daniel Lezcano
Quoted 22 lines · Serge Semin

As for all Baikal-T1 SoC related patchsets, which need this, we replaced the DW APB Timer legacy plain text-based dt-binding file with DT schema. Similarly the MIPS GIC bindings file is also converted to DT schema seeing it also defines the MIPS GIC Timer binding.

Aside from MIPS-specific r4k timer Baikal-T1 chip also provides a functionality of two another timers: embedded into the MIPS GIC timer and three external DW timers available over APB bus. But we can't use them before the corresponding drivers are properly fixed. First of all DW APB Timer shouldn't be bound to a single CPU, since as being accessible over APB they are external with respect to all possible CPUs. Secondly there might be more than just two DW APB Timers in the system (Baikal-T1 has three of them), so permit the driver to use one of them as a clocksource and the rest - for clockevents. Thirdly it's possible to use MIPS GIC timer as a clocksource so register it in the corresponding subsystem (the patch has been found in the Paul Burton MIPS repo so I left the original Signed-off-by attribute). Finally in the same way as r4k timer the MIPS GIC timer should be used with care when CPUFREQ config is enabled since in case of CM2 the timer counting depends on the CPU reference clock frequency while the clocksource subsystem currently doesn't support the timers with non-stable clock.

Quoted 7 lines
Quoted 3 lines

This patchset is rebased and tested on the mainline Linux kernel 5.7-rc4:
base-commit: 0e698dfa2822 ("Linux 5.7-rc4")
tag: v5.7-rc4

Applied patch 1,2,4,5,6,7,8

Thanks!

Great! Thanks. Am I right to expect the series in: git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git at the branch timers/core?

-Sergey

Quoted 10 lines

-- Daniel

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#18 lore raw
Quoted 28 lines · Serge Semin
Quoted 27 lines · Daniel Lezcano
Quoted 25 lines · Serge Semin

As for all Baikal-T1 SoC related patchsets, which need this, we replaced the DW APB Timer legacy plain text-based dt-binding file with DT schema. Similarly the MIPS GIC bindings file is also converted to DT schema seeing it also defines the MIPS GIC Timer binding.

Aside from MIPS-specific r4k timer Baikal-T1 chip also provides a functionality of two another timers: embedded into the MIPS GIC timer and three external DW timers available over APB bus. But we can't use them before the corresponding drivers are properly fixed. First of all DW APB Timer shouldn't be bound to a single CPU, since as being accessible over APB they are external with respect to all possible CPUs. Secondly there might be more than just two DW APB Timers in the system (Baikal-T1 has three of them), so permit the driver to use one of them as a clocksource and the rest - for clockevents. Thirdly it's possible to use MIPS GIC timer as a clocksource so register it in the corresponding subsystem (the patch has been found in the Paul Burton MIPS repo so I left the original Signed-off-by attribute). Finally in the same way as r4k timer the MIPS GIC timer should be used with care when CPUFREQ config is enabled since in case of CM2 the timer counting depends on the CPU reference clock frequency while the clocksource subsystem currently doesn't support the timers with non-stable clock.

This patchset is rebased and tested on the mainline Linux kernel 5.7-rc4:
base-commit: 0e698dfa2822 ("Linux 5.7-rc4")
tag: v5.7-rc4

Quoted 6 lines
Quoted 3 lines

Applied patch 1,2,4,5,6,7,8

Thanks!

Great! Thanks. Am I right to expect the series in: git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git at the branch timers/core?

The series first goes to:

https://git.linaro.org/people/daniel.lezcano/linux.git/log/?h=timers/drivers/next

, then I send the PR to Thomas, who send in turn a PR at the merge windows to Linus for the entire tip tree.

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#19 lore raw
Quoted 36 lines · Daniel Lezcano
Quoted 28 lines · Serge Semin
Quoted 27 lines · Daniel Lezcano
Quoted 25 lines · Serge Semin

As for all Baikal-T1 SoC related patchsets, which need this, we replaced the DW APB Timer legacy plain text-based dt-binding file with DT schema. Similarly the MIPS GIC bindings file is also converted to DT schema seeing it also defines the MIPS GIC Timer binding.

Aside from MIPS-specific r4k timer Baikal-T1 chip also provides a functionality of two another timers: embedded into the MIPS GIC timer and three external DW timers available over APB bus. But we can't use them before the corresponding drivers are properly fixed. First of all DW APB Timer shouldn't be bound to a single CPU, since as being accessible over APB they are external with respect to all possible CPUs. Secondly there might be more than just two DW APB Timers in the system (Baikal-T1 has three of them), so permit the driver to use one of them as a clocksource and the rest - for clockevents. Thirdly it's possible to use MIPS GIC timer as a clocksource so register it in the corresponding subsystem (the patch has been found in the Paul Burton MIPS repo so I left the original Signed-off-by attribute). Finally in the same way as r4k timer the MIPS GIC timer should be used with care when CPUFREQ config is enabled since in case of CM2 the timer counting depends on the CPU reference clock frequency while the clocksource subsystem currently doesn't support the timers with non-stable clock.

This patchset is rebased and tested on the mainline Linux kernel 5.7-rc4:
base-commit: 0e698dfa2822 ("Linux 5.7-rc4")
tag: v5.7-rc4

Quoted 6 lines
Quoted 3 lines

Applied patch 1,2,4,5,6,7,8

Thanks!

Great! Thanks. Am I right to expect the series in: git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git at the branch timers/core?

Quoted 6 lines

The series first goes to:

https://git.linaro.org/people/daniel.lezcano/linux.git/log/?h=timers/drivers/next

, then I send the PR to Thomas, who send in turn a PR at the merge windows to Linus for the entire tip tree.

Ok. Thanks for clarification.

-Sergey

Quoted 8 lines
Signature · 6 lines
-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog