diff mbox series

[ndctl,5/5] Use page size as alignment value

Message ID 20201222042516.2984348-5-santosh@fossix.org (mailing list archive)
State New
Headers show
Series [ndctl,1/5] libndctl: test enablement for non-nfit devices | expand

Commit Message

Santosh Sivaraj Dec. 22, 2020, 4:25 a.m. UTC
The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
the default page size on x86. Change those to the default page size on that
architecture (sysconf/getconf). No functional changes otherwise.

Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
---
 test/dpa-alloc.c    | 23 ++++++++++++++---------
 test/multi-dax.sh   |  6 ++++--
 test/sector-mode.sh |  4 +++-
 3 files changed, 21 insertions(+), 12 deletions(-)

Comments

Dan Williams Jan. 28, 2021, 1:24 a.m. UTC | #1
On Mon, Dec 21, 2020 at 8:26 PM Santosh Sivaraj <santosh@fossix.org> wrote:
>
> The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
> the default page size on x86. Change those to the default page size on that
> architecture (sysconf/getconf). No functional changes otherwise.
>
> Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
> ---
>  test/dpa-alloc.c    | 23 ++++++++++++++---------
>  test/multi-dax.sh   |  6 ++++--
>  test/sector-mode.sh |  4 +++-
>  3 files changed, 21 insertions(+), 12 deletions(-)
>
> diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
> index 10af189..ff6143e 100644
> --- a/test/dpa-alloc.c
> +++ b/test/dpa-alloc.c
> @@ -48,12 +48,13 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>         struct ndctl_region *region, *blk_region = NULL;
>         struct ndctl_namespace *ndns;
>         struct ndctl_dimm *dimm;
> -       unsigned long size;
> +       unsigned long size, page_size;
>         struct ndctl_bus *bus;
>         char uuid_str[40];
>         int round;
>         int rc;
>
> +       page_size = sysconf(_SC_PAGESIZE);
>         /* disable nfit_test.1, not used in this test */
>         bus = ndctl_bus_get_by_provider(ctx, NFIT_PROVIDER1);
>         if (!bus)
> @@ -134,11 +135,11 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>                         return rc;
>                 }
>                 ndctl_namespace_disable_invalidate(ndns);
> -               rc = ndctl_namespace_set_size(ndns, SZ_4K);
> +               rc = ndctl_namespace_set_size(ndns, page_size);
>                 if (rc) {
> -                       fprintf(stderr, "failed to init %s to size: %d\n",
> +                       fprintf(stderr, "failed to init %s to size: %lu\n",
>                                         ndctl_namespace_get_devname(ndns),
> -                                       SZ_4K);
> +                                       page_size);
>                         return rc;
>                 }
>                 namespaces[i].ndns = ndns;
> @@ -160,7 +161,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>                 ndns = namespaces[i % ARRAY_SIZE(namespaces)].ndns;
>                 if (i % ARRAY_SIZE(namespaces) == 0)
>                         round++;
> -               size = SZ_4K * round;
> +               size = page_size * round;
>                 rc = ndctl_namespace_set_size(ndns, size);
>                 if (rc) {
>                         fprintf(stderr, "%s: set_size: %lx failed: %d\n",
> @@ -176,7 +177,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>         i--;
>         round++;
>         ndns = namespaces[i % ARRAY_SIZE(namespaces)].ndns;
> -       size = SZ_4K * round;
> +       size = page_size * round;
>         rc = ndctl_namespace_set_size(ndns, size);
>         if (rc) {
>                 fprintf(stderr, "%s failed to update while labels full\n",
> @@ -185,7 +186,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>         }
>
>         round--;
> -       size = SZ_4K * round;
> +       size = page_size * round;
>         rc = ndctl_namespace_set_size(ndns, size);
>         if (rc) {
>                 fprintf(stderr, "%s failed to reduce size while labels full\n",
> @@ -279,8 +280,12 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>
>         available_slots = ndctl_dimm_get_available_labels(dimm);
>         if (available_slots != default_available_slots - 1) {
> -               fprintf(stderr, "mishandled slot count\n");
> -               return -ENXIO;
> +               fprintf(stderr, "mishandled slot count (%u, %u)\n",
> +                       available_slots, default_available_slots - 1);
> +
> +               /* TODO: fix it on non-acpi platforms */
> +               if (ndctl_bus_has_nfit(bus))
> +                       return -ENXIO;

This change seems unrelated to page size fixups. Care to break it out?
Santosh Sivaraj Jan. 29, 2021, 6:24 a.m. UTC | #2
Dan Williams <dan.j.williams@intel.com> writes:

> On Mon, Dec 21, 2020 at 8:26 PM Santosh Sivaraj <santosh@fossix.org> wrote:
>>
>> The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
>> the default page size on x86. Change those to the default page size on that
>> architecture (sysconf/getconf). No functional changes otherwise.
>>
>> Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
>> ---
>>  test/dpa-alloc.c    | 23 ++++++++++++++---------
>>  test/multi-dax.sh   |  6 ++++--
>>  test/sector-mode.sh |  4 +++-
>>  3 files changed, 21 insertions(+), 12 deletions(-)
>>
>> diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
>> index 10af189..ff6143e 100644
>> --- a/test/dpa-alloc.c
>> +++ b/test/dpa-alloc.c
>> @@ -48,12 +48,13 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>>         struct ndctl_region *region, *blk_region = NULL;
>>         struct ndctl_namespace *ndns;
>>         struct ndctl_dimm *dimm;
>> -       unsigned long size;
>> +       unsigned long size, page_size;
>>         struct ndctl_bus *bus;
>>         char uuid_str[40];
>>         int round;
>>         int rc;
>>
>> +       page_size = sysconf(_SC_PAGESIZE);
>>         /* disable nfit_test.1, not used in this test */
>>         bus = ndctl_bus_get_by_provider(ctx, NFIT_PROVIDER1);
>>         if (!bus)
>> @@ -134,11 +135,11 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>>                         return rc;
>>                 }
>>                 ndctl_namespace_disable_invalidate(ndns);
>> -               rc = ndctl_namespace_set_size(ndns, SZ_4K);
>> +               rc = ndctl_namespace_set_size(ndns, page_size);
>>                 if (rc) {
>> -                       fprintf(stderr, "failed to init %s to size: %d\n",
>> +                       fprintf(stderr, "failed to init %s to size: %lu\n",
>>                                         ndctl_namespace_get_devname(ndns),
>> -                                       SZ_4K);
>> +                                       page_size);
>>                         return rc;
>>                 }
>>                 namespaces[i].ndns = ndns;
>> @@ -160,7 +161,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>>                 ndns = namespaces[i % ARRAY_SIZE(namespaces)].ndns;
>>                 if (i % ARRAY_SIZE(namespaces) == 0)
>>                         round++;
>> -               size = SZ_4K * round;
>> +               size = page_size * round;
>>                 rc = ndctl_namespace_set_size(ndns, size);
>>                 if (rc) {
>>                         fprintf(stderr, "%s: set_size: %lx failed: %d\n",
>> @@ -176,7 +177,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>>         i--;
>>         round++;
>>         ndns = namespaces[i % ARRAY_SIZE(namespaces)].ndns;
>> -       size = SZ_4K * round;
>> +       size = page_size * round;
>>         rc = ndctl_namespace_set_size(ndns, size);
>>         if (rc) {
>>                 fprintf(stderr, "%s failed to update while labels full\n",
>> @@ -185,7 +186,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>>         }
>>
>>         round--;
>> -       size = SZ_4K * round;
>> +       size = page_size * round;
>>         rc = ndctl_namespace_set_size(ndns, size);
>>         if (rc) {
>>                 fprintf(stderr, "%s failed to reduce size while labels full\n",
>> @@ -279,8 +280,12 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>>
>>         available_slots = ndctl_dimm_get_available_labels(dimm);
>>         if (available_slots != default_available_slots - 1) {
>> -               fprintf(stderr, "mishandled slot count\n");
>> -               return -ENXIO;
>> +               fprintf(stderr, "mishandled slot count (%u, %u)\n",
>> +                       available_slots, default_available_slots - 1);
>> +
>> +               /* TODO: fix it on non-acpi platforms */
>> +               if (ndctl_bus_has_nfit(bus))
>> +                       return -ENXIO;
>
> This change seems unrelated to page size fixups. Care to break it out?

Sure Dan, I will add the API to check for DIMM error state flags too. Thanks for
the review, I will send a v2 soon.

Thanks,
Santosh
Santosh Sivaraj Feb. 25, 2021, 5:54 a.m. UTC | #3
Dan Williams <dan.j.williams@intel.com> writes:

> On Mon, Dec 21, 2020 at 8:26 PM Santosh Sivaraj <santosh@fossix.org> wrote:
>>
>> The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
>> the default page size on x86. Change those to the default page size on that
>> architecture (sysconf/getconf). No functional changes otherwise.
>>
>> Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
>> ---
>>  test/dpa-alloc.c    | 23 ++++++++++++++---------
>>  test/multi-dax.sh   |  6 ++++--
>>  test/sector-mode.sh |  4 +++-
>>  3 files changed, 21 insertions(+), 12 deletions(-)
>>
>> diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
>> index 10af189..ff6143e 100644
>> --- a/test/dpa-alloc.c
>> +++ b/test/dpa-alloc.c
>> @@ -48,12 +48,13 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>>         struct ndctl_region *region, *blk_region = NULL;
>>         struct ndctl_namespace *ndns;
>>         struct ndctl_dimm *dimm;
>> -       unsigned long size;
>> +       unsigned long size, page_size;
>>         struct ndctl_bus *bus;
>>         char uuid_str[40];
>>         int round;
>>         int rc;
>>
>> +       page_size = sysconf(_SC_PAGESIZE);
>>         /* disable nfit_test.1, not used in this test */
>>         bus = ndctl_bus_get_by_provider(ctx, NFIT_PROVIDER1);
>>         if (!bus)
>> @@ -134,11 +135,11 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>>                         return rc;
>>                 }
>>                 ndctl_namespace_disable_invalidate(ndns);
>> -               rc = ndctl_namespace_set_size(ndns, SZ_4K);
>> +               rc = ndctl_namespace_set_size(ndns, page_size);
>>                 if (rc) {
>> -                       fprintf(stderr, "failed to init %s to size: %d\n",
>> +                       fprintf(stderr, "failed to init %s to size: %lu\n",
>>                                         ndctl_namespace_get_devname(ndns),
>> -                                       SZ_4K);
>> +                                       page_size);
>>                         return rc;
>>                 }
>>                 namespaces[i].ndns = ndns;
>> @@ -160,7 +161,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>>                 ndns = namespaces[i % ARRAY_SIZE(namespaces)].ndns;
>>                 if (i % ARRAY_SIZE(namespaces) == 0)
>>                         round++;
>> -               size = SZ_4K * round;
>> +               size = page_size * round;
>>                 rc = ndctl_namespace_set_size(ndns, size);
>>                 if (rc) {
>>                         fprintf(stderr, "%s: set_size: %lx failed: %d\n",
>> @@ -176,7 +177,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>>         i--;
>>         round++;
>>         ndns = namespaces[i % ARRAY_SIZE(namespaces)].ndns;
>> -       size = SZ_4K * round;
>> +       size = page_size * round;
>>         rc = ndctl_namespace_set_size(ndns, size);
>>         if (rc) {
>>                 fprintf(stderr, "%s failed to update while labels full\n",
>> @@ -185,7 +186,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>>         }
>>
>>         round--;
>> -       size = SZ_4K * round;
>> +       size = page_size * round;
>>         rc = ndctl_namespace_set_size(ndns, size);
>>         if (rc) {
>>                 fprintf(stderr, "%s failed to reduce size while labels full\n",
>> @@ -279,8 +280,12 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
>>
>>         available_slots = ndctl_dimm_get_available_labels(dimm);
>>         if (available_slots != default_available_slots - 1) {
>> -               fprintf(stderr, "mishandled slot count\n");
>> -               return -ENXIO;
>> +               fprintf(stderr, "mishandled slot count (%u, %u)\n",
>> +                       available_slots, default_available_slots - 1);
>> +
>> +               /* TODO: fix it on non-acpi platforms */
>> +               if (ndctl_bus_has_nfit(bus))
>> +                       return -ENXIO;
>
> This change seems unrelated to page size fixups. Care to break it out?

This change is not required, I have already fixed this up. Refactoring residue.

Thanks,
Santosh
diff mbox series

Patch

diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index 10af189..ff6143e 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -48,12 +48,13 @@  static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 	struct ndctl_region *region, *blk_region = NULL;
 	struct ndctl_namespace *ndns;
 	struct ndctl_dimm *dimm;
-	unsigned long size;
+	unsigned long size, page_size;
 	struct ndctl_bus *bus;
 	char uuid_str[40];
 	int round;
 	int rc;
 
+	page_size = sysconf(_SC_PAGESIZE);
 	/* disable nfit_test.1, not used in this test */
 	bus = ndctl_bus_get_by_provider(ctx, NFIT_PROVIDER1);
 	if (!bus)
@@ -134,11 +135,11 @@  static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 			return rc;
 		}
 		ndctl_namespace_disable_invalidate(ndns);
-		rc = ndctl_namespace_set_size(ndns, SZ_4K);
+		rc = ndctl_namespace_set_size(ndns, page_size);
 		if (rc) {
-			fprintf(stderr, "failed to init %s to size: %d\n",
+			fprintf(stderr, "failed to init %s to size: %lu\n",
 					ndctl_namespace_get_devname(ndns),
-					SZ_4K);
+					page_size);
 			return rc;
 		}
 		namespaces[i].ndns = ndns;
@@ -160,7 +161,7 @@  static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 		ndns = namespaces[i % ARRAY_SIZE(namespaces)].ndns;
 		if (i % ARRAY_SIZE(namespaces) == 0)
 			round++;
-		size = SZ_4K * round;
+		size = page_size * round;
 		rc = ndctl_namespace_set_size(ndns, size);
 		if (rc) {
 			fprintf(stderr, "%s: set_size: %lx failed: %d\n",
@@ -176,7 +177,7 @@  static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 	i--;
 	round++;
 	ndns = namespaces[i % ARRAY_SIZE(namespaces)].ndns;
-	size = SZ_4K * round;
+	size = page_size * round;
 	rc = ndctl_namespace_set_size(ndns, size);
 	if (rc) {
 		fprintf(stderr, "%s failed to update while labels full\n",
@@ -185,7 +186,7 @@  static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 	}
 
 	round--;
-	size = SZ_4K * round;
+	size = page_size * round;
 	rc = ndctl_namespace_set_size(ndns, size);
 	if (rc) {
 		fprintf(stderr, "%s failed to reduce size while labels full\n",
@@ -279,8 +280,12 @@  static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 
 	available_slots = ndctl_dimm_get_available_labels(dimm);
 	if (available_slots != default_available_slots - 1) {
-		fprintf(stderr, "mishandled slot count\n");
-		return -ENXIO;
+		fprintf(stderr, "mishandled slot count (%u, %u)\n",
+			available_slots, default_available_slots - 1);
+
+		/* TODO: fix it on non-acpi platforms */
+		if (ndctl_bus_has_nfit(bus))
+			return -ENXIO;
 	}
 
 	ndctl_region_foreach(bus, region)
diff --git a/test/multi-dax.sh b/test/multi-dax.sh
index 110ba3d..8250128 100755
--- a/test/multi-dax.sh
+++ b/test/multi-dax.sh
@@ -21,6 +21,8 @@  check_min_kver "4.13" || do_skip "may lack multi-dax support"
 
 trap 'err $LINENO' ERR
 
+ALIGN_SIZE=`getconf PAGESIZE`
+
 # setup (reset nfit_test dimms)
 modprobe nfit_test
 $NDCTL disable-region -b $NFIT_TEST_BUS0 all
@@ -31,9 +33,9 @@  rc=1
 query=". | sort_by(.available_size) | reverse | .[0].dev"
 region=$($NDCTL list -b $NFIT_TEST_BUS0 -t pmem -Ri | jq -r "$query")
 
-json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a 4096 -s 16M)
+json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a $ALIGN_SIZE -s 16M)
 chardev1=$(echo $json | jq ". | select(.mode == \"devdax\") | .daxregion.devices[0].chardev")
-json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a 4096 -s 16M)
+json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a $ALIGN_SIZE -s 16M)
 chardev2=$(echo $json | jq ". | select(.mode == \"devdax\") | .daxregion.devices[0].chardev")
 
 _cleanup
diff --git a/test/sector-mode.sh b/test/sector-mode.sh
index eef8dc6..cee0313 100755
--- a/test/sector-mode.sh
+++ b/test/sector-mode.sh
@@ -18,6 +18,8 @@  rc=77
 set -e
 trap 'err $LINENO' ERR
 
+ALIGN_SIZE=`getconf PAGESIZE`
+
 # setup (reset nfit_test dimms)
 modprobe nfit_test
 $NDCTL disable-region -b $NFIT_TEST_BUS0 all
@@ -34,7 +36,7 @@  NAMESPACE=$($NDCTL list -b $NFIT_TEST_BUS1 -N | jq -r "$query")
 REGION=$($NDCTL list -R --namespace=$NAMESPACE | jq -r "(.[]) | .dev")
 echo 0 > /sys/bus/nd/devices/$REGION/read_only
 $NDCTL create-namespace --no-autolabel -e $NAMESPACE -m sector -f -l 4K
-$NDCTL create-namespace --no-autolabel -e $NAMESPACE -m dax -f -a 4K
+$NDCTL create-namespace --no-autolabel -e $NAMESPACE -m dax -f -a $ALIGN_SIZE
 $NDCTL create-namespace --no-autolabel -e $NAMESPACE -m sector -f -l 4K
 
 _cleanup