VULN_CHECK_I913V6 GiddlmZddlddlZddlZddlddlZ ddlZddl Z ddl m Z ddl Z ddlmZddlZddlZddlZddlZ ej(ej.j1ZGddeZGdd eZGd d eZGd d eZGddej>Z y#e $rYwxYw#e$rddlZYrwxYw))base)*N)commandscLeZdZ ddZedZej dZy)SchedulerParamsNcX||_||_||_||_||_||_yN)_cmdcmdline schedulerpriorityaffinitycgroup)selfcmdr r rrrs C/usr/lib/python3.12/site-packages/tuned/plugins/plugin_scheduler.py__init__zSchedulerParams.__init__"s,$)$,$.$-$-$+cf|jy|jj|jSr ) _affinityr bitmask2cpulistrs rrzSchedulerParams.affinity+s( ^^  )) # #DNN 33rcX|d|_y|jj||_yr )rr cpulist2bitmaskrvalues rrzSchedulerParams.affinity2s$ ]4>II--e44>r)NNNNN)__name__ __module__ __qualname__rpropertyrsetterrrrr!s959.2 4 4  //55rrceZdZdZy) IRQAffinitiesc.i|_d|_g|_yr )irqsdefault unchangeablers rrzIRQAffinities.__init__:s$)$,$rN)rrr rr#rrr%r%9srr%c\eZdZdZddddddZdZd Zd Zd Zd Z d Z dZ dZ dZ dZy)SchedulerUtilsz= Class encapsulating scheduler implementation in os module SCHED_FIFO SCHED_BATCHSCHED_RR SCHED_OTHER SCHED_IDLE)fbroictd|jjD|_td|jj D|_y)Nc3FK|]\}}|tt|fywr getattros.0knames r z*SchedulerUtils.__init__..Os# nGmGAt!WR%6!7Gm!c3@K|]}tt||fywr r8r<r>s rr?z*SchedulerUtils.__init__..Qs"qIpGB$5t#.us# vOuGAt!WZ%>!?Our@c3@K|]}tt||fywr rurBs rr?z4SchedulerUtilsSchedutils.__init__..ws"yQxGJ$=t#DQxrCrDrs rrz!SchedulerUtilsSchedutils.__init__ssG vtOmOmOsOsOu vv$""yQUQoQoQvQvQx"yy$rc,tj|Sr )rvrUrSs rrUz&SchedulerUtilsSchedutils.get_schedulerys  ! !# &&rc2tj|||yr )rvr\rYs rr\z&SchedulerUtilsSchedutils.set_scheduler|s 3t,rc,tj|Sr )rvr_rSs rr_z%SchedulerUtilsSchedutils.get_affinity   %%rc0tj||yr )rvrcrbs rrcz%SchedulerUtilsSchedutils.set_affinitys #x(rc,tj|Sr )rvrgrSs rrgz%SchedulerUtilsSchedutils.get_priorityr{rc,tj|Sr )rvrkrjs rrkz)SchedulerUtilsSchedutils.get_priority_min  $ $U ++rc,tj|Sr )rvrorjs rroz)SchedulerUtilsSchedutils.get_priority_maxrrN) rrr rprrUr\r_rcrgrkror#rrrrrros0z '-&)&,,rrrcJeZdZdZddddZdZfdZdZdZd Z e d Z d Z d Z d ZdZdZdZdZdZdZdZdZdzdZdZdZdZdzdZdZdZdZdZd Z d!Z!d"Z"d#Z#d$Z$d%Z%dzd&Z&d'Z'd(Z(fd)Z)d*Z*d+Z+d,Z,e-j\ffd- Z/d.Z0d/Z1fd0Z2d1Z3d2Z4d3Z5e6d4d5d6Z7e6d7d5d8Z8e6d9d5d:Z9e6d;d5d<Z:e6d=d5d>Z;e6d?d5d@Z<e6dAd5dBZ=dCZ>dDZ?dEZ@dzdFZAdGZBdHZCdIZDdJZEdKZFdLZGdMZHdNZIdOZJe6dPddQRdSZKdTZLdUZMdVZNdWZOdzdXZPeQdYdZZReSdYd[ZTeQd\d]ZUeSd\d^ZVeQd_d`ZWeSd_daZXeQdbdcZYeSdbddZZeQdedfZ[eSdedgZ\eQdhdiZ]eSdhdjZ^eQdkdlZ_eSdkdmZ`eQdndoZaeSdndpZbeQdqdrZceSdqdsZdeQdtduZeeSdtdvZfeQdwdxZgeSdwdyZhxZiS){SchedulerPluginaX. Allows tuning of scheduling priorities, process/thread/IRQ affinities, and CPU isolation. To prevent processes/threads/IRQs from using certain CPUs, use the [option]`isolated_cores` option. It changes process/thread affinities, IRQs affinities and it sets `default_smp_affinity` for IRQs. The CPU affinity mask is adjusted for all processes and threads matching [option]`ps_whitelist` option subject to success of the `sched_setaffinity()` system call. The default setting of the [option]`ps_whitelist` regular expression is `.*` to match all processes and thread names. To exclude certain processes and threads use [option]`ps_blacklist` option. The value of this option is also interpreted as a regular expression and process/thread names (`ps -eo cmd`) are matched against that expression. Profile rollback allows all matching processes and threads to run on all CPUs and restores the IRQ settings prior to the profile application. Multiple regular expressions for [option]`ps_whitelist` and [option]`ps_blacklist` options are allowed and separated by `;`. Quoted semicolon `\;` is taken literally. .Isolate CPUs 2-4 ==== ---- [scheduler] isolated_cores=2-4 ps_blacklist=.*pmd.*;.*PMD.*;^DPDK;.*qemu-kvm.* ---- Isolate CPUs 2-4 while ignoring processes and threads matching `ps_blacklist` regular expressions. ==== The [option]`irq_process` option controls whether the scheduler plugin applies the `isolated_cores` parameter to IRQ affinities. The default value is `true`, which means that the scheduler plugin will move all possible IRQs away from the isolated cores. When `irq_process` is set to `false`, the plugin will not change any IRQ affinities. The [option]`default_irq_smp_affinity` option controls the values *TuneD* writes to `/proc/irq/default_smp_affinity`. The file specifies default affinity mask that applies to all non-active IRQs. Once an IRQ is allocated/activated its affinity bitmask will be set to the default mask. The following values are supported: * `calc` + The content of `/proc/irq/default_smp_affinity` will be calculated from the `isolated_cores` parameter. Non-isolated cores are calculated as an inversion of the `isolated_cores`. Then the intersection of the non-isolated cores and the previous content of `/proc/irq/default_smp_affinity` is written to `/proc/irq/default_smp_affinity`. If the intersection is an empty set, then just the non-isolated cores are written to `/proc/irq/default_smp_affinity`. This behavior is the default if the parameter `default_irq_smp_affinity` is omitted. * `ignore` + *TuneD* will not touch `/proc/irq/default_smp_affinity`. * an explicit cpulist + The cpulist (such as `1,3-4`) is unpacked and written directly to `/proc/irq/default_smp_affinity`. .An explicit CPU list to set the default IRQ smp affinity to CPUs 0 and 2 ==== ---- [scheduler] isolated_cores=1,3 default_irq_smp_affinity=0,2 ---- ==== To adjust scheduling policy, priority and affinity for a group of processes/threads, use the following syntax. [subs="quotes"] ---- group.__groupname__=__rule_prio__:__sched__:__prio__:__affinity__:__regex__ ---- Here, `__rule_prio__` defines internal *TuneD* priority of the rule. Rules are sorted based on priority. This is needed for inheritence to be able to reorder previously defined rules. Equal `__rule_prio__` rules should be processed in the order they were defined. However, this is Python interpreter dependant. To disable an inherited rule for `__groupname__` use: [subs="quotes"] ---- group.__groupname__= ---- `__sched__` must be one of: *`f`* for FIFO, *`b`* for batch, *`r`* for round robin, *`o`* for other, *`*`* do not change. `__affinity__` is CPU affinity in hexadecimal. Use `*` for no change. `__prio__` scheduling priority (see `chrt -m`). `__regex__` is Python regular expression. It is matched against the output of: [subs="quotes"] ---- ps -eo cmd ---- Any given process name may match more than one group. In such a case, the priority and scheduling policy are taken from the last matching `__regex__`. .Setting scheduling policy and priorities to kernel threads and watchdog ==== ---- [scheduler] group.kthreads=0:*:1:*:\[.*\]$ group.watchdog=0:f:99:*:\[watchdog.*\] ---- ==== The scheduler plug-in uses perf event loop to catch newly created processes. By default it listens to `perf.RECORD_COMM` and `perf.RECORD_EXIT` events. By setting [option]`perf_process_fork` option to `true`, `perf.RECORD_FORK` events will be also listened to. In other words, child processes created by the `fork()` system call will be processed. Since child processes inherit CPU affinity from their parents, the scheduler plug-in usually does not need to explicitly process these events. As processing perf events can pose a significant CPU overhead, the [option]`perf_process_fork` option parameter is set to `false` by default. Due to this, child processes are not processed by the scheduler plug-in. The CPU overhead of the scheduler plugin can be mitigated by using the scheduler [option]`runtime` option and setting it to `0`. This will completely disable the dynamic scheduler functionality and the perf events will not be monitored and acted upon. The disadvantage ot this approach is the procees/thread tuning will be done only at profile application. .Disabling the scheduler dynamic functionality ==== ---- [scheduler] runtime=0 isolated_cores=1,3 ---- ==== NOTE: For perf events, memory mapped buffer is used. Under heavy load the buffer may overflow. In such cases the `scheduler` plug-in may start missing events and failing to process some newly created processes. Increasing the buffer size may help. The buffer size can be set with the [option]`perf_mmap_pages` option. The value of this parameter has to expressed in powers of 2. If it is not the power of 2, the nearest higher power of 2 value is calculated from it and this calculated value used. If the [option]`perf_mmap_pages` option is omitted, the default kernel value is used. The scheduler plug-in supports process/thread confinement using cgroups v1. [option]`cgroup_mount_point` option specifies the path to mount the cgroup filesystem or where *TuneD* expects it to be mounted. If unset, `/sys/fs/cgroup/cpuset` is expected. If [option]`cgroup_groups_init` option is set to `1` *TuneD* will create (and remove) all cgroups defined with the `cgroup*` options. This is the default behavior. If it is set to `0` the cgroups need to be preset by other means. If [option]`cgroup_mount_point_init` option is set to `1`, *TuneD* will create (and remove) the cgroup mountpoint. It implies `cgroup_groups_init = 1`. If set to `0` the cgroups mount point needs to be preset by other means. This is the default behavior. The [option]`cgroup_for_isolated_cores` option is the cgroup name used for the [option]`isolated_cores` option functionality. For example, if a system has 4 CPUs, `isolated_cores=1` means that all processes/threads will be moved to CPUs 0,2-3. The scheduler plug-in will isolate the specified core by writing the calculated CPU affinity to the `cpuset.cpus` control file of the specified cgroup and move all the matching processes/threads to this group. If this option is unset, classic cpuset affinity using `sched_setaffinity()` will be used. [option]`cgroup.__cgroup_name__` option defines affinities for arbitrary cgroups. Even hierarchic cgroups can be used, but the hieararchy needs to be specified in the correct order. Also *TuneD* does not do any sanity checks here, with the exception that it forces the cgroup to be under [option]`cgroup_mount_point`. The syntax of the scheduler option starting with `group.` has been augmented to use `cgroup.__cgroup_name__` instead of the hexadecimal `__affinity__`. The matching processes will be moved to the cgroup `__cgroup_name__`. It is also possible to use cgroups which have not been defined by the [option]`cgroup.` option as described above, i.e. cgroups not managed by *TuneD*. All cgroup names are sanitized by replacing all all dots (`.`) with slashes (`/`). This is to prevent the plug-in from writing outside [option]`cgroup_mount_point`. .Using cgroups v1 with the scheduler plug-in ==== ---- [scheduler] cgroup_mount_point=/sys/fs/cgroup/cpuset cgroup_mount_point_init=1 cgroup_groups_init=1 cgroup_for_isolated_cores=group cgroup.group1=2 cgroup.group2=0,2 group.ksoftirqd=0:f:2:cgroup.group1:ksoftirqd.* ps_blacklist=ksoftirqd.*;rcuc.*;rcub.*;ktimersoftd.* isolated_cores=1 ---- Cgroup `group1` has the affinity set to CPU 2 and the cgroup `group2` to CPUs 0,2. Given a 4 CPU setup, the [option]`isolated_cores=1` option causes all processes/threads to be moved to CPU cores 0,2-3. Processes/threads that are blacklisted by the [option]`ps_blacklist` regular expression will not be moved. The scheduler plug-in will isolate the specified core by writing the CPU affinity 0,2-3 to the `cpuset.cpus` control file of the `group` and move all the matching processes/threads to this cgroup. ==== Option [option]`cgroup_ps_blacklist` allows excluding processes which belong to the blacklisted cgroups. The regular expression specified by this option is matched against cgroup hierarchies from `/proc/PID/cgroups`. Cgroups v1 hierarchies from `/proc/PID/cgroups` are separated by commas ',' prior to regular expression matching. The following is an example of content against which the regular expression is matched against: `10:hugetlb:/,9:perf_event:/,8:blkio:/` Multiple regular expressions can be separated by semicolon ';'. The semicolon represents a logical 'or' operator. .Cgroup-based exclusion of processes from the scheduler ==== ---- [scheduler] isolated_cores=1 cgroup_ps_blacklist=:/daemons\b ---- The scheduler plug-in will move all processes away from core 1 except processes which belong to cgroup '/daemons'. The '\b' is a regular expression metacharacter that matches a word boundary. ---- [scheduler] isolated_cores=1 cgroup_ps_blacklist=\b8:blkio: ---- The scheduler plug-in will exclude all processes which belong to a cgroup with hierarchy-ID 8 and controller-list blkio. ==== Kernels 5.13 and newer moved some `sched_` and `numa_balancing_` kernel run-time parameters from `/proc/sys/kernel`, managed by the `sysctl` utility, to `debugfs`, typically mounted under `/sys/kernel/debug`. TuneD provides an abstraction mechanism for the following parameters via the scheduler plug-in: [option]`sched_min_granularity_ns`, [option]`sched_latency_ns`, [option]`sched_wakeup_granularity_ns`, [option]`sched_tunable_scaling`, [option]`sched_migration_cost_ns`, [option]`sched_nr_migrate`, [option]`numa_balancing_scan_delay_ms`, [option]`numa_balancing_scan_period_min_ms`, [option]`numa_balancing_scan_period_max_ms` and [option]`numa_balancing_scan_size_mb`. Moreover in kernel 6.6 and newer support for the `sched_wakeup_granularity_ns` and `sched_latency_ns` were removed. The `sched_min_granularity_ns` was renamed to `sched_base_slice_ns`. Based on the kernel used, TuneD will write the specified value to the correct location or ignore it. For the compatibility the alias [option]`sched_base_slice_ns` was added, but the [option]`sched_min_granularity_ns` can be still used instead. .Set tasks' "cache hot" value for migration decisions. ==== ---- [scheduler] sched_migration_cost_ns=500000 ---- On the old kernels, this is equivalent to: ---- [sysctl] kernel.sched_migration_cost_ns=500000 ---- that is, value `500000` will be written to `/proc/sys/kernel/sched_migration_cost_ns`. However, on more recent kernels, the value `500000` will be written to `/sys/kernel/debug/sched/migration_cost_ns`. ==== base_slice_ns)wakeup_granularity_nsmin_granularity_ns latency_nsc<tjdd|_y)Nzupython-perf unavailable, disabling perf support and runtime tuning, you can try to (re)install python(3)-perf packageF)logwarning_perf_availablers r _disable_perfzSchedulerPlugin._disable_perfs++GH$rc tt| ||||||||d|_tj |_ttj|_ |o|jtjtj |_t|jtjtj|_ t|_d|_i|_d|_d|_d|_d|_d|_ t/j0|_|j=d|_d|_ |j=d|_!d|_" tG|_$y#t4t6f$r2|j9|jj;|_YwxYw#t6$rtK|_$YywxYw)NTz.*rr ) command_nameirq)&superrr_has_dynamic_optionsconstsCFG_DEF_DAEMON_daemonintCFG_DEF_SLEEP_INTERVAL_sleep_intervalget_bool CFG_DAEMONrLCFG_SLEEP_INTERVALrr _secure_boot_hint_sched_knob_paths_cache _ps_whitelist _ps_blacklist_kthread_process_cgroup_ps_blacklist_rerperfcpu_map_cpus NameErrorAttributeErrorrget_cpus _storage_key_scheduler_storage_key _irq_process_irq_storage_key_evlistr+_scheduler_utilsrr) rmonitor_repositorystorage_factoryhardware_inventorydevice_matcherdevice_matcher_udevplugin_instance_factory global_cfg variables __class__s rrzSchedulerPlugin.__init__s'(:OM_aorEG^`jluv"$&&$,V::;$%%f&7&79N9NO4<jnnV-F-FHeHefg4j$)$!#$$$$!#$$% 4:!% 1 1!2! $$++,$$,6)+4 ^ $% ""$4: % 63546s$E.F2.>F/.F/2G  G c |y t|}|dkrytdtjtj|dzS#t$rYywxYw)Nr)r ValueErrormathceilr)r mmap_pagesmps r_calc_mmap_pagesz SchedulerPlugin._calc_mmap_pagess\   J21W Q$))DHHRO, , --   s A AAc d|_d|_d|_d|_|jj |j i|_t|jdkDrQtjd|ji|_|jj|j t|_d|_d|_d|_t%j&|j(j+Dcgc]J\}}|dddk(r=t|dkDr/|j-|dd|j.j1|fLc}}|_|j(|_|j.j1|j(d}|j7|}|dk(rtj9d|zd}|(t;||k7rtjd ||fz|j4D]7}|j.j1|j4||j4|<9|j<j?|j4j d d d k(rd|_tAjB|_"|jFr7|jr*|jHr tKjL|_'tKjPtJjRtJjTd d ddd d tJjVtJjXz }|j[|j\|jNtKj^|j\|jN|_|jja|||jjcn|jjc||jHsd|_yycc}}w#|jeY/xYw)NFTrz0recovering scheduling settings from previous runcgroup.perf_mmap_pageszKInvalid 'perf_mmap_pages' value specified: '%s', using default kernel valuezL'perf_mmap_pages' value has to be power of two, specified: '%s', using: '%d'runtimer0) typeconfigtaskcommmmapfreq wakeup_events watermark sample_type)cpusthreads)pages)3r_has_dynamic_tuning_has_static_tuning_runtime_tuning_storagerLr_scheduler_originallenrinfo_restore_ps_affinityunsetrE_cgroups_original_affinityr_cgroup_affinity_initialized_cgroup collections OrderedDictoptionsrG_sanitize_cgroup_path _variablesexpand_cgroups _schedulerrerrorstrr r threadingEvent _terminaterrr thread_map_threadsevsel TYPE_SOFTWARECOUNT_SW_DUMMY SAMPLE_TID SAMPLE_CPUopenrevlistaddrr)rinstanceoptionrperf_mmap_pages_rawrr=rs r_instance_initzSchedulerPlugin._instance_initsb(!&( $("("]]..%$ ! !"Q&88 >? 4==t223$(F$!$.&+$#$,))#++113+d3vxvbqzY7NSVW]S^abSb-1,F,Fvabz,RTXTcTcTjTjksTt+u3+de$-!(((..x/?/?@Q/RS))*=>/99 Z]p pq? S%9=P%P88 Z/* +,   a OO2283F3Fq3IJ8q  YY++// 1=>#E#8!)( \\h..43G3G)H JJd00!! a!A??T__4  6E  JJdjjH,=,=J>{{4::x/@/@AH   ?3   #8 I+dDsAO' 6DO--Pc|jr?|jjD]!}tj|j#yyr )r get_pollfdr:closer>)rrfds r_instance_cleanupz!SchedulerPlugin._instance_cleanup;s9     ( ( *rHHRWW+rc idddtjddddddddd dd dd dd dd dddddddddddddddddddddS)Nisolated_corescgroup_mount_pointcgroup_mount_point_initFcgroup_groups_initTcgroup_for_isolated_corescgroup_ps_blacklist ps_whitelist ps_blacklistkthread_process irq_processdefault_irq_smp_affinitycalcrperf_process_forkfalsesched_min_granularity_nssched_base_slice_nssched_latency_nssched_wakeup_granularity_ns)sched_tunable_scalingsched_migration_cost_nssched_nr_migratenuma_balancing_scan_delay_ms!numa_balancing_scan_period_min_ms!numa_balancing_scan_period_max_msnuma_balancing_scan_size_mb)rDEF_CGROUP_MOUNT_POINT)clss r_get_config_optionsz#SchedulerPlugin._get_config_options@s T 66 e       $  4 4 d $ v d  t $  t! "!$# $!"#'(,(,"&1 rc@|t|jddSdS)N./)rreplacers rrz%SchedulerPlugin._sanitize_cgroup_path]s#).):U  C %DDrct|tjs|}tj|}tj|}|j |rd|zdz}|S)N[]) isinstanceprocfsprocessprocess_cmdline _is_kthread)rr"rTr s r _get_cmdlinezSchedulerPlugin._get_cmdlineasT GV^^ , 3 ^^C 7  " "7 +' g 7]S 7 .rctj}|ji}|jD]n} |js|j |r"|j |}|d}|||<d|vr.|djD]}|j |}|||<p|S#ttf$rE}|jtjk(s|jtjk(rYd}~d}~wwxYw)NrTr) r!pidstatsreload_threadsrIrr$r%keysOSErrorIOErrorerrnoENOENTESRCH)rps processesprocrrTes r get_processeszSchedulerPlugin.get_processesks ")iikd  T%5%5d%;   D !C u+CIcNDY$$&   d #cin'"  G  ww%,, EKK    s$B*A B**C>9:C98C99C>c|jj|}|jj|}|jj|}tj d|||fz||fS)Nz8Read scheduler policy '%s' and priority '%d' of PID '%d')rrUrPrgrdebug)rrTr sched_strrs r_get_rtzSchedulerPlugin._get_rtsm##11#6)##66yA)  " " / / 4()) F(C  !" X rc|jj|}tjd|||fz |jj |}|jj |}||ks||kDrtj d||||fz |jj|||y#ttf$r"}tj d|zYd}~Kd}~wwxYw#ttf$rk}t|dr6|jtjk(rtjd|zntj d||fzYd}~yYd}~yd}~wwxYw)NzBSetting scheduler policy to '%s' and priority to '%d' of PID '%d'.z9Priority for %s must be in range %d - %d. '%d' was given.z(Failed to get allowed priority range: %sr,zAFailed to set scheduling parameters of PID %d, the task vanished.z1Failed to set scheduling parameters of PID %d: %s) rrPrr5rkror SystemErrorr*r\hasattrr,r.)rrTrZr[r6prio_minprio_maxr2s r_set_rtzSchedulerPlugin._set_rtsT##66u=))) P$   ##44U;8##44U;8 XoIII H &&sE48 w  99 7    w  aagg4IIQ   IIA a s1AB3C'3C$CC$'E!6AEE!cN|ddtjjzdk7S)Nstatflagsr)r!pidstat PF_KTHREADrr"s rr$zSchedulerPlugin._is_kthreads%  !FNN$=$= = BBrc|jdk(rytj|j|j|duS)NrF)rresearch_get_stat_cgrouprCs r_process_in_blacklisted_cgroupz.SchedulerPlugin._process_in_blacklisted_cgroups; !!R'  4//1F1Fw1O PX\ \\rc |j} |dddk(rtjd|zy|j|rtjd|zy|dj rC|j |rtjd|zytj d|zytjd ||j|fztjd ||j|fztjd |t|jj|fzy#ttf$r{}|jtj k(s|jtj"k(rtjd |zYd}~ytj%d ||fzYd}~yd}~wt&t(f$r$}tj%d ||fzYd}~yd}~wwxYw)Nr?stateZz9Affinity of zombie task with PID %d could not be changed.Tz`Affinity of task with PID %d could not be changed, the task was moved into a blacklisted cgroup.z[Affinity of kernel thread with PID %d cannot be changed, the task's affinity mask is fixed.zRAffinity of task with PID %d cannot be changed, the task's affinity mask is fixed.zTask %d cmdline: %szTask %d cgroup: %szTask %d affinity: %sz6Failed to get task info for PID %d, the task vanished.z&Failed to get task info for PID %d: %sF)rTrr5rHis_bound_to_cpur$rrr%rGlistrr_r*r+r,r-r.rrKeyError)rr"rTr2s r_ignore_set_affinity_errorz*SchedulerPlugin._ignore_set_affinity_errors # fog#%III    ))'2IIp    fo%%'  YYl    [[e   88 !S$*;*;G*D$E EF88 C)>)>w)G#H HI88 "c40E0E0R0RSV0W+X%Y YZ  7 ggEKK!7IIF   99 5 Qx  ( #99 5 Qx sB#E)EA CA9CCc$t|dddk(S)Nrr)r)rrs r_is_cgroup_affinityz#SchedulerPlugin._is_cgroup_affinitys Xr i ''rFc |j|}|j|j |r||_y||_yyy#t$r't|j}||j|<Y[wxYwr )rrNrr rr)rrTr is_cgrouprQs r_store_orig_process_affinityz,SchedulerPlugin._store_orig_process_affinityst*  $ $S )6 __!6FMFO "7 * DII &6#)4C *s=-A-,A-c |jjtjdt |dddj dD]&} |j dddd}|dk7r|cSdcSy#t $rY5wxYw) NrrTno_error z:cpuset:rr)r read_filerPROCFS_MOUNT_POINTrsplit IndexError)rrTlrs r_get_cgroup_affinityz$SchedulerPlugin._get_cgroup_affinitys 99  V-F-FCRZ[hl  m s stx ya WWZ  #AB 'Fr\6*s* z    sA60A66 BBc|j|}|j}|dk7r|d|}|jjd|zt |dy)Nrz%s/tasksTr^)r_cgroup_mount_pointr write_to_filer)rrTrpaths r _set_cgroupzSchedulerPlugin._set_cgroupsP  % %f -& ! !$ s]6 "4))*t+SX$GrcV|dd}t|t xrt|dkD}||fS)Nrr)r rMr)rrr[s r_parse_cgroup_affinityz&SchedulerPlugin._parse_cgroup_affinitys4 !":&VT**>s6{Q) F rcJd}||S |j|\}}|r$|j|}|j||n8|j|}|r|j |||}|j |||j ||||S#ttf$r}t|drS|jtjk(r6tjd|z||jvr |j|=d}ntjd||fzYd}~|Sd}~wwxYw)NTr,z5Failed to read affinity of PID %d, the task vanished.FzLRefusing to set CPU affinity of PID %d, reading original affinity failed: %s)rmrfrk _get_affinity_get_intersect_affinity _set_affinityr\r9r*r:r,r.rr5rr) rrTr intersectrTr[r prev_affinityr2s r_tune_process_affinityz&SchedulerPlugin._tune_process_affinity s1 $  ;44X>Iv--c2MS&!&&s+M,,hX sH%$$SI + w   aagg4IIE    d&&& ! !# & DII\ a + sBBD"A9DD"c|j|||}|sy|j||}|r||jvry||j|_yr )rWrtrr )rrTrrZr[rrTs r _tune_processzSchedulerPlugin._tune_process?sT  sE4 0$  $ $S( 3$ D444 *-$3'rc|jj|}||dk7rtjd|zy t |}||fS#t $rtjd|zYywxYw)Nrz>Invalid scheduler: %s. Scheduler and priority will be ignored.)NNz=Invalid priority: %s. Scheduler and priority will be ignored.)rrNrrrr)rrM str_priorityr rs r_convert_sched_paramsz%SchedulerPlugin._convert_sched_paramsHs##44]C)=C/99 M < H X  IIM  s A !A0/A0c|dk(rd}|S|j|r|}|S|jj|}|stj d|zd}|S)Nrz)Invalid affinity: %s. It will be ignored.)rYr hex2cpulistrr)r str_affinityrs r_convert_affinityz!SchedulerPlugin._convert_affinityWslS8 /  -8 / ii##L18 II9H /rcl|\}}}}}|j||\}}|j|}|||||fSr )ryr})rvals rule_prior rrregexs r_convert_sched_cfgz"SchedulerPlugin._convert_sched_cfgdsM6:39i8U44 x9h  # #H -( Y(E ::rc|jd|} tj|tj|jj|dd|jj|jddddst jd|zyy#t $r%}t jd|d|Yd}~d}~wwxYw)NrzUnable to create cgroup '': z cpuset.memsTr^z3Unable to initialize 'cpuset.mems ' for cgroup '%s') rhr:mkdirrDEF_CGROUP_MODEr*rrr rira)rrrjr2s r_cgroup_create_groupz$SchedulerPlugin._cgroup_create_groupks,,f 5$=88D&(() )) ! !T="AII4#;#;]KX\] "  YYDtKL  =994 ;<<=s$B C 'CC c|j3|j|jvr|j|j|jD]}|j|yr )rrrrcgs r_cgroup_initialize_groupsz)SchedulerPlugin._cgroup_initialize_groupsvsI \\dlldmm&CT\\* MMbR  rc tjd tj|jt j |jjdddddd|jg\}}|dk7r#tjd |jzyy#t$r"}tjd|zYd}~~d}~wwxYw) NzInitializing cgroups settingsz'Unable to create cgroup mount point: %smountz-trz-ocpusetrzUnable to mount '%s') rr5r:makedirsrhrrr*rr execute)rr2retouts r_cgroup_initializez"SchedulerPlugin._cgroup_initialize|s)) +,<;;t'')?)?@yy  '448UYUmUm!no*3AX99 #d&>&> >? <99 6 :;;}}}t;|d }t=} i|_|D]\}\} } } } } t3j@|}|j-Dcgc] \}}t3jB||||f"}}}t=|Dcgc]\}}|||| | | |ffc}}}| jE|t3jFddt/|}| | | g|j>|<| j-D]!\}\}}} } } }|jI||| | | #|jJjM|jN|jP|jRrO|jTrBtWjX|jZ|g|_.|j\j_yyy#t"t$f$r"}t&j)d|zYd}~yd}~wwxYwcc}}wcc}}w#t2j($r,}t&j)d t/|zYd}~d}~wwxYwcc}}wcc}}w)Nrr1rrIerror applying tuning, cannot get information about running processes: %s:zgroup\.c|ddS)Nrrr#) option_valss rz8SchedulerPlugin._instance_apply_static..s +a.2Cr)keyz(error compiling regular expression: '%s'z(?!>!!#5h?  2 HPGZGZG`G`GbcGbmfeE ((a01Gb)c! !  xx F# D Q $))$/ 0! SCD)f)(@f?y)Xx  5A,.88:W:xsC1c9J9Vc :9W  cVY(EJK  !5 E 66$eSZ 85$-x#B8%  ?c >CHhc3  x--D// \\h..&&0A0A8*U8 /\G 7  99 X    d  (( II83u:EF  X sO%N.'O"AO(3O.P0:P0 P6 .O=OO.P-!P((P-cz |j}|j j D]\}}||vs|||jk7r|j3|j'|j||j|j|j|j||j|j|j||ji|_|jj!|j"y#ttf$r"}tj d|zYd}~yd}~wwxYw)NzKerror unapplying tuning, cannot get information about running processes: %s)r3r*r+rrrrGr r rr=rrkrrqrrr)rr/r2rT orig_paramss rrz$SchedulerPlugin._restore_ps_affinitys  2 2288:c; mr#w+"5"55 '    )LLk++$S+,,-(sK001; $--d112# 7  99 Z    sD D:D55D:cttj}d}|dk7r|dkDr|jj |j d|dddd}|dvrC|j d D]/}|jj|j dd|d 1|d z}|dk7r|dkDr|dk(rtjd |zyy) N rrrtasksTr)rrr`r^rz(Unable to cleanup tasks from cgroup '%s') rrCGROUP_CLEANUP_TASKS_RETRYr rarhrcrirr)rrcntdatares r_cgroup_cleanup_tasks_onez)SchedulerPlugin._cgroup_cleanup_tasks_ones F - -.# $  sQw ))  D,D,DfgVd  $4 ) ZZ  YY(@(@'JAZ^_!83  sQw AX;;9FBCrc|j3|j|jvr|j|j|jD]}|j|yr )rrrrs r_cgroup_cleanup_tasksz%SchedulerPlugin._cgroup_cleanup_taskssI \\dlldmm&C!!$,,/ MMb!!"% rctt| |||jr@|jr4|j j |jj|j|j|j|js |jr|j|jr|jyyr )rr_instance_unapply_staticrrrrrjoinrrrrrrr)rrrollbackrs rrz(SchedulerPlugin._instance_unapply_static"s7(K \\h..  ! !>!>! ""#rc,tjd|z|jd|dd}|jj |dd}|dk(ry|jj |jj |}|jj |jj |}d|z}||k(r)tjtj||fzytjtj|||fzy) NzVerifying cgroup '%s' affinityrrrTrzcgroup '%s' affinityF) rr5rhr racpulist2string cpulist_packrrSTR_VERIFY_PROFILE_VALUE_OKrSTR_VERIFY_PROFILE_VALUE_FAIL)rrrrjcurrent_affinityaffinity_descriptions r_cgroup_verify_affinity_onez+SchedulerPlugin._cgroup_verify_affinity_one/s)) ,v 56// G$YY((4(P YY--dii.D.DEU.VW YY % %dii&<&A-E00E5c||jvrV|j|=tjd|z|jj |j |jyy)Nz)removed PID %d from the rollback database)rrr5rrr)rrrTs r _remove_pidzSchedulerPlugin._remove_pidhsXD $ $$ $99 83 >?==T00 %rc|jj|j}tj}|j j }|D]}|j||jjst|j |jdzdkDr;|jjs d}|rd}|jD]}|j j|}|s"d}t|tj sC|j"r^t|tj$rD|j&tj(k(r'|j+|t-|j.|t|tj$s|j&tj0k(s|j3|t-|j.|r|jjsyy)NirTF)r re_lookup_compilerselectpollrrregisterris_setrrr read_on_cpur r comm_event_perf_process_fork_value task_eventr RECORD_FORKrrtid RECORD_EXITr) rrr3rfdsr read_eventscpuevents rrzSchedulerPlugin._thread_codeosr ii!!("8"89! $ ##%# b==     & & ( $))D((4/ 01A5h>Q>Q>X>X>ZK [ **3/e { UDOO , %% udoo . JJ$** * hEII2 udoo .5::AQAQ3Q 3uyy>2     & & ( (rr) per_devicec|ry|rH|Edjtjdt|Dcgc]}d|z c}|_yyycc}wN|z(? |jj|}tjd|zt dd5}|j |dddy#1swYyxYw#t tf$r%}tjdd|Yd}~yd}~wwxYw)Nz(Setting default SMP IRQ affinity to '%s'/proc/irq/default_smp_affinityr/z+Failed to set default SMP IRQ affinity to 'r) r r2rr5rr3r*r+r)rrr6r1r2s r_set_default_irq_affinityz)SchedulerPlugin._set_default_irq_affinity6s))''1<99 7 -s3qGGL 433 7 99as5?A(AA(A%!A(%A((B7BBc>t}tj}|jD]} ||d}tj d|d|d|j|||}t|t|k(rS|j||d}|dk(r||j|<{|dk(s|jj||jjd}|jj|}|j d k(r|j|||}n|j d k7r |j }|j d k7r|j#||_|j&j|j(|y#t $rYlwxYw) NrzRead affinity of IRQ '': 'rFrr0r:rr)r%r! interruptsr)rr5rNrprr8r'r)appendr rar{rr;r(rr) rr irq_originalr'rrsrrprev_affinity_hexs r_set_all_irq_affinityz%SchedulerPlugin._set_all_irq_affinityAsz,    $ YY[c Ij)MII m++M8XN9 )nM**  Y 63 Qh*Lc r $$S)"ii))*JK))''(9:- ))V3++M8XN9 ++x7339 ))X5!!),'<--D))<8+    s$F FFcb|jj|jd}|y|jj D]\}}|j ||d|j dk7r|j}|j||jj|jy)NTr) rrLrr'rGr8rr(r;r)rr@rrs r_restore_all_irq_affinityz)SchedulerPlugin._restore_all_irq_affinity`s""4#8#8$?, #((..0mc8#x.1 ))X5""8!!(+--d++,rct|jt|}|r*tjtj ||fz|Stj tj|||fz|Sr )rissubsetrrrrrr)rirq_descriptioncorrect_affinityrrs r_verify_irq_affinityz$SchedulerPlugin._verify_irq_affinityksz &&s+;'<=#88F . .)* +, *99V 1 1) *rc|jj|jd}tj}d}|j D]}}||j vr.|r,d|z}tjtj|z? ||d}tjd|d|dd|z} |j| ||sd}|jjd } |jj!| }|j"d k7r0|jd ||j"d k(r|n |j"sd}|S#t$rYwxYw) NTz-IRQ %s does not support changing SMP affinityrzRead SMP affinity of IRQ 'r=rzSMP affinity of IRQ %sFr:rzdefault IRQ SMP affinityr)rrLrr!r>r)r)rrr STR_VERIFY_PROFILE_VALUE_MISSINGr5rIrNr rar{r) rrHrr@r'rr descriptionrrGcurrent_affinity_hexs r_verify_all_irq_affinityz(SchedulerPlugin._verify_all_irq_affinitywsT""4#8#8$?,    $ # YY[c \ & &&>ACGKHHV 4 4{ BC   Cy,II  !.4O  $ $  S$,,$&YY**+?@ ))X5d>W>WXr$*N*NRX*X&((?* 3 *    s >E EEr )rrcd}d|_|t|jj|}t|j}|j |r/t ||z }|jj||_nA|jj|j} tjd|d| d|s|r|y|r|jr|j||Sy|r]|jr |jd|jz} n|} |j| |jr|j|y|jr|j!y)Nz#Invalid isolated_cores specified, 'z"' does not match available cores 'rTz cgroup.%s)rrr rrrFrMrrrrrNrrr-rBrD) rrrrrrrisolatedpresentstr_cpus ps_affinitys r_isolated_coreszSchedulerPlugin._isolated_coress7 ($. $))**5128 _7 Gh&'HYY--h7DNyy'' 3HII &h.     ( (> BB  ll ,KK% x(  ""$ rcB|dk(r |d|}d|zS|d|d|}d|zS)Nrrz/sys/kernel/debug/%sr#)rprefix namespaceknobrjs r_sched_assembly_pathz$SchedulerPlugin._sched_assembly_paths9 r\ %4 $ && 4 04 $ &&rc|}|dk(r6|jj|}||r|j|||}|Sd}|S)NrZr)_dict_sched_knob_maprLrZ)rrjrWrXrYlpathlknobs r_sched_assembly_path2z%SchedulerPlugin._sched_assembly_path2sU %'  $ $ ( ( .5   & &vy% @U ,U ,rc|d|d|}|jj|}|s|dk(r|Sd|d|}tjj |s^|j |||}tjj |s|j ||||}|dk7r|jd|_||j|<|S)N_rz/proc/sys/kernel/T)rrLr:rjexistsrZr_r)rrWrXrYrrjs r_get_sched_knob_pathz$SchedulerPlugin._get_sched_knob_pathsi.# % % ) )# .$ TRZ ;%. 5$    # #FIt <4 ''..   % %dFIt DD bjT++3!D&*$s# +rcd}|j|||}|dk7r_|jj|d}|@tj d|z|j rtj dd|_|S)Nr)rzError reading '%s'zUThis may not work with Secure Boot or kernel_lockdown (this hint is logged only once)F)rcr rarrr)rrWrXrYrrjs r_get_sched_knobzSchedulerPlugin._get_sched_knobsu $ " "69d ;$ RZ ))  dd  34 lII"T)* YYfg#T +rc|y|j|||}|stjd|zy|sM|jj |||rt j gndstjd|d|d|S)Nz(knob '%s' ignored, unsupported by kernelFr^zError writing value 'z' to 'r)rcrr5r rir,r-r)rrWrXrYrsimremoverjs r_set_sched_knobzSchedulerPlugin._set_sched_knobsw ]  " "69d ;$ 99 7$ >?  )) ! !$!' ~U " 4YYUDAB ,rr c(|jdddSNrrZrrerrs r_get_sched_min_granularity_nsz-SchedulerPlugin._get_sched_min_granularity_nss  b'+? @@rc.|jddd|||Srkrirrrrgrhs r_set_sched_min_granularity_nsz-SchedulerPlugin._set_sched_min_granularity_nss  b'+?V TTrr c$|j|Sr )rnrms r_get_sched_base_slice_nsz(SchedulerPlugin._get_sched_base_slice_nss + +H 55rc*|j||||Sr )rrrqs r_set_sched_base_slice_nsz(SchedulerPlugin._set_sched_base_slice_nss + +E8S& IIrr c(|jdddSNrrZrrlrms r_get_sched_latency_nsz%SchedulerPlugin._get_sched_latency_ns  b'< 88rc.|jddd|||Srxrprqs r_set_sched_latency_nsz%SchedulerPlugin._set_sched_latency_ns   b'<V LLrrc(|jdddSNrrZrrlrms r _get_sched_wakeup_granularity_nsz0SchedulerPlugin._get_sched_wakeup_granularity_nss  b'+B CCrc.|jddd|||Srrprqs r _set_sched_wakeup_granularity_nsz0SchedulerPlugin._set_sched_wakeup_granularity_nss  b'+BE3PV WWrrc(|jdddSNrrZtunable_scalingrlrms r_get_sched_tunable_scalingz*SchedulerPlugin._get_sched_tunable_scalings  b'+< ==rc.|jddd|||Srrprqs r_set_sched_tunable_scalingz*SchedulerPlugin._set_sched_tunable_scalings  b'+ ??rc.|jddd|||Srrprqs r_set_sched_migration_cost_nsz,SchedulerPlugin._set_sched_migration_cost_ns#s  b'+>sF SSrrc(|jdddSNrrZ nr_migraterlrms r_get_sched_nr_migratez%SchedulerPlugin._get_sched_nr_migrate'rzrc.|jddd|||Srrprqs r_set_sched_nr_migratez%SchedulerPlugin._set_sched_nr_migrate+r}rrc(|jdddSNrZnuma_balancing scan_delay_msrlrms r!_get_numa_balancing_scan_delay_msz1SchedulerPlugin._get_numa_balancing_scan_delay_ms/s  g'7 IIrc.|jddd|||Srrprqs r!_set_numa_balancing_scan_delay_msz1SchedulerPlugin._set_numa_balancing_scan_delay_ms3s  g'7%QTV\ ]]rrc(|jdddSNrZrscan_period_min_msrlrms r&_get_numa_balancing_scan_period_min_msz6SchedulerPlugin._get_numa_balancing_scan_period_min_ms7  g'79M NNrc.|jddd|||Srrprqs r&_set_numa_balancing_scan_period_min_msz6SchedulerPlugin._set_numa_balancing_scan_period_min_ms;!  g'79MuVY[a bbrrc(|jdddSNrZrscan_period_max_msrlrms r&_get_numa_balancing_scan_period_max_msz6SchedulerPlugin._get_numa_balancing_scan_period_max_ms?rrc.|jddd|||Srrprqs r&_set_numa_balancing_scan_period_max_msz6SchedulerPlugin._set_numa_balancing_scan_period_max_msCrrrc(|jdddSNrZr scan_size_mbrlrms r _get_numa_balancing_scan_size_mbz0SchedulerPlugin._get_numa_balancing_scan_size_mbGs  g'7 HHrc.|jddd|||Srrprqs r _set_numa_balancing_scan_size_mbz0SchedulerPlugin._set_numa_balancing_scan_size_mbKs  g'7PSU[ \\r)F)jrrr rpr\rrrrr classmethodrrr%r3r7r=r$rHrOrRrWrYr\rfrkrmrtrvryr}rrrrrrrrrrrrrrr ROLLBACK_SOFTrrrrrrrcommand_customrrrrrrrrorqrpr#rGr"r-r8r;rBrDrIrNrUrZr_rcreri command_getrn command_setrrrtrvryr|rrrrrrrrrrrrrrrr __classcell__)rs@rrrsk\ '  %6N .?$B 8E68C] D,(   H>.  ; M! @B H Q"+/ :x3, D& :@9M9M &  038&U;d<de4Z5Ze4Z5Z"7<8<U3848+%@KAK$59D:D   D   0 9> -   >!"E"F"H'   ()A*A()U*U#$6%6#$J%J !9"9 !M"M+,D-D+,X-X%&>'>%&R'R'(@)@'(T)T !9"9 !M"M,-J.J,-^.^12O3O12c3c12O3O12c3c+,I-I+,]-]rr)!rr decorators tuned.logstunedrE subprocessrr ImportErrorr tuned.constsrr!tuned.utils.commandsrr,r:rrr,rrvlogsrLrobjectrr%r+rrPluginrr#rrrs    )   jjnn5f50F-*V-*^,~,>]dkk]As#B/ B:/B76B7: CC