Skip to content

Commit

Permalink
[LibOS] Add /sys/devices/system/cpu/{offline,present} files
Browse files Browse the repository at this point in the history
Also improve the `sysfs` LibOS regression test to verify that these new
CPU-related files exist, plus that the old CPU- and NUMA-node-related
files exist.

Signed-off-by: Dmitrii Kuvaiskii <[email protected]>
  • Loading branch information
Dmitrii Kuvaiskii committed Aug 3, 2023
1 parent 3b5c88b commit 92636ae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libos/src/fs/sys/cpu_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ static bool is_online(size_t ind, const void* arg) {
return g_pal_public_state->topo_info.threads[ind].is_online;
}

static bool is_offline(size_t ind, const void* arg) {
return !is_online(ind, arg);
}

static bool return_true(size_t ind, const void* arg) {
__UNUSED(ind);
__UNUSED(arg);
Expand All @@ -31,7 +35,11 @@ int sys_cpu_general_load(struct libos_dentry* dent, char** out_data, size_t* out

if (strcmp(name, "online") == 0) {
ret = sys_print_as_ranges(str, sizeof(str), topo->threads_cnt, is_online, NULL);
} else if (strcmp(name, "possible") == 0) {
} else if (strcmp(name, "offline") == 0) {
ret = sys_print_as_ranges(str, sizeof(str), topo->threads_cnt, is_offline, NULL);
} else if (strcmp(name, "possible") == 0 || strcmp(name, "present") == 0) {
/* we simplify and always output "present" CPUs same as "possible" CPUs; this will need to
* be changed if we add support for hot-plugging CPUs / shutting down / powering up CPUs */
ret = sys_print_as_ranges(str, sizeof(str), topo->threads_cnt, return_true, NULL);
} else {
log_debug("unrecognized file: %s", name);
Expand Down
2 changes: 2 additions & 0 deletions libos/src/fs/sys/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ int sys_load(const char* str, char** out_data, size_t* out_size) {

static void init_cpu_dir(struct pseudo_node* cpu) {
pseudo_add_str(cpu, "online", &sys_cpu_general_load);
pseudo_add_str(cpu, "offline", &sys_cpu_general_load);
pseudo_add_str(cpu, "possible", &sys_cpu_general_load);
pseudo_add_str(cpu, "present", &sys_cpu_general_load);

struct pseudo_node* cpuX = pseudo_add_dir(cpu, NULL);
cpuX->name_exists = &sys_resource_name_exists;
Expand Down
6 changes: 6 additions & 0 deletions libos/test/regression/test_libos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,10 @@ def test_040_sysfs(self):
lines = stdout.splitlines()

self.assertIn('/sys/devices/system/cpu: directory', lines)
self.assertIn('/sys/devices/system/cpu/online: file', lines)
self.assertIn('/sys/devices/system/cpu/offline: file', lines)
self.assertIn('/sys/devices/system/cpu/possible: file', lines)
self.assertIn('/sys/devices/system/cpu/present: file', lines)
for i in range(cpus_cnt):
cpu = f'/sys/devices/system/cpu/cpu{i}'
self.assertIn(f'{cpu}: directory', lines)
Expand All @@ -1167,6 +1171,8 @@ def test_040_sysfs(self):
self.assertIn(f'{cache}/physical_line_partition: file', lines)

self.assertIn('/sys/devices/system/node: directory', lines)
self.assertIn('/sys/devices/system/node/online: file', lines)
self.assertIn('/sys/devices/system/node/possible: file', lines)
nodes_cnt = len([line for line in lines
if re.match(r'/sys/devices/system/node/node[0-9]+:', line)])
self.assertGreater(nodes_cnt, 0)
Expand Down

0 comments on commit 92636ae

Please sign in to comment.