diff options
author | Lukasz Stanislawski <l.stanislaws@samsung.com> | 2018-06-15 09:24:33 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.ap-northeast-2.compute.internal> | 2018-06-15 09:24:33 +0000 |
commit | 169ab5cdc183e79830d5998d964516f4f0e92857 (patch) | |
tree | a771c9fcaee76bdf0c3ebec2f8729e0d0066f6a6 | |
parent | e7112bd7d40b979a9af64dea22a4a8a5979783c9 (diff) | |
parent | 72aef455de0ac5447765c4443a38960a5eb6567e (diff) | |
download | ttsd-worker-task-169ab5cdc183e79830d5998d964516f4f0e92857.tar.gz ttsd-worker-task-169ab5cdc183e79830d5998d964516f4f0e92857.tar.bz2 ttsd-worker-task-169ab5cdc183e79830d5998d964516f4f0e92857.zip |
Merge "procfs: implement reading cpus count"
-rw-r--r-- | src/procfs.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/procfs.c b/src/procfs.c index 95478a2..763c0d8 100644 --- a/src/procfs.c +++ b/src/procfs.c @@ -22,6 +22,7 @@ #define LOADAVG_FILEPATH "/proc/loadavg" #define UPTIME_FILEPATH "/proc/uptime" +#define POSSIBLE_CPUS_FILEPATH "/sys/devices/system/cpu/possible" int procfs_read_system_load_average(struct procfs_load_average_info *info) { @@ -101,5 +102,25 @@ int procfs_read_uptime(unsigned long *uptime) int procfs_read_cpu_count(int *cpu_count) { - return -1; + ON_NULL_RETURN_VAL(cpu_count, -1); + + int cpus, dummy; + + FILE *possible_fp = fopen(POSSIBLE_CPUS_FILEPATH, "r"); + if (!possible_fp) { + ERR("failed to open " POSSIBLE_CPUS_FILEPATH); + return -1; + } + + if (fscanf(possible_fp, "%d-%d", &dummy, &cpus) != 2) { + ERR("failed to read " POSSIBLE_CPUS_FILEPATH); + fclose(possible_fp); + return -1; + } + + *cpu_count = cpus + 1; + + fclose(possible_fp); + + return 0; } |