Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3315047ybt; Mon, 29 Jun 2020 22:48:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwz+qXgexu88fSQb65V2iFxuu3/+CACkEA1y0fLJcfXyKVNPyj26/NW+QMt/ZCz4SSIbLvl X-Received: by 2002:a17:906:455:: with SMTP id e21mr17554105eja.550.1593496084149; Mon, 29 Jun 2020 22:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593496084; cv=none; d=google.com; s=arc-20160816; b=nRlSsQ/eypw+6XZ+uJIeag3QiJxtgqgXdtCeiWPjnHRq8EXf7Jdyr+ig8uScUtQCyD c4sENLLCf/Ky4YWgDo/1R5i2mwxh6VROEBbr3D16RBgmd38eLLNN/Oexu7d0VmI1mo+9 6anFe8ZUhj3er78l2VkxGq0qJ1RaSWjKNXS06AoBQo4IUz4x2no+Vp4RgwNXHyLkg8Ye xHiWlonh7hSH+6ZUe5ywr+07TFdXhigQXgGQAXUw2Mh/QYvYTD2MBimfjuBxHuroOxju 0reI7A/FuiVp0d6QKTpEuCXGF+QndYH/8ljcY9ngzdeMBbekSKUOm3rP/dOxno73loY1 +/NA== 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:dkim-signature :dkim-signature:from; bh=UmigHx4BW8UOIynqAPFCArO8Ak7spa6ugzxCvPtvbYY=; b=e8ZAcGpb59iHGkMH7lbgT0447znpfSrxJBzskDCFMPb8y//4OjJEHVdxNfi7mefIVr 7NX+CkLSZoyJvT4Zh41zJ7ebgGRp+zEHaDv3ntqcRSCt1DRI0rJqRcklJSKxMuISs1az 46WCGfW3NbdKA5PbXo8X3lEDXa57oweDhXXZiFJ0NCqUsAOmvwzDywa8b4/ULz3cJUag 2UfPEYAW6r1f+UlmKn0+dSG5bPkstVAx193CocFV1RkDaWo9rkJkYcmjoOYHifwbDdGf NHKdVNc9yUBiU1smh9tHXTKCa3I354DsJYURG+P5BjKSerWQHTC5jk7/CR66mGfXkBaU O2qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xxvCKva9; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u17si1176714edd.139.2020.06.29.22.47.41; Mon, 29 Jun 2020 22:48:04 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xxvCKva9; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730072AbgF3Fqg (ORCPT + 99 others); Tue, 30 Jun 2020 01:46:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729836AbgF3Fqf (ORCPT ); Tue, 30 Jun 2020 01:46:35 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1348DC061755 for ; Mon, 29 Jun 2020 22:46:35 -0700 (PDT) From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1593495993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UmigHx4BW8UOIynqAPFCArO8Ak7spa6ugzxCvPtvbYY=; b=xxvCKva9RnnBYSKhEn/oFk6GeNyTICD8JlRgqOP9lmH0a3AVC/I061UBqPV6ijq/2TyTQg 5hwnT3OFraM5ZDBhXCak3k5UQv9G7z1xUzrpLmqVx94xL8nCcpFNzvXettOcKy/BZI96pz bPw1VgUB5MdJpEBG7KEsM2dvDat2CE2wkiSmQ0mCih0mEsMQ7FJJxqmvrGfQ+aaHoyzNWP F4woHpUniQT/YG1LuY9E9XpKM4vhUiKq7zrqadY9u/lQo1vVvK8vzwOPBmGjJN2nK5dE+t yqWcqiNltd8GDcukDboajYzofWHgCk/H2TlRATT90kzxLRS1XLT0tJ0ePgTriw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1593495993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UmigHx4BW8UOIynqAPFCArO8Ak7spa6ugzxCvPtvbYY=; b=Dr+zoPA+8MQv7+LzU7NqEM6ykc3bBaGhRPqfTb57yMiC9ZgBc8aN+k7DvAMaAeNN55QU+g q6pEtb/sma+PW0Cw== To: Peter Zijlstra , Ingo Molnar , Will Deacon Cc: Thomas Gleixner , "Paul E. McKenney" , "Sebastian A. Siewior" , Steven Rostedt , LKML , "Ahmed S. Darwish" Subject: [PATCH v3 20/20] hrtimer: Use sequence counter with associated raw spinlock Date: Tue, 30 Jun 2020 07:44:52 +0200 Message-Id: <20200630054452.3675847-21-a.darwish@linutronix.de> In-Reply-To: <20200630054452.3675847-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200630054452.3675847-1-a.darwish@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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