Skip to content

Commit

Permalink
[backend] support cpu flag exclude constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschroeter authored and M0ses committed Jul 26, 2021
1 parent 9f61422 commit b03ba91
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
10 changes: 9 additions & 1 deletion docs/api/api/constraints.rng
Expand Up @@ -91,7 +91,15 @@
<element name="cpu">
<oneOrMore>
<element name="flag">
<ref name="cpu-flags"/>
<optional>
<attribute name="exclude">
<choice>
<value>false</value>
<value>true</value>
</choice>
</attribute>
</optional>
<text />
</element>
</oneOrMore>
</element>
Expand Down
1 change: 1 addition & 0 deletions docs/api/api/constraints.xml
Expand Up @@ -13,6 +13,7 @@
<cpu>
<flag>fpu</flag>
<flag>mmx</flag>
<flag exclude="true">nol0kernel</flag>
</cpu>
<processors>2</processors>
<disk>
Expand Down
14 changes: 8 additions & 6 deletions src/backend/BSDispatcher/Constraints.pm
Expand Up @@ -114,9 +114,14 @@ sub oracle {
return 0 if $constraints->{'hardware'}->{'memoryperjob'} && getmbsize($constraints->{'hardware'}->{'memoryperjob'}) * ($worker->{'hardware'}->{'jobs'} || 1) > ( $memory + $swap );
return 0 if $constraints->{'hardware'}->{'physicalmemory'} && getmbsize($constraints->{'hardware'}->{'physicalmemory'}) > $memory;
if ($constraints->{'hardware'}->{'cpu'}) {
return 0 unless $worker->{'hardware'}->{'cpu'};
my %workerflags = map {$_ => 1} @{$worker->{'hardware'}->{'cpu'}->{'flag'} || []};
return 0 if grep {!$workerflags{$_}} @{$constraints->{'hardware'}->{'cpu'}->{'flag'} || []};
for my $flag (@{$constraints->{'hardware'}->{'cpu'}->{'flag'} || []}) {
if ($flag->{'exclude'} && $flag->{'exclude'} eq 'true') {
return 0 if $workerflags{$flag->{'_content'}};
} else {
return 0 unless $workerflags{$flag->{'_content'}};
}
}
}
}
return 1;
Expand Down Expand Up @@ -167,10 +172,7 @@ sub mergeconstraints {
$con->{'hardware'}->{$el} = ref($con2->{'hardware'}->{$el}) ? BSUtil::clone($con2->{'hardware'}->{$el}) : $con2->{'hardware'}->{$el};
}
if ($con2->{'hardware'}->{'cpu'} && $con2->{'hardware'}->{'cpu'}->{'flag'}) {
my %oldflags = map {$_ => 1} @{$con->{'hardware'}->{'cpu'}->{'flag'} || []};
for (@{$con2->{'hardware'}->{'cpu'}->{'flag'}}) {
push @{$con->{'hardware'}->{'cpu'}->{'flag'}}, $_ unless $oldflags{$_};
}
push @{$con->{'hardware'}->{'cpu'}->{'flag'}}, @{$con2->{'hardware'}->{'cpu'}->{'flag'}};
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/backend/BSXML.pm
Expand Up @@ -1739,7 +1739,11 @@ our @constraint = (
],
[ 'hardware' =>
[ 'cpu' =>
[ 'flag' ],
[[ 'flag'=>
'exclude', # true or false. default is false.
[],
'_content' # the cpu flag from /proc/cpuinfo
]],
],
'processors',
'jobs',
Expand Down
3 changes: 3 additions & 0 deletions src/backend/testdata/constraint/kernel
Expand Up @@ -15,6 +15,9 @@
</conditions>
<hardware>
<processors>1</processors>
<cpu>
<flag exclude="true">EL0</flag>
</cpu>
<disk>
<size unit="G">6</size>
</disk>
Expand Down
1 change: 1 addition & 0 deletions src/backend/testdata/test_dispatcher
Expand Up @@ -51,6 +51,7 @@ td simple05 false "kernel-default" armv7l small kernel
td simple06 false "kernel-default" aarch64 small kernel
td simple07 true "kernel-default" aarch64 medium kernel
td simple08 true "kernel-default" aarch64 large kernel
td simple09 false "kernel-default" armv7l large kernel # requires native kernel support (EL0)

# simple source constraints like used by suse kernel
td sandbox31 false "kernel-obs-qa" i586 medium kernel
Expand Down
1 change: 1 addition & 0 deletions src/backend/testdata/workerinfo/large
Expand Up @@ -13,6 +13,7 @@
<hardware>
<cpu>
<flag>mmx</flag>
<flag>EL0</flag>
</cpu>
<nativeonly/>
<processors>32</processors>
Expand Down

0 comments on commit b03ba91

Please sign in to comment.