From nobody Thu Dec 18 23:37:35 2025 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0B68188A07; Mon, 26 Aug 2024 13:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724679298; cv=none; b=uxlicKYqVCOVZ90PrMiaIVmKx+5SGBeFN2Tn8bENAgdTMbey1tqfncjTV2Okk8gccUth5duZm+N2da2tNzfzcrWc52KwVgh352AnlRI+pHaB1rOSKyuYHCkRKDs2l0SAaPI9jEy7MoAxl4t/AIHmBH9plnXlrpFWEedPaAWrL60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724679298; c=relaxed/simple; bh=O5dmONWuYyRuWWhfrNfnUtbM1C3oQLku+aC/6TmaoYQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dwK+46hK/HVW37fi2AREESp1+lBm6BOwT8AvK9vHwJMLWEfYnOnsUVNKB1Awq2oNDzuGzYT+0UcpKs8bwxCixLqf8fjNtoiH8BBdvZ4KqhFRVgWOPk6d+XwfNg2HWQINBMK5jxlgWlRsFUE/5xYCgunuO57N0xt8D0pcRc54TVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Wss9J6vBzz2Cnc8; Mon, 26 Aug 2024 21:34:44 +0800 (CST) Received: from kwepemd100013.china.huawei.com (unknown [7.221.188.163]) by mail.maildlp.com (Postfix) with ESMTPS id D09541A016C; Mon, 26 Aug 2024 21:34:53 +0800 (CST) Received: from huawei.com (10.67.174.121) by kwepemd100013.china.huawei.com (7.221.188.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 26 Aug 2024 21:34:53 +0800 From: Chen Ridong To: , , , , , , CC: , , Subject: [PATCH v2 -next 09/11] cgroup/cpuset: move v1 interfaces to cpuset-v1.c Date: Mon, 26 Aug 2024 13:27:01 +0000 Message-ID: <20240826132703.558956-10-chenridong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826132703.558956-1-chenridong@huawei.com> References: <20240826132703.558956-1-chenridong@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd100013.china.huawei.com (7.221.188.163) Content-Type: text/plain; charset="utf-8" Move legacy cpuset controller interfaces files and corresponding code into cpuset-v1.c. 'update_flag', 'cpuset_write_resmask' and 'cpuset_common_seq_show' are also used for v1, so declare them in cpuset-internal.h. 'cpuset_write_s64', 'cpuset_read_s64' and 'fmeter_getrate' are only used cpuset-v1.c now, make it static. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset-internal.h | 9 +- kernel/cgroup/cpuset-v1.c | 194 ++++++++++++++++++++++++++++++- kernel/cgroup/cpuset.c | 195 +------------------------------- 3 files changed, 199 insertions(+), 199 deletions(-) diff --git a/kernel/cgroup/cpuset-internal.h b/kernel/cgroup/cpuset-interna= l.h index 07551ff0812e..a6c71c86e58d 100644 --- a/kernel/cgroup/cpuset-internal.h +++ b/kernel/cgroup/cpuset-internal.h @@ -271,15 +271,16 @@ void callback_lock_irq(void); void callback_unlock_irq(void); void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus); void update_tasks_nodemask(struct cpuset *cs); +int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, int turning_on); +ssize_t cpuset_write_resmask(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off); +int cpuset_common_seq_show(struct seq_file *sf, void *v); =20 /* * cpuset-v1.c */ +extern struct cftype legacy_files[]; void fmeter_init(struct fmeter *fmp); -int fmeter_getrate(struct fmeter *fmp); -int cpuset_write_s64(struct cgroup_subsys_state *css, struct cftype *cft, - s64 val); -s64 cpuset_read_s64(struct cgroup_subsys_state *css, struct cftype *cft); void cpuset_update_task_spread_flags(struct cpuset *cs, struct task_struct *tsk); void update_tasks_flags(struct cpuset *cs); diff --git a/kernel/cgroup/cpuset-v1.c b/kernel/cgroup/cpuset-v1.c index 246fc962f549..ffb8711cc8fa 100644 --- a/kernel/cgroup/cpuset-v1.c +++ b/kernel/cgroup/cpuset-v1.c @@ -100,7 +100,7 @@ static void fmeter_markevent(struct fmeter *fmp) } =20 /* Process any previous ticks, then return current value. */ -int fmeter_getrate(struct fmeter *fmp) +static int fmeter_getrate(struct fmeter *fmp) { int val; =20 @@ -161,7 +161,7 @@ static int update_relax_domain_level(struct cpuset *cs,= s64 val) return 0; } =20 -int cpuset_write_s64(struct cgroup_subsys_state *css, struct cftype *cft, +static int cpuset_write_s64(struct cgroup_subsys_state *css, struct cftype= *cft, s64 val) { struct cpuset *cs =3D css_cs(css); @@ -187,7 +187,7 @@ int cpuset_write_s64(struct cgroup_subsys_state *css, s= truct cftype *cft, return retval; } =20 -s64 cpuset_read_s64(struct cgroup_subsys_state *css, struct cftype *cft) +static s64 cpuset_read_s64(struct cgroup_subsys_state *css, struct cftype = *cft) { struct cpuset *cs =3D css_cs(css); cpuset_filetype_t type =3D cft->private; @@ -373,3 +373,191 @@ int validate_change_legacy(struct cpuset *cur, struct= cpuset *trial) return ret; } =20 +static u64 cpuset_read_u64(struct cgroup_subsys_state *css, struct cftype = *cft) +{ + struct cpuset *cs =3D css_cs(css); + cpuset_filetype_t type =3D cft->private; + + switch (type) { + case FILE_CPU_EXCLUSIVE: + return is_cpu_exclusive(cs); + case FILE_MEM_EXCLUSIVE: + return is_mem_exclusive(cs); + case FILE_MEM_HARDWALL: + return is_mem_hardwall(cs); + case FILE_SCHED_LOAD_BALANCE: + return is_sched_load_balance(cs); + case FILE_MEMORY_MIGRATE: + return is_memory_migrate(cs); + case FILE_MEMORY_PRESSURE_ENABLED: + return cpuset_memory_pressure_enabled; + case FILE_MEMORY_PRESSURE: + return fmeter_getrate(&cs->fmeter); + case FILE_SPREAD_PAGE: + return is_spread_page(cs); + case FILE_SPREAD_SLAB: + return is_spread_slab(cs); + default: + BUG(); + } + + /* Unreachable but makes gcc happy */ + return 0; +} + +static int cpuset_write_u64(struct cgroup_subsys_state *css, struct cftype= *cft, + u64 val) +{ + struct cpuset *cs =3D css_cs(css); + cpuset_filetype_t type =3D cft->private; + int retval =3D 0; + + cpus_read_lock(); + cpuset_lock(); + if (!is_cpuset_online(cs)) { + retval =3D -ENODEV; + goto out_unlock; + } + + switch (type) { + case FILE_CPU_EXCLUSIVE: + retval =3D update_flag(CS_CPU_EXCLUSIVE, cs, val); + break; + case FILE_MEM_EXCLUSIVE: + retval =3D update_flag(CS_MEM_EXCLUSIVE, cs, val); + break; + case FILE_MEM_HARDWALL: + retval =3D update_flag(CS_MEM_HARDWALL, cs, val); + break; + case FILE_SCHED_LOAD_BALANCE: + retval =3D update_flag(CS_SCHED_LOAD_BALANCE, cs, val); + break; + case FILE_MEMORY_MIGRATE: + retval =3D update_flag(CS_MEMORY_MIGRATE, cs, val); + break; + case FILE_MEMORY_PRESSURE_ENABLED: + cpuset_memory_pressure_enabled =3D !!val; + break; + case FILE_SPREAD_PAGE: + retval =3D update_flag(CS_SPREAD_PAGE, cs, val); + break; + case FILE_SPREAD_SLAB: + retval =3D update_flag(CS_SPREAD_SLAB, cs, val); + break; + default: + retval =3D -EINVAL; + break; + } +out_unlock: + cpuset_unlock(); + cpus_read_unlock(); + return retval; +} + +/* + * for the common functions, 'private' gives the type of file + */ + +struct cftype legacy_files[] =3D { + { + .name =3D "cpus", + .seq_show =3D cpuset_common_seq_show, + .write =3D cpuset_write_resmask, + .max_write_len =3D (100U + 6 * NR_CPUS), + .private =3D FILE_CPULIST, + }, + + { + .name =3D "mems", + .seq_show =3D cpuset_common_seq_show, + .write =3D cpuset_write_resmask, + .max_write_len =3D (100U + 6 * MAX_NUMNODES), + .private =3D FILE_MEMLIST, + }, + + { + .name =3D "effective_cpus", + .seq_show =3D cpuset_common_seq_show, + .private =3D FILE_EFFECTIVE_CPULIST, + }, + + { + .name =3D "effective_mems", + .seq_show =3D cpuset_common_seq_show, + .private =3D FILE_EFFECTIVE_MEMLIST, + }, + + { + .name =3D "cpu_exclusive", + .read_u64 =3D cpuset_read_u64, + .write_u64 =3D cpuset_write_u64, + .private =3D FILE_CPU_EXCLUSIVE, + }, + + { + .name =3D "mem_exclusive", + .read_u64 =3D cpuset_read_u64, + .write_u64 =3D cpuset_write_u64, + .private =3D FILE_MEM_EXCLUSIVE, + }, + + { + .name =3D "mem_hardwall", + .read_u64 =3D cpuset_read_u64, + .write_u64 =3D cpuset_write_u64, + .private =3D FILE_MEM_HARDWALL, + }, + + { + .name =3D "sched_load_balance", + .read_u64 =3D cpuset_read_u64, + .write_u64 =3D cpuset_write_u64, + .private =3D FILE_SCHED_LOAD_BALANCE, + }, + + { + .name =3D "sched_relax_domain_level", + .read_s64 =3D cpuset_read_s64, + .write_s64 =3D cpuset_write_s64, + .private =3D FILE_SCHED_RELAX_DOMAIN_LEVEL, + }, + + { + .name =3D "memory_migrate", + .read_u64 =3D cpuset_read_u64, + .write_u64 =3D cpuset_write_u64, + .private =3D FILE_MEMORY_MIGRATE, + }, + + { + .name =3D "memory_pressure", + .read_u64 =3D cpuset_read_u64, + .private =3D FILE_MEMORY_PRESSURE, + }, + + { + .name =3D "memory_spread_page", + .read_u64 =3D cpuset_read_u64, + .write_u64 =3D cpuset_write_u64, + .private =3D FILE_SPREAD_PAGE, + }, + + { + /* obsolete, may be removed in the future */ + .name =3D "memory_spread_slab", + .read_u64 =3D cpuset_read_u64, + .write_u64 =3D cpuset_write_u64, + .private =3D FILE_SPREAD_SLAB, + }, + + { + .name =3D "memory_pressure_enabled", + .flags =3D CFTYPE_ONLY_ON_ROOT, + .read_u64 =3D cpuset_read_u64, + .write_u64 =3D cpuset_write_u64, + .private =3D FILE_MEMORY_PRESSURE_ENABLED, + }, + + { } /* terminate */ +}; + diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 4412a4168902..2f52fe488f3a 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1107,8 +1107,6 @@ enum partition_cmd { partcmd_invalidate, /* Make partition invalid */ }; =20 -static int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, - int turning_on); static void update_sibling_cpumasks(struct cpuset *parent, struct cpuset *= cs, struct tmpmasks *tmp); =20 @@ -2703,7 +2701,7 @@ bool current_cpuset_is_being_rebound(void) * Call with cpuset_mutex held. */ =20 -static int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, +int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, int turning_on) { struct cpuset *trialcs; @@ -3088,59 +3086,10 @@ static void cpuset_attach(struct cgroup_taskset *ts= et) mutex_unlock(&cpuset_mutex); } =20 -static int cpuset_write_u64(struct cgroup_subsys_state *css, struct cftype= *cft, - u64 val) -{ - struct cpuset *cs =3D css_cs(css); - cpuset_filetype_t type =3D cft->private; - int retval =3D 0; - - cpus_read_lock(); - mutex_lock(&cpuset_mutex); - if (!is_cpuset_online(cs)) { - retval =3D -ENODEV; - goto out_unlock; - } - - switch (type) { - case FILE_CPU_EXCLUSIVE: - retval =3D update_flag(CS_CPU_EXCLUSIVE, cs, val); - break; - case FILE_MEM_EXCLUSIVE: - retval =3D update_flag(CS_MEM_EXCLUSIVE, cs, val); - break; - case FILE_MEM_HARDWALL: - retval =3D update_flag(CS_MEM_HARDWALL, cs, val); - break; - case FILE_SCHED_LOAD_BALANCE: - retval =3D update_flag(CS_SCHED_LOAD_BALANCE, cs, val); - break; - case FILE_MEMORY_MIGRATE: - retval =3D update_flag(CS_MEMORY_MIGRATE, cs, val); - break; - case FILE_MEMORY_PRESSURE_ENABLED: - cpuset_memory_pressure_enabled =3D !!val; - break; - case FILE_SPREAD_PAGE: - retval =3D update_flag(CS_SPREAD_PAGE, cs, val); - break; - case FILE_SPREAD_SLAB: - retval =3D update_flag(CS_SPREAD_SLAB, cs, val); - break; - default: - retval =3D -EINVAL; - break; - } -out_unlock: - mutex_unlock(&cpuset_mutex); - cpus_read_unlock(); - return retval; -} - /* * Common handling for a write to a "cpus" or "mems" file. */ -static ssize_t cpuset_write_resmask(struct kernfs_open_file *of, +ssize_t cpuset_write_resmask(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { struct cpuset *cs =3D css_cs(of_css(of)); @@ -3215,7 +3164,7 @@ static ssize_t cpuset_write_resmask(struct kernfs_ope= n_file *of, * and since these maps can change value dynamically, one could read * gibberish by doing partial reads while a list was changing. */ -static int cpuset_common_seq_show(struct seq_file *sf, void *v) +int cpuset_common_seq_show(struct seq_file *sf, void *v) { struct cpuset *cs =3D css_cs(seq_css(sf)); cpuset_filetype_t type =3D seq_cft(sf)->private; @@ -3256,37 +3205,6 @@ static int cpuset_common_seq_show(struct seq_file *s= f, void *v) return ret; } =20 -static u64 cpuset_read_u64(struct cgroup_subsys_state *css, struct cftype = *cft) -{ - struct cpuset *cs =3D css_cs(css); - cpuset_filetype_t type =3D cft->private; - switch (type) { - case FILE_CPU_EXCLUSIVE: - return is_cpu_exclusive(cs); - case FILE_MEM_EXCLUSIVE: - return is_mem_exclusive(cs); - case FILE_MEM_HARDWALL: - return is_mem_hardwall(cs); - case FILE_SCHED_LOAD_BALANCE: - return is_sched_load_balance(cs); - case FILE_MEMORY_MIGRATE: - return is_memory_migrate(cs); - case FILE_MEMORY_PRESSURE_ENABLED: - return cpuset_memory_pressure_enabled; - case FILE_MEMORY_PRESSURE: - return fmeter_getrate(&cs->fmeter); - case FILE_SPREAD_PAGE: - return is_spread_page(cs); - case FILE_SPREAD_SLAB: - return is_spread_slab(cs); - default: - BUG(); - } - - /* Unreachable but makes gcc happy */ - return 0; -} - static int sched_partition_show(struct seq_file *seq, void *v) { struct cpuset *cs =3D css_cs(seq_css(seq)); @@ -3350,113 +3268,6 @@ static ssize_t sched_partition_write(struct kernfs_= open_file *of, char *buf, return retval ?: nbytes; } =20 -/* - * for the common functions, 'private' gives the type of file - */ - -static struct cftype legacy_files[] =3D { - { - .name =3D "cpus", - .seq_show =3D cpuset_common_seq_show, - .write =3D cpuset_write_resmask, - .max_write_len =3D (100U + 6 * NR_CPUS), - .private =3D FILE_CPULIST, - }, - - { - .name =3D "mems", - .seq_show =3D cpuset_common_seq_show, - .write =3D cpuset_write_resmask, - .max_write_len =3D (100U + 6 * MAX_NUMNODES), - .private =3D FILE_MEMLIST, - }, - - { - .name =3D "effective_cpus", - .seq_show =3D cpuset_common_seq_show, - .private =3D FILE_EFFECTIVE_CPULIST, - }, - - { - .name =3D "effective_mems", - .seq_show =3D cpuset_common_seq_show, - .private =3D FILE_EFFECTIVE_MEMLIST, - }, - - { - .name =3D "cpu_exclusive", - .read_u64 =3D cpuset_read_u64, - .write_u64 =3D cpuset_write_u64, - .private =3D FILE_CPU_EXCLUSIVE, - }, - - { - .name =3D "mem_exclusive", - .read_u64 =3D cpuset_read_u64, - .write_u64 =3D cpuset_write_u64, - .private =3D FILE_MEM_EXCLUSIVE, - }, - - { - .name =3D "mem_hardwall", - .read_u64 =3D cpuset_read_u64, - .write_u64 =3D cpuset_write_u64, - .private =3D FILE_MEM_HARDWALL, - }, - - { - .name =3D "sched_load_balance", - .read_u64 =3D cpuset_read_u64, - .write_u64 =3D cpuset_write_u64, - .private =3D FILE_SCHED_LOAD_BALANCE, - }, - - { - .name =3D "sched_relax_domain_level", - .read_s64 =3D cpuset_read_s64, - .write_s64 =3D cpuset_write_s64, - .private =3D FILE_SCHED_RELAX_DOMAIN_LEVEL, - }, - - { - .name =3D "memory_migrate", - .read_u64 =3D cpuset_read_u64, - .write_u64 =3D cpuset_write_u64, - .private =3D FILE_MEMORY_MIGRATE, - }, - - { - .name =3D "memory_pressure", - .read_u64 =3D cpuset_read_u64, - .private =3D FILE_MEMORY_PRESSURE, - }, - - { - .name =3D "memory_spread_page", - .read_u64 =3D cpuset_read_u64, - .write_u64 =3D cpuset_write_u64, - .private =3D FILE_SPREAD_PAGE, - }, - - { - /* obsolete, may be removed in the future */ - .name =3D "memory_spread_slab", - .read_u64 =3D cpuset_read_u64, - .write_u64 =3D cpuset_write_u64, - .private =3D FILE_SPREAD_SLAB, - }, - - { - .name =3D "memory_pressure_enabled", - .flags =3D CFTYPE_ONLY_ON_ROOT, - .read_u64 =3D cpuset_read_u64, - .write_u64 =3D cpuset_write_u64, - .private =3D FILE_MEMORY_PRESSURE_ENABLED, - }, - - { } /* terminate */ -}; - /* * This is currently a minimal set for the default hierarchy. It can be * expanded later on by migrating more features and control files from v1. --=20 2.34.1