Skip to contentSkip to conversation

nvme/053: provide time extension alternative

PATCH In review Luis Chamberlain 3 participants 6 messages Dec 18, 2024 – Jan 16, 2025 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme/053: provide time extension alternative

I get this failure when I run this test:

awk: ...rescan.awk:2: warning: The time extension is obsolete. Use the timex extension from gawkextlib

I can't find this extension either, so just use systime() and use system(sleep) for the sleep command.

---
 tests/nvme/053 | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
tests/nvme/053 +6 -5
index 3ade8d368be6..65a7b86519bc 100755
@@ -27,13 +27,14 @@ rescan_controller() {
 
 create_rescan_script() {
 	cat >"$TMPDIR/rescan.awk" <<EOF
-@load "time"
-
 BEGIN {
     srand(seed);
-    finish = gettimeofday() + strtonum(timeout);
-    while (gettimeofday() < finish) {
-	sleep(0.1 + 5 * rand());
+    start_time = systime();
+    finish = start_time + strtonum(timeout);
+    while (systime() < finish) {
+	sleep_time = 0.1 + 5 * rand();
+        cmd = "sleep " sleep_time;
+        system(cmd);
 	printf("1\n") > path;
 	close(path);
     }
Signature · 1 line
2.43.0
#1 lore raw
Quoted 4 lines · Luis Chamberlain

I get this failure when I run this test:

awk: ...rescan.awk:2: warning: The time extension is obsolete. Use the timex extension from gawkextlib

Hi Luis, thank you for catching this.

Quoted 2 lines

I can't find this extension either, so just use systime() and use system(sleep) for the sleep command.

FYI, here I share the link to the past discussion that resulted in the awk script in nvme/053 [1]. In that discussion, Martin noted that

'But the fork-and-exec to "awk" is slow.'

So I wonder if this system(sleep) in the awk while loop could be slow also.

Assuming this system(sleep) approach is slow and not preferred, I suggest to go back to the approach that the Martin's v1 patch took [2]. The while loop is implemented with bash. The awk script was introduced for the float calculation to get the random float number from 0.1 to 5.0. However, I think such calculation can be done with bash as follows:

get_sleep_time() {
        local duration=$((RANDOM % 50 + 1))

	echo "$((duration / 10))"."$((duration % 10))"
}

With this, we should be able to drop the awk script form the test case.

Martin, what do you think?

[1] https://lore.kernel.org/linux-nvme/[email protected]/
[2] https://lore.kernel.org/linux-nvme/[email protected]/

#2 lore raw
Quoted 2 lines · Shinichiro Kawasaki

Martin, what do you think?

Martin, poke.

Luis

#3 lore raw
In reply to Shinichiro Kawasaki
Quoted 9 lines · Shinichiro Kawasaki
Quoted 4 lines · Luis Chamberlain

I get this failure when I run this test:

awk: ...rescan.awk:2: warning: The time extension is obsolete. Use the timex extension from gawkextlib

get_sleep_time() {
        local duration=$((RANDOM % 50 + 1))

Quoted 7 lines
	echo "$((duration / 10))"."$((duration % 10))"
}

With this, we should be able to drop the awk script form the test case.

Martin, what do you think?

Fine with me, and actually, nice. This way we don't need awk at all. Do you want me to submit a patch, or will you do it yourself?

Martin

#5 lore raw
In reply to Luis Chamberlain
Quoted 7 lines · Luis Chamberlain

I get this failure when I run this test:

awk: ...rescan.awk:2: warning: The time extension is obsolete. Use the timex extension from gawkextlib

I can't find this extension either, so just use systime() and use system(sleep) for the sleep command.

While I'm ok with Shinshiro's propsal for working around this issue, I wonder which gawk version you are using? In the history of gawk, I can see that the deprecation of the "time" extension (gawk 5.2.0) was taken back in gawk 5.2.2:

c3c6419 ("Make the time extension deprecated.")
6e195e4 ("Undeprecate the time extension, add strptime, update tests and doc.")

The NEWS file says "The time extension is no longer deprecated. The strptime() function from gawkextlib's timex extension has been added to it."

Regards,
Martin

#4 lore raw
In reply to Martin Wilck
Quoted 13 lines · Martin Wilck
Quoted 12 lines · Shinichiro Kawasaki
Quoted 4 lines · Luis Chamberlain

I get this failure when I run this test:

awk: ...rescan.awk:2: warning: The time extension is obsolete. Use the timex extension from gawkextlib

get_sleep_time() {
        local duration=$((RANDOM % 50 + 1))

	echo "$((duration / 10))"."$((duration % 10))"
}
Quoted 7 lines
Quoted 4 lines

With this, we should be able to drop the awk script form the test case.

Martin, what do you think?

Fine with me, and actually, nice. This way we don't need awk at all. Do you want me to submit a patch, or will you do it yourself?

Thanks for the response. I have prepared the fix patch, and will post it soon.