[Devel] [PATCH RH9 09/12] sched: Split tg_set_cfs_bandwidth() and export default_cfs_period()

Alexander Mikhalitsyn alexander.mikhalitsyn at virtuozzo.com
Thu Sep 23 14:31:33 MSK 2021


From: Kirill Tkhai <ktkhai at virtuozzo.com>

This is needed for CONFIG_CFS_CPULIMIT.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>

https://jira.sw.ru/browse/PSBM-133986

(cherry picked from commit dcff66d4a02c9fc56536b3e002b4dee3e9efd3fa)
Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
---
 kernel/sched/core.c  | 20 +++++++++++++++-----
 kernel/sched/fair.c  |  9 ---------
 kernel/sched/sched.h |  8 ++++++++
 3 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index d824282e942b..2159edeb0e02 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -9969,7 +9969,7 @@ static const u64 max_cfs_runtime = MAX_BW * NSEC_PER_USEC;
 
 static int __cfs_schedulable(struct task_group *tg, u64 period, u64 runtime);
 
-static int tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota,
+static int __tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota,
 				u64 burst)
 {
 	int i, ret = 0, runtime_enabled, runtime_was_enabled;
@@ -10008,11 +10008,9 @@ static int tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota,
 	 * Prevent race between setting of cfs_rq->runtime_enabled and
 	 * unthrottle_offline_cfs_rqs().
 	 */
-	get_online_cpus();
-	mutex_lock(&cfs_constraints_mutex);
 	ret = __cfs_schedulable(tg, period, quota);
 	if (ret)
-		goto out_unlock;
+		goto out;
 
 	runtime_enabled = quota != RUNTIME_INF;
 	runtime_was_enabled = cfs_b->quota != RUNTIME_INF;
@@ -10050,7 +10048,19 @@ static int tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota,
 	}
 	if (runtime_was_enabled && !runtime_enabled)
 		cfs_bandwidth_usage_dec();
-out_unlock:
+out:
+
+	return ret;
+}
+
+static int tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota,
+				u64 burst)
+{
+	int ret;
+
+	get_online_cpus();
+	mutex_lock(&cfs_constraints_mutex);
+	ret = __tg_set_cfs_bandwidth(tg, period, quota, burst);
 	mutex_unlock(&cfs_constraints_mutex);
 	put_online_cpus();
 
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index c42ff00885c0..266862d677d8 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4737,15 +4737,6 @@ void cfs_bandwidth_usage_inc(void) {}
 void cfs_bandwidth_usage_dec(void) {}
 #endif /* CONFIG_JUMP_LABEL */
 
-/*
- * default period for cfs group bandwidth.
- * default: 0.1s, units: nanoseconds
- */
-static inline u64 default_cfs_period(void)
-{
-	return 100000000ULL;
-}
-
 static inline u64 sched_cfs_bandwidth_slice(void)
 {
 	return (u64)sysctl_sched_cfs_bandwidth_slice * NSEC_PER_USEC;
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 9cddbc9920f8..45b2cb7203ea 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -158,6 +158,14 @@ extern void call_trace_sched_update_nr_running(struct rq *rq, int count);
  * Single value that denotes runtime == period, ie unlimited time.
  */
 #define RUNTIME_INF		((u64)~0ULL)
+/*
+ * default period for cfs group bandwidth.
+ * default: 0.1s, units: nanoseconds
+ */
+static inline u64 default_cfs_period(void)
+{
+	return 100000000ULL;
+}
 
 static inline int idle_policy(int policy)
 {
-- 
2.31.1



More information about the Devel mailing list