clocksource: Fix MIPS GIC and DW APB Timer for Baikal-T1 SoC support
Subsystems (6)
v4 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".
Paul Burton (1):
clocksource: mips-gic-timer: Register as sched_clock
Serge Semin (6):
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: Set clockevent any-possible-CPU mask
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 | 18 +-- drivers/clocksource/dw_apb_timer_of.c | 9 +- drivers/clocksource/mips-gic-timer.c | 50 +++++- include/linux/dw_apb_timer.h | 2 +- 9 files changed, 293 insertions(+), 122 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
PATCH v4 1/7 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.
---
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
@@ -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
PATCH v4 2/7 dt-bindings: timer: Move snps,dw-apb-timer DT schema from rtc
In reply to Serge SeminThis 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
@@ -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
PATCH v4 3/7 dt-bindings: interrupt-controller: Convert mti,gic to DT schema
In reply to Serge SeminModern 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.
---
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
@@ -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
PATCH v4 4/7 clocksource: dw_apb_timer: Set clockevent any-possible-CPU mask
In reply to Serge SeminCurrently the DW APB Timer driver binds all clockevent timers to CPU #0. 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 lets set the DW APB clockevent timer cpumask to be 'cpu_possible_mask'. 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.c | 18 +++++++----------- drivers/clocksource/dw_apb_timer_of.c | 3 +-- include/linux/dw_apb_timer.h | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-)
drivers/clocksource/dw_apb_timer.c +7 -11
@@ -106,6 +106,7 @@ static irqreturn_t dw_apb_clockevent_irq(int irq, void *data) dw_ced->eoi (&dw_ced->timer); evt->event_handler (evt); +return IRQ_HANDLED ; }
@@ -123,8 +124,7 @@ static int apbt_shutdown(struct clock_event_device *evt)struct dw_apb_clock_event_device *dw_ced =ced_to_dw_apb_ced (evt);u32 ctrl; -pr_debug ("%s CPU %d state=shutdown\n" , __func__, -cpumask_first (evt->cpumask)); +pr_debug ("%s state=shutdown\n" , __func__); ctrl =apbt_readl (&dw_ced->timer,APBTMR_N_CONTROL ); ctrl &= ~APBTMR_CONTROL_ENABLE ;
@@ -137,8 +137,7 @@ static int apbt_set_oneshot(struct clock_event_device *evt)struct dw_apb_clock_event_device *dw_ced =ced_to_dw_apb_ced (evt);u32 ctrl; -pr_debug ("%s CPU %d state=oneshot\n" , __func__, -cpumask_first (evt->cpumask)); +pr_debug ("%s state=oneshot\n" , __func__); ctrl =apbt_readl (&dw_ced->timer,APBTMR_N_CONTROL );/*
@@ -170,8 +169,7 @@ static int apbt_set_periodic(struct clock_event_device *evt)unsigned long period =DIV_ROUND_UP (dw_ced->timer.freq,HZ );u32 ctrl; -pr_debug ("%s CPU %d state=periodic\n" , __func__, -cpumask_first (evt->cpumask)); +pr_debug ("%s state=periodic\n" , __func__); ctrl =apbt_readl (&dw_ced->timer,APBTMR_N_CONTROL ); ctrl |=APBTMR_CONTROL_MODE_PERIODIC ;
@@ -194,8 +192,7 @@ static int apbt_resume(struct clock_event_device *evt) {struct dw_apb_clock_event_device *dw_ced =ced_to_dw_apb_ced (evt); -pr_debug ("%s CPU %d state=resume\n" , __func__, -cpumask_first (evt->cpumask)); +pr_debug ("%s state=resume\n" , __func__);apbt_enable_int (&dw_ced->timer);return 0 ;
@@ -222,7 +219,6 @@ 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. * @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.
@@ -237,7 +233,7 @@ static int apbt_next_event(unsigned long delta,* releasing the IRQ. */ struct dw_apb_clock_event_device * -dw_apb_clockevent_init (int cpu,const char *name,unsigned rating, +dw_apb_clockevent_init (const char *name,unsigned int rating,void __iomem *base,int irq,unsigned long freq) { struct dw_apb_clock_event_device *dw_ced =
@@ -257,7 +253,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_possible_mask; dw_ced->ced.features =CLOCK_EVT_FEAT_PERIODIC |CLOCK_EVT_FEAT_ONESHOT |CLOCK_EVT_FEAT_DYNIRQ ; dw_ced->ced.set_state_shutdown = apbt_shutdown;
drivers/clocksource/dw_apb_timer_of.c +1 -2
@@ -73,8 +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, - rate); + ced =dw_apb_clockevent_init (event_timer->name,300 , iobase, irq, rate);if (!ced)panic ("Unable to initialise clockevent device" );
include/linux/dw_apb_timer.h +1 -1
@@ -39,7 +39,7 @@ void dw_apb_clockevent_resume(struct dw_apb_clock_event_device *dw_ced);void dw_apb_clockevent_stop (struct dw_apb_clock_event_device *dw_ced);struct dw_apb_clock_event_device * -dw_apb_clockevent_init (int cpu,const char *name,unsigned rating, +dw_apb_clockevent_init (const char *name,unsigned int rating,void __iomem *base,int irq,unsigned long freq);struct dw_apb_clocksource * dw_apb_clocksource_init(unsigned rating, const char *name, void __iomem *base,
Signature · 1 line
2.25.1
kbuild test robot
build botRe: [PATCH v4 4/7] clocksource: dw_apb_timer: Set clockevent any-possible-CPU mask
I love your patch! Yet something to improve:
Hi Serge,
I love your patch! Yet something to improve:
[auto build test ERROR on tip/timers/core]
[also build test ERROR on abelloni/rtc-next tip/irq/core linus/master v5.7-rc6 next-20200519] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Serge-Semin/clocksource-Fix-MIPS-GIC-and-DW-APB-Timer-for-Baikal-T1-SoC-support/20200521-085612 base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 4479730e9263befbb9ce9563a09563db2acb8f7c config: i386-allyesconfig (attached as .config) compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0 reproduce (this is a W=1 build): # save the attached .config to linux build tree make ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All error/warnings (new ones prefixed by >>, old ones prefixed by <<):
In file included from include/asm-generic/percpu.h:7:0, from arch/x86/include/asm/percpu.h:556,
from arch/x86/include/asm/preempt.h:6,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:51,
from include/linux/seqlock.h:36,
from include/linux/time.h:6,
from include/uapi/linux/timex.h:56,
from include/linux/timex.h:56,
from include/linux/clocksource.h:13,
from include/linux/clockchips.h:14,
from include/linux/dw_apb_timer.h:13,
from arch/x86/kernel/apb_timer.c:27:arch/x86/kernel/apb_timer.c: In function 'apbt_clockevent_register':
>> include/linux/percpu-defs.h:444:1: warning: passing argument 1 of 'dw_apb_clockevent_init' makes pointer from integer without a cast [-Wint-conversion]
({ ^
>> arch/x86/include/asm/smp.h:168:30: note: in expansion of macro '__this_cpu_read'
#define __smp_processor_id() __this_cpu_read(cpu_number)
^~~~~~~~~~~~~~~
>> include/linux/smp.h:218:29: note: in expansion of macro '__smp_processor_id'
# define smp_processor_id() __smp_processor_id()
^~~~~~~~~~~~~~~~~~
>> arch/x86/kernel/apb_timer.c:147:39: note: in expansion of macro 'smp_processor_id'adev->timer = dw_apb_clockevent_init(smp_processor_id(), "apbt0", ^~~~~~~~~~~~~~~~
In file included from arch/x86/kernel/apb_timer.c:27:0:include/linux/dw_apb_timer.h:42:1: note: expected 'const char *' but argument is of type 'int' dw_apb_clockevent_init(const char *name, unsigned int rating, ^~~~~~~~~~~~~~~~~~~~~~
>> arch/x86/kernel/apb_timer.c:147:59: warning: passing argument 2 of 'dw_apb_clockevent_init' makes integer from pointer without a cast [-Wint-conversion]
adev->timer = dw_apb_clockevent_init(smp_processor_id(), "apbt0",
^~~~~~~
In file included from arch/x86/kernel/apb_timer.c:27:0:include/linux/dw_apb_timer.h:42:1: note: expected 'unsigned int' but argument is of type 'char *' dw_apb_clockevent_init(const char *name, unsigned int rating, ^~~~~~~~~~~~~~~~~~~~~~
>> arch/x86/kernel/apb_timer.c:148:3: warning: passing argument 3 of 'dw_apb_clockevent_init' makes pointer from integer without a cast [-Wint-conversion]
intel_mid_timer_options == INTEL_MID_TIMER_LAPIC_APBT ?
^~~~~~~~~~~~~~~~~~~~~~~
In file included from arch/x86/kernel/apb_timer.c:27:0:include/linux/dw_apb_timer.h:42:1: note: expected 'void *' but argument is of type 'int'
dw_apb_clockevent_init(const char *name, unsigned int rating,
^~~~~~~~~~~~~~~~~~~~~~arch/x86/kernel/apb_timer.c:150:3: warning: passing argument 4 of 'dw_apb_clockevent_init' makes integer from pointer without a cast [-Wint-conversion] adev_virt_addr(adev), 0, apbt_freq);
^~~~~~~~~~~~~~
In file included from arch/x86/kernel/apb_timer.c:27:0:include/linux/dw_apb_timer.h:42:1: note: expected 'int' but argument is of type 'void *'
dw_apb_clockevent_init(const char *name, unsigned int rating,
^~~~~~~~~~~~~~~~~~~~~~
>> arch/x86/kernel/apb_timer.c:147:16: error: too many arguments to function 'dw_apb_clockevent_init'
adev->timer = dw_apb_clockevent_init(smp_processor_id(), "apbt0",
^~~~~~~~~~~~~~~~~~~~~~
In file included from arch/x86/kernel/apb_timer.c:27:0:include/linux/dw_apb_timer.h:42:1: note: declared here
dw_apb_clockevent_init(const char *name, unsigned int rating,
^~~~~~~~~~~~~~~~~~~~~~arch/x86/kernel/apb_timer.c: In function 'apbt_setup_secondary_clock':arch/x86/kernel/apb_timer.c:187:40: warning: passing argument 1 of 'dw_apb_clockevent_init' makes pointer from integer without a cast [-Wint-conversion] adev->timer = dw_apb_clockevent_init(cpu, adev->name,
^~~
In file included from arch/x86/kernel/apb_timer.c:27:0:include/linux/dw_apb_timer.h:42:1: note: expected 'const char *' but argument is of type 'int'
dw_apb_clockevent_init(const char *name, unsigned int rating,
^~~~~~~~~~~~~~~~~~~~~~arch/x86/kernel/apb_timer.c:187:45: warning: passing argument 2 of 'dw_apb_clockevent_init' makes integer from pointer without a cast [-Wint-conversion] adev->timer = dw_apb_clockevent_init(cpu, adev->name,
^~~~
In file included from arch/x86/kernel/apb_timer.c:27:0:include/linux/dw_apb_timer.h:42:1: note: expected 'unsigned int' but argument is of type 'char *'
dw_apb_clockevent_init(const char *name, unsigned int rating,
^~~~~~~~~~~~~~~~~~~~~~arch/x86/kernel/apb_timer.c:42:33: warning: passing argument 3 of 'dw_apb_clockevent_init' makes pointer from integer without a cast [-Wint-conversion] #define APBT_CLOCKEVENT_RATING 110
^
>> arch/x86/kernel/apb_timer.c:188:4: note: in expansion of macro 'APBT_CLOCKEVENT_RATING'
APBT_CLOCKEVENT_RATING, adev_virt_addr(adev),
^~~~~~~~~~~~~~~~~~~~~~
In file included from arch/x86/kernel/apb_timer.c:27:0:include/linux/dw_apb_timer.h:42:1: note: expected 'void *' but argument is of type 'int'
dw_apb_clockevent_init(const char *name, unsigned int rating,
^~~~~~~~~~~~~~~~~~~~~~arch/x86/kernel/apb_timer.c:188:28: warning: passing argument 4 of 'dw_apb_clockevent_init' makes integer from pointer without a cast [-Wint-conversion] APBT_CLOCKEVENT_RATING, adev_virt_addr(adev),
^~~~~~~~~~~~~~
In file included from arch/x86/kernel/apb_timer.c:27:0:include/linux/dw_apb_timer.h:42:1: note: expected 'int' but argument is of type 'void *'
dw_apb_clockevent_init(const char *name, unsigned int rating,
^~~~~~~~~~~~~~~~~~~~~~arch/x86/kernel/apb_timer.c:187:17: error: too many arguments to function 'dw_apb_clockevent_init'adev->timer = dw_apb_clockevent_init(cpu, adev->name,
^~~~~~~~~~~~~~~~~~~~~~
In file included from arch/x86/kernel/apb_timer.c:27:0:include/linux/dw_apb_timer.h:42:1: note: declared here
dw_apb_clockevent_init(const char *name, unsigned int rating,
^~~~~~~~~~~~~~~~~~~~~~
vim +/dw_apb_clockevent_init +147 arch/x86/kernel/apb_timer.c
bb24c4716185f6 Jacob Pan 2009-09-02 133
bb24c4716185f6 Jacob Pan 2009-09-02 134 static int __init apbt_clockevent_register(void)
bb24c4716185f6 Jacob Pan 2009-09-02 135 {
bb24c4716185f6 Jacob Pan 2009-09-02 136 struct sfi_timer_table_entry *mtmr;
89cbc76768c2fa Christoph Lameter 2014-08-17 137 struct apbt_dev *adev = this_cpu_ptr(&cpu_apbt_dev);
bb24c4716185f6 Jacob Pan 2009-09-02 138
bb24c4716185f6 Jacob Pan 2009-09-02 139 mtmr = sfi_get_mtmr(APBT_CLOCKEVENT0_NUM);
bb24c4716185f6 Jacob Pan 2009-09-02 140 if (mtmr == NULL) {
bb24c4716185f6 Jacob Pan 2009-09-02 141 printk(KERN_ERR "Failed to get MTMR %d from SFI\n",
bb24c4716185f6 Jacob Pan 2009-09-02 142 APBT_CLOCKEVENT0_NUM);
bb24c4716185f6 Jacob Pan 2009-09-02 143 return -ENODEV;
bb24c4716185f6 Jacob Pan 2009-09-02 144 }
bb24c4716185f6 Jacob Pan 2009-09-02 145
3010673ef5f7be Jacob Pan 2010-03-02 146 adev->num = smp_processor_id();
06c3df49521c1b Jamie Iles 2011-06-06 @147 adev->timer = dw_apb_clockevent_init(smp_processor_id(), "apbt0",
712b6aa8731a7e Kuppuswamy Sathyanarayanan 2013-10-17 @148 intel_mid_timer_options == INTEL_MID_TIMER_LAPIC_APBT ?
06c3df49521c1b Jamie Iles 2011-06-06 149 APBT_CLOCKEVENT_RATING - 100 : APBT_CLOCKEVENT_RATING,
06c3df49521c1b Jamie Iles 2011-06-06 150 adev_virt_addr(adev), 0, apbt_freq);
06c3df49521c1b Jamie Iles 2011-06-06 151 /* Firmware does EOI handling for us. */
06c3df49521c1b Jamie Iles 2011-06-06 152 adev->timer->eoi = NULL;
bb24c4716185f6 Jacob Pan 2009-09-02 153
712b6aa8731a7e Kuppuswamy Sathyanarayanan 2013-10-17 154 if (intel_mid_timer_options == INTEL_MID_TIMER_LAPIC_APBT) {
06c3df49521c1b Jamie Iles 2011-06-06 155 global_clock_event = &adev->timer->ced;
bb24c4716185f6 Jacob Pan 2009-09-02 156 printk(KERN_DEBUG "%s clockevent registered as global\n",
bb24c4716185f6 Jacob Pan 2009-09-02 157 global_clock_event->name);
bb24c4716185f6 Jacob Pan 2009-09-02 158 }
bb24c4716185f6 Jacob Pan 2009-09-02 159
06c3df49521c1b Jamie Iles 2011-06-06 160 dw_apb_clockevent_register(adev->timer);
bb24c4716185f6 Jacob Pan 2009-09-02 161
bb24c4716185f6 Jacob Pan 2009-09-02 162 sfi_free_mtmr(mtmr);
bb24c4716185f6 Jacob Pan 2009-09-02 163 return 0;
bb24c4716185f6 Jacob Pan 2009-09-02 164 }
bb24c4716185f6 Jacob Pan 2009-09-02 165
bb24c4716185f6 Jacob Pan 2009-09-02 166 #ifdef CONFIG_SMP
a5ef2e70405c8a Thomas Gleixner 2010-09-28 167
a5ef2e70405c8a Thomas Gleixner 2010-09-28 168 static void apbt_setup_irq(struct apbt_dev *adev)
a5ef2e70405c8a Thomas Gleixner 2010-09-28 169 {
a5ef2e70405c8a Thomas Gleixner 2010-09-28 170 irq_modify_status(adev->irq, 0, IRQ_MOVE_PCNTXT);
e4d2ebcab11b30 Feng Tang 2010-12-03 171 irq_set_affinity(adev->irq, cpumask_of(adev->cpu));
a5ef2e70405c8a Thomas Gleixner 2010-09-28 172 }
a5ef2e70405c8a Thomas Gleixner 2010-09-28 173
bb24c4716185f6 Jacob Pan 2009-09-02 174 /* Should be called with per cpu */
bb24c4716185f6 Jacob Pan 2009-09-02 175 void apbt_setup_secondary_clock(void)
bb24c4716185f6 Jacob Pan 2009-09-02 176 {
bb24c4716185f6 Jacob Pan 2009-09-02 177 struct apbt_dev *adev;
bb24c4716185f6 Jacob Pan 2009-09-02 178 int cpu;
bb24c4716185f6 Jacob Pan 2009-09-02 179
bb24c4716185f6 Jacob Pan 2009-09-02 180 /* Don't register boot CPU clockevent */
bb24c4716185f6 Jacob Pan 2009-09-02 181 cpu = smp_processor_id();
f6e9456c9272bb Robert Richter 2010-07-21 182 if (!cpu)
bb24c4716185f6 Jacob Pan 2009-09-02 183 return;
bb24c4716185f6 Jacob Pan 2009-09-02 184
89cbc76768c2fa Christoph Lameter 2014-08-17 185 adev = this_cpu_ptr(&cpu_apbt_dev);
06c3df49521c1b Jamie Iles 2011-06-06 186 if (!adev->timer) {
06c3df49521c1b Jamie Iles 2011-06-06 187 adev->timer = dw_apb_clockevent_init(cpu, adev->name,
06c3df49521c1b Jamie Iles 2011-06-06 @188 APBT_CLOCKEVENT_RATING, adev_virt_addr(adev),
06c3df49521c1b Jamie Iles 2011-06-06 189 adev->irq, apbt_freq);
06c3df49521c1b Jamie Iles 2011-06-06 190 adev->timer->eoi = NULL;
06c3df49521c1b Jamie Iles 2011-06-06 191 } else {
06c3df49521c1b Jamie Iles 2011-06-06 192 dw_apb_clockevent_resume(adev->timer);
06c3df49521c1b Jamie Iles 2011-06-06 193 }
bb24c4716185f6 Jacob Pan 2009-09-02 194
06c3df49521c1b Jamie Iles 2011-06-06 195 printk(KERN_INFO "Registering CPU %d clockevent device %s, cpu %08x\n",
06c3df49521c1b Jamie Iles 2011-06-06 196 cpu, adev->name, adev->cpu);
bb24c4716185f6 Jacob Pan 2009-09-02 197
bb24c4716185f6 Jacob Pan 2009-09-02 198 apbt_setup_irq(adev);
06c3df49521c1b Jamie Iles 2011-06-06 199 dw_apb_clockevent_register(adev->timer);
bb24c4716185f6 Jacob Pan 2009-09-02 200
bb24c4716185f6 Jacob Pan 2009-09-02 201 return;
bb24c4716185f6 Jacob Pan 2009-09-02 202 }
bb24c4716185f6 Jacob Pan 2009-09-02 203 :::::: The code at line 147 was first introduced by commit
:::::: 06c3df49521c1b112b777cc4946e5de057c814ba clocksource: apb: Share APB timer code with other platforms
:::::: TO: Jamie Iles <[email protected]>
:::::: CC: John Stultz <[email protected]>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kbuild test robot
build botRe: [PATCH v4 4/7] clocksource: dw_apb_timer: Set clockevent any-possible-CPU mask
In reply to Serge SeminI love your patch! Perhaps something to improve:
Hi Serge,
I love your patch! Perhaps something to improve:
[auto build test WARNING on tip/timers/core]
[also build test WARNING on abelloni/rtc-next tip/irq/core linus/master v5.7-rc6 next-20200519] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Serge-Semin/clocksource-Fix-MIPS-GIC-and-DW-APB-Timer-for-Baikal-T1-SoC-support/20200521-085612 base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 4479730e9263befbb9ce9563a09563db2acb8f7c config: x86_64-allmodconfig (attached as .config) compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0 reproduce: # apt-get install sparse # sparse version: v0.6.1-193-gb8fad4bc-dirty # save the attached .config to linux build tree make W=1 C=1 ARCH=x86_64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
>> arch/x86/kernel/apb_timer.c:147:46: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected char const *name @@ got intchar const *name @@ >> arch/x86/kernel/apb_timer.c:147:46: sparse: expected char const *name >> arch/x86/kernel/apb_timer.c:147:46: sparse: got int [assigned] pscr_ret__ >> arch/x86/kernel/apb_timer.c:147:66: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected unsigned int rating @@ got d int rating @@ >> arch/x86/kernel/apb_timer.c:147:66: sparse: expected unsigned int rating >> arch/x86/kernel/apb_timer.c:147:66: sparse: got char * >> arch/x86/kernel/apb_timer.c:148:71: sparse: sparse: incorrect type in argument 3 (different base types) @@ expected void [noderef] <asn:2> *base @@ got > *base @@ >> arch/x86/kernel/apb_timer.c:148:71: sparse: expected void [noderef] <asn:2> *base >> arch/x86/kernel/apb_timer.c:148:71: sparse: got int >> arch/x86/kernel/apb_timer.c:150:31: sparse: sparse: incorrect type in argument 4 (different base types) @@ expected int irq @@ got void [noderef] <asn:int irq @@ >> arch/x86/kernel/apb_timer.c:150:31: sparse: expected int irq >> arch/x86/kernel/apb_timer.c:150:31: sparse: got void [noderef] <asn:2> * >> arch/x86/kernel/apb_timer.c:147:45: sparse: sparse: too many arguments for function dw_apb_clockevent_init arch/x86/kernel/apb_timer.c:187:54: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected char const *name @@ got intchar const *name @@ arch/x86/kernel/apb_timer.c:187:54: sparse: expected char const *name >> arch/x86/kernel/apb_timer.c:187:54: sparse: got int [assigned] cpu arch/x86/kernel/apb_timer.c:187:59: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected unsigned int rating @@ got d int rating @@ arch/x86/kernel/apb_timer.c:187:59: sparse: expected unsigned int rating arch/x86/kernel/apb_timer.c:187:59: sparse: got char * arch/x86/kernel/apb_timer.c:188:25: sparse: sparse: incorrect type in argument 3 (different base types) @@ expected void [noderef] <asn:2> *base @@ got > *base @@ arch/x86/kernel/apb_timer.c:188:25: sparse: expected void [noderef] <asn:2> *base arch/x86/kernel/apb_timer.c:188:25: sparse: got int arch/x86/kernel/apb_timer.c:188:63: sparse: sparse: incorrect type in argument 4 (different base types) @@ expected int irq @@ got void [noderef] <asn:int irq @@ arch/x86/kernel/apb_timer.c:188:63: sparse: expected int irq arch/x86/kernel/apb_timer.c:188:63: sparse: got void [noderef] <asn:2> * arch/x86/kernel/apb_timer.c:187:53: sparse: sparse: too many arguments for function dw_apb_clockevent_init >> arch/x86/kernel/apb_timer.c:147:46: sparse: sparse: non size-preserving integer to pointer cast >> arch/x86/kernel/apb_timer.c:147:66: sparse: sparse: non size-preserving pointer to integer cast
arch/x86/kernel/apb_timer.c:187:54: sparse: sparse: non size-preserving integer to pointer cast arch/x86/kernel/apb_timer.c:187:59: sparse: sparse: non size-preserving pointer to integer cast
vim +147 arch/x86/kernel/apb_timer.c
bb24c4716185f6 Jacob Pan 2009-09-02 133
bb24c4716185f6 Jacob Pan 2009-09-02 134 static int __init apbt_clockevent_register(void)
bb24c4716185f6 Jacob Pan 2009-09-02 135 {
bb24c4716185f6 Jacob Pan 2009-09-02 136 struct sfi_timer_table_entry *mtmr;
89cbc76768c2fa Christoph Lameter 2014-08-17 137 struct apbt_dev *adev = this_cpu_ptr(&cpu_apbt_dev);
bb24c4716185f6 Jacob Pan 2009-09-02 138
bb24c4716185f6 Jacob Pan 2009-09-02 139 mtmr = sfi_get_mtmr(APBT_CLOCKEVENT0_NUM);
bb24c4716185f6 Jacob Pan 2009-09-02 140 if (mtmr == NULL) {
bb24c4716185f6 Jacob Pan 2009-09-02 141 printk(KERN_ERR "Failed to get MTMR %d from SFI\n",
bb24c4716185f6 Jacob Pan 2009-09-02 142 APBT_CLOCKEVENT0_NUM);
bb24c4716185f6 Jacob Pan 2009-09-02 143 return -ENODEV;
bb24c4716185f6 Jacob Pan 2009-09-02 144 }
bb24c4716185f6 Jacob Pan 2009-09-02 145
3010673ef5f7be Jacob Pan 2010-03-02 146 adev->num = smp_processor_id();
06c3df49521c1b Jamie Iles 2011-06-06 @147 adev->timer = dw_apb_clockevent_init(smp_processor_id(), "apbt0",
712b6aa8731a7e Kuppuswamy Sathyanarayanan 2013-10-17 @148 intel_mid_timer_options == INTEL_MID_TIMER_LAPIC_APBT ?
06c3df49521c1b Jamie Iles 2011-06-06 149 APBT_CLOCKEVENT_RATING - 100 : APBT_CLOCKEVENT_RATING,
06c3df49521c1b Jamie Iles 2011-06-06 @150 adev_virt_addr(adev), 0, apbt_freq);
06c3df49521c1b Jamie Iles 2011-06-06 151 /* Firmware does EOI handling for us. */
06c3df49521c1b Jamie Iles 2011-06-06 152 adev->timer->eoi = NULL;
bb24c4716185f6 Jacob Pan 2009-09-02 153
712b6aa8731a7e Kuppuswamy Sathyanarayanan 2013-10-17 154 if (intel_mid_timer_options == INTEL_MID_TIMER_LAPIC_APBT) {
06c3df49521c1b Jamie Iles 2011-06-06 155 global_clock_event = &adev->timer->ced;
bb24c4716185f6 Jacob Pan 2009-09-02 156 printk(KERN_DEBUG "%s clockevent registered as global\n",
bb24c4716185f6 Jacob Pan 2009-09-02 157 global_clock_event->name);
bb24c4716185f6 Jacob Pan 2009-09-02 158 }
bb24c4716185f6 Jacob Pan 2009-09-02 159
06c3df49521c1b Jamie Iles 2011-06-06 160 dw_apb_clockevent_register(adev->timer);
bb24c4716185f6 Jacob Pan 2009-09-02 161
bb24c4716185f6 Jacob Pan 2009-09-02 162 sfi_free_mtmr(mtmr);
bb24c4716185f6 Jacob Pan 2009-09-02 163 return 0;
bb24c4716185f6 Jacob Pan 2009-09-02 164 }
bb24c4716185f6 Jacob Pan 2009-09-02 165
bb24c4716185f6 Jacob Pan 2009-09-02 166 #ifdef CONFIG_SMP
a5ef2e70405c8a Thomas Gleixner 2010-09-28 167
a5ef2e70405c8a Thomas Gleixner 2010-09-28 168 static void apbt_setup_irq(struct apbt_dev *adev)
a5ef2e70405c8a Thomas Gleixner 2010-09-28 169 {
a5ef2e70405c8a Thomas Gleixner 2010-09-28 170 irq_modify_status(adev->irq, 0, IRQ_MOVE_PCNTXT);
e4d2ebcab11b30 Feng Tang 2010-12-03 171 irq_set_affinity(adev->irq, cpumask_of(adev->cpu));
a5ef2e70405c8a Thomas Gleixner 2010-09-28 172 }
a5ef2e70405c8a Thomas Gleixner 2010-09-28 173
bb24c4716185f6 Jacob Pan 2009-09-02 174 /* Should be called with per cpu */
bb24c4716185f6 Jacob Pan 2009-09-02 175 void apbt_setup_secondary_clock(void)
bb24c4716185f6 Jacob Pan 2009-09-02 176 {
bb24c4716185f6 Jacob Pan 2009-09-02 177 struct apbt_dev *adev;
bb24c4716185f6 Jacob Pan 2009-09-02 178 int cpu;
bb24c4716185f6 Jacob Pan 2009-09-02 179
bb24c4716185f6 Jacob Pan 2009-09-02 180 /* Don't register boot CPU clockevent */
bb24c4716185f6 Jacob Pan 2009-09-02 181 cpu = smp_processor_id();
f6e9456c9272bb Robert Richter 2010-07-21 182 if (!cpu)
bb24c4716185f6 Jacob Pan 2009-09-02 183 return;
bb24c4716185f6 Jacob Pan 2009-09-02 184
89cbc76768c2fa Christoph Lameter 2014-08-17 185 adev = this_cpu_ptr(&cpu_apbt_dev);
06c3df49521c1b Jamie Iles 2011-06-06 186 if (!adev->timer) {
06c3df49521c1b Jamie Iles 2011-06-06 @187 adev->timer = dw_apb_clockevent_init(cpu, adev->name,
06c3df49521c1b Jamie Iles 2011-06-06 188 APBT_CLOCKEVENT_RATING, adev_virt_addr(adev),
06c3df49521c1b Jamie Iles 2011-06-06 189 adev->irq, apbt_freq);
06c3df49521c1b Jamie Iles 2011-06-06 190 adev->timer->eoi = NULL;
06c3df49521c1b Jamie Iles 2011-06-06 191 } else {
06c3df49521c1b Jamie Iles 2011-06-06 192 dw_apb_clockevent_resume(adev->timer);
06c3df49521c1b Jamie Iles 2011-06-06 193 }
bb24c4716185f6 Jacob Pan 2009-09-02 194
06c3df49521c1b Jamie Iles 2011-06-06 195 printk(KERN_INFO "Registering CPU %d clockevent device %s, cpu %08x\n",
06c3df49521c1b Jamie Iles 2011-06-06 196 cpu, adev->name, adev->cpu);
bb24c4716185f6 Jacob Pan 2009-09-02 197
bb24c4716185f6 Jacob Pan 2009-09-02 198 apbt_setup_irq(adev);
06c3df49521c1b Jamie Iles 2011-06-06 199 dw_apb_clockevent_register(adev->timer);
bb24c4716185f6 Jacob Pan 2009-09-02 200
bb24c4716185f6 Jacob Pan 2009-09-02 201 return;
bb24c4716185f6 Jacob Pan 2009-09-02 202 }
bb24c4716185f6 Jacob Pan 2009-09-02 203 :::::: The code at line 147 was first introduced by commit
:::::: 06c3df49521c1b112b777cc4946e5de057c814ba clocksource: apb: Share APB timer code with other platforms
:::::: TO: Jamie Iles <[email protected]>
:::::: CC: John Stultz <[email protected]>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v4 4/7] clocksource: dw_apb_timer: Set clockevent any-possible-CPU mask
In reply to Serge SeminDaniel,
Quoted 19 lines · Serge Semin
Currently the DW APB Timer driver binds all clockevent timers to CPU #0. 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.
Quoted 5 lines
So in order to fix all of these issues lets set the DW APB clockevent timer cpumask to be '
cpu_possible_mask'. 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.
Hm, seems to me it has been a mistake to remove the CPU affiliation for the timers since x86 has got a specific use-case with assigning the timers to all detected CPUs. Though for our needs we don't need this feature. I'll make the affiliation optional then. Like this:
Quoted 7 lines
dw_apb_clockevent_init(int cpu, const char *name, unsigned rating,
void__iomem*base, int irq, unsigned long freq)
{
...dw_ced->ced.cpumask = cpu < 0 ? cpu_possible_mask : cpumask_of(cpu);...
}
DW APB Timer OF-based devices won't make the timer affiliated to the CPU #0, but to any possible CPU by passing -1 to the dw_apb_clockevent_init():
--- drivers/clocksource/dw_apb_timer_of.c
+++ drivers/clocksource/dw_apb_timer_of.c
- ced = dw_apb_clockevent_init(0, event_timer->name, 300, iobase, irq,
rate);
+ ced = dw_apb_clockevent_init(-1, event_timer->name, 300, iobase, irq,
rate);What do you think?
-Sergey
Quoted 127 lines
Signed-off-by Serge Semin <[email protected]>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.c | 18 +++++++----------- drivers/clocksource/dw_apb_timer_of.c | 3 +-- include/linux/dw_apb_timer.h | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-)drivers/clocksource/dw_apb_timer.c +7
-11@@ -106,6 +106,7 @@ static irqreturn_t dw_apb_clockevent_irq(int irq, void *data) dw_ced->eoi (&dw_ced->timer); evt->event_handler (evt); +return IRQ_HANDLED ; }@@ -123,8 +124,7 @@ static int apbt_shutdown(struct clock_event_device *evt)struct dw_apb_clock_event_device *dw_ced =ced_to_dw_apb_ced (evt);u32 ctrl; -pr_debug ("%s CPU %d state=shutdown\n" , __func__, -cpumask_first (evt->cpumask)); +pr_debug ("%s state=shutdown\n" , __func__); ctrl =apbt_readl (&dw_ced->timer,APBTMR_N_CONTROL ); ctrl &= ~APBTMR_CONTROL_ENABLE ;@@ -137,8 +137,7 @@ static int apbt_set_oneshot(struct clock_event_device *evt)struct dw_apb_clock_event_device *dw_ced =ced_to_dw_apb_ced (evt);u32 ctrl; -pr_debug ("%s CPU %d state=oneshot\n" , __func__, -cpumask_first (evt->cpumask)); +pr_debug ("%s state=oneshot\n" , __func__); ctrl =apbt_readl (&dw_ced->timer,APBTMR_N_CONTROL );/* @@ -170,8 +169,7 @@ static int apbt_set_periodic(struct clock_event_device *evt)unsigned long period =DIV_ROUND_UP (dw_ced->timer.freq,HZ );u32 ctrl; -pr_debug ("%s CPU %d state=periodic\n" , __func__, -cpumask_first (evt->cpumask)); +pr_debug ("%s state=periodic\n" , __func__); ctrl =apbt_readl (&dw_ced->timer,APBTMR_N_CONTROL ); ctrl |=APBTMR_CONTROL_MODE_PERIODIC ;@@ -194,8 +192,7 @@ static int apbt_resume(struct clock_event_device *evt) {struct dw_apb_clock_event_device *dw_ced =ced_to_dw_apb_ced (evt); -pr_debug ("%s CPU %d state=resume\n" , __func__, -cpumask_first (evt->cpumask)); +pr_debug ("%s state=resume\n" , __func__);apbt_enable_int (&dw_ced->timer);return 0 ;@@ -222,7 +219,6 @@ 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. * @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. @@ -237,7 +233,7 @@ static int apbt_next_event(unsigned long delta,* releasing the IRQ. */ struct dw_apb_clock_event_device * -dw_apb_clockevent_init (int cpu,const char *name,unsigned rating, +dw_apb_clockevent_init (const char *name,unsigned int rating,void __iomem *base,int irq,unsigned long freq) { struct dw_apb_clock_event_device *dw_ced =@@ -257,7 +253,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_possible_mask; dw_ced->ced.features =CLOCK_EVT_FEAT_PERIODIC |CLOCK_EVT_FEAT_ONESHOT |CLOCK_EVT_FEAT_DYNIRQ ; dw_ced->ced.set_state_shutdown = apbt_shutdown;drivers/clocksource/dw_apb_timer_of.c +1
-2@@ -73,8 +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, - rate); + ced =dw_apb_clockevent_init (event_timer->name,300 , iobase, irq, rate);if (!ced)panic ("Unable to initialise clockevent device" );include/linux/dw_apb_timer.h +1
-1@@ -39,7 +39,7 @@ void dw_apb_clockevent_resume(struct dw_apb_clock_event_device *dw_ced);void dw_apb_clockevent_stop (struct dw_apb_clock_event_device *dw_ced);struct dw_apb_clock_event_device * -dw_apb_clockevent_init (int cpu,const char *name,unsigned rating, +dw_apb_clockevent_init (const char *name,unsigned int rating,void __iomem *base,int irq,unsigned long freq);struct dw_apb_clocksource * dw_apb_clocksource_init(unsigned rating, const char *name, void __iomem *base,Signature · 1 line
2.25.1
PATCH v4 5/7 clocksource: dw_apb_timer_of: Fix missing clockevent timers
In reply to Serge SeminCommit 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.
--- drivers/clocksource/dw_apb_timer_of.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/clocksource/dw_apb_timer_of.c +2 -4
@@ -146,10 +146,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);
@@ -160,6 +156,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
PATCH v4 6/7 clocksource: mips-gic-timer: Register as sched_clock
In reply to Serge SeminFrom: 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.
---
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
@@ -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
PATCH v4 7/7 clocksource: mips-gic-timer: Mark GIC timer as unstable if ref clock changes
In reply to Serge SeminCurrently 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.
---
Changelog v3:
- Mark clocksource as unstable instead of lowering its rating.
--- drivers/clocksource/Kconfig | 1 + drivers/clocksource/mips-gic-timer.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-)
drivers/clocksource/Kconfig +1 -0
@@ -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
@@ -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 git_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 ) { +git_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 git_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
Re: [PATCH v4 7/7] clocksource: mips-gic-timer: Mark GIC timer as unstable if ref clock changes
Hi Serge,
Quoted 12 lines · 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.
Quoted 6 lines
Note we don't need to set the
CLOCK_SOURCE_MUST_VERIFYflag 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.Signed-off-by Serge Semin <[email protected]>
Thanks for your patch!
drivers/clocksource/mips-gic-timer.c line 29
Quoted 9 lines
drivers/clocksource/mips-gic-timer.c +3
-0@@ -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 git_clocksource_unstable (char *reason);
gic_clocksource_unstable? (everywhere)
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH v4 7/7] clocksource: mips-gic-timer: Mark GIC timer as unstable if ref clock changes
Quoted 25 lines · Geert Uytterhoeven
Hi Serge,
Quoted 12 lines · 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.
Quoted 6 lines
Note we don't need to set the
CLOCK_SOURCE_MUST_VERIFYflag 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.Signed-off-by Serge Semin <[email protected]>Thanks for your patch!
Quoted 11 lines
drivers/clocksource/mips-gic-timer.c line 29
Quoted 9 lines
drivers/clocksource/mips-gic-timer.c +3
-0@@ -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 git_clocksource_unstable (char *reason);
gic_clocksource_unstable? (everywhere)
This is the most used word lately. So my hands write git everywhere by itself.) Thanks for noticing this.
-Sergey
Quoted 11 lines
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds