Received: by 10.192.165.156 with SMTP id m28csp1176738imm; Fri, 13 Apr 2018 14:51:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/St2apqxk9hP4eItiIEG/Z2uOJ1BPbO1uK4raqgpmD7ySL1HYO6w2Y3ilDzMIQEzOAvdPX X-Received: by 10.98.226.24 with SMTP id a24mr12954339pfi.223.1523656310426; Fri, 13 Apr 2018 14:51:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523656310; cv=none; d=google.com; s=arc-20160816; b=G6TOKo6B/MeABeHE5+Dyn+DdGLcG4LHRL5329MDpUSxYR+/cBYjKHCkbO8NRGa1dYO lW0afRfuUj/I4LKYitAWBdIAYFFoKexN62Yh9m6p62/FftC+QrM4AcZeqlR7qssQMPWc do1bikEKX1qpcV9PZJmqL7MAZ7kM9hb8YKrs3C3WiYIMsTyU37SRYukN3PCLRnT56OoC mzkYSWqZCd/bG+1drWf2FUjPCI5G+VNyy7+unckARc8tTZO//z1dHOAQmR6AyZdE2WoX I7+BN4BYYJ2vkKKedZLbOl31CFVjOC+g/rxWG004fxRw44sQSTVCjYPG4gf0VvuGWFxx i7nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=eMnsy5bReHrhDrjOM9CC21fov3LNiv6BgvfO0Q/njLU=; b=A3z9hnrPRGNSMw7U8ZsLk+fwVQIeRwgRW3KC4tNGJRvPdDivaA8BguLX6uZrKB79tq +7JNajo3F+3ATOkTzdqLcIIh8DheWC2KK9BqRlkpnEkAR35NBdhIIYpSmjss9ALUuUOI rE7F3i6sUO3Qgo16MK7OeV2r4fzsM/wrz6SflrqIpFa0y7FuQjsXx3qKKdk1AiiMr5L3 IkeT4ZIXCwSVFzENh4oDWdAhzO9mCcAH12Gskox9OVWJ3AGj6V022ajRs9G5d89YfMbW lQ6O3xkGto6oqWDBUPqwCKt9R0aJkH9LBoqhfGgVS1EZnqR4IFujECalftC9A5YrSaiH XIzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=RvYrVLNW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f10si87215pgc.127.2018.04.13.14.51.36; Fri, 13 Apr 2018 14:51:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=RvYrVLNW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752186AbeDMVuA (ORCPT + 99 others); Fri, 13 Apr 2018 17:50:00 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:43223 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751144AbeDMVtf (ORCPT ); Fri, 13 Apr 2018 17:49:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1523656176; x=1555192176; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Lvl3UK93wrL3mbn50lk1jKX9u0cmmgquB7pKJ/AZPNs=; b=RvYrVLNWAgc+o+XWiE02AHNCxb6TRAUY5JRAVlrLMKIlxi/0LK7+o04P 89dwArN2vUlDgo7uROP6BrabwiuFtPmO5wMqye8jJUyer0RQpSMewMhkC JdsRZkZimk2a6WnNywjYeJdt+Xssy4mRZTPHDdkzQvFOaQ+uMpP2vDrSO VYDhsiMgEI1oGs4FwXLwmgTK/3Nth6BIJOyxpV9Xe0hBkuZa3GOyWjUL0 zHP+OvPeAVR62R0gDQWO7uAOiPUFK3I5DSui22/+qxzvpr9Hx00h+WCE2 0NI0o9S/ocAaHW1x/ks2J078SRFo9RTeSClrAgfPTFQ2I0KrC5h3+saum w==; X-IronPort-AV: E=Sophos;i="5.48,446,1517846400"; d="scan'208";a="75828833" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 14 Apr 2018 05:49:35 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 13 Apr 2018 14:41:27 -0700 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Apr 2018 14:49:35 -0700 From: Atish Patra To: palmer@sifive.com, linux-riscv@lists.infradead.org Cc: albert@sifive.com, tglx@linutronix.de, mjc@sifive.com, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/2] RISCV: Register clocksource and events correctly Date: Fri, 13 Apr 2018 14:49:33 -0700 Message-Id: <1523656174-249811-2-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523656174-249811-1-git-send-email-atish.patra@wdc.com> References: <1523656174-249811-1-git-send-email-atish.patra@wdc.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, timer_probe() is called for every cpu and clocksource is registered multiple times for each cpu which is wrong. Probe timer only once during init and register the clock source at that time. Move the clock event registration cpu online notification callback. Take this opportunity to remove redundant functions as well. Signed-off-by: Atish Patra --- arch/riscv/include/asm/smp.h | 2 +- arch/riscv/kernel/time.c | 9 +------- drivers/clocksource/riscv_timer.c | 44 ++++++++++++++++++++++++++------------- include/linux/cpuhotplug.h | 1 + 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h index 85e4220..01b8df8 100644 --- a/arch/riscv/include/asm/smp.h +++ b/arch/riscv/include/asm/smp.h @@ -25,7 +25,7 @@ #ifdef CONFIG_SMP /* SMP initialization hook for setup_arch */ -void __init init_clockevent(void); +void init_clockevent(void); /* SMP initialization hook for setup_arch */ void __init setup_smp(void); diff --git a/arch/riscv/kernel/time.c b/arch/riscv/kernel/time.c index 67709cb..bcd3e76 100644 --- a/arch/riscv/kernel/time.c +++ b/arch/riscv/kernel/time.c @@ -39,13 +39,6 @@ void riscv_timer_interrupt(void) #endif } -void __init init_clockevent(void) -{ - timer_probe(); - csr_set(sie, SIE_STIE); -} - - static long __init timebase_frequency(void) { struct device_node *cpu; @@ -65,5 +58,5 @@ void __init time_init(void) { riscv_timebase = timebase_frequency(); lpj_fine = riscv_timebase / HZ; - init_clockevent(); + timer_probe(); } diff --git a/drivers/clocksource/riscv_timer.c b/drivers/clocksource/riscv_timer.c index 59a734c..8b45af2 100644 --- a/drivers/clocksource/riscv_timer.c +++ b/drivers/clocksource/riscv_timer.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #define MINDELTA 100 @@ -71,16 +72,6 @@ DEFINE_PER_CPU(struct clocksource, riscv_clocksource) = { .read = rdtime, }; -void timer_riscv_init(int cpu_id, - unsigned long riscv_timebase, - int (*next)(unsigned long, struct clock_event_device*)) -{ - struct clock_event_device *ce = per_cpu_ptr(&riscv_clock_event, cpu_id); - - ce->cpumask = cpumask_of(cpu_id); - clockevents_config_and_register(ce, riscv_timebase, MINDELTA, MAXDELTA); -} - static int hart_of_timer(struct device_node *dev) { u32 hart; @@ -100,21 +91,44 @@ static u64 notrace timer_riscv_sched_read(void) return get_cycles64(); } +static int timer_riscv_starting_cpu(unsigned int cpu) +{ + struct clock_event_device *ce = per_cpu_ptr(&riscv_clock_event, cpu); + + ce->cpumask = cpumask_of(cpu); + clockevents_config_and_register(ce, riscv_timebase, MINDELTA, MAXDELTA); + /* Enable timer interrupt for this cpu */ + csr_set(sie, SIE_STIE); + + return 0; +} + +static int timer_riscv_dying_cpu(unsigned int cpu) +{ + /* Disable timer interrupt for this cpu */ + csr_clear(sie, SIE_STIE); + + return 0; +} + static int __init timer_riscv_init_dt(struct device_node *n) { + int err = 0; int cpu_id = hart_of_timer(n); - struct clock_event_device *ce = per_cpu_ptr(&riscv_clock_event, cpu_id); struct clocksource *cs = per_cpu_ptr(&riscv_clocksource, cpu_id); if (cpu_id == smp_processor_id()) { clocksource_register_hz(cs, riscv_timebase); sched_clock_register(timer_riscv_sched_read, 64, riscv_timebase); - ce->cpumask = cpumask_of(cpu_id); - clockevents_config_and_register(ce, riscv_timebase, MINDELTA, MAXDELTA); + err = cpuhp_setup_state(CPUHP_AP_RISCV_TIMER_STARTING, + "clockevents/riscv/timer:starting", + timer_riscv_starting_cpu, timer_riscv_dying_cpu); + if (err) + pr_err("RISCV timer register failed [%d] for cpu = [%d]\n", + err, cpu_id); } - - return 0; + return err; } TIMER_OF_DECLARE(riscv_timer, "riscv", timer_riscv_init_dt); diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index 1a32e55..c68f924 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -126,6 +126,7 @@ enum cpuhp_state { CPUHP_AP_MARCO_TIMER_STARTING, CPUHP_AP_MIPS_GIC_TIMER_STARTING, CPUHP_AP_ARC_TIMER_STARTING, + CPUHP_AP_RISCV_TIMER_STARTING, CPUHP_AP_KVM_STARTING, CPUHP_AP_KVM_ARM_VGIC_INIT_STARTING, CPUHP_AP_KVM_ARM_VGIC_STARTING, -- 2.7.4