Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4603954imb; Wed, 6 Mar 2019 18:13:37 -0800 (PST) X-Google-Smtp-Source: APXvYqyk9n9MgaXYeFfFA22SO933O/d+i2l8vQ95ux4ZD+NVUWmEn8QROwgl+3S++QTiAczqywM5 X-Received: by 2002:a17:902:32b:: with SMTP id 40mr9920345pld.122.1551924817235; Wed, 06 Mar 2019 18:13:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551924817; cv=none; d=google.com; s=arc-20160816; b=bz+MZvASoww5dnJ6KFuaJwiZSR82hZm2OZ2rGeIFqT8+39YmsuuLCc3WWvdBkwzJoN gv4x2mIDn+RDBHjvISdnj+KhTX/t1rkLaRQGZ8n2L0SheSTGxhf2Po6Lg60BwjMiHnhk gAJneiBZ/zDeYcnYwzrNZgQMBauiimck1Yo2uK+7n7+wVd5LGezmsNM3jMURliAAhpX1 W8YzXbcVuJC0z8MMAgwJD1p/cPJlG4QFLELZaZYFiCnVfuskKoPJ+aqk4zFXlhVFvzDc AHJemqY8KG5vMqitbSWurRWrgtnlB6m/aTXmQ0Qsdp/+UswyDqd9jtP8cmfscbvKFnVy djDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lMptHAcBEYC7MEKdBI7yXvacPzttGiXkC9lEO09Rpg0=; b=Q6ZcjYjRjcKOrUJtpqrCgB8z8+lUzJjORqmwuEEVlbEEE9v/2ZkvCNEk2WsxglTrXF C46t6rmLfQ5BWUbdqVHSj9poGUUDhxjxx2UroBwHn5ASB1FJOgUm1k+aCPHQRmVupDk/ BHBNPzP3u/k2cDpHuCgQ5+RDsO/LdfpplpxnH8SW4smPTL/VH14k+SLToXrG6QkEX7zu sdCy/2T7+Nvkjk9cChYs8HxfGIKK9l8APtUhzLP2YL8vIhP1xGw0NSDNvTapVtfOX8xU ro6I23oI7FyjdfM1tVrD8SKNjSVrmHHwUxuC882LhEUuto7048//4HnAmKldK8B1EJIt jGew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="e+/oJeqZ"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m63si3008918pfj.107.2019.03.06.18.13.21; Wed, 06 Mar 2019 18:13:37 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="e+/oJeqZ"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726747AbfCGCM1 (ORCPT + 99 others); Wed, 6 Mar 2019 21:12:27 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:34649 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726121AbfCGCM0 (ORCPT ); Wed, 6 Mar 2019 21:12:26 -0500 Received: by mail-pg1-f196.google.com with SMTP id i130so9966532pgd.1; Wed, 06 Mar 2019 18:12:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=lMptHAcBEYC7MEKdBI7yXvacPzttGiXkC9lEO09Rpg0=; b=e+/oJeqZrjaFVeqghbgseyLoD0wRM9R/eHJQP86ZgIXTTHFvqJnVhI4hKwt/uRkAao 22r4VR8vSwHe1K+SC6sMoM+f6RxJiA2bSeLHRtyiTkiuzlYmyeZ/4AGsDM8CWnNT6aUY G+YsOrKGLgkQ2qU4CewiAML7usp75K5SarFDE7GtPuUq3OwAgwdVcyFUKcFOz9vlf61P zeFgjQxn/+8UBCzgMeNQcDPFRDjhkRssRjaxSxVqrYqQ92BE94XoCT25NJM5EB4PGfvD 21Ia9oX3VPGy9Z/xC/tcLpE2IAaFB42Tox7it7mxyfYlNu0XeuTsRjx4pp3amhFlDtWd VTeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=lMptHAcBEYC7MEKdBI7yXvacPzttGiXkC9lEO09Rpg0=; b=chIZ1aKdOo8ru5L6OKkXP0zHh/w73/4UwhrSHRLJvOd5plwsH9wW4HOym3XtztguwS xLEQYEth8YuetWkGJ+QqxFGlq4cnYZhv1T6Dn7Ml4eCL77l7oSmDjFfUOvKDDl9AuPID 9CFdFc2meVkyaCdy4Lb6lSW5i5Wxg6iRHM1naAMZqCQYsGDVmgfz2k/o3qvJpMiqWA29 itqG192nuh4sdaqMNa3uANWL++S8UTO8kqIuOLKE/JDtoSFmJw+loHFjb65w9aLh+vOT 94FIhU9u6lKudFIcPQWr4hB8qJGXjGz0fzjx3yxRpM9v6D6B3pk8vH9LsdXgAb0FoQZ2 QqiA== X-Gm-Message-State: APjAAAXY61tejmjhV68a0jCqTFCjYMqxXKvEiF4x9B/KW7xy5ZPc6e02 Q/bLQe3KwnkHYZjWyph44jc= X-Received: by 2002:a17:902:8346:: with SMTP id z6mr10466671pln.74.1551924746166; Wed, 06 Mar 2019 18:12:26 -0800 (PST) Received: from localhost ([175.223.39.30]) by smtp.gmail.com with ESMTPSA id n15sm9374635pfi.173.2019.03.06.18.12.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Mar 2019 18:12:24 -0800 (PST) Date: Thu, 7 Mar 2019 11:12:21 +0900 From: Sergey Senozhatsky To: John Ogness Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Daniel Wang , Andrew Morton , Linus Torvalds , Greg Kroah-Hartman , Alan Cox , Jiri Slaby , Peter Feiner , linux-serial@vger.kernel.org, Sergey Senozhatsky Subject: Re: [RFC PATCH v1 02/25] printk-rb: add prb locking functions Message-ID: <20190307021221.GA9676@jagdpanzerIV> References: <20190212143003.48446-1-john.ogness@linutronix.de> <20190212143003.48446-3-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190212143003.48446-3-john.ogness@linutronix.de> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (02/12/19 15:29), John Ogness wrote: > +static bool __prb_trylock(struct prb_cpulock *cpu_lock, > + unsigned int *cpu_store) > +{ > + unsigned long *flags; > + unsigned int cpu; > + > + cpu = get_cpu(); > + > + *cpu_store = atomic_read(&cpu_lock->owner); > + /* memory barrier to ensure the current lock owner is visible */ > + smp_rmb(); > + if (*cpu_store == -1) { > + flags = per_cpu_ptr(cpu_lock->irqflags, cpu); > + local_irq_save(*flags); > + if (atomic_try_cmpxchg_acquire(&cpu_lock->owner, > + cpu_store, cpu)) { > + return true; > + } > + local_irq_restore(*flags); > + } else if (*cpu_store == cpu) { > + return true; > + } > + > + put_cpu(); > + return false; > +} > + > +/* > + * prb_lock: Perform a processor-reentrant spin lock. > + * @cpu_lock: A pointer to the lock object. > + * @cpu_store: A "flags" pointer to store lock status information. > + * > + * If no processor has the lock, the calling processor takes the lock and > + * becomes the owner. If the calling processor is already the owner of the > + * lock, this function succeeds immediately. If lock is locked by another > + * processor, this function spins until the calling processor becomes the > + * owner. > + * > + * It is safe to call this function from any context and state. > + */ > +void prb_lock(struct prb_cpulock *cpu_lock, unsigned int *cpu_store) > +{ > + for (;;) { > + if (__prb_trylock(cpu_lock, cpu_store)) > + break; > + cpu_relax(); > + } > +} Any chance to make it more fair? A ticket based lock, perhaps? -ss