[lxc-devel] [lxcfs/master] fixes
brauner on Github
lxc-bot at linuxcontainers.org
Fri Mar 6 12:50:29 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 365 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200306/7b8e608e/attachment.bin>
-------------- next part --------------
From fd65c77c6e824b4d24b88b706ff4583d6fda8271 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 6 Mar 2020 10:34:40 +0100
Subject: [PATCH 1/4] proc_cpuview: cleanup
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/proc_cpuview.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/proc_cpuview.c b/src/proc_cpuview.c
index 39fce6a..47b5a4d 100644
--- a/src/proc_cpuview.c
+++ b/src/proc_cpuview.c
@@ -550,8 +550,8 @@ int cpuview_proc_stat(const char *cg, const char *cpuset,
if (physcpu >= cg_cpu_usage_size)
continue;
- curcpu ++;
- cpu_cnt ++;
+ curcpu++;
+ cpu_cnt++;
if (!cpu_in_cpuset(physcpu, cpuset)) {
for (i = curcpu; i <= physcpu; i++)
From 39f231dabbc5836c10f65aefe0cd549a2d3136e2 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 6 Mar 2020 11:10:04 +0100
Subject: [PATCH 2/4] proc_cpuview: cleanup
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/proc_cpuview.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/proc_cpuview.c b/src/proc_cpuview.c
index 47b5a4d..99885aa 100644
--- a/src/proc_cpuview.c
+++ b/src/proc_cpuview.c
@@ -518,16 +518,17 @@ int cpuview_proc_stat(const char *cg, const char *cpuset,
size_t linelen = 0, total_len = 0;
int curcpu = -1; /* cpu numbering starts at 0 */
int physcpu, i;
- int max_cpus = max_cpu_count(cg), cpu_cnt = 0;
+ int cpu_cnt = 0;
uint64_t user = 0, nice = 0, system = 0, idle = 0, iowait = 0, irq = 0,
softirq = 0, steal = 0, guest = 0, guest_nice = 0;
uint64_t user_sum = 0, system_sum = 0, idle_sum = 0;
uint64_t user_surplus = 0, system_surplus = 0;
+ int nprocs, max_cpus;
ssize_t l;
uint64_t total_sum, threshold;
struct cg_proc_stat *stat_node;
- int nprocs = get_nprocs_conf();
+ nprocs = get_nprocs_conf();
if (cg_cpu_usage_size < nprocs)
nprocs = cg_cpu_usage_size;
@@ -596,10 +597,6 @@ int cpuview_proc_stat(const char *cg, const char *cpuset,
}
}
- /* Cannot use more CPUs than is available due to cpuset */
- if (max_cpus > cpu_cnt)
- max_cpus = cpu_cnt;
-
stat_node = find_or_create_proc_stat_node(cg_cpu_usage, nprocs, cg);
if (!stat_node)
return log_error(0, "Failed to find/create stat node for %s", cg);
@@ -624,6 +621,11 @@ int cpuview_proc_stat(const char *cg, const char *cpuset,
total_sum = diff_cpu_usage(stat_node->usage, cg_cpu_usage, diff, nprocs);
+ /* Cannot use more CPUs than is available in cpuset. */
+ max_cpus = max_cpu_count(cg);
+ if (max_cpus > cpu_cnt)
+ max_cpus = cpu_cnt;
+
for (curcpu = 0, i = -1; curcpu < nprocs; curcpu++) {
stat_node->usage[curcpu].online = cg_cpu_usage[curcpu].online;
From f9434b9a1ea0fd4ca32ea5a5cdbece45ad314092 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 6 Mar 2020 13:44:55 +0100
Subject: [PATCH 3/4] proc_cpuview: fix /proc/stat cpu virtualization
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/proc_cpuview.c | 16 ++++++++--------
src/proc_fuse.c | 18 ++++++++++--------
2 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/src/proc_cpuview.c b/src/proc_cpuview.c
index 99885aa..1d37b5d 100644
--- a/src/proc_cpuview.c
+++ b/src/proc_cpuview.c
@@ -597,6 +597,11 @@ int cpuview_proc_stat(const char *cg, const char *cpuset,
}
}
+ /* Cannot use more CPUs than is available in cpuset. */
+ max_cpus = max_cpu_count(cg);
+ if (max_cpus > cpu_cnt || !max_cpus)
+ max_cpus = cpu_cnt;
+
stat_node = find_or_create_proc_stat_node(cg_cpu_usage, nprocs, cg);
if (!stat_node)
return log_error(0, "Failed to find/create stat node for %s", cg);
@@ -621,11 +626,6 @@ int cpuview_proc_stat(const char *cg, const char *cpuset,
total_sum = diff_cpu_usage(stat_node->usage, cg_cpu_usage, diff, nprocs);
- /* Cannot use more CPUs than is available in cpuset. */
- max_cpus = max_cpu_count(cg);
- if (max_cpus > cpu_cnt)
- max_cpus = cpu_cnt;
-
for (curcpu = 0, i = -1; curcpu < nprocs; curcpu++) {
stat_node->usage[curcpu].online = cg_cpu_usage[curcpu].online;
@@ -851,7 +851,7 @@ int proc_cpuinfo_read(char *buf, size_t size, off_t offset,
char *cache = d->buf;
size_t cache_size = d->buflen;
- if (offset){
+ if (offset) {
int left;
if (offset > d->size)
@@ -1016,7 +1016,7 @@ int read_cpuacct_usage_all(char *cg, char *cpuset,
{
__do_free char *usage_str = NULL;
__do_free struct cpuacct_usage *cpu_usage = NULL;
- int cpucount = get_nprocs_conf();
+ int cpucount;
int i = 0, j = 0, read_pos = 0, read_cnt = 0;
int ret;
int cg_cpu;
@@ -1024,7 +1024,6 @@ int read_cpuacct_usage_all(char *cg, char *cpuset,
int64_t ticks_per_sec;
ticks_per_sec = sysconf(_SC_CLK_TCK);
-
if (ticks_per_sec < 0 && errno == EINVAL) {
lxcfs_v(
"%s\n",
@@ -1033,6 +1032,7 @@ int read_cpuacct_usage_all(char *cg, char *cpuset,
return -1;
}
+ cpucount = get_nprocs_conf();
cpu_usage = malloc(sizeof(struct cpuacct_usage) * cpucount);
if (!cpu_usage)
return -ENOMEM;
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index ce930d9..475e948 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -793,8 +793,16 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
* If the cpuacct cgroup is present, it is used to calculate the container's
* CPU usage. If not, values from the host's /proc/stat are used.
*/
- if (read_cpuacct_usage_all(cg, cpuset, &cg_cpu_usage, &cg_cpu_usage_size) != 0)
- lxcfs_v("%s\n", "proc_stat_read failed to read from cpuacct, falling back to the host's /proc/stat");
+ if (read_cpuacct_usage_all(cg, cpuset, &cg_cpu_usage, &cg_cpu_usage_size) == 0) {
+ if (cgroup_ops->can_use_cpuview(cgroup_ops) && opts && opts->use_cfs) {
+ total_len = cpuview_proc_stat(cg, cpuset, cg_cpu_usage,
+ cg_cpu_usage_size, f,
+ d->buf, d->buflen);
+ goto out;
+ }
+ } else {
+ lxcfs_v("proc_stat_read failed to read from cpuacct, falling back to the host's /proc/stat");
+ }
f = fopen_cached("/proc/stat", "re", &fopen_cache);
if (!f)
@@ -804,12 +812,6 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
if (getline(&line, &linelen, f) < 0)
return log_error(0, "proc_stat_read read first line failed");
- if (cgroup_ops->can_use_cpuview(cgroup_ops) && opts && opts->use_cfs) {
- total_len = cpuview_proc_stat(cg, cpuset, cg_cpu_usage,
- cg_cpu_usage_size, f, d->buf, d->buflen);
- goto out;
- }
-
while (getline(&line, &linelen, f) != -1) {
ssize_t l;
char cpu_char[10]; /* That's a lot of cores */
From 3b24c6c4d593eda39ab667c257569fb8b0256dda Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 6 Mar 2020 13:49:08 +0100
Subject: [PATCH 4/4] lxcfs: s/disable-cfs/--enable-cfs/g
Switch the logic.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxcfs.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/lxcfs.c b/src/lxcfs.c
index 1094270..b614f48 100644
--- a/src/lxcfs.c
+++ b/src/lxcfs.c
@@ -1081,7 +1081,7 @@ int main(int argc, char *argv[])
}
opts->swap_off = false;
opts->use_pidfd = false;
- opts->use_cfs = true;
+ opts->use_cfs = false;
/* accomodate older init scripts */
swallow_arg(&argc, argv, "-s");
@@ -1112,9 +1112,9 @@ int main(int argc, char *argv[])
/* --enable-pidfd */
opts->use_pidfd = swallow_arg(&argc, argv, "--enable-pidfd");
- /* --disable-cfs */
- if (swallow_arg(&argc, argv, "--disable-cfs"))
- opts->use_cfs = false;
+ /* --enable-cfs */
+ if (swallow_arg(&argc, argv, "--enable-cfs"))
+ opts->use_cfs = true;
if (swallow_option(&argc, argv, "-o", &v)) {
/* Parse multiple values */
More information about the lxc-devel
mailing list