Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp3999863ybg; Sun, 7 Jun 2020 18:02:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbPET3etbM2D+1W0arhcm0BzLFaBHxzgwvcoExaGkX1Bd3qkZ3XQCLG5KMrypVuC+WDTj/ X-Received: by 2002:aa7:c6d1:: with SMTP id b17mr20890280eds.39.1591578132126; Sun, 07 Jun 2020 18:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591578132; cv=none; d=google.com; s=arc-20160816; b=EueTXTZEQSeARzLmCLRly8lCTyKBqiv2zwMOHyZecfG+2Il/W0z+U0Jzfg4lHIWZWZ urhcVoJdFtEyMiOqzdbUuJ4czw7GcbuFM7LzvkuXiWWO7ppdYID54ec6VKa4N1RDlEwZ qanqMXn6bH8J10fay5ro6EHUl0eyTXCoJtfCdS+VY1Qv8v3kjM6zCe/8G1S70l9Lq1HI r2t1Roxb9Ht/Fjb/w16zadm6s2P4yoJe8KImkptk6xcHWs3+2VDPjfUQbFq9E7wIY+hs vu7SB6KQMsEX4BXvFNKuR+bHuc88EoQtL7CvNiQSNiKkiHRi4VHLua/Qnt/rgtOujFQZ eJBQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UmigHx4BW8UOIynqAPFCArO8Ak7spa6ugzxCvPtvbYY=; b=IBNxWzVPXhv77JCCINfZqdZDXolAv1x4CxwpBn6A4mJfIxtGYwWFrVHjtj6+FY/HGJ ze33PcAWIAvq4Yt/HLt8oh54gkYzR5MIUEPRUBdQzyT8uvMD9sgb/rHP1MuEj7b2RfEu nIxDSzPl2ngTbJZQyCavHA/zUxJNXTU/oLVXjx64vnslEWsCbtArdBqTB2ewuHmqomIh AsZwF6O9Sez7wzKGEOouYwtsVONiWcFhNnLSfCPxvwKqkI6AI+4PoF9ZxbxFpKRDTAZd 59dW50pTWsxAeRTKk1Dfk6geWPjHSHNfREam74hVhGJhf69mR0rtKK94d0156vEZsvyF H5ZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s23si8468852edx.34.2020.06.07.18.01.49; Sun, 07 Jun 2020 18:02:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729094AbgFHA7L (ORCPT + 99 others); Sun, 7 Jun 2020 20:59:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729074AbgFHA7D (ORCPT ); Sun, 7 Jun 2020 20:59:03 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97276C08C5C3 for ; Sun, 7 Jun 2020 17:59:03 -0700 (PDT) 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 1ji67u-00011Q-Pp; Mon, 08 Jun 2020 02:58:58 +0200 From: "Ahmed S. Darwish" To: Peter Zijlstra , Ingo Molnar , Will Deacon Cc: Thomas Gleixner , "Paul E. McKenney" , "Sebastian A. Siewior" , Steven Rostedt , LKML , "Ahmed S. Darwish" Subject: [PATCH v2 18/18] hrtimer: Use sequence counter with associated raw spinlock Date: Mon, 8 Jun 2020 02:57:29 +0200 Message-Id: <20200608005729.1874024-19-a.darwish@linutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200608005729.1874024-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200608005729.1874024-1-a.darwish@linutronix.de> 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 A sequence counter write side critical section must be protected by some form of locking to serialize writers. A plain seqcount_t does not contain the information of which lock must be held when entering a write side critical section. Use the new seqcount_raw_spinlock_t data type, which allows to associate a raw spinlock with the sequence counter. This enables lockdep to verify that the raw spinlock used for writer serialization is held when the write side critical section is entered. If lockdep is disabled this lock association is compiled out and has neither storage size nor runtime overhead. Signed-off-by: Ahmed S. Darwish --- include/linux/hrtimer.h | 2 +- kernel/time/hrtimer.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index 15c8ac313678..25993b86ac5c 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -159,7 +159,7 @@ struct hrtimer_clock_base { struct hrtimer_cpu_base *cpu_base; unsigned int index; clockid_t clockid; - seqcount_t seq; + seqcount_raw_spinlock_t seq; struct hrtimer *running; struct timerqueue_head active; ktime_t (*get_time)(void); diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index d89da1c7e005..c4038511d5c9 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -135,7 +135,11 @@ static const int hrtimer_clock_to_base_table[MAX_CLOCKS] = { * timer->base->cpu_base */ static struct hrtimer_cpu_base migration_cpu_base = { - .clock_base = { { .cpu_base = &migration_cpu_base, }, }, + .clock_base = { { + .cpu_base = &migration_cpu_base, + .seq = SEQCNT_RAW_SPINLOCK_ZERO(migration_cpu_base.seq, + &migration_cpu_base.lock), + }, }, }; #define migration_base migration_cpu_base.clock_base[0] @@ -1998,8 +2002,11 @@ int hrtimers_prepare_cpu(unsigned int cpu) int i; for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { - cpu_base->clock_base[i].cpu_base = cpu_base; - timerqueue_init_head(&cpu_base->clock_base[i].active); + struct hrtimer_clock_base *clock_b = &cpu_base->clock_base[i]; + + clock_b->cpu_base = cpu_base; + seqcount_raw_spinlock_init(&clock_b->seq, &cpu_base->lock); + timerqueue_init_head(&clock_b->active); } cpu_base->cpu = cpu; -- 2.20.1