1

Cgroups allow artificially limiting CPU time available to a process using cpu.cfs_quota_us and cpu.cfs_period_us parameters.

This however results in a discrepancy when the program monitors its CPU usage (e.g. by comparing wall time and CPU time) and graceful degradation algorithms (such as decreasing quality of something realtime) may not kick in.

How do I make the program think it consumes 100% of CPU while limiting it with a cgroup policy?

Vi.
  • 5,528
  • 7
  • 34
  • 68
  • well, your graceful degradation isn't coded appropriately – assuming any program could have an amount of up to 100% of CPU time was never correct, and especially under Linux, with RT_PRIO and whatnot in the mainline sincew 2.6.18 . In practice, such algorithms should be coded to analyze the discrepancy between the time they'd like to have of a certain period (say, 1s) and what they've got (say, 0.1s). – Marcus Müller Aug 11 '21 at 14:01
  • (plus, honestly, if you've got something you can gracefully degrade, then you'll want to have some control theory approach, which will probably incorporate both a differential and integral part of the observed want-to-have ratio, which (can) completely eradicate the need for 100% to be of any special meaning) – Marcus Müller Aug 11 '21 at 14:15
  • It may be a third party program and the algorithm may be rather simple: if CPU usage gets over certain threshold (e.g. 85%) then switch to other mode. – Vi. Aug 11 '21 at 14:20
  • yeah, but then that third-party program never worked well – don't know whether we really should be discussing how to fix bad software? I mean your question literally describes the way out – compare your own scheduled time to some "should-be" value. Just don't use the wall clock time, that rarely, if ever, makes sense (plus it comes with a context switch to get that time, so it's quite expensive. been there, benchmarked that) – Marcus Müller Aug 11 '21 at 14:21
  • This is mostly needed to test software, not to develop/fix it. Simulating running on a weak system more realistically than just with cgroups alone. – Vi. Aug 11 '21 at 14:22
  • hm. Again, are you *sure* the software under consideration compares its CPU time to wall clock time? I've never encountered that, and you might be trying to solve a hard-to-solve problem that's not actually there. – Marcus Müller Aug 11 '21 at 16:44

0 Answers0