diff options
author | Khem Raj <raj.khem@gmail.com> | 2019-06-16 22:14:17 -0700 |
---|---|---|
committer | Khem Raj <raj.khem@gmail.com> | 2019-06-16 22:25:54 -0700 |
commit | 5673dae7b2b9f87197c6d24b4687b03959b0d7e7 (patch) | |
tree | 7ff448240f969d744a15f3aeb73cd880f597df91 | |
parent | 36fcb1a8d1fcabcfd8bbd6772c6f2837799b8ec3 (diff) | |
download | meta-openembedded-5673dae7b2b9f87197c6d24b4687b03959b0d7e7.tar.gz |
stressapptest: Implement reading sysfs and use it if sysconf is not there
This helps in building on musl platform where _SC_LEVEL1_DCACHE_LINESIZE
is not available
Signed-off-by: Khem Raj <raj.khem@gmail.com>
-rw-r--r-- | meta-oe/recipes-benchmark/stressapptest/stressapptest/read_sysfs_for_cachesize.patch | 72 | ||||
-rw-r--r-- | meta-oe/recipes-benchmark/stressapptest/stressapptest_1.0.9.bb | 1 |
2 files changed, 73 insertions, 0 deletions
diff --git a/meta-oe/recipes-benchmark/stressapptest/stressapptest/read_sysfs_for_cachesize.patch b/meta-oe/recipes-benchmark/stressapptest/stressapptest/read_sysfs_for_cachesize.patch new file mode 100644 index 000000000..8c251aeb9 --- /dev/null +++ b/meta-oe/recipes-benchmark/stressapptest/stressapptest/read_sysfs_for_cachesize.patch | |||
@@ -0,0 +1,72 @@ | |||
1 | sysconf params like _SC_LEVEL1_DCACHE_LINESIZE are not universally | ||
2 | implemented, therefore check for them being available, if not there | ||
3 | then read the sysfs directly to get the value | ||
4 | |||
5 | Upstream-Status: Pending | ||
6 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
7 | --- a/src/sat.cc | ||
8 | +++ b/src/sat.cc | ||
9 | @@ -1482,15 +1482,47 @@ int Sat::CpuCount() { | ||
10 | return sysconf(_SC_NPROCESSORS_CONF); | ||
11 | } | ||
12 | |||
13 | +int Sat::ReadInt(const char *filename, int *value) { | ||
14 | + char line[64]; | ||
15 | + int fd = open(filename, O_RDONLY), err = -1; | ||
16 | + | ||
17 | + if (fd < 0) | ||
18 | + return -1; | ||
19 | + if (read(fd, line, sizeof(line)) > 0) { | ||
20 | + *value = atoi(line); | ||
21 | + err = 0; | ||
22 | + } | ||
23 | + | ||
24 | + close(fd); | ||
25 | + return err; | ||
26 | +} | ||
27 | + | ||
28 | // Return the worst case (largest) cache line size of the various levels of | ||
29 | // cache actually prsent in the machine. | ||
30 | int Sat::CacheLineSize() { | ||
31 | - int max_linesize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); | ||
32 | - int linesize = sysconf(_SC_LEVEL2_CACHE_LINESIZE); | ||
33 | + int max_linesize, linesize; | ||
34 | +#ifdef _SC_LEVEL1_DCACHE_LINESIZE | ||
35 | + max_linesize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); | ||
36 | +#else | ||
37 | + ReadInt("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size", &max_linesize); | ||
38 | +#endif | ||
39 | +#ifdef _SC_LEVEL2_DCACHE_LINESIZE | ||
40 | + linesize = sysconf(_SC_LEVEL2_DCACHE_LINESIZE); | ||
41 | +#else | ||
42 | + ReadInt("/sys/devices/system/cpu/cpu0/cache/index1/coherency_line_size", &linesize); | ||
43 | +#endif | ||
44 | if (linesize > max_linesize) max_linesize = linesize; | ||
45 | - linesize = sysconf(_SC_LEVEL3_CACHE_LINESIZE); | ||
46 | +#ifdef _SC_LEVEL3_DCACHE_LINESIZE | ||
47 | + linesize = sysconf(_SC_LEVEL3_DCACHE_LINESIZE); | ||
48 | +#else | ||
49 | + ReadInt("/sys/devices/system/cpu/cpu0/cache/index2/coherency_line_size", &linesize); | ||
50 | +#endif | ||
51 | if (linesize > max_linesize) max_linesize = linesize; | ||
52 | - linesize = sysconf(_SC_LEVEL4_CACHE_LINESIZE); | ||
53 | +#ifdef _SC_LEVEL4_DCACHE_LINESIZE | ||
54 | + linesize = sysconf(_SC_LEVEL4_DCACHE_LINESIZE); | ||
55 | +#else | ||
56 | + ReadInt("/sys/devices/system/cpu/cpu0/cache/index3/coherency_line_size", &linesize); | ||
57 | +#endif | ||
58 | if (linesize > max_linesize) max_linesize = linesize; | ||
59 | return max_linesize; | ||
60 | } | ||
61 | --- a/src/sat.h | ||
62 | +++ b/src/sat.h | ||
63 | @@ -136,7 +136,8 @@ class Sat { | ||
64 | int CpuCount(); | ||
65 | // Return the worst-case (largest) cache line size of the system. | ||
66 | int CacheLineSize(); | ||
67 | - | ||
68 | + // Read int values from kernel file system e.g. sysfs | ||
69 | + int ReadInt(const char *filename, int *value); | ||
70 | // Collect error counts from threads. | ||
71 | int64 GetTotalErrorCount(); | ||
72 | |||
diff --git a/meta-oe/recipes-benchmark/stressapptest/stressapptest_1.0.9.bb b/meta-oe/recipes-benchmark/stressapptest/stressapptest_1.0.9.bb index 679201c52..aa1bf1cd3 100644 --- a/meta-oe/recipes-benchmark/stressapptest/stressapptest_1.0.9.bb +++ b/meta-oe/recipes-benchmark/stressapptest/stressapptest_1.0.9.bb | |||
@@ -11,6 +11,7 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=55ea9d559f985fb4834317d8ed6b9e58" | |||
11 | 11 | ||
12 | SRC_URI = "https://github.com/${PN}/${PN}/archive/v${PV}.tar.gz \ | 12 | SRC_URI = "https://github.com/${PN}/${PN}/archive/v${PV}.tar.gz \ |
13 | file://libcplusplus-compat.patch \ | 13 | file://libcplusplus-compat.patch \ |
14 | file://read_sysfs_for_cachesize.patch \ | ||
14 | " | 15 | " |
15 | 16 | ||
16 | SRC_URI[md5sum] = "d3a526c174c049dd7a1068dc74a62be2" | 17 | SRC_URI[md5sum] = "d3a526c174c049dd7a1068dc74a62be2" |