Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2704996ybh; Mon, 9 Mar 2020 11:16:42 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvsCbrCENC3pmX3nBdOXas6v4kQS0cEy6ssTSDhEE7oaf0nXHS7/BSONKvgiPMEVo+TBSWH X-Received: by 2002:aca:918:: with SMTP id 24mr393537oij.35.1583777802493; Mon, 09 Mar 2020 11:16:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583777802; cv=none; d=google.com; s=arc-20160816; b=pGschTDPOvoyd1CKgIruIzsAGl/JQH+DFRfP06n9AYQRvQ2D0leIWvxS3fVcNqNIJi gdxMaJGnjkHZD24W7UqCwZkd0sjhgqxlcMlCvhDdDkKPvh46JZWbc8L3hyUS+ad/rdiF h72TckfQtPnu24ofeixl/xXPlEdCVR5nSDT0F/TZBYPd2LUo7me6mUTaKbF4DOGrM5Ez u1rsdebKn9t88su5PIbaQCfjlGCnWPgtUWAiYpr4tmW5XViahhJUcNCDXaIAzB/yTooY eEcQjYu1gzoH1skiea6KW0fBq4tz8jV0+JYVJwDC8pAIxqFUywP5Gba7wN7i3X5Bxs5B krUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=S2FdCZw03EUAgF6n53gBBZ/xH5AWu1k0upmv8Q8ms5s=; b=UAclcnPrXmeqv5zBqiWPWAhbp0YI3q950rduRAJIQCX8lu8kInn6BdjcVHj2V+go1l dtPLXW31fIkQCWhnmkEt1Q4YArbNItUbXSO0673UF+w4HNICcecPLAJp5fIJ6h5uxt06 fr6kERJutcSl9W6VyyNPLvVQr3eWemglvK/cFXov82iOvsMDK7cRSS2ix0M+cITDyREZ xA3ZDXgaxrUnXlmg5ajbJwSgYQoqEKiJFWr9MrfaQZx6ZkAg1FUTmfYxJUAV8Zpqofqk N8kkh8GZ/n4xj2jstIKD1Z0ZLGvozBp3DYGz+q30qpvEbUOFjmpBXLhnC1Ht+wkeu0NB C+Bw== ARC-Authentication-Results: i=1; mx.google.com; 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 l25si4426626oie.234.2020.03.09.11.16.30; Mon, 09 Mar 2020 11:16:42 -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; 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 S1727409AbgCISPd (ORCPT + 99 others); Mon, 9 Mar 2020 14:15:33 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:59880 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726467AbgCISPd (ORCPT ); Mon, 9 Mar 2020 14:15:33 -0400 Received: from [5.158.153.53] (helo=debian-buster-darwi.lab.linutronix.de.) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1jBMw6-0004Yd-M5; Mon, 09 Mar 2020 19:15:30 +0100 From: "Ahmed S. Darwish" To: Thomas Gleixner Cc: Sebastian Andrzej Siewior , "Ahmed S . Darwish" , LKML Subject: [PATCH] sched/clock: expire timer in hardirq context Date: Mon, 9 Mar 2020 18:15:29 +0000 Message-Id: <20200309181529.26558-1-a.darwish@linutronix.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To minimize latency, PREEMPT_RT kernels expires hrtimes in preemptible softirq context by default. This can be overriden by marking the timer's expiry with HRTIMER_MODE_HARD. sched_clock_timer is missing this annotation: if its callback is preempted and the duration of the preemption exceeds the wrap around time of the underlying clocksource, sched clock will get out of sync. Mark the sched_clock_timer for expiry in hard interrupt context. Signed-off-by: Ahmed S. Darwish --- kernel/time/sched_clock.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index e4332e3e2d56..fa3f800d7d76 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c @@ -208,7 +208,8 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate) if (sched_clock_timer.function != NULL) { /* update timeout for clock wrap */ - hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL); + hrtimer_start(&sched_clock_timer, cd.wrap_kt, + HRTIMER_MODE_REL_HARD); } r = rate; @@ -254,9 +255,9 @@ void __init generic_sched_clock_init(void) * Start the timer to keep sched_clock() properly updated and * sets the initial epoch. */ - hrtimer_init(&sched_clock_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + hrtimer_init(&sched_clock_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD); sched_clock_timer.function = sched_clock_poll; - hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL); + hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL_HARD); } /* @@ -293,7 +294,7 @@ void sched_clock_resume(void) struct clock_read_data *rd = &cd.read_data[0]; rd->epoch_cyc = cd.actual_read_sched_clock(); - hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL); + hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL_HARD); rd->read_sched_clock = cd.actual_read_sched_clock; } -- 2.20.1