@@ -6224,321 +6224,6 @@ void sched_move_task(struct task_struct *tsk)
62246224
62256225 task_rq_unlock (rq , tsk , & rf );
62266226}
6227- #endif /* CONFIG_CGROUP_SCHED */
6228-
6229- #ifdef CONFIG_RT_GROUP_SCHED
6230- /*
6231- * Ensure that the real time constraints are schedulable.
6232- */
6233- static DEFINE_MUTEX (rt_constraints_mutex );
6234-
6235- /* Must be called with tasklist_lock held */
6236- static inline int tg_has_rt_tasks (struct task_group * tg )
6237- {
6238- struct task_struct * g , * p ;
6239-
6240- /*
6241- * Autogroups do not have RT tasks; see autogroup_create().
6242- */
6243- if (task_group_is_autogroup (tg ))
6244- return 0 ;
6245-
6246- for_each_process_thread (g , p ) {
6247- if (rt_task (p ) && task_group (p ) == tg )
6248- return 1 ;
6249- }
6250-
6251- return 0 ;
6252- }
6253-
6254- struct rt_schedulable_data {
6255- struct task_group * tg ;
6256- u64 rt_period ;
6257- u64 rt_runtime ;
6258- };
6259-
6260- static int tg_rt_schedulable (struct task_group * tg , void * data )
6261- {
6262- struct rt_schedulable_data * d = data ;
6263- struct task_group * child ;
6264- unsigned long total , sum = 0 ;
6265- u64 period , runtime ;
6266-
6267- period = ktime_to_ns (tg -> rt_bandwidth .rt_period );
6268- runtime = tg -> rt_bandwidth .rt_runtime ;
6269-
6270- if (tg == d -> tg ) {
6271- period = d -> rt_period ;
6272- runtime = d -> rt_runtime ;
6273- }
6274-
6275- /*
6276- * Cannot have more runtime than the period.
6277- */
6278- if (runtime > period && runtime != RUNTIME_INF )
6279- return - EINVAL ;
6280-
6281- /*
6282- * Ensure we don't starve existing RT tasks.
6283- */
6284- if (rt_bandwidth_enabled () && !runtime && tg_has_rt_tasks (tg ))
6285- return - EBUSY ;
6286-
6287- total = to_ratio (period , runtime );
6288-
6289- /*
6290- * Nobody can have more than the global setting allows.
6291- */
6292- if (total > to_ratio (global_rt_period (), global_rt_runtime ()))
6293- return - EINVAL ;
6294-
6295- /*
6296- * The sum of our children's runtime should not exceed our own.
6297- */
6298- list_for_each_entry_rcu (child , & tg -> children , siblings ) {
6299- period = ktime_to_ns (child -> rt_bandwidth .rt_period );
6300- runtime = child -> rt_bandwidth .rt_runtime ;
6301-
6302- if (child == d -> tg ) {
6303- period = d -> rt_period ;
6304- runtime = d -> rt_runtime ;
6305- }
6306-
6307- sum += to_ratio (period , runtime );
6308- }
6309-
6310- if (sum > total )
6311- return - EINVAL ;
6312-
6313- return 0 ;
6314- }
6315-
6316- static int __rt_schedulable (struct task_group * tg , u64 period , u64 runtime )
6317- {
6318- int ret ;
6319-
6320- struct rt_schedulable_data data = {
6321- .tg = tg ,
6322- .rt_period = period ,
6323- .rt_runtime = runtime ,
6324- };
6325-
6326- rcu_read_lock ();
6327- ret = walk_tg_tree (tg_rt_schedulable , tg_nop , & data );
6328- rcu_read_unlock ();
6329-
6330- return ret ;
6331- }
6332-
6333- static int tg_set_rt_bandwidth (struct task_group * tg ,
6334- u64 rt_period , u64 rt_runtime )
6335- {
6336- int i , err = 0 ;
6337-
6338- /*
6339- * Disallowing the root group RT runtime is BAD, it would disallow the
6340- * kernel creating (and or operating) RT threads.
6341- */
6342- if (tg == & root_task_group && rt_runtime == 0 )
6343- return - EINVAL ;
6344-
6345- /* No period doesn't make any sense. */
6346- if (rt_period == 0 )
6347- return - EINVAL ;
6348-
6349- mutex_lock (& rt_constraints_mutex );
6350- read_lock (& tasklist_lock );
6351- err = __rt_schedulable (tg , rt_period , rt_runtime );
6352- if (err )
6353- goto unlock ;
6354-
6355- raw_spin_lock_irq (& tg -> rt_bandwidth .rt_runtime_lock );
6356- tg -> rt_bandwidth .rt_period = ns_to_ktime (rt_period );
6357- tg -> rt_bandwidth .rt_runtime = rt_runtime ;
6358-
6359- for_each_possible_cpu (i ) {
6360- struct rt_rq * rt_rq = tg -> rt_rq [i ];
6361-
6362- raw_spin_lock (& rt_rq -> rt_runtime_lock );
6363- rt_rq -> rt_runtime = rt_runtime ;
6364- raw_spin_unlock (& rt_rq -> rt_runtime_lock );
6365- }
6366- raw_spin_unlock_irq (& tg -> rt_bandwidth .rt_runtime_lock );
6367- unlock :
6368- read_unlock (& tasklist_lock );
6369- mutex_unlock (& rt_constraints_mutex );
6370-
6371- return err ;
6372- }
6373-
6374- static int sched_group_set_rt_runtime (struct task_group * tg , long rt_runtime_us )
6375- {
6376- u64 rt_runtime , rt_period ;
6377-
6378- rt_period = ktime_to_ns (tg -> rt_bandwidth .rt_period );
6379- rt_runtime = (u64 )rt_runtime_us * NSEC_PER_USEC ;
6380- if (rt_runtime_us < 0 )
6381- rt_runtime = RUNTIME_INF ;
6382-
6383- return tg_set_rt_bandwidth (tg , rt_period , rt_runtime );
6384- }
6385-
6386- static long sched_group_rt_runtime (struct task_group * tg )
6387- {
6388- u64 rt_runtime_us ;
6389-
6390- if (tg -> rt_bandwidth .rt_runtime == RUNTIME_INF )
6391- return -1 ;
6392-
6393- rt_runtime_us = tg -> rt_bandwidth .rt_runtime ;
6394- do_div (rt_runtime_us , NSEC_PER_USEC );
6395- return rt_runtime_us ;
6396- }
6397-
6398- static int sched_group_set_rt_period (struct task_group * tg , u64 rt_period_us )
6399- {
6400- u64 rt_runtime , rt_period ;
6401-
6402- rt_period = rt_period_us * NSEC_PER_USEC ;
6403- rt_runtime = tg -> rt_bandwidth .rt_runtime ;
6404-
6405- return tg_set_rt_bandwidth (tg , rt_period , rt_runtime );
6406- }
6407-
6408- static long sched_group_rt_period (struct task_group * tg )
6409- {
6410- u64 rt_period_us ;
6411-
6412- rt_period_us = ktime_to_ns (tg -> rt_bandwidth .rt_period );
6413- do_div (rt_period_us , NSEC_PER_USEC );
6414- return rt_period_us ;
6415- }
6416- #endif /* CONFIG_RT_GROUP_SCHED */
6417-
6418- #ifdef CONFIG_RT_GROUP_SCHED
6419- static int sched_rt_global_constraints (void )
6420- {
6421- int ret = 0 ;
6422-
6423- mutex_lock (& rt_constraints_mutex );
6424- read_lock (& tasklist_lock );
6425- ret = __rt_schedulable (NULL , 0 , 0 );
6426- read_unlock (& tasklist_lock );
6427- mutex_unlock (& rt_constraints_mutex );
6428-
6429- return ret ;
6430- }
6431-
6432- static int sched_rt_can_attach (struct task_group * tg , struct task_struct * tsk )
6433- {
6434- /* Don't accept realtime tasks when there is no way for them to run */
6435- if (rt_task (tsk ) && tg -> rt_bandwidth .rt_runtime == 0 )
6436- return 0 ;
6437-
6438- return 1 ;
6439- }
6440-
6441- #else /* !CONFIG_RT_GROUP_SCHED */
6442- static int sched_rt_global_constraints (void )
6443- {
6444- unsigned long flags ;
6445- int i ;
6446-
6447- raw_spin_lock_irqsave (& def_rt_bandwidth .rt_runtime_lock , flags );
6448- for_each_possible_cpu (i ) {
6449- struct rt_rq * rt_rq = & cpu_rq (i )-> rt ;
6450-
6451- raw_spin_lock (& rt_rq -> rt_runtime_lock );
6452- rt_rq -> rt_runtime = global_rt_runtime ();
6453- raw_spin_unlock (& rt_rq -> rt_runtime_lock );
6454- }
6455- raw_spin_unlock_irqrestore (& def_rt_bandwidth .rt_runtime_lock , flags );
6456-
6457- return 0 ;
6458- }
6459- #endif /* CONFIG_RT_GROUP_SCHED */
6460-
6461- static int sched_rt_global_validate (void )
6462- {
6463- if (sysctl_sched_rt_period <= 0 )
6464- return - EINVAL ;
6465-
6466- if ((sysctl_sched_rt_runtime != RUNTIME_INF ) &&
6467- (sysctl_sched_rt_runtime > sysctl_sched_rt_period ))
6468- return - EINVAL ;
6469-
6470- return 0 ;
6471- }
6472-
6473- static void sched_rt_do_global (void )
6474- {
6475- def_rt_bandwidth .rt_runtime = global_rt_runtime ();
6476- def_rt_bandwidth .rt_period = ns_to_ktime (global_rt_period ());
6477- }
6478-
6479- int sched_rt_handler (struct ctl_table * table , int write ,
6480- void __user * buffer , size_t * lenp ,
6481- loff_t * ppos )
6482- {
6483- int old_period , old_runtime ;
6484- static DEFINE_MUTEX (mutex );
6485- int ret ;
6486-
6487- mutex_lock (& mutex );
6488- old_period = sysctl_sched_rt_period ;
6489- old_runtime = sysctl_sched_rt_runtime ;
6490-
6491- ret = proc_dointvec (table , write , buffer , lenp , ppos );
6492-
6493- if (!ret && write ) {
6494- ret = sched_rt_global_validate ();
6495- if (ret )
6496- goto undo ;
6497-
6498- ret = sched_dl_global_validate ();
6499- if (ret )
6500- goto undo ;
6501-
6502- ret = sched_rt_global_constraints ();
6503- if (ret )
6504- goto undo ;
6505-
6506- sched_rt_do_global ();
6507- sched_dl_do_global ();
6508- }
6509- if (0 ) {
6510- undo :
6511- sysctl_sched_rt_period = old_period ;
6512- sysctl_sched_rt_runtime = old_runtime ;
6513- }
6514- mutex_unlock (& mutex );
6515-
6516- return ret ;
6517- }
6518-
6519- int sched_rr_handler (struct ctl_table * table , int write ,
6520- void __user * buffer , size_t * lenp ,
6521- loff_t * ppos )
6522- {
6523- int ret ;
6524- static DEFINE_MUTEX (mutex );
6525-
6526- mutex_lock (& mutex );
6527- ret = proc_dointvec (table , write , buffer , lenp , ppos );
6528- /*
6529- * Make sure that internally we keep jiffies.
6530- * Also, writing zero resets the timeslice to default:
6531- */
6532- if (!ret && write ) {
6533- sched_rr_timeslice =
6534- sysctl_sched_rr_timeslice <= 0 ? RR_TIMESLICE :
6535- msecs_to_jiffies (sysctl_sched_rr_timeslice );
6536- }
6537- mutex_unlock (& mutex );
6538- return ret ;
6539- }
6540-
6541- #ifdef CONFIG_CGROUP_SCHED
65426227
65436228static inline struct task_group * css_tg (struct cgroup_subsys_state * css )
65446229{
0 commit comments