Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp1243964pxa; Fri, 28 Aug 2020 07:37:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiB/UF8TpuzargtU39U1V5dERjmNAYR0/83N5Oh2O99iKmiGtesMetgvNKArzdiROLIiSQ X-Received: by 2002:a50:f747:: with SMTP id j7mr2196843edn.270.1598625469325; Fri, 28 Aug 2020 07:37:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598625469; cv=none; d=google.com; s=arc-20160816; b=GSolhP7wgUH4fZd7W4gTtjaysT42Vw/qhFA0k/QwhrjMlca45i8kI/p23PlKnCN6mL xqxcMw1cQOTahE9AonvoXA4RBBNd2HkTzvhhCZGhv7AMwEugT2t+tadUumfIQvohUyqz aySpwPyQFtnbMSt5/oXKvCmozbLdlwiNIr71BzA7O1SesOV6mkfbmFEz0WFSj0LUgRe9 xHX1/5FM2zGk9WLhNMunZCilMH96vLgXo1jn8J2+Mv0jWLCGhFx7MEPGyM5mHZD0rdAW u5aa1T7ZkNuo/FyWsjmGWyIm2ZW/Rhk9AKjEzTRPmOesPbxTqvn5SnoIAovWC2/PWuqF 5BYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from :dkim-signature:dkim-signature:date; bh=BSovyqDfmPCPEib/KWIWlJ0IAJg/5IQArvXAUs+2PUY=; b=fO7eaPzTxPS3eHPIsvr7bNfC2bPtcuBXw5oCx+qaSBZDPUM8fKy9Zmf+/wfKAJ948M 20Bi/qmbTp8WqFh1TwKAY5k7pdefGw86rNfEav7btGCklMXP1oxn/PFFiMylqyPJr+cu A+YCjTxpYqilDRpsSM8iTYVePeG7wTbytfTMggxf3hu+GwSTWemWsaPJoyoNtud+n+eN 0++82OHEzsgP6/GuKvv9qQEQ7uQSYnJchpxUcCN3SiqTGfbLnGEBMN5bp8z4AoG83DPJ S9/XO1mY5FlYiFb/da7sMSyT+MMk+LpVfTLn2B/vRxHHZokABB9TuwWtNkxZ8JdWKaEw JHyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pt0kC2B6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bQnestss; 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 m7si723107edq.500.2020.08.28.07.37.26; Fri, 28 Aug 2020 07:37:49 -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=pt0kC2B6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bQnestss; 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 S1727918AbgH1Ogc (ORCPT + 99 others); Fri, 28 Aug 2020 10:36:32 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:45624 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgH1OgM (ORCPT ); Fri, 28 Aug 2020 10:36:12 -0400 Date: Fri, 28 Aug 2020 16:36:23 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1598625364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BSovyqDfmPCPEib/KWIWlJ0IAJg/5IQArvXAUs+2PUY=; b=pt0kC2B6nyFbu8RDsQ6n4PquGn0T4ZoO8QQ61dO/ffkQgkCmGmsJB5rY9xbvkPln/ptxoY I5Dk+CqLkNa9NILFD4sBF9QNUopSeQOBIJdZDNJN+I0mGYb5G5J8eZP9LYwH2h9J7KqGZS thEuF+WeE5GJ56taBRgalvT7+/tl+WfBY1BsBg771+HfT2ajIAKEF+y/0ip5uTpaTXhlI/ TAUI1qpr5UXadHhFeUWWuwkCYb9A2ZZkAqJFr0zQgLhSRR+qX0pe/8/2HmaosK7nar4ciu KydrdM0vQW8+NPOg8MNye8pwEqhmXoxphv37SNnbwhDZKWPzIHyVLOHOPBQB/A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1598625364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BSovyqDfmPCPEib/KWIWlJ0IAJg/5IQArvXAUs+2PUY=; b=bQnestssn8lajILGdoZtMd7gyV1QUAV8D5cb3JQ1Pslw1lKGjk/FwixMQvoW4ahN7Hr8O0 XhjxlQP7eyWvNPAA== From: "Ahmed S. Darwish" To: peterz@infradead.org Cc: Ingo Molnar , Will Deacon , Thomas Gleixner , "Sebastian A. Siewior" , "Paul E. McKenney" , Steven Rostedt , LKML Subject: Re: [PATCH v1 4/5] seqlock: seqcount_LOCKTYPE_t: Introduce PREEMPT_RT support Message-ID: <20200828143623.GA10273@lx-t490> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200828010710.5407-1-a.darwish@linutronix.de> <20200828010710.5407-5-a.darwish@linutronix.de> <20200828085938.GS1362448@hirez.programming.kicks-ass.net> <20200828093130.GA7672@lx-t490> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200828093130.GA7672@lx-t490> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 28, 2020 at 11:31:32AM +0200, Ahmed S. Darwish wrote: > On Fri, Aug 28, 2020 at 10:59:38AM +0200, peterz@infradead.org wrote: > > On Fri, Aug 28, 2020 at 03:07:09AM +0200, Ahmed S. Darwish wrote: > > > +#define __SEQ_RT IS_ENABLED(CONFIG_PREEMPT_RT) > > > + > > > +SEQCOUNT_LOCKTYPE(raw_spinlock, raw_spinlock_t, false, s->lock, raw_spin, raw_spin_lock(s->lock)) > > > +SEQCOUNT_LOCKTYPE(spinlock, spinlock_t, __SEQ_RT, s->lock, spin, spin_lock(s->lock)) > > > +SEQCOUNT_LOCKTYPE(rwlock, rwlock_t, __SEQ_RT, s->lock, read, read_lock(s->lock)) > > > +SEQCOUNT_LOCKTYPE(mutex, struct mutex, true, s->lock, mutex, mutex_lock(s->lock)) > > > +SEQCOUNT_LOCKTYPE(ww_mutex, struct ww_mutex, true, &s->lock->base, ww_mutex, ww_mutex_lock(s->lock, NULL)) > > > > Ooh, reading is hard, but ^^^^ you already have that. > > > > Haha, I was just answering the other mail :) > > > > +/* > > > + * Automatically disable preemption for seqcount_LOCKTYPE_t writers, if the > > > + * associated lock does not implicitly disable preemption. > > > + * > > > + * Don't do it for PREEMPT_RT. Check __SEQ_LOCK(). > > > + */ > > > +#define __seq_enforce_preemption_protection(s) \ > > > + (!IS_ENABLED(CONFIG_PREEMPT_RT) && __seqcount_lock_preemptible(s)) > > > > Then what is this doing ?!? I'm confused now. > > There were a number of call sites (at DRM mainly) that protected their > seqcount_t write sections with mutex and ww_mutex. So, they manually > disabled preemption before entering the seqcount_t write sections. > > Unfortunately these write sections were big, and spinlocks were also > acquired inside them. This was all very bad for RT... > > So the idea was to relieve call sites from the responsibility of > disabling/enabling preemption upon entering a seqcount_LOCKNAME_t write > section, and let seqlock.h automatically handle it if LOCKNAME_t is > preemptible (the macro's condition, second part). > > Having seqlock.h control the preempt disable/enable allows us to never > disable preemption for RT, which is exactly what is needed since we > already handle any possible livelock through the mechanisms described at > __SEQ_LOCK (the macro's condition test, first part). > So to summarize, __seqcount_lock_preemptible() has two use cases: 1. For !PREEMPT_RT, to automatically disable preemption on the write side when the seqcount associated lock is preemptible. 2. For PREEMPT_RT, to lock/unlock the seqcount associated lock on the read side if it is RT-preemptible (sleeping lock). Thanks, -- Ahmed S. Darwish Linutronix GmbH