From owner-svn-src-all@freebsd.org Wed Jun 6 15:06:44 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D81AAFD0004; Wed, 6 Jun 2018 15:06:43 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-qt0-x244.google.com (mail-qt0-x244.google.com [IPv6:2607:f8b0:400d:c0d::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 82656784CD; Wed, 6 Jun 2018 15:06:43 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-qt0-x244.google.com with SMTP id i18-v6so6663592qtp.12; Wed, 06 Jun 2018 08:06:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=diGLwL8ukBvgfLf6E/dXBNTNiQe1zne2hnIQ0AgVqrQ=; b=rMnSx9En5xIYuEeam3OMEHSILpanDG6e8OT+vA09HUdGoJsz7UeQWX6jmwOPgITMcP y5yiMH2jyQdd+EbQdUgKszC6jkgiElqrJv1hIoYhProxWnGAM78iSqU2OYfKbNWV81aw FuUkZ1Pu6rngVsW5CaA/t4C9TIBcxVmEh1JfFU6rWH0mV6fZMz63odvWWfi+vFsAS0N+ r193W189LP1TTi4Rvf3qXhA+U45Ds5xvyRh6svFgxttkHigwMtqwgdiIkcnzpzNju2DC WfkwST8AZ5+rtpcoApA5dzF8ILNtVgKMhTNZ3yPQwuBJUcczsZoeKhvFlOxJhyognrWt OibA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=diGLwL8ukBvgfLf6E/dXBNTNiQe1zne2hnIQ0AgVqrQ=; b=qUMsSMJwCJTXgrbDVRmpQbml5VYXEIM5mh2lRcPe0u19SE7+BL/fpX6lIZqlW3NNzL YTaBZ2HOienfFE1KsW5FLgMNZFjrNGTwFsP4yV52o8qy+yroDmxu0KcsHUzGlpW8ME16 mmv7iEDATlLP9ut3aq/9HSsCPDKaNjF0/hgqqdegiGU1ao7LVKtrDAmlR3qQ6Ckfr8NE INASPGMCsFcQvxBYv0eRnhLtpb0hIsWPvDB/5oKW8axl+hDiZptqlJDHVVfrdLyKmF+X NJIKkHc3pzoNRchsihNxacAr0tVJ7ouWDKRTkS1BKs3w8LjAcuPTpMeDPplVSsvhu6rV Rxnw== X-Gm-Message-State: APt69E10hK1fUS7h51rKqymgphKm3QdbJN2V3LeeMrkYtBsDwHUcBued rLmVYIIUBovJTQifCsEwoA189PISIZCTD5bJhzFN8g== X-Google-Smtp-Source: ADUXVKLHZJ3afBz2JSiwMbF8CFcGcy5uMfqHYjAeAIoDaudZZ0VFRIEng9TeXaUsEcgKLCila0nciCGBHx91teBAX4o= X-Received: by 2002:ac8:34aa:: with SMTP id w39-v6mr2998336qtb.237.1528297602857; Wed, 06 Jun 2018 08:06:42 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ac8:1c4e:0:0:0:0:0 with HTTP; Wed, 6 Jun 2018 08:06:42 -0700 (PDT) In-Reply-To: <201806061359.w56DxpSZ020224@repo.freebsd.org> References: <201806061359.w56DxpSZ020224@repo.freebsd.org> From: Mateusz Guzik Date: Wed, 6 Jun 2018 17:06:42 +0200 Message-ID: Subject: Re: svn commit: r334712 - head/sys/compat/linuxkpi/common/include/asm To: Hans Petter Selasky Cc: src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.26 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jun 2018 15:06:44 -0000 On Wed, Jun 6, 2018 at 3:59 PM, Hans Petter Selasky wrote: > Author: hselasky > Date: Wed Jun 6 13:59:51 2018 > New Revision: 334712 > URL: https://svnweb.freebsd.org/changeset/base/334712 > > Log: > Implement the atomic_dec_if_positive() function in the LinuxKPI. > > Submitted by: Johannes Lundberg > MFC after: 1 week > Sponsored by: Mellanox Technologies > Sponsored by: Limelight Networks > > Modified: > head/sys/compat/linuxkpi/common/include/asm/atomic.h > > Modified: head/sys/compat/linuxkpi/common/include/asm/atomic.h > ============================================================ > ================== > --- head/sys/compat/linuxkpi/common/include/asm/atomic.h Wed Jun > 6 13:37:31 2018 (r334711) > +++ head/sys/compat/linuxkpi/common/include/asm/atomic.h Wed Jun > 6 13:59:51 2018 (r334712) > @@ -235,6 +235,22 @@ atomic_cmpxchg(atomic_t *v, int old, int new) > __ret.val; \ > }) > > +static inline int > +atomic_dec_if_positive(atomic_t *v) > +{ > + int retval; > + int curr; > + > + do { > + curr = atomic_read(v); > + retval = curr - 1; > + if (unlikely(retval < 0)) > + break; > + } while (!likely(atomic_cmpset_int(&v->counter, curr, retval))); > + > + return (retval); > +} > + > cmpset loops are crap since they require an explicit re-read of the target value see fcmpset and refcount_acquire_if_not_zero for an example use -- Mateusz Guzik