From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD3BFC10F0E for ; Mon, 15 Apr 2019 20:16:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9CF332070D for ; Mon, 15 Apr 2019 20:16:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729048AbfDOUQE (ORCPT ); Mon, 15 Apr 2019 16:16:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41004 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728193AbfDOUQD (ORCPT ); Mon, 15 Apr 2019 16:16:03 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45FB889C3E; Mon, 15 Apr 2019 20:16:03 +0000 (UTC) Received: from amt.cnet (ovpn-112-12.gru2.redhat.com [10.97.112.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id A553C60139; Mon, 15 Apr 2019 20:15:58 +0000 (UTC) Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id E48B910518E; Mon, 15 Apr 2019 17:15:38 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.7/8.14.7/Submit) id x3FKFcPQ013912; Mon, 15 Apr 2019 17:15:38 -0300 Message-Id: <20190415201429.427759476@amt.cnet> User-Agent: quilt/0.60-1 Date: Mon, 15 Apr 2019 17:12:15 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org Cc: Thomas Gleixner , Anna-Maria Gleixner , Daniel Bristot de Oliveira , Luiz Capitulino , Haris Okanovic , Marcelo Tosatti Subject: [patch 2/3] timers: do not raise softirq unconditionally (spinlockless version) References: <20190415201213.600254019@amt.cnet> Content-Disposition: inline; filename=02-do-not-raise-softirq-unconditionally-second-attempt X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 15 Apr 2019 20:16:03 +0000 (UTC) Sender: linux-rt-users-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Check base->pending_map locklessly and skip raising timer softirq if empty. What allows the lockless (and potentially racy against mod_timer) check is that mod_timer will raise another timer softirq after modifying base->pending_map. Signed-off-by: Marcelo Tosatti --- kernel/time/timer.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) Index: linux-rt-devel/kernel/time/timer.c =================================================================== --- linux-rt-devel.orig/kernel/time/timer.c 2019-04-15 14:21:02.788704354 -0300 +++ linux-rt-devel/kernel/time/timer.c 2019-04-15 14:22:56.755047354 -0300 @@ -1776,6 +1776,24 @@ if (time_before(jiffies, base->clk)) return; } + +#ifdef CONFIG_PREEMPT_RT_FULL +/* On RT, irq work runs from softirq */ + if (irq_work_needs_cpu()) + goto raise; +#endif + base = this_cpu_ptr(&timer_bases[BASE_STD]); + if (!housekeeping_cpu(base->cpu, HK_FLAG_TIMER)) { + if (!bitmap_empty(base->pending_map, WHEEL_SIZE)) + goto raise; + base++; + if (!bitmap_empty(base->pending_map, WHEEL_SIZE)) + goto raise; + + return; + } + +raise: raise_softirq(TIMER_SOFTIRQ); }