netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarod Wilson <jarod@redhat.com>
To: Jiri Pirko <jiri@resnulli.us>
Cc: netdev@vger.kernel.org, davem@davemloft.net, idosch@mellanox.com,
	eladr@mellanox.com, yotamg@mellanox.com, ogerlitz@mellanox.com,
	yishaih@mellanox.com, dledford@redhat.com, sean.hefty@intel.com,
	hal.rosenstock@gmail.com, eugenia@mellanox.com,
	roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com,
	hadarh@mellanox.com, jhs@mojatatu.com, john.fastabend@gmail.com,
	jeffrey.t.kirsher@intel.com, brouer@redhat.com,
	ivecera@redhat.com, rami.rosen@intel.com,
	hannes@stressinduktion.org, gospo@cumulusnetworks.com
Subject: Re: [patch net-next v2 1/9] Introduce devlink infrastructure
Date: Wed, 24 Feb 2016 11:12:07 -0500	[thread overview]
Message-ID: <20160224161206.GA38500@redhat.com> (raw)
In-Reply-To: <20160224071958.GB2151@nanopsycho.orion>

On Wed, Feb 24, 2016 at 08:19:58AM +0100, Jiri Pirko wrote:
> Tue, Feb 23, 2016 at 10:19:48PM CET, jarod@redhat.com wrote:
> >On Tue, Feb 23, 2016 at 04:51:26PM +0100, Jiri Pirko wrote:
> >> From: Jiri Pirko <jiri@mellanox.com>
> >> 
> >> Introduce devlink infrastructure for drivers to register and expose to
> >> userspace via generic Netlink interface.
> >> 
> >> There are two basic objects defined:
> >> devlink - one instance for every "parent device", for example switch ASIC
> >> devlink port - one instance for every physical port of the device.
> >> 
> >> This initial portion implements basic get/dump of objects to userspace.
> >> Also, port splitter and port type setting is implemented.
> >...
> >> +/**
> >> + *	devlink_alloc - Allocate new devlink instance resources
> >> + *
> >> + *	@ops: ops
> >> + *	@priv_size: size of user private data
> >> + *
> >> + *	Allocate new devlink instance resources, including devlink index
> >> + *	and name.
> >> + */
> >> +struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size)
> >> +{
> >> +	static atomic_t dev_counter = ATOMIC_INIT(0);
> >> +	struct devlink *devlink;
> >> +
> >> +	devlink = kzalloc(sizeof(*devlink) + priv_size, GFP_KERNEL);
> >> +	if (!devlink)
> >> +		return NULL;
> >> +	devlink->ops = ops;
> >> +	devlink_net_set(devlink, &init_net);
> >> +
> >> +different_name:
> >> +	devlink->index = atomic_inc_return(&dev_counter);
> >> +	if (devlink->index < 0) {
> >> +		/* wrapped */
> >> +		atomic_dec(&dev_counter);
> >> +		kfree(devlink);
> >> +		return NULL;
> >> +	}
> >> +	/* atomic_inc_return makes it start at 1, make it start at 0 */
> >> +	devlink->index--;
> >> +
> >> +	dev_set_name(&devlink->dev, DEVLINK_GENL_NAME "%d", devlink->index);
> >> +	if (devlink_name_exists(devlink_net(devlink), devlink_name(devlink)))
> >> +		goto different_name;
> >> +
> >> +	INIT_LIST_HEAD(&devlink->port_list);
> >> +	device_initialize(&devlink->dev);
> >> +	devlink->dev.class = &devlink_class;
> >> +	devlink->dev.platform_data = devlink;
> >> +	return devlink;
> >> +}
> >> +EXPORT_SYMBOL_GPL(devlink_alloc);
> >
> >The increment then decrement bit feels... Clunky and a little confusing.
> >Why not just atomic_read(&dev_counter) before different_name:, then an
> >atomic_inc_return(&dev_counter) under the if clause before the goto, and
> >eliminate the devlink->index-- bit?
> 
> If I split it it would not be atomic op anymore. But the
> devlink->index-- is just to adjust the start, nothing else.
> This is copied from nl80211 code.

Argh, I'm a moron. You need to increment dev_counter, can't just read it's
current value. Still fugly, but okay, does actually serve a purpose this
way.

-- 
Jarod Wilson
jarod@redhat.com

  reply	other threads:[~2016-02-24 16:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-23 15:51 [patch net-next v2 0/9] Introduce devlink interface and first drivers to use it Jiri Pirko
2016-02-23 15:51 ` [patch net-next v2 1/9] Introduce devlink infrastructure Jiri Pirko
2016-02-23 21:19   ` Jarod Wilson
2016-02-24  7:19     ` Jiri Pirko
2016-02-24 16:12       ` Jarod Wilson [this message]
2016-02-23 15:51 ` [patch net-next v2 2/9] mlx4: Implement devlink interface Jiri Pirko
2016-02-23 15:51 ` [patch net-next v2 3/9] mlx4: Implement port type setting via " Jiri Pirko
2016-02-23 15:51 ` [patch net-next v2 4/9] mlxsw: Implement " Jiri Pirko
2016-02-23 15:51 ` [patch net-next v2 5/9] mlxsw: core: Add devlink port splitter callbacks Jiri Pirko
2016-02-23 15:51 ` [patch net-next v2 6/9] mlxsw: spectrum: Unmap local port from module during teardown Jiri Pirko
2016-02-23 15:51 ` [patch net-next v2 7/9] mlxsw: spectrum: Store local port to module mapping during init Jiri Pirko
2016-02-23 15:51 ` [patch net-next v2 8/9] mlxsw: spectrum: Mark unused ports using NULL Jiri Pirko
2016-02-23 15:51 ` [patch net-next v2 9/9] mlxsw: spectrum: Introduce port splitting Jiri Pirko
2016-02-25 20:12 ` [patch net-next v2 0/9] Introduce devlink interface and first drivers to use it David Miller
2016-02-25 20:44   ` Hannes Frederic Sowa
2016-02-25 21:12     ` Jiri Pirko
2016-02-25 21:53       ` Hannes Frederic Sowa
2016-02-25 22:58         ` Jiri Pirko
2016-02-25 21:50   ` Andy Gospodarek

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=20160224161206.GA38500@redhat.com \
    --to=jarod@redhat.com \
    --cc=brouer@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dledford@redhat.com \
    --cc=eladr@mellanox.com \
    --cc=eugenia@mellanox.com \
    --cc=gospo@cumulusnetworks.com \
    --cc=hadarh@mellanox.com \
    --cc=hal.rosenstock@gmail.com \
    --cc=hannes@stressinduktion.org \
    --cc=idosch@mellanox.com \
    --cc=ivecera@redhat.com \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=john.fastabend@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@cumulusnetworks.com \
    --cc=ogerlitz@mellanox.com \
    --cc=rami.rosen@intel.com \
    --cc=roopa@cumulusnetworks.com \
    --cc=sean.hefty@intel.com \
    --cc=yishaih@mellanox.com \
    --cc=yotamg@mellanox.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).