mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-20 06:07:59 +00:00
8f9355b360
In the init configuration one can configure the donation of CPU time via 'resource' tags that have the attribute 'name' set to "CPU" and the attribute 'quantum' set to the percentage of CPU quota that init shall donate. The pattern is the same as when donating RAM quota. ! <start name="test"> ! <resource name="CPU" quantum="75"/> ! </start> This would cause init to try donating 75% of its CPU quota to the child "test". Init and core do not preserve CPU quota for their own requirements by default as it is done with RAM quota. The CPU quota that a process owns can be applied through the thread constructor. The constructor has been enhanced by an argument that indicates the percentage of the programs CPU quota that shall be granted to the new thread. So 'Thread(33, "test")' would cause the backing CPU session to try to grant 33% of the programs CPU quota to the thread "test". By now, the CPU quota of a thread can't be altered after construction. Constructing a thread with CPU quota 0 doesn't mean the thread gets never scheduled but that the thread has no guaranty to receive CPU time. Such threads have to live with excess CPU time. Threads that already existed in the official repositories of Genode were adapted in the way that they receive a quota of 0. This commit also provides a run test 'cpu_quota' in base-hw (the only kernel that applies the CPU-quota scheme currently). The test basically runs three threads with different physical CPU quota. The threads simply count for 30 seconds each and the test then checks wether the counter values relate to the CPU-quota distribution. fix #1275
162 lines
4.0 KiB
Plaintext
162 lines
4.0 KiB
Plaintext
#
|
|
# Build
|
|
#
|
|
|
|
build "core init drivers/timer test/cpu_quota"
|
|
|
|
#
|
|
# Boot image
|
|
#
|
|
|
|
create_boot_directory
|
|
|
|
install_config {
|
|
<config prio_levels="4">
|
|
<parent-provides>
|
|
<service name="ROM"/>
|
|
<service name="RAM"/>
|
|
<service name="IRQ"/>
|
|
<service name="IO_MEM"/>
|
|
<service name="CAP"/>
|
|
<service name="PD"/>
|
|
<service name="RM"/>
|
|
<service name="CPU"/>
|
|
<service name="LOG"/>
|
|
<service name="SIGNAL"/>
|
|
</parent-provides>
|
|
<default-route>
|
|
<any-service><parent/><any-child/></any-service>
|
|
</default-route>
|
|
|
|
<start name="timer">
|
|
<resource name="RAM" quantum="10M"/>
|
|
<provides><service name="Timer"/></provides>
|
|
</start>
|
|
|
|
<start name="init_1" priority="-1">
|
|
<binary name="init"/>
|
|
<resource name="RAM" quantum="10M"/>
|
|
<resource name="CPU" quantum="10"/>
|
|
<config prio_levels="2">
|
|
<parent-provides>
|
|
<service name="ROM"/>
|
|
<service name="RAM"/>
|
|
<service name="IRQ"/>
|
|
<service name="IO_MEM"/>
|
|
<service name="CAP"/>
|
|
<service name="PD"/>
|
|
<service name="RM"/>
|
|
<service name="CPU"/>
|
|
<service name="LOG"/>
|
|
<service name="SIGNAL"/>
|
|
<service name="Timer"/>
|
|
</parent-provides>
|
|
<default-route>
|
|
<any-service><parent/><any-child/></any-service>
|
|
</default-route>
|
|
|
|
<!-- should receive 10 % of the CPU time -->
|
|
<start name="test_slow" priority="-1">
|
|
<binary name="test-cpu_quota"/>
|
|
<resource name="RAM" quantum="10M"/>
|
|
<resource name="CPU" quantum="50"/>
|
|
</start>
|
|
|
|
</config>
|
|
</start>
|
|
|
|
<start name="init_2" priority="-2">
|
|
<binary name="init"/>
|
|
<resource name="RAM" quantum="100M"/>
|
|
<resource name="CPU" quantum="80"/>
|
|
<config>
|
|
<parent-provides>
|
|
<service name="ROM"/>
|
|
<service name="RAM"/>
|
|
<service name="CPU"/>
|
|
<service name="RM"/>
|
|
<service name="CAP"/>
|
|
<service name="PD"/>
|
|
<service name="LOG"/>
|
|
<service name="SIGNAL"/>
|
|
<service name="Timer"/>
|
|
</parent-provides>
|
|
<default-route>
|
|
<any-service><parent/></any-service>
|
|
</default-route>
|
|
|
|
<!-- should receive 25 % of the CPU time -->
|
|
<start name="test_middle">
|
|
<binary name="test-cpu_quota"/>
|
|
<resource name="RAM" quantum="10M"/>
|
|
<resource name="CPU" quantum="25"/>
|
|
</start>
|
|
|
|
<!-- should receive 65 % of the CPU time -->
|
|
<start name="test_fast">
|
|
<binary name="test-cpu_quota"/>
|
|
<resource name="RAM" quantum="10M"/>
|
|
<resource name="CPU" quantum="75"/>
|
|
</start>
|
|
|
|
</config>
|
|
</start>
|
|
</config>
|
|
}
|
|
|
|
build_boot_image "core init timer test-cpu_quota"
|
|
|
|
#
|
|
# Execution
|
|
#
|
|
|
|
append qemu_args "-nographic -m 64"
|
|
|
|
run_genode_until "test.*\n.*test.*\n.*test.*\n" 60
|
|
|
|
#
|
|
# Conclusion
|
|
#
|
|
|
|
set slow_opt 0.10
|
|
set middle_opt 0.25
|
|
set fast_opt 0.65
|
|
set err 0.02
|
|
|
|
regexp {[0-9]+} [regexp -inline {slow.*[0-9]+} $output] slow_cnt
|
|
regexp {[0-9]+} [regexp -inline {middle.*[0-9]+} $output] middle_cnt
|
|
regexp {[0-9]+} [regexp -inline {fast.*[0-9]+} $output] fast_cnt
|
|
set total_cnt [expr $fast_cnt + $middle_cnt + $slow_cnt]
|
|
|
|
set slow_fac [expr $slow_cnt / double($total_cnt) ]
|
|
set middle_fac [expr $middle_cnt / double($total_cnt) ]
|
|
set fast_fac [expr $fast_cnt / double($total_cnt) ]
|
|
|
|
set failed 0
|
|
if {[expr $slow_fac > $slow_opt + $err || $slow_fac < $slow_opt - $err]} {
|
|
set is_pc [expr round($slow_fac * 10000) / 100]
|
|
set opt_pc [expr round($slow_opt * 10000) / 100]
|
|
puts stderr "Error: Slow counter received $is_pc% of the CPU time."
|
|
puts stderr " Should receive $opt_pc%."
|
|
set failed 1
|
|
}
|
|
if {[expr $middle_fac > $middle_opt + $err || $middle_fac < $middle_opt - $err]} {
|
|
set is_pc [expr round($middle_fac * 10000) / 100]
|
|
set opt_pc [expr round($middle_opt * 10000) / 100]
|
|
puts stderr "Error: Middle counter received $is_pc% of the CPU time."
|
|
puts stderr " Should receive $opt_pc%."
|
|
set failed 1
|
|
}
|
|
if {[expr $fast_fac > $fast_opt + $err || $fast_fac < $fast_opt - $err]} {
|
|
set is_pc [expr round($fast_fac * 10000) / 100]
|
|
set opt_pc [expr round($fast_opt * 10000) / 100]
|
|
puts stderr "Error: Fast counter received $is_pc% of the CPU time."
|
|
puts stderr " Should receive $opt_pc%."
|
|
set failed 1
|
|
}
|
|
if {$failed} {
|
|
exit -1
|
|
} else {
|
|
puts "Test succeeded"
|
|
}
|