Pipewireパッケージ(ちょっと変更)
Revisão | 0ecc7ca5f52c05a5e1e77e25163d5b8fdd7041dc (tree) |
---|---|
Hora | 2023-11-16 01:11:19 |
Autor | Jonas Holmberg <jonashg@axis...> |
Commiter | Jonas Holmberg |
module-rt: Remove RLIMIT_RTTIME while trying rt policy
Trying rt scheduling policy while RLIMIT_RTTIME is set could result in
SIGXCPU if the limit is exceeded. Set an infinite limit temporarily
while checking if rt policy is allowed.
@@ -549,6 +549,8 @@ static bool check_realtime_privileges(struct impl *impl) | ||
549 | 549 | int err, old_policy, new_policy, min, max; |
550 | 550 | struct sched_param old_sched_params; |
551 | 551 | struct sched_param new_sched_params; |
552 | + struct rlimit old_rlim; | |
553 | + struct rlimit no_rlim = { -1, -1 }; | |
552 | 554 | int try = 0; |
553 | 555 | |
554 | 556 | if (!impl->rlimits_enabled) |
@@ -596,11 +598,21 @@ static bool check_realtime_privileges(struct impl *impl) | ||
596 | 598 | if ((old_policy & PW_SCHED_RESET_ON_FORK) != 0) |
597 | 599 | new_policy |= PW_SCHED_RESET_ON_FORK; |
598 | 600 | |
601 | + /* Disable RLIMIT_RTTIME while trying new_policy. */ | |
602 | + if ((err = getrlimit(RLIMIT_RTTIME, &old_rlim)) < 0) | |
603 | + pw_log_debug("getrlimit() failed: %s", spa_strerror(err)); | |
604 | + if ((err = setrlimit(RLIMIT_RTTIME, &no_rlim)) < 0) | |
605 | + pw_log_debug("setrlimit() failed: %s", spa_strerror(err)); | |
606 | + | |
599 | 607 | if (pthread_setschedparam(pthread_self(), new_policy, &new_sched_params) == 0) { |
600 | 608 | impl->rt_prio = new_sched_params.sched_priority; |
601 | 609 | pthread_setschedparam(pthread_self(), old_policy, &old_sched_params); |
610 | + if ((err = setrlimit(RLIMIT_RTTIME, &old_rlim)) < 0) | |
611 | + pw_log_debug("setrlimit() failed: %s", spa_strerror(err)); | |
602 | 612 | return true; |
603 | 613 | } |
614 | + if ((err = setrlimit(RLIMIT_RTTIME, &old_rlim)) < 0) | |
615 | + pw_log_debug("setrlimit() failed: %s", spa_strerror(err)); | |
604 | 616 | } |
605 | 617 | pw_log_info("Can't set rt prio to %d: %m (try increasing rlimits)", (int)priority); |
606 | 618 | return false; |
@@ -648,18 +660,18 @@ static int set_nice(struct impl *impl, int nice_level, bool warn) | ||
648 | 660 | return res; |
649 | 661 | } |
650 | 662 | |
651 | -static int set_rlimit(struct impl *impl) | |
663 | +static int set_rlimit(struct rlimit *rlim) | |
652 | 664 | { |
653 | 665 | int res = 0; |
654 | 666 | |
655 | - if (setrlimit(RLIMIT_RTTIME, &impl->rl) < 0) | |
667 | + if (setrlimit(RLIMIT_RTTIME, rlim) < 0) | |
656 | 668 | res = -errno; |
657 | 669 | |
658 | 670 | if (res < 0) |
659 | 671 | pw_log_debug("setrlimit() failed: %s", spa_strerror(res)); |
660 | 672 | else |
661 | 673 | pw_log_debug("rt.time.soft:%"PRIi64" rt.time.hard:%"PRIi64, |
662 | - (int64_t)impl->rl.rlim_cur, (int64_t)impl->rl.rlim_max); | |
674 | + (int64_t)rlim->rlim_cur, (int64_t)rlim->rlim_max); | |
663 | 675 | |
664 | 676 | return res; |
665 | 677 | } |
@@ -1023,7 +1035,7 @@ static int do_rtkit_setup(struct spa_loop *loop, bool async, uint32_t seq, | ||
1023 | 1035 | impl->rl.rlim_cur = SPA_MIN(impl->rl.rlim_cur, impl->rttime_max); |
1024 | 1036 | impl->rl.rlim_max = SPA_MIN(impl->rl.rlim_max, impl->rttime_max); |
1025 | 1037 | |
1026 | - set_rlimit(impl); | |
1038 | + set_rlimit(&impl->rl); | |
1027 | 1039 | |
1028 | 1040 | return 0; |
1029 | 1041 | } |
@@ -1144,7 +1156,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) | ||
1144 | 1156 | use_rtkit = can_use_rtkit; |
1145 | 1157 | } |
1146 | 1158 | if (!use_rtkit) |
1147 | - set_rlimit(impl); | |
1159 | + set_rlimit(&impl->rl); | |
1148 | 1160 | |
1149 | 1161 | if (impl->uclamp_max > 1024) { |
1150 | 1162 | pw_log_warn("uclamp.max out of bounds. Got %d, clamping to 1024.", impl->uclamp_max); |