Skip to content

Commit 341c43c

Browse files
authored
Merge pull request #665 from loyou/psi_support
proc_fuse: add psi(pressure stall information) procfs
2 parents d7a0f91 + 31da3ae commit 341c43c

File tree

8 files changed

+435
-21
lines changed

8 files changed

+435
-21
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ such as:
1616
/proc/swaps
1717
/proc/uptime
1818
/proc/slabinfo
19+
/proc/pressure/io
20+
/proc/pressure/cpu
21+
/proc/pressure/memory
1922
/sys/devices/system/cpu/online
2023
```
2124

@@ -109,6 +112,9 @@ docker run -it -m 256m --memory-swap 256m \
109112
-v /var/lib/lxcfs/proc/swaps:/proc/swaps:rw \
110113
-v /var/lib/lxcfs/proc/uptime:/proc/uptime:rw \
111114
-v /var/lib/lxcfs/proc/slabinfo:/proc/slabinfo:rw \
115+
-v /var/lib/lxcfs/proc/pressure/io:/proc/pressure/io:rw \
116+
-v /var/lib/lxcfs/proc/pressure/cpu:/proc/pressure/cpu:rw \
117+
-v /var/lib/lxcfs/proc/pressure/memory:/proc/pressure/memory:rw \
112118
-v /var/lib/lxcfs/sys/devices/system/cpu:/sys/devices/system/cpu:rw \
113119
ubuntu:18.04 /bin/bash
114120
```

src/api_extensions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ static char *api_extensions[] = {
2323
"proc_swaps",
2424
"proc_uptime",
2525
"proc_slabinfo",
26+
"proc_pressure_io",
27+
"proc_pressure_cpu",
28+
"proc_pressure_memory",
2629
"shared_pidns",
2730
"cpuview_daemon",
2831
"loadavg_daemon",

src/bindings.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,24 @@ enum lxcfs_virt_t {
6666

6767
LXC_TYPE_SYS_DEVICES_SYSTEM_CPU_ONLINE,
6868
#define LXC_TYPE_SYS_DEVICES_SYSTEM_CPU_ONLINE_PATH "/sys/devices/system/cpu/online"
69+
70+
LXC_TYPE_PROC,
71+
LXC_TYPE_PROC_PRESSURE,
72+
LXC_TYPE_PROC_PRESSURE_IO,
73+
#define LXC_TYPE_PROC_PRESSURE_IO_PATH "/proc/pressure/io"
74+
75+
LXC_TYPE_PROC_PRESSURE_CPU,
76+
#define LXC_TYPE_PROC_PRESSURE_CPU_PATH "/proc/pressure/cpu"
77+
78+
LXC_TYPE_PROC_PRESSURE_MEMORY,
79+
#define LXC_TYPE_PROC_PRESSURE_MEMORY_PATH "/proc/pressure/memory"
6980
LXC_TYPE_MAX,
7081
};
7182

7283
/* Macros below used to check the class from the file types above */
7384
#define LXCFS_TYPE_CGROUP(type) (type >= LXC_TYPE_CGDIR && type <= LXC_TYPE_CGFILE)
74-
#define LXCFS_TYPE_PROC(type) (type >= LXC_TYPE_PROC_MEMINFO && type <= LXC_TYPE_PROC_SLABINFO)
85+
#define LXCFS_TYPE_PROC(type) ((type >= LXC_TYPE_PROC_MEMINFO && type <= LXC_TYPE_PROC_SLABINFO) || \
86+
(type >= LXC_TYPE_PROC && type <= LXC_TYPE_PROC_PRESSURE_MEMORY))
7587
#define LXCFS_TYPE_SYS(type) (type >= LXC_TYPE_SYS && type <= LXC_TYPE_SYS_DEVICES_SYSTEM_CPU_ONLINE)
7688
#define LXCFS_TYPE_OK(type) (type >= LXC_TYPE_CGDIR && type < LXC_TYPE_MAX)
7789

src/cgroups/cgfsng.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,54 @@ static bool cgfsng_can_use_cpuview(struct cgroup_ops *ops)
854854
return true;
855855
}
856856

857+
static int cgfsng_get_pressure_io_fd(struct cgroup_ops *ops, const char *cgroup)
858+
{
859+
__do_free char *path = NULL;
860+
struct hierarchy *h;
861+
862+
h = ops->get_hierarchy(ops, "blkio");
863+
if (!h)
864+
return -1;
865+
866+
if (faccessat(h->fd, "io.pressure", F_OK, 0))
867+
return -1;
868+
869+
path = must_make_path_relative(cgroup, "io.pressure", NULL);
870+
return openat(h->fd, path, O_RDWR | O_CLOEXEC | O_NOFOLLOW);
871+
}
872+
873+
static int cgfsng_get_pressure_cpu_fd(struct cgroup_ops *ops, const char *cgroup)
874+
{
875+
__do_free char *path = NULL;
876+
struct hierarchy *h;
877+
878+
h = ops->get_hierarchy(ops, "cpu");
879+
if (!h)
880+
return -1;
881+
882+
if (faccessat(h->fd, "cpu.pressure", F_OK, 0))
883+
return -1;
884+
885+
path = must_make_path_relative(cgroup, "cpu.pressure", NULL);
886+
return openat(h->fd, path, O_RDWR | O_CLOEXEC | O_NOFOLLOW);
887+
}
888+
889+
static int cgfsng_get_pressure_memory_fd(struct cgroup_ops *ops, const char *cgroup)
890+
{
891+
__do_free char *path = NULL;
892+
struct hierarchy *h;
893+
894+
h = ops->get_hierarchy(ops, "memory");
895+
if (!h)
896+
return -1;
897+
898+
if (faccessat(h->fd, "memory.pressure", F_OK, 0))
899+
return -1;
900+
901+
path = must_make_path_relative(cgroup, "memory.pressure", NULL);
902+
return openat(h->fd, path, O_RDWR | O_CLOEXEC | O_NOFOLLOW);
903+
}
904+
857905
/* At startup, parse_hierarchies finds all the info we need about cgroup
858906
* mountpoints and current cgroups, and stores it in @d.
859907
*/
@@ -1074,6 +1122,10 @@ struct cgroup_ops *cgfsng_ops_init(void)
10741122
cgfsng_ops->get_io_merged = cgfsng_get_io_merged;
10751123
cgfsng_ops->get_io_wait_time = cgfsng_get_io_wait_time;
10761124

1125+
/* psi */
1126+
cgfsng_ops->get_pressure_io_fd = cgfsng_get_pressure_io_fd;
1127+
cgfsng_ops->get_pressure_cpu_fd = cgfsng_get_pressure_cpu_fd;
1128+
cgfsng_ops->get_pressure_memory_fd = cgfsng_get_pressure_memory_fd;
10771129

10781130
return move_ptr(cgfsng_ops);
10791131
}

src/cgroups/cgroup.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ struct cgroup_ops {
155155
char **value);
156156
bool (*can_use_cpuview)(struct cgroup_ops *ops);
157157

158-
/* io */
158+
/* blkio */
159159
int (*get_io_service_bytes)(struct cgroup_ops *ops, const char *cgroup,
160160
char **value);
161161
int (*get_io_service_time)(struct cgroup_ops *ops, const char *cgroup,
@@ -166,6 +166,11 @@ struct cgroup_ops {
166166
char **value);
167167
int (*get_io_wait_time)(struct cgroup_ops *ops, const char *cgroup,
168168
char **value);
169+
/* psi */
170+
int (*get_pressure_io_fd)(struct cgroup_ops *ops, const char *cgroup);
171+
int (*get_pressure_cpu_fd)(struct cgroup_ops *ops, const char *cgroup);
172+
int (*get_pressure_memory_fd)(struct cgroup_ops *ops,
173+
const char *cgroup);
169174
};
170175

171176
extern struct cgroup_ops *cgroup_ops;

src/lxcfs.c

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,20 @@ static int do_proc_open(const char *path, struct fuse_file_info *fi)
524524
return __proc_open(path, fi);
525525
}
526526

527+
static int do_proc_opendir(const char *path, struct fuse_file_info *fi)
528+
{
529+
char *error;
530+
int (*__proc_opendir)(const char *path, struct fuse_file_info *fi);
531+
532+
dlerror();
533+
__proc_opendir = (int (*)(const char *path, struct fuse_file_info *fi))dlsym(dlopen_handle, "proc_opendir");
534+
error = dlerror();
535+
if (error)
536+
return log_error(-1, "%s - Failed to find proc_opendir()", error);
537+
538+
return __proc_opendir(path, fi);
539+
}
540+
527541
static int do_proc_access(const char *path, int mode)
528542
{
529543
char *error;
@@ -608,6 +622,20 @@ static int do_proc_release(const char *path, struct fuse_file_info *fi)
608622
return __proc_release(path, fi);
609623
}
610624

625+
static int do_proc_releasedir(const char *path, struct fuse_file_info *fi)
626+
{
627+
char *error;
628+
int (*__proc_releasedir)(const char *path, struct fuse_file_info *fi);
629+
630+
dlerror();
631+
__proc_releasedir = (int (*)(const char *path, struct fuse_file_info *)) dlsym(dlopen_handle, "proc_releasedir");
632+
error = dlerror();
633+
if (error)
634+
return log_error(-1, "%s - Failed to find proc_releasedir()", error);
635+
636+
return __proc_releasedir(path, fi);
637+
}
638+
611639
static int do_sys_release(const char *path, struct fuse_file_info *fi)
612640
{
613641
char *error;
@@ -724,8 +752,12 @@ static int lxcfs_opendir(const char *path, struct fuse_file_info *fi)
724752
return ret;
725753
}
726754

727-
if (strcmp(path, "/proc") == 0)
728-
return 0;
755+
if (strncmp(path, "/proc", 5) == 0) {
756+
up_users();
757+
ret = do_proc_opendir(path, fi);
758+
down_users();
759+
return ret;
760+
}
729761

730762
if (strncmp(path, "/sys", 4) == 0) {
731763
up_users();
@@ -768,7 +800,7 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
768800
return ret;
769801
}
770802

771-
if (strcmp(path, "/proc") == 0) {
803+
if (LXCFS_TYPE_PROC(type)) {
772804
up_users();
773805
ret = do_proc_readdir(path, buf, filler, offset, fi);
774806
down_users();
@@ -837,12 +869,14 @@ static int lxcfs_releasedir(const char *path, struct fuse_file_info *fi)
837869
return ret;
838870
}
839871

840-
if (path) {
841-
if (strcmp(path, "/") == 0)
842-
return 0;
843-
if (strcmp(path, "/proc") == 0)
844-
return 0;
872+
if (LXCFS_TYPE_PROC(type)) {
873+
up_users();
874+
ret = do_proc_releasedir(path, fi);
875+
down_users();
876+
return ret;
845877
}
878+
if (path && strcmp(path, "/") == 0)
879+
return 0;
846880

847881
lxcfs_error("unknown file type: path=%s, type=%d, fi->fh=%" PRIu64,
848882
path, type, fi->fh);

0 commit comments

Comments
 (0)