diff mbox series

[RFC,v2,18/18] tools/testing/cxl: Add Dynamic Capacity events

Message ID 20230604-dcd-type2-upstream-v2-18-f740c47e7916@intel.com
State New, archived
Headers show
Series DCD: Add support for Dynamic Capacity Devices (DCD) | expand

Commit Message

Ira Weiny Aug. 29, 2023, 5:21 a.m. UTC
OS software needs to be alerted when new extents arrive on a Dynamic
Capacity Device (DCD).  On test DCDs extents are added through sysfs.

Add events on DCD extent injection.  Directly call the event irq
callback to simulate irqs to process the test extents.

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 tools/testing/cxl/test/mem.c | 57 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

Comments

Jonathan Cameron Aug. 30, 2023, 12:23 p.m. UTC | #1
On Mon, 28 Aug 2023 22:21:09 -0700
Ira Weiny <ira.weiny@intel.com> wrote:

> OS software needs to be alerted when new extents arrive on a Dynamic
> Capacity Device (DCD).  On test DCDs extents are added through sysfs.
> 
> Add events on DCD extent injection.  Directly call the event irq
> callback to simulate irqs to process the test extents.
> 
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Trivial comments inline.

Reviewed-by: Jonathan.Cameron@huawei.com>

> ---
>  tools/testing/cxl/test/mem.c | 57 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 57 insertions(+)
> 
> diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
> index d6041a2145c5..20364fee9df9 100644
> --- a/tools/testing/cxl/test/mem.c
> +++ b/tools/testing/cxl/test/mem.c
> @@ -2008,6 +2008,41 @@ static bool new_extent_valid(struct device *dev, size_t new_start,
>  	return false;
>  }
>  
> +struct dcd_event_dyn_cap dcd_event_rec_template = {
> +	.hdr = {
> +		.id = UUID_INIT(0xca95afa7, 0xf183, 0x4018,
> +				0x8c, 0x2f, 0x95, 0x26, 0x8e, 0x10, 0x1a, 0x2a),
> +		.length = sizeof(struct dcd_event_dyn_cap),
> +	},
> +};
> +
> +static int send_dc_event(struct mock_event_store *mes, enum dc_event type,
> +			 u64 start, u64 length, const char *tag_str)

Arguably it's not sending the event, but rather adding it to the event log and
flicking the irq. So maybe naming needs some thought?

> +{
> +	struct device *dev = mes->mds->cxlds.dev;
> +	struct dcd_event_dyn_cap *dcd_event_rec;
> +
> +	dcd_event_rec = devm_kzalloc(dev, sizeof(*dcd_event_rec), GFP_KERNEL);
> +	if (!dcd_event_rec)
> +		return -ENOMEM;
> +
> +	memcpy(dcd_event_rec, &dcd_event_rec_template, sizeof(*dcd_event_rec));

devm_kmemdup?

> +	dcd_event_rec->data.event_type = type;
> +	dcd_event_rec->data.extent.start_dpa = cpu_to_le64(start);
> +	dcd_event_rec->data.extent.length = cpu_to_le64(length);
> +	memcpy(dcd_event_rec->data.extent.tag, tag_str,
> +	       min(sizeof(dcd_event_rec->data.extent.tag),
> +		   strlen(tag_str)));
> +
> +	mes_add_event(mes, CXL_EVENT_TYPE_DCD,
> +		      (struct cxl_event_record_raw *)dcd_event_rec);
> +
> +	/* Fake the irq */
> +	cxl_mem_get_event_records(mes->mds, CXLDEV_EVENT_STATUS_DCD);
> +
> +	return 0;
> +}
> +
Dave Jiang Aug. 31, 2023, 11:20 p.m. UTC | #2
On 8/28/23 22:21, Ira Weiny wrote:
> OS software needs to be alerted when new extents arrive on a Dynamic
> Capacity Device (DCD).  On test DCDs extents are added through sysfs.
> 
> Add events on DCD extent injection.  Directly call the event irq
> callback to simulate irqs to process the test extents.
> 
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
>   tools/testing/cxl/test/mem.c | 57 ++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 57 insertions(+)
> 
> diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
> index d6041a2145c5..20364fee9df9 100644
> --- a/tools/testing/cxl/test/mem.c
> +++ b/tools/testing/cxl/test/mem.c
> @@ -2008,6 +2008,41 @@ static bool new_extent_valid(struct device *dev, size_t new_start,
>   	return false;
>   }
>   
> +struct dcd_event_dyn_cap dcd_event_rec_template = {
> +	.hdr = {
> +		.id = UUID_INIT(0xca95afa7, 0xf183, 0x4018,
> +				0x8c, 0x2f, 0x95, 0x26, 0x8e, 0x10, 0x1a, 0x2a),
> +		.length = sizeof(struct dcd_event_dyn_cap),
> +	},
> +};
> +
> +static int send_dc_event(struct mock_event_store *mes, enum dc_event type,
> +			 u64 start, u64 length, const char *tag_str)
> +{
> +	struct device *dev = mes->mds->cxlds.dev;
> +	struct dcd_event_dyn_cap *dcd_event_rec;
> +
> +	dcd_event_rec = devm_kzalloc(dev, sizeof(*dcd_event_rec), GFP_KERNEL);
> +	if (!dcd_event_rec)
> +		return -ENOMEM;
> +
> +	memcpy(dcd_event_rec, &dcd_event_rec_template, sizeof(*dcd_event_rec));
> +	dcd_event_rec->data.event_type = type;
> +	dcd_event_rec->data.extent.start_dpa = cpu_to_le64(start);
> +	dcd_event_rec->data.extent.length = cpu_to_le64(length);
> +	memcpy(dcd_event_rec->data.extent.tag, tag_str,
> +	       min(sizeof(dcd_event_rec->data.extent.tag),
> +		   strlen(tag_str)));
> +
> +	mes_add_event(mes, CXL_EVENT_TYPE_DCD,
> +		      (struct cxl_event_record_raw *)dcd_event_rec);
> +
> +	/* Fake the irq */
> +	cxl_mem_get_event_records(mes->mds, CXLDEV_EVENT_STATUS_DCD);
> +
> +	return 0;
> +}
> +
>   /*
>    * Format <start>:<length>:<tag>
>    *
> @@ -2021,6 +2056,7 @@ static ssize_t dc_inject_extent_store(struct device *dev,
>   				      const char *buf, size_t count)
>   {
>   	char *start_str __free(kfree) = kstrdup(buf, GFP_KERNEL);
> +	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
>   	unsigned long long start, length;
>   	char *len_str, *tag_str;
>   	size_t buf_len = count;
> @@ -2063,6 +2099,13 @@ static ssize_t dc_inject_extent_store(struct device *dev,
>   	if (rc)
>   		return rc;
>   
> +	rc = send_dc_event(&mdata->mes, DCD_ADD_CAPACITY, start, length,
> +			   tag_str);
> +	if (rc) {
> +		dev_err(dev, "Failed to add event %d\n", rc);
> +		return rc;
> +	}
> +
>   	return count;
>   }
>   static DEVICE_ATTR_WO(dc_inject_extent);
> @@ -2071,6 +2114,7 @@ static ssize_t dc_del_extent_store(struct device *dev,
>   				   struct device_attribute *attr,
>   				   const char *buf, size_t count)
>   {
> +	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
>   	unsigned long long start;
>   	int rc;
>   
> @@ -2083,6 +2127,12 @@ static ssize_t dc_del_extent_store(struct device *dev,
>   	if (rc)
>   		return rc;
>   
> +	rc = send_dc_event(&mdata->mes, DCD_RELEASE_CAPACITY, start, 0, "");
> +	if (rc) {
> +		dev_err(dev, "Failed to add event %d\n", rc);
> +		return rc;
> +	}
> +
>   	return count;
>   }
>   static DEVICE_ATTR_WO(dc_del_extent);
> @@ -2111,6 +2161,13 @@ static ssize_t dc_force_del_extent_store(struct device *dev,
>   	if (rc)
>   		return rc;
>   
> +	rc = send_dc_event(&mdata->mes, DCD_FORCED_CAPACITY_RELEASE,
> +			      start, 0, "");
> +	if (rc) {
> +		dev_err(dev, "Failed to add event %d\n", rc);
> +		return rc;
> +	}
> +
>   	return count;
>   }
>   static DEVICE_ATTR_WO(dc_force_del_extent);
>
Ira Weiny Sept. 6, 2023, 9:39 p.m. UTC | #3
Jonathan Cameron wrote:
> On Mon, 28 Aug 2023 22:21:09 -0700
> Ira Weiny <ira.weiny@intel.com> wrote:
> 
> > OS software needs to be alerted when new extents arrive on a Dynamic
> > Capacity Device (DCD).  On test DCDs extents are added through sysfs.
> > 
> > Add events on DCD extent injection.  Directly call the event irq
> > callback to simulate irqs to process the test extents.
> > 
> > Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> Trivial comments inline.
> 
> Reviewed-by: Jonathan.Cameron@huawei.com>
> 
> > ---
> >  tools/testing/cxl/test/mem.c | 57 ++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 57 insertions(+)
> > 
> > diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
> > index d6041a2145c5..20364fee9df9 100644
> > --- a/tools/testing/cxl/test/mem.c
> > +++ b/tools/testing/cxl/test/mem.c
> > @@ -2008,6 +2008,41 @@ static bool new_extent_valid(struct device *dev, size_t new_start,
> >  	return false;
> >  }
> >  
> > +struct dcd_event_dyn_cap dcd_event_rec_template = {
> > +	.hdr = {
> > +		.id = UUID_INIT(0xca95afa7, 0xf183, 0x4018,
> > +				0x8c, 0x2f, 0x95, 0x26, 0x8e, 0x10, 0x1a, 0x2a),
> > +		.length = sizeof(struct dcd_event_dyn_cap),
> > +	},
> > +};
> > +
> > +static int send_dc_event(struct mock_event_store *mes, enum dc_event type,
> > +			 u64 start, u64 length, const char *tag_str)
> 
> Arguably it's not sending the event, but rather adding it to the event log and
> flicking the irq. So maybe naming needs some thought?

I spent all my naming energy on what to call extents at each layer...  ;-)

Yea I'll rename to add_dc_event() or something like that.

> 
> > +{
> > +	struct device *dev = mes->mds->cxlds.dev;
> > +	struct dcd_event_dyn_cap *dcd_event_rec;
> > +
> > +	dcd_event_rec = devm_kzalloc(dev, sizeof(*dcd_event_rec), GFP_KERNEL);
> > +	if (!dcd_event_rec)
> > +		return -ENOMEM;
> > +
> > +	memcpy(dcd_event_rec, &dcd_event_rec_template, sizeof(*dcd_event_rec));
> 
> devm_kmemdup?

Yep would work well.

Thanks again for all the review,
Ira
diff mbox series

Patch

diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
index d6041a2145c5..20364fee9df9 100644
--- a/tools/testing/cxl/test/mem.c
+++ b/tools/testing/cxl/test/mem.c
@@ -2008,6 +2008,41 @@  static bool new_extent_valid(struct device *dev, size_t new_start,
 	return false;
 }
 
+struct dcd_event_dyn_cap dcd_event_rec_template = {
+	.hdr = {
+		.id = UUID_INIT(0xca95afa7, 0xf183, 0x4018,
+				0x8c, 0x2f, 0x95, 0x26, 0x8e, 0x10, 0x1a, 0x2a),
+		.length = sizeof(struct dcd_event_dyn_cap),
+	},
+};
+
+static int send_dc_event(struct mock_event_store *mes, enum dc_event type,
+			 u64 start, u64 length, const char *tag_str)
+{
+	struct device *dev = mes->mds->cxlds.dev;
+	struct dcd_event_dyn_cap *dcd_event_rec;
+
+	dcd_event_rec = devm_kzalloc(dev, sizeof(*dcd_event_rec), GFP_KERNEL);
+	if (!dcd_event_rec)
+		return -ENOMEM;
+
+	memcpy(dcd_event_rec, &dcd_event_rec_template, sizeof(*dcd_event_rec));
+	dcd_event_rec->data.event_type = type;
+	dcd_event_rec->data.extent.start_dpa = cpu_to_le64(start);
+	dcd_event_rec->data.extent.length = cpu_to_le64(length);
+	memcpy(dcd_event_rec->data.extent.tag, tag_str,
+	       min(sizeof(dcd_event_rec->data.extent.tag),
+		   strlen(tag_str)));
+
+	mes_add_event(mes, CXL_EVENT_TYPE_DCD,
+		      (struct cxl_event_record_raw *)dcd_event_rec);
+
+	/* Fake the irq */
+	cxl_mem_get_event_records(mes->mds, CXLDEV_EVENT_STATUS_DCD);
+
+	return 0;
+}
+
 /*
  * Format <start>:<length>:<tag>
  *
@@ -2021,6 +2056,7 @@  static ssize_t dc_inject_extent_store(struct device *dev,
 				      const char *buf, size_t count)
 {
 	char *start_str __free(kfree) = kstrdup(buf, GFP_KERNEL);
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
 	unsigned long long start, length;
 	char *len_str, *tag_str;
 	size_t buf_len = count;
@@ -2063,6 +2099,13 @@  static ssize_t dc_inject_extent_store(struct device *dev,
 	if (rc)
 		return rc;
 
+	rc = send_dc_event(&mdata->mes, DCD_ADD_CAPACITY, start, length,
+			   tag_str);
+	if (rc) {
+		dev_err(dev, "Failed to add event %d\n", rc);
+		return rc;
+	}
+
 	return count;
 }
 static DEVICE_ATTR_WO(dc_inject_extent);
@@ -2071,6 +2114,7 @@  static ssize_t dc_del_extent_store(struct device *dev,
 				   struct device_attribute *attr,
 				   const char *buf, size_t count)
 {
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
 	unsigned long long start;
 	int rc;
 
@@ -2083,6 +2127,12 @@  static ssize_t dc_del_extent_store(struct device *dev,
 	if (rc)
 		return rc;
 
+	rc = send_dc_event(&mdata->mes, DCD_RELEASE_CAPACITY, start, 0, "");
+	if (rc) {
+		dev_err(dev, "Failed to add event %d\n", rc);
+		return rc;
+	}
+
 	return count;
 }
 static DEVICE_ATTR_WO(dc_del_extent);
@@ -2111,6 +2161,13 @@  static ssize_t dc_force_del_extent_store(struct device *dev,
 	if (rc)
 		return rc;
 
+	rc = send_dc_event(&mdata->mes, DCD_FORCED_CAPACITY_RELEASE,
+			      start, 0, "");
+	if (rc) {
+		dev_err(dev, "Failed to add event %d\n", rc);
+		return rc;
+	}
+
 	return count;
 }
 static DEVICE_ATTR_WO(dc_force_del_extent);