diff mbox series

tunables: sort tunables list

Message ID xn7cevukgd.fsf@greed.delorie.com
State New
Headers show
Series tunables: sort tunables list | expand

Commit Message

DJ Delorie June 11, 2024, 11:29 p.m. UTC
Florian Weimer <fweimer@redhat.com> writes:
> Can we sort during generation of dl-tunable_list.h?
> It would fix bug 30027, too.

How about this?

Comments

Florian Weimer June 12, 2024, 8:35 a.m. UTC | #1
* DJ Delorie:

> Florian Weimer <fweimer@redhat.com> writes:
>> Can we sort during generation of dl-tunable_list.h?
>> It would fix bug 30027, too.
>
> How about this?

> +  # bubble sort is good enough, and more portable than GAWK's sorti()
> +  for (i = 0; i < typecount - 1; i ++) {
> +    for (j = i + 1; j < typecount; j ++) {
> +      if (typesa[i] > typesa[j]) {
> +	  temp = typesa[i];
> +	  typesa[i] = typesa[j];
> +	  typesa[j] = temp;
> +      }
> +    }
> +  }

We already require GNU awk and use asorti, so I'd prefer built-in
sorting here, too.

The other mechanics look right to me.  I remember doing something
similar, but must have discarded it because of the issue you mentioned
before (new tunables landing in the middle of the list).

Thanks,
Florian
diff mbox series

Patch

diff --git a/scripts/gen-tunables.awk b/scripts/gen-tunables.awk
index fc3b41376f..548f597fed 100644
--- a/scripts/gen-tunables.awk
+++ b/scripts/gen-tunables.awk
@@ -131,6 +131,25 @@  END {
     exit 1
   }
 
+  # TYPES is an associative array where the index is the data
+  # TYPESA is an indexed array where the value is the data
+  # We sort TYPESA
+  typecount = 0
+  for (tnm in types) {
+    typesa[typecount] = tnm;
+    typecount ++
+  }
+  # bubble sort is good enough, and more portable than GAWK's sorti()
+  for (i = 0; i < typecount - 1; i ++) {
+    for (j = i + 1; j < typecount; j ++) {
+      if (typesa[i] > typesa[j]) {
+	  temp = typesa[i];
+	  typesa[i] = typesa[j];
+	  typesa[j] = temp;
+      }
+    }
+  }
+
   print "/* AUTOGENERATED by gen-tunables.awk.  */"
   print "#ifndef _TUNABLES_H_"
   print "# error \"Do not include this file directly.\""
@@ -141,7 +160,8 @@  END {
   # Now, the enum names
   print "\ntypedef enum"
   print "{"
-  for (tnm in types) {
+  for (i = 0; i < typecount; i++) {
+    tnm = typesa[i];
     split (tnm, indices, SUBSEP);
     t = indices[1];
     n = indices[2];
@@ -157,7 +177,8 @@  END {
   print "# include \"dl-tunable-types.h\""
   # Finally, the tunable list.
   print "static tunable_t tunable_list[] attribute_relro __attribute_used__ = {"
-  for (tnm in types) {
+  for (i = 0; i < typecount; i++) {
+    tnm = typesa[i];
     split (tnm, indices, SUBSEP);
     t = indices[1];
     n = indices[2];
@@ -172,7 +193,8 @@  END {
   # Map of tunable with environment variables aliases used during parsing.  */
   print "\nstatic const tunable_id_t tunable_env_alias_list[] ="
   printf "{\n"
-  for (tnm in types) {
+  for (i = 0; i < typecount; i++) {
+    tnm = typesa[i];
     split (tnm, indices, SUBSEP);
     t = indices[1];
     n = indices[2];