mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-07 13:43:51 +00:00
047b830974
Setting domain level is not supported at cpuset v2, so move corresponding code into cpuset-v1.c. The 'cpuset_write_s64' and 'cpuset_read_s64' are only used for setting domain level, move them to cpuset-v1.c. Currently, expose to cpuset.c. After cpuset legacy interface files are move to cpuset-v1.c, they can be static. The 'rebuild_sched_domains_locked' is exposed to cpuset-v1.c. The change from original code is that using 'cpuset_lock' and 'cpuset_unlock' functions to lock or unlock cpuset_mutex. Signed-off-by: Chen Ridong <chenridong@huawei.com> Acked-by: Waiman Long <longman@redhat.com> Signed-off-by: Tejun Heo <tj@kernel.org>
197 lines
5.7 KiB
C
197 lines
5.7 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "cpuset-internal.h"
|
|
|
|
/*
|
|
* Frequency meter - How fast is some event occurring?
|
|
*
|
|
* These routines manage a digitally filtered, constant time based,
|
|
* event frequency meter. There are four routines:
|
|
* fmeter_init() - initialize a frequency meter.
|
|
* fmeter_markevent() - called each time the event happens.
|
|
* fmeter_getrate() - returns the recent rate of such events.
|
|
* fmeter_update() - internal routine used to update fmeter.
|
|
*
|
|
* A common data structure is passed to each of these routines,
|
|
* which is used to keep track of the state required to manage the
|
|
* frequency meter and its digital filter.
|
|
*
|
|
* The filter works on the number of events marked per unit time.
|
|
* The filter is single-pole low-pass recursive (IIR). The time unit
|
|
* is 1 second. Arithmetic is done using 32-bit integers scaled to
|
|
* simulate 3 decimal digits of precision (multiplied by 1000).
|
|
*
|
|
* With an FM_COEF of 933, and a time base of 1 second, the filter
|
|
* has a half-life of 10 seconds, meaning that if the events quit
|
|
* happening, then the rate returned from the fmeter_getrate()
|
|
* will be cut in half each 10 seconds, until it converges to zero.
|
|
*
|
|
* It is not worth doing a real infinitely recursive filter. If more
|
|
* than FM_MAXTICKS ticks have elapsed since the last filter event,
|
|
* just compute FM_MAXTICKS ticks worth, by which point the level
|
|
* will be stable.
|
|
*
|
|
* Limit the count of unprocessed events to FM_MAXCNT, so as to avoid
|
|
* arithmetic overflow in the fmeter_update() routine.
|
|
*
|
|
* Given the simple 32 bit integer arithmetic used, this meter works
|
|
* best for reporting rates between one per millisecond (msec) and
|
|
* one per 32 (approx) seconds. At constant rates faster than one
|
|
* per msec it maxes out at values just under 1,000,000. At constant
|
|
* rates between one per msec, and one per second it will stabilize
|
|
* to a value N*1000, where N is the rate of events per second.
|
|
* At constant rates between one per second and one per 32 seconds,
|
|
* it will be choppy, moving up on the seconds that have an event,
|
|
* and then decaying until the next event. At rates slower than
|
|
* about one in 32 seconds, it decays all the way back to zero between
|
|
* each event.
|
|
*/
|
|
|
|
#define FM_COEF 933 /* coefficient for half-life of 10 secs */
|
|
#define FM_MAXTICKS ((u32)99) /* useless computing more ticks than this */
|
|
#define FM_MAXCNT 1000000 /* limit cnt to avoid overflow */
|
|
#define FM_SCALE 1000 /* faux fixed point scale */
|
|
|
|
/* Initialize a frequency meter */
|
|
void fmeter_init(struct fmeter *fmp)
|
|
{
|
|
fmp->cnt = 0;
|
|
fmp->val = 0;
|
|
fmp->time = 0;
|
|
spin_lock_init(&fmp->lock);
|
|
}
|
|
|
|
/* Internal meter update - process cnt events and update value */
|
|
static void fmeter_update(struct fmeter *fmp)
|
|
{
|
|
time64_t now;
|
|
u32 ticks;
|
|
|
|
now = ktime_get_seconds();
|
|
ticks = now - fmp->time;
|
|
|
|
if (ticks == 0)
|
|
return;
|
|
|
|
ticks = min(FM_MAXTICKS, ticks);
|
|
while (ticks-- > 0)
|
|
fmp->val = (FM_COEF * fmp->val) / FM_SCALE;
|
|
fmp->time = now;
|
|
|
|
fmp->val += ((FM_SCALE - FM_COEF) * fmp->cnt) / FM_SCALE;
|
|
fmp->cnt = 0;
|
|
}
|
|
|
|
/* Process any previous ticks, then bump cnt by one (times scale). */
|
|
static void fmeter_markevent(struct fmeter *fmp)
|
|
{
|
|
spin_lock(&fmp->lock);
|
|
fmeter_update(fmp);
|
|
fmp->cnt = min(FM_MAXCNT, fmp->cnt + FM_SCALE);
|
|
spin_unlock(&fmp->lock);
|
|
}
|
|
|
|
/* Process any previous ticks, then return current value. */
|
|
int fmeter_getrate(struct fmeter *fmp)
|
|
{
|
|
int val;
|
|
|
|
spin_lock(&fmp->lock);
|
|
fmeter_update(fmp);
|
|
val = fmp->val;
|
|
spin_unlock(&fmp->lock);
|
|
return val;
|
|
}
|
|
|
|
/*
|
|
* Collection of memory_pressure is suppressed unless
|
|
* this flag is enabled by writing "1" to the special
|
|
* cpuset file 'memory_pressure_enabled' in the root cpuset.
|
|
*/
|
|
|
|
int cpuset_memory_pressure_enabled __read_mostly;
|
|
|
|
/*
|
|
* __cpuset_memory_pressure_bump - keep stats of per-cpuset reclaims.
|
|
*
|
|
* Keep a running average of the rate of synchronous (direct)
|
|
* page reclaim efforts initiated by tasks in each cpuset.
|
|
*
|
|
* This represents the rate at which some task in the cpuset
|
|
* ran low on memory on all nodes it was allowed to use, and
|
|
* had to enter the kernels page reclaim code in an effort to
|
|
* create more free memory by tossing clean pages or swapping
|
|
* or writing dirty pages.
|
|
*
|
|
* Display to user space in the per-cpuset read-only file
|
|
* "memory_pressure". Value displayed is an integer
|
|
* representing the recent rate of entry into the synchronous
|
|
* (direct) page reclaim by any task attached to the cpuset.
|
|
*/
|
|
|
|
void __cpuset_memory_pressure_bump(void)
|
|
{
|
|
rcu_read_lock();
|
|
fmeter_markevent(&task_cs(current)->fmeter);
|
|
rcu_read_unlock();
|
|
}
|
|
|
|
static int update_relax_domain_level(struct cpuset *cs, s64 val)
|
|
{
|
|
#ifdef CONFIG_SMP
|
|
if (val < -1 || val > sched_domain_level_max + 1)
|
|
return -EINVAL;
|
|
#endif
|
|
|
|
if (val != cs->relax_domain_level) {
|
|
cs->relax_domain_level = val;
|
|
if (!cpumask_empty(cs->cpus_allowed) &&
|
|
is_sched_load_balance(cs))
|
|
rebuild_sched_domains_locked();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int cpuset_write_s64(struct cgroup_subsys_state *css, struct cftype *cft,
|
|
s64 val)
|
|
{
|
|
struct cpuset *cs = css_cs(css);
|
|
cpuset_filetype_t type = cft->private;
|
|
int retval = -ENODEV;
|
|
|
|
cpus_read_lock();
|
|
cpuset_lock();
|
|
if (!is_cpuset_online(cs))
|
|
goto out_unlock;
|
|
|
|
switch (type) {
|
|
case FILE_SCHED_RELAX_DOMAIN_LEVEL:
|
|
retval = update_relax_domain_level(cs, val);
|
|
break;
|
|
default:
|
|
retval = -EINVAL;
|
|
break;
|
|
}
|
|
out_unlock:
|
|
cpuset_unlock();
|
|
cpus_read_unlock();
|
|
return retval;
|
|
}
|
|
|
|
s64 cpuset_read_s64(struct cgroup_subsys_state *css, struct cftype *cft)
|
|
{
|
|
struct cpuset *cs = css_cs(css);
|
|
cpuset_filetype_t type = cft->private;
|
|
|
|
switch (type) {
|
|
case FILE_SCHED_RELAX_DOMAIN_LEVEL:
|
|
return cs->relax_domain_level;
|
|
default:
|
|
BUG();
|
|
}
|
|
|
|
/* Unreachable but makes gcc happy */
|
|
return 0;
|
|
}
|