From: David Ahern <dsahern@gmail.com>
To: Ido Schimmel <idosch@idosch.org>, netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, amcohen@nvidia.com,
roopa@nvidia.com, sharpd@nvidia.com, bpoirier@nvidia.com,
mlxsw@nvidia.com, Ido Schimmel <idosch@nvidia.com>
Subject: Re: [PATCH net-next 01/10] netdevsim: fib: Convert the current occupancy to an atomic variable
Date: Tue, 26 Jan 2021 21:33:27 -0700 [thread overview]
Message-ID: <b307a304-09ef-d8e8-7296-92ddddfc348c@gmail.com> (raw)
In-Reply-To: <20210126132311.3061388-2-idosch@idosch.org>
On 1/26/21 6:23 AM, Ido Schimmel wrote:
> @@ -889,22 +882,29 @@ static void nsim_nexthop_destroy(struct nsim_nexthop *nexthop)
> static int nsim_nexthop_account(struct nsim_fib_data *data, u64 occ,
> bool add, struct netlink_ext_ack *extack)
> {
> - int err = 0;
> + int i, err = 0;
>
> if (add) {
> - if (data->nexthops.num + occ <= data->nexthops.max) {
> - data->nexthops.num += occ;
> - } else {
> - err = -ENOSPC;
> - NL_SET_ERR_MSG_MOD(extack, "Exceeded number of supported nexthops");
> - }
> + for (i = 0; i < occ; i++)
> + if (!atomic64_add_unless(&data->nexthops.num, 1,
> + data->nexthops.max)) {
seems like this can be
if (!atomic64_add_unless(&data->nexthops.num, occ,
data->nexthops.max)) {
and then the err_num_decrease is not needed
> + err = -ENOSPC;
> + NL_SET_ERR_MSG_MOD(extack, "Exceeded number of supported nexthops");
> + goto err_num_decrease;
> + }
> } else {
> - if (WARN_ON(occ > data->nexthops.num))
> + if (WARN_ON(occ > atomic64_read(&data->nexthops.num)))
> return -EINVAL;
> - data->nexthops.num -= occ;
> + atomic64_sub(occ, &data->nexthops.num);
> }
>
> return err;
> +
> +err_num_decrease:
> + for (i--; i >= 0; i--)
> + atomic64_dec(&data->nexthops.num);
and if this path is really needed, why not atomic64_sub here?
> + return err;
> +
> }
>
> static int nsim_nexthop_add(struct nsim_fib_data *data,
>
next prev parent reply other threads:[~2021-01-27 5:18 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-26 13:23 [PATCH net-next 00/10] Add notifications when route hardware flags change Ido Schimmel
2021-01-26 13:23 ` [PATCH net-next 01/10] netdevsim: fib: Convert the current occupancy to an atomic variable Ido Schimmel
2021-01-27 4:33 ` David Ahern [this message]
2021-01-27 10:51 ` Amit Cohen
2021-01-28 3:42 ` David Ahern
2021-01-26 13:23 ` [PATCH net-next 02/10] netdevsim: fib: Perform the route programming in a non-atomic context Ido Schimmel
2021-01-27 4:36 ` David Ahern
2021-01-26 13:23 ` [PATCH net-next 03/10] net: ipv4: Pass fib_rt_info as const to fib_dump_info() Ido Schimmel
2021-01-27 4:38 ` David Ahern
2021-01-26 13:23 ` [PATCH net-next 04/10] net: ipv4: Publish fib_nlmsg_size() Ido Schimmel
2021-01-27 4:41 ` David Ahern
2021-01-26 13:23 ` [PATCH net-next 05/10] net: ipv4: Emit notification when fib hardware flags are changed Ido Schimmel
2021-01-27 5:02 ` David Ahern
2021-01-27 11:46 ` Amit Cohen
2021-01-28 3:34 ` David Ahern
2021-01-29 3:04 ` Jakub Kicinski
2021-01-29 3:33 ` David Ahern
2021-01-29 4:15 ` Jakub Kicinski
2021-01-30 15:36 ` Ido Schimmel
2021-01-30 15:11 ` Ido Schimmel
2021-01-26 13:23 ` [PATCH net-next 06/10] net: Pass 'net' struct as first argument to fib6_info_hw_flags_set() Ido Schimmel
2021-01-27 5:08 ` David Ahern
2021-01-26 13:23 ` [PATCH net-next 07/10] net: Do not call fib6_info_hw_flags_set() when IPv6 is disabled Ido Schimmel
2021-01-26 13:23 ` [PATCH net-next 08/10] net: ipv6: Emit notification when fib hardware flags are changed Ido Schimmel
2021-01-27 5:14 ` David Ahern
2021-01-28 3:36 ` David Ahern
2021-01-26 13:23 ` [PATCH net-next 09/10] selftests: Extend fib tests to run with and without flags notifications Ido Schimmel
2021-01-26 13:23 ` [PATCH net-next 10/10] selftests: netdevsim: Add fib_notifications test Ido Schimmel
2021-01-28 3:41 ` David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b307a304-09ef-d8e8-7296-92ddddfc348c@gmail.com \
--to=dsahern@gmail.com \
--cc=amcohen@nvidia.com \
--cc=bpoirier@nvidia.com \
--cc=davem@davemloft.net \
--cc=idosch@idosch.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=mlxsw@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=roopa@nvidia.com \
--cc=sharpd@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).