@@ -273,7 +273,7 @@ class SchedulerPlugin(base.Plugin):
273
273
processes are not processed by the scheduler plug-in.
274
274
+
275
275
The CPU overhead of the scheduler plugin can be mitigated by using
276
- the scheduler [option]`runtime ` option and setting it to `0`. This
276
+ the scheduler [option]`dynamic ` option and setting it to `0`. This
277
277
will completely disable the dynamic scheduler functionality and the
278
278
perf events will not be monitored and acted upon. The disadvantage
279
279
ot this approach is the procees/thread tuning will be done only at
@@ -283,7 +283,7 @@ class SchedulerPlugin(base.Plugin):
283
283
====
284
284
----
285
285
[scheduler]
286
- runtime =0
286
+ dynamic =0
287
287
isolated_cores=1,3
288
288
----
289
289
====
@@ -465,6 +465,10 @@ def supports_static_tuning(cls):
465
465
466
466
@classmethod
467
467
def supports_dynamic_tuning (cls ):
468
+ return True
469
+
470
+ @classmethod
471
+ def uses_periodic_tuning (cls ):
468
472
return False
469
473
470
474
def _calc_mmap_pages (self , mmap_pages ):
@@ -482,10 +486,6 @@ def _calc_mmap_pages(self, mmap_pages):
482
486
def _instance_init (self , instance ):
483
487
super (SchedulerPlugin , self )._instance_init (instance )
484
488
instance ._evlist = None
485
- # this is hack, runtime_tuning should be covered by dynamic_tuning configuration
486
- # TODO: add per plugin dynamic tuning configuration and use dynamic_tuning configuration
487
- # instead of runtime_tuning
488
- instance ._runtime_tuning = True
489
489
490
490
# FIXME: do we want to do this here?
491
491
# recover original values in case of crash
@@ -510,42 +510,44 @@ def _instance_init(self, instance):
510
510
instance ._scheduler = instance .options
511
511
512
512
perf_mmap_pages_raw = self ._variables .expand (instance .options ["perf_mmap_pages" ])
513
- perf_mmap_pages = self ._calc_mmap_pages (perf_mmap_pages_raw )
514
- if perf_mmap_pages == 0 :
513
+ instance . _perf_mmap_pages = self ._calc_mmap_pages (perf_mmap_pages_raw )
514
+ if instance . _perf_mmap_pages == 0 :
515
515
log .error ("Invalid 'perf_mmap_pages' value specified: '%s', using default kernel value" % perf_mmap_pages_raw )
516
- perf_mmap_pages = None
517
- if perf_mmap_pages is not None and str (perf_mmap_pages ) != perf_mmap_pages_raw :
516
+ instance . _perf_mmap_pages = None
517
+ if instance . _perf_mmap_pages is not None and str (instance . _perf_mmap_pages ) != perf_mmap_pages_raw :
518
518
log .info ("'perf_mmap_pages' value has to be power of two, specified: '%s', using: '%d'" %
519
- (perf_mmap_pages_raw , perf_mmap_pages ))
519
+ (perf_mmap_pages_raw , instance . _perf_mmap_pages ))
520
520
for k in instance ._scheduler :
521
521
instance ._scheduler [k ] = self ._variables .expand (instance ._scheduler [k ])
522
- if self ._cmd .get_bool (instance ._scheduler .get ("runtime" , 1 )) == "0" :
523
- instance ._runtime_tuning = False
524
- instance ._terminate = threading .Event ()
525
- if self ._daemon and instance ._runtime_tuning :
526
- try :
527
- instance ._threads = perf .thread_map ()
528
- evsel = perf .evsel (type = perf .TYPE_SOFTWARE ,
529
- config = perf .COUNT_SW_DUMMY ,
530
- task = 1 , comm = 1 , mmap = 0 , freq = 0 ,
531
- wakeup_events = 1 , watermark = 1 ,
532
- sample_type = perf .SAMPLE_TID | perf .SAMPLE_CPU )
533
- evsel .open (cpus = self ._cpus , threads = instance ._threads )
534
- instance ._evlist = perf .evlist (self ._cpus , instance ._threads )
535
- instance ._evlist .add (evsel )
536
- if perf_mmap_pages is None :
537
- instance ._evlist .mmap ()
538
- else :
539
- instance ._evlist .mmap (pages = perf_mmap_pages )
540
- # no perf
541
- except :
542
- instance ._runtime_tuning = False
543
522
544
523
def _instance_cleanup (self , instance ):
545
524
if instance ._evlist :
546
525
for fd in instance ._evlist .get_pollfd ():
547
526
os .close (fd .name )
548
527
528
+ def _instance_init_dynamic (self , instance ):
529
+ super (SchedulerPlugin , self )._instance_init_dynamic (instance )
530
+ instance ._terminate = threading .Event ()
531
+ try :
532
+ instance ._threads = perf .thread_map ()
533
+ evsel = perf .evsel (type = perf .TYPE_SOFTWARE ,
534
+ config = perf .COUNT_SW_DUMMY ,
535
+ task = 1 , comm = 1 , mmap = 0 , freq = 0 ,
536
+ wakeup_events = 1 , watermark = 1 ,
537
+ sample_type = perf .SAMPLE_TID | perf .SAMPLE_CPU )
538
+ evsel .open (cpus = self ._cpus , threads = instance ._threads )
539
+ instance ._evlist = perf .evlist (self ._cpus , instance ._threads )
540
+ instance ._evlist .add (evsel )
541
+ if instance ._perf_mmap_pages is None :
542
+ instance ._evlist .mmap ()
543
+ else :
544
+ instance ._evlist .mmap (pages = instance ._perf_mmap_pages )
545
+ instance ._thread = threading .Thread (target = self ._thread_code , args = [instance ])
546
+ instance ._thread .start ()
547
+ # no perf
548
+ except Exception :
549
+ instance ._dynamic_tuning_enabled = False
550
+
549
551
@classmethod
550
552
def _get_config_options (cls ):
551
553
return {
@@ -949,7 +951,7 @@ def _instance_apply_static(self, instance):
949
951
and len (vals ) == 5 ]
950
952
sched_cfg = sorted (buf , key = lambda option_vals : option_vals [1 ][0 ])
951
953
sched_all = dict ()
952
- # for runtime tuning
954
+ # for dynamic tuning
953
955
instance ._sched_lookup = {}
954
956
for option , (rule_prio , scheduler , priority , affinity , regex ) \
955
957
in sched_cfg :
@@ -973,9 +975,6 @@ def _instance_apply_static(self, instance):
973
975
priority , affinity )
974
976
self ._storage .set (self ._scheduler_storage_key ,
975
977
self ._scheduler_original )
976
- if self ._daemon and instance ._runtime_tuning :
977
- instance ._thread = threading .Thread (target = self ._thread_code , args = [instance ])
978
- instance ._thread .start ()
979
978
980
979
def _restore_ps_affinity (self ):
981
980
try :
@@ -1020,9 +1019,6 @@ def _cgroup_cleanup_tasks(self):
1020
1019
1021
1020
def _instance_unapply_static (self , instance , rollback = consts .ROLLBACK_SOFT ):
1022
1021
super (SchedulerPlugin , self )._instance_unapply_static (instance , rollback )
1023
- if self ._daemon and instance ._runtime_tuning :
1024
- instance ._terminate .set ()
1025
- instance ._thread .join ()
1026
1022
self ._restore_ps_affinity ()
1027
1023
self ._cgroup_restore_affinity ()
1028
1024
self ._cgroup_cleanup_tasks ()
@@ -1031,6 +1027,10 @@ def _instance_unapply_static(self, instance, rollback = consts.ROLLBACK_SOFT):
1031
1027
if self ._cgroup_mount_point_init :
1032
1028
self ._cgroup_finalize ()
1033
1029
1030
+ def _instance_deinit_dynamic (self , instance ):
1031
+ instance ._terminate .set ()
1032
+ instance ._thread .join ()
1033
+
1034
1034
def _cgroup_verify_affinity_one (self , cgroup , affinity ):
1035
1035
log .debug ("Verifying cgroup '%s' affinity" % cgroup )
1036
1036
path = "%s/%s/%s" % (self ._cgroup_mount_point , cgroup , "cpuset.cpus" )
0 commit comments