test/cpu_quota: tolerate errors in session quota

Previously we pre-calculated the translation errors for the session
quota to make a discret check in the test. But since the order, in which
init childs get their CPU quota isn't always the same anymore (we should
have never made assumptions about that) the translation errors differ
from trial to trial. However, the errors are below 0.01% of the super
period. We now tolerate them in the run script.

Ref #2304
This commit is contained in:
Martin Stein 2017-03-02 17:08:32 +01:00 committed by Christian Helmuth
parent f79bcbd72a
commit 574a1bd198
2 changed files with 30 additions and 21 deletions

View File

@ -124,6 +124,10 @@ struct Main
Main(Env &env) : env(env)
{
Cpu_session::Quota quota = env.cpu().quota();
log("quota super period ", quota.super_period_us);
log("quota ", quota.us);
log("start measurement ...");
timer.sigh(timer_signal.cap);
auto measure = [&] (unsigned duration_sec) {
@ -148,9 +152,6 @@ struct Main
/* conclusion */
synchronizer.threshold(CONCLUSION_NR_OF_THREADS);
synchronizer.synchronize();
Cpu_session::Quota quota = env.cpu().quota();
log("quota super period ", quota.super_period_us);
log("quota ", quota.us);
log(counter_a);
log(counter_b);
log("done");

View File

@ -135,7 +135,7 @@ proc check_counter { name opt cnt total_cnt } {
global err_cnt
set bad 0
set class "Good: "
set class "Good:"
set tol 0.01
set is 0
@ -176,23 +176,37 @@ proc check_counter { name opt cnt total_cnt } {
if {[expr abs($err) > $tol]} {
set class "Bad: "
set class "Bad: "
set err_cnt [expr $err_cnt + 1]
}
puts "$class$name received $is_fmt% CPU (goal $opt_fmt% tol $tol_fmt% err $err_fmt%)"
puts "$class $name received $is_fmt% CPU (goal $opt_fmt% tol $tol_fmt% err $err_fmt%)"
}
proc check_quota { name opt_sp quota_sp opt quota } {
proc check_quota { name opt_sp quota_sp opt_pc quota } {
global err_cnt
if {[expr $quota != $opt]} {
puts "Bad: $name has quota $quota us (goal $opt us)"
set opt [expr $opt_sp * $opt_pc / 100]
set quota_err [expr $quota - $opt]
set quota_class "Good:"
set sp_class "Good:"
#
# We tolerate rounding errors up to 0.01% of the super period as the two
# quota translations from init to core and then from core to the user are
# distinct.
#
set quota_tol [expr $opt_sp * 1 / 10000]
if {[expr abs($quota_err) > $quota_tol]} {
set quota_class "Bad: "
set err_cnt [expr $err_cnt + 1]
}
if {[expr $quota_sp != $opt_sp]} {
puts "Bad: $name has super period $quota_sp us (goal $opt_sp us)"
set sp_class "Bad: "
set err_cnt [expr $err_cnt + 1]
}
puts "$quota_class $name has_quota $quota us (goal $opt tol $quota_tol err $quota_err us)"
puts "$sp_class $name has super period $quota_sp us (goal $opt_sp us)"
}
# pre-define variables if regexp does not match
@ -207,17 +221,11 @@ regexp {[0-9]+} [regexp -inline {slow. quota super period [0-9]+} $output] slow_
regexp {[0-9]+} [regexp -inline {midl. quota super period [0-9]+} $output] midl_quota_sp
regexp {[0-9]+} [regexp -inline {fast. quota super period [0-9]+} $output] fast_quota_sp
#
# We have to consider the rounding errors as the two translations from init to
# core and then from core to the user are distinct.
#
# Slow quota (1000000 * (0x8000 * 5 / 100)) / 0x8000 = 49987
# Slow quota (1000000 * (0x8000 * 20 / 100)) / 0x8000 = 199981
# Slow quota (1000000 * (0x8000 * 60 / 100)) / 0x8000 = 599975
#
check_quota "Slow test" 1000000 $slow_quota_sp 49987 $slow_quota
check_quota "Middle test" 1000000 $midl_quota_sp 199981 $midl_quota
check_quota "Fast test" 1000000 $fast_quota_sp 599975 $fast_quota
set super_period_us 1000000
check_quota "Slow test" $super_period_us $slow_quota_sp 5 $slow_quota
check_quota "Middle test" $super_period_us $midl_quota_sp 20 $midl_quota
check_quota "Fast test" $super_period_us $fast_quota_sp 60 $fast_quota
regexp {[0-9]+} [regexp -inline {slow. counter A [0-9]+} $output] slow_a_cnt
regexp {[0-9]+} [regexp -inline {midl. counter A [0-9]+} $output] midl_a_cnt