[3/4] vdpa_sim: support vendor satistics

Message ID 20221221061652.15202-4-jasowang@redhat.com
State New
Headers
Series Vendor stats support in vdpasim_net |

Commit Message

Jason Wang Dec. 21, 2022, 6:16 a.m. UTC
  This patch adds a new config ops callback to allow individual
simulator to implement the vendor stats callback.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 13 +++++++++++++
 drivers/vdpa/vdpa_sim/vdpa_sim.h |  3 +++
 2 files changed, 16 insertions(+)
  

Comments

Stefano Garzarella Dec. 21, 2022, 1:34 p.m. UTC | #1
On Wed, Dec 21, 2022 at 02:16:51PM +0800, Jason Wang wrote:

Little typo in the title s/satistics/statistics

>This patch adds a new config ops callback to allow individual
>simulator to implement the vendor stats callback.
>
>Signed-off-by: Jason Wang <jasowang@redhat.com>
>---
> drivers/vdpa/vdpa_sim/vdpa_sim.c | 13 +++++++++++++
> drivers/vdpa/vdpa_sim/vdpa_sim.h |  3 +++
> 2 files changed, 16 insertions(+)
>
>diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
>index 55aaa023a6e2..02e892f819e7 100644
>--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
>+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
>@@ -426,6 +426,18 @@ static int vdpasim_get_vq_state(struct vdpa_device *vdpa, u16 idx,
> 	return 0;
> }
>
>+static int vdpasim_get_vq_stats(struct vdpa_device *vdpa, u16 idx,
>+				struct sk_buff *msg,
>+				struct netlink_ext_ack *extack)
>+{
>+	struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
>+
>+	if (vdpasim->dev_attr.get_stats)
>+		return vdpasim->dev_attr.get_stats(vdpasim, idx,
>+						   msg, extack);
>+	return -EINVAL;

Maybe -EOPNOTSUPP is better when the device doesn't support it.
Like we do in vendor_stats_fill() in drivers/vdpa/vdpa.c

>+}
>+
> static u32 vdpasim_get_vq_align(struct vdpa_device *vdpa)
> {
> 	return VDPASIM_QUEUE_ALIGN;
>@@ -710,6 +722,7 @@ static const struct vdpa_config_ops vdpasim_config_ops = {
> 	.set_vq_ready           = vdpasim_set_vq_ready,
> 	.get_vq_ready           = vdpasim_get_vq_ready,
> 	.set_vq_state           = vdpasim_set_vq_state,
>+	.get_vendor_vq_stats    = vdpasim_get_vq_stats,

Should we add this callback also in vdpasim_batch_config_ops?

Thanks,
Stefano

> 	.get_vq_state           = vdpasim_get_vq_state,
> 	.get_vq_align           = vdpasim_get_vq_align,
> 	.get_vq_group           = vdpasim_get_vq_group,
>diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h
>index 51c070a543f1..d2a08c0abad7 100644
>--- a/drivers/vdpa/vdpa_sim/vdpa_sim.h
>+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h
>@@ -48,6 +48,9 @@ struct vdpasim_dev_attr {
> 	work_func_t work_fn;
> 	void (*get_config)(struct vdpasim *vdpasim, void *config);
> 	void (*set_config)(struct vdpasim *vdpasim, const void *config);
>+	int (*get_stats)(struct vdpasim *vdpasim, u16 idx,
>+			 struct sk_buff *msg,
>+			 struct netlink_ext_ack *extack);
> };
>
> /* State of each vdpasim device */
>-- 
>2.25.1
>
  
Jason Wang Dec. 22, 2022, 4:19 a.m. UTC | #2
在 2022/12/21 21:34, Stefano Garzarella 写道:
> On Wed, Dec 21, 2022 at 02:16:51PM +0800, Jason Wang wrote:
>
> Little typo in the title s/satistics/statistics


Fixed.


>
>> This patch adds a new config ops callback to allow individual
>> simulator to implement the vendor stats callback.
>>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>> ---
>> drivers/vdpa/vdpa_sim/vdpa_sim.c | 13 +++++++++++++
>> drivers/vdpa/vdpa_sim/vdpa_sim.h |  3 +++
>> 2 files changed, 16 insertions(+)
>>
>> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c 
>> b/drivers/vdpa/vdpa_sim/vdpa_sim.c
>> index 55aaa023a6e2..02e892f819e7 100644
>> --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
>> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
>> @@ -426,6 +426,18 @@ static int vdpasim_get_vq_state(struct 
>> vdpa_device *vdpa, u16 idx,
>>     return 0;
>> }
>>
>> +static int vdpasim_get_vq_stats(struct vdpa_device *vdpa, u16 idx,
>> +                struct sk_buff *msg,
>> +                struct netlink_ext_ack *extack)
>> +{
>> +    struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
>> +
>> +    if (vdpasim->dev_attr.get_stats)
>> +        return vdpasim->dev_attr.get_stats(vdpasim, idx,
>> +                           msg, extack);
>> +    return -EINVAL;
>
> Maybe -EOPNOTSUPP is better when the device doesn't support it.
> Like we do in vendor_stats_fill() in drivers/vdpa/vdpa.c
>

That's right.


>> +}
>> +
>> static u32 vdpasim_get_vq_align(struct vdpa_device *vdpa)
>> {
>>     return VDPASIM_QUEUE_ALIGN;
>> @@ -710,6 +722,7 @@ static const struct vdpa_config_ops 
>> vdpasim_config_ops = {
>>     .set_vq_ready           = vdpasim_set_vq_ready,
>>     .get_vq_ready           = vdpasim_get_vq_ready,
>>     .set_vq_state           = vdpasim_set_vq_state,
>> +    .get_vendor_vq_stats    = vdpasim_get_vq_stats,
>
> Should we add this callback also in vdpasim_batch_config_ops?


Yes.

Thanks


>
> Thanks,
> Stefano
>
>>     .get_vq_state           = vdpasim_get_vq_state,
>>     .get_vq_align           = vdpasim_get_vq_align,
>>     .get_vq_group           = vdpasim_get_vq_group,
>> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h 
>> b/drivers/vdpa/vdpa_sim/vdpa_sim.h
>> index 51c070a543f1..d2a08c0abad7 100644
>> --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h
>> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h
>> @@ -48,6 +48,9 @@ struct vdpasim_dev_attr {
>>     work_func_t work_fn;
>>     void (*get_config)(struct vdpasim *vdpasim, void *config);
>>     void (*set_config)(struct vdpasim *vdpasim, const void *config);
>> +    int (*get_stats)(struct vdpasim *vdpasim, u16 idx,
>> +             struct sk_buff *msg,
>> +             struct netlink_ext_ack *extack);
>> };
>>
>> /* State of each vdpasim device */
>> -- 
>> 2.25.1
>>
>
  

Patch

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 55aaa023a6e2..02e892f819e7 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -426,6 +426,18 @@  static int vdpasim_get_vq_state(struct vdpa_device *vdpa, u16 idx,
 	return 0;
 }
 
+static int vdpasim_get_vq_stats(struct vdpa_device *vdpa, u16 idx,
+				struct sk_buff *msg,
+				struct netlink_ext_ack *extack)
+{
+	struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
+
+	if (vdpasim->dev_attr.get_stats)
+		return vdpasim->dev_attr.get_stats(vdpasim, idx,
+						   msg, extack);
+	return -EINVAL;
+}
+
 static u32 vdpasim_get_vq_align(struct vdpa_device *vdpa)
 {
 	return VDPASIM_QUEUE_ALIGN;
@@ -710,6 +722,7 @@  static const struct vdpa_config_ops vdpasim_config_ops = {
 	.set_vq_ready           = vdpasim_set_vq_ready,
 	.get_vq_ready           = vdpasim_get_vq_ready,
 	.set_vq_state           = vdpasim_set_vq_state,
+	.get_vendor_vq_stats    = vdpasim_get_vq_stats,
 	.get_vq_state           = vdpasim_get_vq_state,
 	.get_vq_align           = vdpasim_get_vq_align,
 	.get_vq_group           = vdpasim_get_vq_group,
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h
index 51c070a543f1..d2a08c0abad7 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.h
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h
@@ -48,6 +48,9 @@  struct vdpasim_dev_attr {
 	work_func_t work_fn;
 	void (*get_config)(struct vdpasim *vdpasim, void *config);
 	void (*set_config)(struct vdpasim *vdpasim, const void *config);
+	int (*get_stats)(struct vdpasim *vdpasim, u16 idx,
+			 struct sk_buff *msg,
+			 struct netlink_ext_ack *extack);
 };
 
 /* State of each vdpasim device */