From: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Mark Bloch <markb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
"linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: Christoph Lameter <cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH v4] IB/core: Make device counter infrastructure dynamic
Date: Fri, 20 May 2016 14:43:14 -0400 [thread overview]
Message-ID: <fa41b16b-cfdb-5595-b23d-951a011493a1@redhat.com> (raw)
In-Reply-To: <VI1PR05MB1391B8F7E83C21B653BC0C92D24B0-79XLn2atqDP8GeyK7vyn2tqRiQSDpxhJvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 3940 bytes --]
On 05/20/2016 12:53 PM, Mark Bloch wrote:
>
>
>> -----Original Message-----
>> From: Doug Ledford [mailto:dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org]
>> Sent: Friday, May 20, 2016 7:15 PM
>> To: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>> Cc: Christoph Lameter <cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org>; Mark Bloch <markb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>;
>> Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>> Subject: [PATCH v4] IB/core: Make device counter infrastructure dynamic
> [snip]
>> +static struct rdma_hw_stats *iwch_alloc_stats(struct ib_device *ibdev,
>> + u8 port_num)
>> +{
>> + struct rdma_hw_stats *stats;
>> +
>> + /* Our driver only supports device level stats */
>> + if (port_num != 0)
>> + return NULL;
>> +
>> + /* Guard against buggy edits of the names array */
>> + BUILD_BUG_ON(ARRAY_SIZE(names) != NR_COUNTERS);
>> +
>> + stats = kzalloc(sizeof(*stats) + NR_COUNTERS * sizeof(u64),
>> GFP_KERNEL);
>> + if (!stats)
>> + return NULL;
>> + stats->name = names;
>> + stats->num_counters = NR_COUNTERS;
>> + stats->lifespan = -1;
>> + return stats;
>> +}
> [snip]
>
>> +static struct rdma_hw_stats *c4iw_alloc_stats(struct ib_device *ibdev,
>> + u8 port_num)
>> +{
>> + struct rdma_hw_stats *stats;
>> +
>> + BUILD_BUG_ON(ARRAY_SIZE(names) != NR_COUNTERS);
>> +
>> + if (port_num != 0)
>> + return NULL;
>> +
>> + stats = kzalloc(sizeof(*stats) + NR_COUNTERS * sizeof(u64),
>> GFP_KERNEL);
>> + if (!stats)
>> + return NULL;
>> + stats->name = names;
>> + stats->num_counters = NR_COUNTERS;
>> + stats->lifespan = -1;
>> + return stats;
>> +}
> [snip]
>> +static struct rdma_hw_stats *i40iw_alloc_hw_stats(struct ib_device *ibdev,
>> + u8 port_num)
>> +{
>> + struct i40iw_device *iwdev = to_iwdev(ibdev);
>> + struct i40iw_sc_dev *dev = &iwdev->sc_dev;
>> + struct rdma_hw_stats *stats;
>> +
>> + BUILD_BUG_ON(ARRAY_SIZE(i40iw_hw_stat_names) !=
>> + (I40IW_HW_STAT_INDEX_MAX_32 +
>> I40IW_HW_STAT_INDEX_MAX_64));
>> +
>> + stats = kzalloc(sizeof(*stats) +
>> + I40IW_HW_STAT_INDEX_MAX_32 * sizeof(u64) +
>> + I40IW_HW_STAT_INDEX_MAX_64 * sizeof(u64),
>> GFP_KERNEL);
>> + if (!stats)
>> + return NULL;
>> + stats->name = i40iw_hw_stat_names;
>> + stats->num_counters = I40IW_HW_STAT_INDEX_MAX_32 +
>> + I40IW_HW_STAT_INDEX_MAX_64;
>> + /*
>> + * PFs get the default update lifespan, but VFs only update once
>> + * per second
>> + */
>> + if (dev->is_pf)
>> + stats->lifespan = -1;
>> + else
>> + stats->lifespan = msecs_to_jiffies(1000);
>> + return stats;
>> +}
> Just a little nitpick, what about creating a function that allocates the rdma_hw_stats struct?
> Something like:
>
> static inline static struct rdma_hw_stats *allocate_hw_stats_struct(const char **name,
> int num_counters,
> unsigned long lifespan)
> {
> struct rdma_hw_stats *stats;
>
> stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64));
> if (!stats)
> return NULL;
>
> stats->name = name;
> stats->num_counters = num_counters;
> if (lifespan == -1)
> stats->lifespan = -1;
> else
> stats->lifespan = msecs_to_jiffies(lifespan);
>
> return stats;
> }
>
> And putting it in ib_verbs.h?
> I feel like that copying this piece of code across drivers (3 with this patch, adding mlx5 + mlx4 makes it 5)
> makes little sense, also I don't feel the drivers should care/know about how to allocate it.
> Specifically: kzalloc(sizeof(*stats) + num_counters * sizeof(u64)) seems out of place inside a driver,
> It should be part of the infrastructure.
Sure, I'll add that. I've got to fix the build issue too.
> Other than that, it looks really good.
>
> Mark
>
--
Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
GPG KeyID: 0E572FDD
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 884 bytes --]
next prev parent reply other threads:[~2016-05-20 18:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-20 16:14 [PATCH v4] IB/core: Make device counter infrastructure dynamic Doug Ledford
[not found] ` <ecc98d137bffc959e6459d9ffd0fe53da0d84c9d.1463760487.git.dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-05-20 16:53 ` Mark Bloch
[not found] ` <VI1PR05MB1391B8F7E83C21B653BC0C92D24B0-79XLn2atqDP8GeyK7vyn2tqRiQSDpxhJvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2016-05-20 18:43 ` Doug Ledford [this message]
2016-05-20 16:56 ` kbuild test robot
2016-05-20 17:07 ` Christoph Lameter
2016-05-24 17:25 ` Jason Gunthorpe
[not found] ` <20160524172551.GE8037-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-05-24 23:01 ` Christoph Lameter
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=fa41b16b-cfdb-5595-b23d-951a011493a1@redhat.com \
--to=dledford-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=markb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
/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