]> xenbits.xensource.com Git - osstest.git/commitdiff
host allocation: Group jobs by their reuse parameters
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 17 Nov 2017 16:49:42 +0000 (16:49 +0000)
committerIan Jackson <iwj@xenproject.org>
Wed, 7 Oct 2020 16:48:33 +0000 (17:48 +0100)
This promotes reuse by arranging that jobs that can reuse a host get
to run consecutively.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Osstest/JobDB/Executive.pm
Osstest/JobDB/Standalone.pm
ts-host-reuse
ts-hosts-allocate-Executive

index 3062957241dc684435d1cce6964922866e874247..8c235d454ed4a0c4cd56fc4258aa81d099e834d9 100644 (file)
@@ -389,6 +389,53 @@ END
     }
 }
 
+sub jobdb_set_hosts_infraprioritygroup ($$$$;$) { # method
+    my ($mo, $flight, $job, $group_key, $rref) = @_;
+    # Sets the runvar hosts_infraprioritygroup in $flight,$job
+    # The runvar values are NUM:GROUPKEY
+    # such that each GROUPKEY always has the same NUM, within the flight
+    # $rref is \%r (for use within a ts-*) or undef
+
+    my $vn = 'hosts_infraprioritygroup';
+
+    my $queryq = $dbh_tests->prepare(<<END);
+        SELECT job, val,
+               (job = ?) AS thisjob
+          FROM runvars
+         WHERE flight=?
+           AND name=?
+      ORDER BY thisjob DESC
+END
+    my $insertq = $dbh_tests->prepare(<<END);
+        INSERT INTO runvars (flight,job, name,val, synth)
+                     VALUES (?,     ?,   ?,   ?,   't')
+END
+
+    my $resulting;
+    db_retry($dbh_tests,[],sub {
+       my $use = 1;
+       $resulting = undef;
+        $queryq->execute($job, $flight, $vn);
+       while (my ($tjob, $tval, $thisjob) = $queryq->fetchrow_array()) {
+           if ($thisjob) {
+               logm("$vn: job is already in group $tval");
+               return;
+           }
+           $tval =~ m/^(\d+)\:/ or die "$flight $job $tval ?";
+           if ($' eq $group_key) {
+               $use = $1;
+               last;
+           } elsif ($1 >= $use) {
+               $use = $1 + 1;
+           }
+       }
+       $resulting = "$use:$group_key";
+       logm("$vn: inserting job into group $resulting");
+       $insertq->execute($flight,$job,$vn, $resulting);
+    });
+    $rref->{$vn} = $resulting if $rref && defined $resulting;
+}
+
 sub jobdb_flight_started_for_log_capture ($$) { #method
     my ($mo, $flight) = @_;
     my $started= $dbh_tests->selectrow_array(<<END);
index 4f320ccfcdcfb158a981805841a9d6864ca50016..1db4dc785caf8f4f36c881054086ce445a968e70 100644 (file)
@@ -118,6 +118,8 @@ sub jobdb_resource_shared_mark_ready { } #method
 
 sub jobdb_check_other_job { } #method
 
+sub jobdb_set_hosts_infraprioritygroup { } # method
+
 sub jobdb_flight_started_for_log_capture ($$) { #method
     my ($mo, $flight) = @_;
     return time - 60*60; # just the most recent serial log then,
index 5bdb07d1bc9b2e764c251f48a6e8b01141110a28..29abe987e9aa9fd422dc6d1e8af24eb8ce3d90bf 100755 (executable)
@@ -141,6 +141,7 @@ sub act_prealloc () {
     compute_test_sharetype();
     $ho = selecthost($whhost, undef, 1);
     set_runtime_hostflag($ho->{Ident}, "reuse-$sharetype");
+    $mjobdb->jobdb_set_hosts_infraprioritygroup($flight, $job, $sharetype, \%r);
 }
 
 sub act_start_test () {
index fc107c08e25c1350858e5eab29306be997fbab2b..a50f8bf3d9ba599edf901d82cca7e137b4abae00 100755 (executable)
@@ -733,9 +733,13 @@ sub alloc_hosts () {
         ? -10000
         : -10 * @hids;
 
+    my $infrapriority =
+       ($r{hosts_infraprioritygroup} // '') =~ m/^(\d+):/ ? $1 : undef;
+
     my $ok = alloc_resources(WaitStart =>
                     ($ENV{OSSTEST_RESOURCE_WAITSTART} || $fi->{started}),
                     WaitStartAdjust => $waitstartadjust,
+                    InfraPriority => $infrapriority,
                    DebugFh => \*DEBUG,
                     \&attempt_allocation);